From 3b26fda2c56711476efc0bbecd8555f07c6131d1 Mon Sep 17 00:00:00 2001 From: Felipe Reyes Date: Thu, 20 Nov 2014 11:37:06 -0300 Subject: [PATCH] Revert "Changed the way charmhelpers.core.hookenv.config is imported" --- hooks/nova_cc_context.py | 32 ++++++++++++++--------------- unit_tests/test_nova_cc_contexts.py | 2 ++ unit_tests/test_nova_cc_utils.py | 13 ++++-------- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/hooks/nova_cc_context.py b/hooks/nova_cc_context.py index b190dbd5..94557ffd 100644 --- a/hooks/nova_cc_context.py +++ b/hooks/nova_cc_context.py @@ -1,7 +1,7 @@ from charmhelpers.core.hookenv import ( - relation_ids, relation_set, log, ERROR, + config, relation_ids, relation_set, log, ERROR, unit_get, related_units, relation_get, relations_for_id) -from charmhelpers.core import hookenv + from charmhelpers.fetch import apt_install, filter_installed_packages from charmhelpers.contrib.openstack import context, neutron, utils @@ -181,14 +181,14 @@ def canonical_url(vip_setting='vip'): if https(): scheme = 'https' - if hookenv.config('prefer-ipv6'): + if config('prefer-ipv6'): if is_clustered(): - addr = '[%s]' % hookenv.config(vip_setting) + addr = '[%s]' % config(vip_setting) else: - addr = '[%s]' % get_ipv6_addr(exc_list=[hookenv.config('vip')])[0] + addr = '[%s]' % get_ipv6_addr(exc_list=[config('vip')])[0] else: if is_clustered(): - addr = hookenv.config(vip_setting) + addr = config(vip_setting) else: addr = unit_get('private-address') @@ -209,8 +209,8 @@ class NeutronCCContext(context.NeutronContext): @property def neutron_security_groups(self): - sec_groups = (hookenv.config('neutron-security-groups') or - hookenv.config('quantum-security-groups')) + sec_groups = (config('neutron-security-groups') or + config('quantum-security-groups')) return sec_groups.lower() == 'yes' def _ensure_packages(self): @@ -220,9 +220,9 @@ class NeutronCCContext(context.NeutronContext): def __call__(self): ctxt = super(NeutronCCContext, self).__call__() - ctxt['external_network'] = hookenv.config('neutron-external-network') - if hookenv.config('quantum-plugin') in ['nvp', 'nsx']: - _config = hookenv.config() + ctxt['external_network'] = config('neutron-external-network') + if config('quantum-plugin') in ['nvp', 'nsx']: + _config = config() for k, v in _config.iteritems(): if k.startswith('nvp'): ctxt[k.replace('-', '_')] = v @@ -251,7 +251,7 @@ class IdentityServiceContext(context.IdentityServiceContext): ctxt['service_port'] ) ctxt['keystone_ec2_url'] = ec2_tokens - ctxt['region'] = hookenv.config('region') + ctxt['region'] = config('region') return ctxt @@ -265,21 +265,21 @@ class NeutronPostgresqlDBContext(context.PostgresqlDBContext): def __init__(self): super(NeutronPostgresqlDBContext, - self).__init__(hookenv.config('neutron-database')) + self).__init__(config('neutron-database')) class NovaConfigContext(context.WorkerConfigContext): def __call__(self): ctxt = super(NovaConfigContext, self).__call__() - ctxt['cpu_allocation_ratio'] = hookenv.config('cpu-allocation-ratio') - ctxt['ram_allocation_ratio'] = hookenv.config('ram-allocation-ratio') + ctxt['cpu_allocation_ratio'] = config('cpu-allocation-ratio') + ctxt['ram_allocation_ratio'] = config('ram-allocation-ratio') return ctxt class NovaIPv6Context(context.BindHostContext): def __call__(self): ctxt = super(NovaIPv6Context, self).__call__() - ctxt['use_ipv6'] = hookenv.config('prefer-ipv6') + ctxt['use_ipv6'] = config('prefer-ipv6') return ctxt diff --git a/unit_tests/test_nova_cc_contexts.py b/unit_tests/test_nova_cc_contexts.py index 1f4660ff..1945d949 100644 --- a/unit_tests/test_nova_cc_contexts.py +++ b/unit_tests/test_nova_cc_contexts.py @@ -14,6 +14,7 @@ TO_PATCH = [ 'relation_ids', 'relation_get', 'related_units', + 'config', 'log', 'unit_get', 'relations_for_id', @@ -29,6 +30,7 @@ class NovaComputeContextTests(CharmTestCase): def setUp(self): super(NovaComputeContextTests, self).setUp(context, TO_PATCH) self.relation_get.side_effect = self.test_relation.get + self.config.side_effect = self.test_config.get self.log.side_effect = fake_log @mock.patch.object(utils, 'os_release') diff --git a/unit_tests/test_nova_cc_utils.py b/unit_tests/test_nova_cc_utils.py index 6c9864c5..7351a2ec 100644 --- a/unit_tests/test_nova_cc_utils.py +++ b/unit_tests/test_nova_cc_utils.py @@ -155,9 +155,8 @@ class NovaCCUtilsTests(CharmTestCase): _map = utils.resource_map() return _map - @patch('charmhelpers.core.hookenv.config') @patch('charmhelpers.contrib.openstack.context.SubordinateConfigContext') - def test_resource_map_quantum(self, subcontext, config_): + def test_resource_map_quantum(self, subcontext): self.is_relation_made.return_value = False self._resource_map(network_manager='quantum') _map = utils.resource_map() @@ -168,9 +167,8 @@ class NovaCCUtilsTests(CharmTestCase): ] [self.assertIn(q_conf, _map.keys()) for q_conf in confs] - @patch('charmhelpers.core.hookenv.config') @patch('charmhelpers.contrib.openstack.context.SubordinateConfigContext') - def test_resource_map_neutron(self, subcontext, config_): + def test_resource_map_neutron(self, subcontext): self.is_relation_made.return_value = False self._resource_map(network_manager='neutron') _map = utils.resource_map() @@ -261,11 +259,9 @@ class NovaCCUtilsTests(CharmTestCase): for service in console_services: self.assertIn(service, _map['/etc/nova/nova.conf']['services']) - @patch('charmhelpers.core.hookenv.config') @patch('os.path.exists') @patch('charmhelpers.contrib.openstack.context.SubordinateConfigContext') - def test_restart_map_api_before_frontends(self, subcontext, _exists, - config_): + def test_restart_map_api_before_frontends(self, subcontext, _exists): self.is_relation_made.return_value = False _exists.return_value = False self._resource_map(network_manager='neutron') @@ -307,9 +303,8 @@ class NovaCCUtilsTests(CharmTestCase): pkgs = utils.determine_packages() self.assertIn('quantum-server', pkgs) - @patch('charmhelpers.core.hookenv.config') @patch('charmhelpers.contrib.openstack.context.SubordinateConfigContext') - def test_determine_packages_neutron(self, subcontext, config_): + def test_determine_packages_neutron(self, subcontext): self.is_relation_made.return_value = False self._resource_map(network_manager='neutron') pkgs = utils.determine_packages()