當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。