Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

Commit

Permalink
Added united test and added kilo/juno condition
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny-verma committed Feb 20, 2016
1 parent da212da commit ec48ad5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
10 changes: 8 additions & 2 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions hooks/neutron_api_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,16 @@ def __call__(self):
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'] = \
Expand Down
21 changes: 15 additions & 6 deletions hooks/neutron_api_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)


Expand Down
16 changes: 15 additions & 1 deletion unit_tests/test_neutron_api_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,16 +483,30 @@ def test_neutron_api_relation_joined(self, _canonical_url):
)

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',
Expand Down

0 comments on commit ec48ad5

Please sign in to comment.