當前位置: 首頁>>代碼示例>>Python>>正文


Python hookenv.relation_id方法代碼示例

本文整理匯總了Python中charmhelpers.core.hookenv.relation_id方法的典型用法代碼示例。如果您正苦於以下問題:Python hookenv.relation_id方法的具體用法?Python hookenv.relation_id怎麽用?Python hookenv.relation_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在charmhelpers.core.hookenv的用法示例。


在下文中一共展示了hookenv.relation_id方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_relation_clear

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_id [as 別名]
def test_relation_clear(self, local_unit,
                            relation_get,
                            relation_set):
        local_unit.return_value = 'local-unit'
        relation_get.return_value = {
            'private-address': '10.5.0.1',
            'foo': 'bar',
            'public-address': '146.192.45.6'
        }
        hookenv.relation_clear('relation:1')
        relation_get.assert_called_with(rid='relation:1',
                                        unit='local-unit')
        relation_set.assert_called_with(
            relation_id='relation:1',
            **{'private-address': '10.5.0.1',
               'foo': None,
               'public-address': '146.192.45.6'}) 
開發者ID:juju,項目名稱:charm-helpers,代碼行數:19,代碼來源:test_hookenv.py

示例2: test_gets_execution_environment_no_relation

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_id [as 別名]
def test_gets_execution_environment_no_relation(
            self, os_, relations_get, relations, relation_id,
            local_unit, relation_type, config):
        config.return_value = 'some-config'
        relation_type.return_value = 'some-type'
        local_unit.return_value = 'some-unit'
        relation_id.return_value = None
        relations.return_value = 'all-relations'
        relations_get.return_value = 'some-relations'
        os_.environ = 'some-environment'

        result = hookenv.execution_environment()

        self.assertEqual(result, {
            'conf': 'some-config',
            'unit': 'some-unit',
            'rels': 'all-relations',
            'env': 'some-environment',
        }) 
開發者ID:juju,項目名稱:charm-helpers,代碼行數:21,代碼來源:test_hookenv.py

示例3: test_gets_the_relation_id

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_id [as 別名]
def test_gets_the_relation_id(self, os_, relation_ids, remote_service_name):
        os_.environ = {
            'JUJU_RELATION_ID': 'foo',
        }

        self.assertEqual(hookenv.relation_id(), 'foo')

        relation_ids.return_value = ['r:1', 'r:2']
        remote_service_name.side_effect = ['other', 'service']
        self.assertEqual(hookenv.relation_id('rel', 'service/0'), 'r:2')
        relation_ids.assert_called_once_with('rel')
        self.assertEqual(remote_service_name.call_args_list, [
            call('r:1'),
            call('r:2'),
        ])
        remote_service_name.side_effect = ['other', 'service']
        self.assertEqual(hookenv.relation_id('rel', 'service'), 'r:2') 
開發者ID:juju,項目名稱:charm-helpers,代碼行數:19,代碼來源:test_hookenv.py

示例4: peer_store_and_set

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_id [as 別名]
def peer_store_and_set(relation_id=None, peer_relation_name='cluster',
                       peer_store_fatal=False, relation_settings=None,
                       delimiter='_', **kwargs):
    """Store passed-in arguments both in argument relation and in peer storage.

    It functions like doing relation_set() and peer_store() at the same time,
    with the same data.

    @param relation_id: the id of the relation to store the data on. Defaults
                        to the current relation.
    @param peer_store_fatal: Set to True, the function will raise an exception
                             should the peer sotrage not be avialable."""

    relation_settings = relation_settings if relation_settings else {}
    relation_set(relation_id=relation_id,
                 relation_settings=relation_settings,
                 **kwargs)
    if is_relation_made(peer_relation_name):
        for key, value in six.iteritems(dict(list(kwargs.items()) +
                                             list(relation_settings.items()))):
            key_prefix = relation_id or current_relation_id()
            peer_store(key_prefix + delimiter + key,
                       value,
                       relation_name=peer_relation_name)
    else:
        if peer_store_fatal:
            raise ValueError('Unable to detect '
                             'peer relation {}'.format(peer_relation_name)) 
開發者ID:openstack,項目名稱:charm-swift-proxy,代碼行數:30,代碼來源:__init__.py

示例5: test_gets_related_units

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_id [as 別名]
def test_gets_related_units(self, relation_id, check_output):
        relid = 123
        units = ['foo', 'bar']
        relation_id.return_value = relid
        check_output.return_value = json.dumps(units).encode('UTF-8')

        result = hookenv.related_units()

        self.assertEqual(result, units)
        check_output.assert_called_with(['relation-list', '--format=json',
                                         '-r', relid]) 
開發者ID:juju,項目名稱:charm-helpers,代碼行數:13,代碼來源:test_hookenv.py

示例6: test_gets_related_units_empty_array

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_id [as 別名]
def test_gets_related_units_empty_array(self, relation_id, check_output):
        relid = str(123)
        units = []
        relation_id.return_value = relid
        check_output.return_value = json.dumps(None).encode('UTF-8')

        result = hookenv.related_units()

        self.assertEqual(result, units)
        check_output.assert_called_with(['relation-list', '--format=json',
                                         '-r', relid]) 
開發者ID:juju,項目名稱:charm-helpers,代碼行數:13,代碼來源:test_hookenv.py

示例7: test_related_units_no_relation

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_id [as 別名]
def test_related_units_no_relation(self, relation_id, check_output):
        units = ['foo', 'bar']
        relation_id.return_value = None
        check_output.return_value = json.dumps(units).encode('UTF-8')

        result = hookenv.related_units()

        self.assertEqual(result, units)
        check_output.assert_called_with(['relation-list', '--format=json']) 
開發者ID:juju,項目名稱:charm-helpers,代碼行數:11,代碼來源:test_hookenv.py

示例8: test_gets_related_units_for_id

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_id [as 別名]
def test_gets_related_units_for_id(self, relation_id, check_output):
        relid = 123
        units = ['foo', 'bar']
        check_output.return_value = json.dumps(units).encode('UTF-8')

        result = hookenv.related_units(relid)

        self.assertEqual(result, units)
        check_output.assert_called_with(['relation-list', '--format=json',
                                         '-r', relid])
        self.assertFalse(relation_id.called) 
開發者ID:juju,項目名稱:charm-helpers,代碼行數:13,代碼來源:test_hookenv.py

示例9: test_relation_id_none_if_no_env

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_id [as 別名]
def test_relation_id_none_if_no_env(self, os_):
        os_.environ = {}
        self.assertEqual(hookenv.relation_id(), None) 
開發者ID:juju,項目名稱:charm-helpers,代碼行數:5,代碼來源:test_hookenv.py

示例10: test_sets_relation_with_relation_id

# 需要導入模塊: from charmhelpers.core import hookenv [as 別名]
# 或者: from charmhelpers.core.hookenv import relation_id [as 別名]
def test_sets_relation_with_relation_id(self, check_call_, check_output,
                                            local_unit):
        hookenv.relation_set(relation_id="foo", bar="baz")
        check_call_.assert_called_with(['relation-set', '-r', 'foo',
                                        'bar=baz']) 
開發者ID:juju,項目名稱:charm-helpers,代碼行數:7,代碼來源:test_hookenv.py


注:本文中的charmhelpers.core.hookenv.relation_id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。