From ec48ad5f9070332a58ec1627dd73535a84136af5 Mon Sep 17 00:00:00 2001 From: Sunny Verma Date: Fri, 19 Feb 2016 19:01:11 -0500 Subject: [PATCH] Added united test and added kilo/juno condition --- config.yaml | 10 ++++++++-- hooks/neutron_api_context.py | 10 +++++----- hooks/neutron_api_hooks.py | 21 +++++++++++++++------ unit_tests/test_neutron_api_hooks.py | 16 +++++++++++++++- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/config.yaml b/config.yaml index 2afe5f5c..27d95b41 100755 --- a/config.yaml +++ b/config.yaml @@ -284,10 +284,16 @@ options: nuage-packages: type: string default: "nuage-openstack-neutron nuagenetlib" - description: Its [nuage-openstack-neutron nuagenetlib] for Nuage VSP >=3.2R4 and [nuage-neutron python-nuagenetlib] of Nuage VSP <=3.2R3 + description: | + Its [nuage-openstack-neutron nuagenetlib] for Nuage VSP >=3.2R4 & KILO + and [nuage-neutron python-nuagenetlib] of Nuage VSP <=3.0 & JUNO vsd-cms-name: type: string - description: Please give Maas env id so that it is unique per openstack env. + description: | + This is required only for 3.2 R4 and above releases of Nuage and Kilo. + Please give Maas env id so that it is unique per openstack cluster. + This name is used to create th CMS ID on Nuage-VSD which should be unique per OSP cluster. + Your Deployment will fail if this config is not provided. vsd-server: type: string default: diff --git a/hooks/neutron_api_context.py b/hooks/neutron_api_context.py index 8db4f703..6682f5e5 100644 --- a/hooks/neutron_api_context.py +++ b/hooks/neutron_api_context.py @@ -185,16 +185,16 @@ class NeutronCCContext(context.NeutronContext): for unit in related_units(rid): rdata = relation_get(rid=rid, unit=unit) vsd_ip = rdata.get('vsd-ip-address') - cms_id_value = rdata.get('nuage-cms-id') + if os_release('neutron-server') >= 'kilo': + cms_id_value = rdata.get('nuage-cms-id') + log('relation data:cms_id: {}'.format(cms_id_value)) + if cms_id_value is not None: + ctxt['cms_id'] = '{}'.format(cms_id_value) log('relation data:vsd-ip-address: {}'.format(vsd_ip)) - log('relation data:cms_id: {}'.format(cms_id_value)) if vsd_ip is not None: ctxt['vsd_server'] = '{}:8443'.format(vsd_ip) - if cms_id_value is not None: - ctxt['cms_id'] = '{}'.format(cms_id_value) if 'vsd_server' not in ctxt: ctxt['vsd_server'] = '1.1.1.1:8443' - ctxt['verbose'] = config('verbose') ctxt['debug'] = config('debug') ctxt['neutron_bind_port'] = \ diff --git a/hooks/neutron_api_hooks.py b/hooks/neutron_api_hooks.py index 5af34160..fa49a72d 100755 --- a/hooks/neutron_api_hooks.py +++ b/hooks/neutron_api_hooks.py @@ -204,11 +204,18 @@ def install(): @hooks.hook('vsd-rest-api-relation-joined') @restart_on_change(restart_map(), stopstart=True) +@os_requires_version('kilo') def relation_set_nuage_cms_name(rid=None): - relation_data = { - 'vsd-cms-name': '{}'.format(config('vsd-cms-name')) - } - relation_set(relation_id=rid, **relation_data) + if config('vsd-cms-name') is None: + e ="Neutron Api hook failed as vsd-cms-name" \ + " is not specified" + status_set('blocked', e) + else: + relation_data = { + 'vsd-cms-name': '{}'. + format(config('vsd-cms-name')) + } + relation_set(relation_id=rid, **relation_data) @hooks.hook('vsd-rest-api-relation-changed') @@ -219,12 +226,14 @@ def vsd_changed(relation_id=None, remote_unit=None): if not vsd_ip_address: return vsd_address = '{}:8443'.format(vsd_ip_address) - cms_id = relation_get('nuage-cms-id') + if os_release('neutron') >= 'kilo': + cms_id = relation_get('nuage-cms-id') + log("nuage-vsd-api-relation-changed : cms_id:{}".format(cms_id)) nuage_config_file = neutron_plugin_attribute(config('neutron-plugin'), 'config', 'neutron') log('vsd-rest-api-relation-changed: ip address:{}'.format(vsd_address)) log('vsd-rest-api-relation-changed:{}'.format(nuage_config_file)) - log("nuage-vsd-api-relation-changed : cms_id:{}".format(cms_id)) + CONFIGS.write(nuage_config_file) diff --git a/unit_tests/test_neutron_api_hooks.py b/unit_tests/test_neutron_api_hooks.py index a60a0651..612f3e65 100644 --- a/unit_tests/test_neutron_api_hooks.py +++ b/unit_tests/test_neutron_api_hooks.py @@ -483,16 +483,30 @@ class NeutronAPIHooksTests(CharmTestCase): ) def test_vsd_api_relation_changed(self): + self.os_release.return_value = 'kilo' self.test_config.set('neutron-plugin', 'vsp') self.test_relation.set({ 'vsd-ip-address': '10.11.12.13', + 'nuage-cms-id': 'abc' }) self._call_hook('vsd-rest-api-relation-changed') - config_file = '/etc/neutron/plugins/nuage/nuage_plugin.ini' self.assertTrue(self.CONFIGS.write.called_with(config_file)) def test_vsd_api_relation_joined(self): + self.os_release.return_value = 'juno' + with self.assertRaises(Exception) as context: + self._call_hook('vsd-rest-api-relation-joined') + self.assertEqual( + context.exception.message, + "This hook is not supported on releases before kilo" + ) + self.os_release.return_value = 'kilo' + self._call_hook('vsd-rest-api-relation-joined') + e ="Neutron Api hook failed as vsd-cms-name" \ + " is not specified" + self.status_set.assert_called_with( + 'blocked', e) self.test_config.set('vsd-cms-name', '1234567890') _relation_data = { 'vsd-cms-name': '1234567890',