当前位置: 首页>>代码示例>>Python>>正文


Python hookenv.local_unit方法代码示例

本文整理汇总了Python中charmhelpers.core.hookenv.local_unit方法的典型用法代码示例。如果您正苦于以下问题:Python hookenv.local_unit方法的具体用法?Python hookenv.local_unit怎么用?Python hookenv.local_unit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在charmhelpers.core.hookenv的用法示例。


在下文中一共展示了hookenv.local_unit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_relation_clear

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import local_unit [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

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import local_unit [as 别名]
def test_gets_execution_environment(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 = 'some-id'
        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',
            'reltype': 'some-type',
            'unit': 'some-unit',
            'relid': 'some-id',
            'rel': 'some-relations',
            'rels': 'all-relations',
            'env': 'some-environment',
        }) 
开发者ID:juju,项目名称:charm-helpers,代码行数:24,代码来源:test_hookenv.py

示例3: test_gets_execution_environment_no_relation

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import local_unit [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

示例4: setUp

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import local_unit [as 别名]
def setUp(self):
        del hookenv._atstart[:]
        del hookenv._atexit[:]
        hookenv.cache.clear()
        coordinator.Singleton._instances.clear()

        def install(patch):
            patch.start()
            self.addCleanup(patch.stop)

        install(patch.object(hookenv, 'local_unit', return_value='foo/1'))
        install(patch.object(hookenv, 'is_leader', return_value=False))
        install(patch.object(hookenv, 'metadata',
                             return_value={'peers': {'cluster': None}}))
        install(patch.object(hookenv, 'log'))

        # Ensure _timestamp always increases.
        install(patch.object(coordinator, '_utcnow',
                             side_effect=self._utcnow)) 
开发者ID:juju,项目名称:charm-helpers,代码行数:21,代码来源:test_coordinator.py

示例5: test_acquire_leader

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import local_unit [as 别名]
def test_acquire_leader(self):
        # When acquire() is called by the leader, it needs
        # to make a grant decision immediately. It can't defer
        # making the decision until a future hook, as no future
        # hooks will be triggered.
        hookenv.is_leader.return_value = True
        c = coordinator.Serial()  # Not Base. Test hooks into default_grant.
        lock = 'mylock'
        unit = hookenv.local_unit()
        c.grants = {}
        c.requests = {unit: {}}
        with patch.object(c, 'default_grant') as default_grant:
            default_grant.side_effect = iter([False, True])

            self.assertFalse(c.acquire(lock))
            ts = c.request_timestamp(lock)

            self.assertTrue(c.acquire(lock))
            self.assertEqual(ts, c.request_timestamp(lock))

            # If it it granted, the leader doesn't make a decision again.
            self.assertTrue(c.acquire(lock))
            self.assertEqual(ts, c.request_timestamp(lock))

            self.assertEqual(default_grant.call_count, 2) 
开发者ID:juju,项目名称:charm-helpers,代码行数:27,代码来源:test_coordinator.py

示例6: setUp

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import local_unit [as 别名]
def setUp(self):
        def install(*args, **kw):
            p = patch.object(*args, **kw)
            p.start()
            self.addCleanup(p.stop)

        install(hookenv, 'relation_types', return_value=['rel', 'pear'])
        install(hookenv, 'peer_relation_id', return_value='pear:9')
        install(hookenv, 'relation_ids',
                side_effect=lambda x: ['{}:{}'.format(x, i)
                                       for i in range(9, 11)])
        install(hookenv, 'related_units',
                side_effect=lambda x: ['svc_' + x.replace(':', '/')])
        install(hookenv, 'local_unit', return_value='foo/1')
        install(hookenv, 'relation_get')
        install(hookenv, 'relation_set')
        # install(hookenv, 'is_leader', return_value=False) 
开发者ID:juju,项目名称:charm-helpers,代码行数:19,代码来源:test_context.py

示例7: local_unit_name

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import local_unit [as 别名]
def local_unit_name(self):
        """
        @return local unit name
        """
        return hookenv.local_unit().replace('/', '-') 
开发者ID:openstack,项目名称:charms.openstack,代码行数:7,代码来源:adapters.py

示例8: create_sync_src_info_file

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import local_unit [as 别名]
def create_sync_src_info_file(self):
        """Touch a file which indicates where this sync file came from

        :returns: None
        """
        unit_name = hookenv.local_unit().replace('/', '_')
        touch_file = '{}/juju-zone-src-{}'.format(ZONE_DIR, unit_name)
        open(touch_file, 'w+').close() 
开发者ID:openstack,项目名称:charm-designate-bind,代码行数:10,代码来源:designate_bind.py

示例9: prepare_tls_certificates

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import local_unit [as 别名]
def prepare_tls_certificates(tls):
    status_set('maintenance', 'Requesting tls certificates.')
    common_name = hookenv.unit_public_ip()
    sans = []
    sans.append(hookenv.unit_public_ip())
    sans.append(hookenv.unit_private_ip())
    sans.append(socket.gethostname())
    certificate_name = hookenv.local_unit().replace('/', '_')
    tls.request_server_cert(common_name, sans, certificate_name) 
开发者ID:juju-solutions,项目名称:layer-etcd,代码行数:11,代码来源:etcd.py

示例10: test_gets_the_local_unit

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import local_unit [as 别名]
def test_gets_the_local_unit(self, os_):
        os_.environ = {
            'JUJU_UNIT_NAME': 'foo',
        }

        self.assertEqual(hookenv.local_unit(), 'foo') 
开发者ID:juju,项目名称:charm-helpers,代码行数:8,代码来源:test_hookenv.py

示例11: test_gets_relations

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import local_unit [as 别名]
def test_gets_relations(self, relation_get, related_units,
                            relation_ids, relation_types, local_unit):
        local_unit.return_value = 'u0'
        relation_types.return_value = ['t1', 't2']
        relation_ids.return_value = ['i1']
        related_units.return_value = ['u1', 'u2']
        relation_get.return_value = {'key': 'val'}

        result = hookenv.relations()

        self.assertEqual(result, {
            't1': {
                'i1': {
                    'u0': {'key': 'val'},
                    'u1': {'key': 'val'},
                    'u2': {'key': 'val'},
                },
            },
            't2': {
                'i1': {
                    'u0': {'key': 'val'},
                    'u1': {'key': 'val'},
                    'u2': {'key': 'val'},
                },
            },
        }) 
开发者ID:juju,项目名称:charm-helpers,代码行数:28,代码来源:test_hookenv.py

示例12: test_sets_relation_with_kwargs

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import local_unit [as 别名]
def test_sets_relation_with_kwargs(self, check_call_, check_output,
                                       local_unit):
        hookenv.relation_set(foo="bar")
        check_call_.assert_called_with(['relation-set', 'foo=bar']) 
开发者ID:juju,项目名称:charm-helpers,代码行数:6,代码来源:test_hookenv.py

示例13: test_sets_relation_with_dict

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import local_unit [as 别名]
def test_sets_relation_with_dict(self, check_call_, check_output,
                                     local_unit):
        hookenv.relation_set(relation_settings={"foo": "bar"})
        check_call_.assert_called_with(['relation-set', 'foo=bar']) 
开发者ID:juju,项目名称:charm-helpers,代码行数:6,代码来源:test_hookenv.py

示例14: test_sets_relation_with_relation_id

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import local_unit [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

示例15: test_sets_relation_with_missing_value

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import local_unit [as 别名]
def test_sets_relation_with_missing_value(self, check_call_, check_output,
                                              local_unit):
        hookenv.relation_set(foo=None)
        check_call_.assert_called_with(['relation-set', 'foo=']) 
开发者ID:juju,项目名称:charm-helpers,代码行数:6,代码来源:test_hookenv.py


注:本文中的charmhelpers.core.hookenv.local_unit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。