diff --git a/.bzrignore b/.bzrignore new file mode 100644 index 00000000..6350e986 --- /dev/null +++ b/.bzrignore @@ -0,0 +1 @@ +.coverage diff --git a/.coverage b/.coverage deleted file mode 100644 index 5e1b0a19..00000000 Binary files a/.coverage and /dev/null differ diff --git a/hooks/neutron_api_context.py b/hooks/neutron_api_context.py index 6fedd78a..7a5ef885 100644 --- a/hooks/neutron_api_context.py +++ b/hooks/neutron_api_context.py @@ -42,10 +42,14 @@ class NeutronCCContext(context.NeutronContext): ctxt['verbose'] = config('verbose') ctxt['debug'] = config('debug') for rid in relation_ids('neutron-api'): + print "rid" for unit in related_units(rid): + print "unit" ctxt['nova_url'] = relation_get(attribute='nova_url', rid=rid, unit=unit) if ctxt['nova_url']: + print "Ive set nova_url" return ctxt + print "Ive not set nova_url" return ctxt diff --git a/unit_tests/test_neutron_api_context.py b/unit_tests/test_neutron_api_context.py index 65f1cc16..72cea8c0 100644 --- a/unit_tests/test_neutron_api_context.py +++ b/unit_tests/test_neutron_api_context.py @@ -1,7 +1,7 @@ from test_utils import CharmTestCase from mock import patch import neutron_api_context as context - +import charmhelpers TO_PATCH = [ 'relation_get', 'relation_ids', @@ -10,6 +10,42 @@ TO_PATCH = [ ] +class IdentityServiceContext(CharmTestCase): + def setUp(self): + super(IdentityServiceContext, self).setUp(context, TO_PATCH) + self.relation_get.side_effect = self.test_relation.get + self.config.side_effect = self.test_config.get + self.test_config.set('region', 'region457') + + @patch.object(charmhelpers.contrib.openstack.context, 'context_complete') + @patch.object(charmhelpers.contrib.openstack.context, 'relation_get') + @patch.object(charmhelpers.contrib.openstack.context, 'related_units') + @patch.object(charmhelpers.contrib.openstack.context, 'relation_ids') + @patch.object(charmhelpers.contrib.openstack.context, 'log') + def test_ids_ctxt(self, _log, _rids, _runits, _rget, _ctxt_comp): + _rids.return_value = 'rid1' + _runits.return_value = 'runit' + _ctxt_comp.return_value = True + id_data = { + 'service_port': 9876, + 'service_host': '127.0.0.4', + 'auth_host': '127.0.0.5', + 'auth_port': 5432, + 'service_tenant': 'ten', + 'service_username': 'admin', + 'service_password': 'adminpass', + } + _rget.return_value = id_data + ids_ctxt = context.IdentityServiceContext() + self.assertEquals(ids_ctxt()['region'], 'region457') + + @patch.object(charmhelpers.contrib.openstack.context, 'relation_ids') + @patch.object(charmhelpers.contrib.openstack.context, 'log') + def test_ids_ctxt_no_rels(self, _log, _rids): + _rids.return_value = [] + ids_ctxt = context.IdentityServiceContext() + self.assertEquals(ids_ctxt(), None) + class NeutronAPIContextsTest(CharmTestCase): def setUp(self): @@ -27,7 +63,7 @@ class NeutronAPIContextsTest(CharmTestCase): @patch.object(context.NeutronCCContext, 'network_manager') @patch.object(context.NeutronCCContext, 'plugin') - def test_quantum_plugin_context_no_setting(self, plugin, nm): + def test_neutroncc_context_no_setting(self, plugin, nm): plugin.return_value = None napi_ctxt = context.NeutronCCContext() ctxt_data = { @@ -38,13 +74,24 @@ class NeutronAPIContextsTest(CharmTestCase): with patch.object(napi_ctxt, '_ensure_packages'): self.assertEquals(ctxt_data, napi_ctxt()) - def test_quantum_plugin_context_manager(self): + @patch.object(context.NeutronCCContext, 'network_manager') + @patch.object(context.NeutronCCContext, 'plugin') + def test_neutroncc_context_api_rel(self, plugin, nm): + nova_url = 'http://127.0.0.10' + plugin.return_value = None + self.related_units.return_value = ['unit1'] + self.relation_ids.return_value = ['rid2'] + self.test_relation.set({'nova_url': nova_url}) + napi_ctxt = context.NeutronCCContext() + self.assertEquals(nova_url, napi_ctxt()['nova_url']) + + def test_neutroncc_context_manager(self): napi_ctxt = context.NeutronCCContext() self.assertEquals(napi_ctxt.network_manager, 'neutron') self.assertEquals(napi_ctxt.plugin, 'ovs') self.assertEquals(napi_ctxt.neutron_security_groups, True) - def test_quantum_plugin_context_manager_pkgs(self): + def test_neutroncc_context_manager_pkgs(self): napi_ctxt = context.NeutronCCContext() with patch.object(napi_ctxt, '_ensure_packages') as ep: napi_ctxt._ensure_packages() diff --git a/unit_tests/test_utils.py b/unit_tests/test_utils.py index c9c7bace..86ee0f73 100644 --- a/unit_tests/test_utils.py +++ b/unit_tests/test_utils.py @@ -95,11 +95,11 @@ class TestRelation(object): def set(self, relation_data): self.relation_data = relation_data - def get(self, attr=None, unit=None, rid=None): - if attr is None: + def get(self, attribute=None, unit=None, rid=None): + if attribute is None: return self.relation_data - elif attr in self.relation_data: - return self.relation_data[attr] + elif attribute in self.relation_data: + return self.relation_data[attribute] return None