fix handling of vendor-data and vendor-data-url config options

Also fix the doc to mention Rocky as the turning point, because that's
what the code does

Change-Id: Ie5fe7e0b023920489182fd060c52b1043bb209a9
This commit is contained in:
Junien Fridrick 2019-01-09 09:46:49 +01:00
parent 684a93515d
commit 48a862175f
3 changed files with 13 additions and 12 deletions

View File

@ -257,7 +257,7 @@ options:
description: | description: |
A JSON-formatted string that will serve as vendor metadata A JSON-formatted string that will serve as vendor metadata
(via "StaticJSON" provider) to all VM's within an OpenStack deployment, (via "StaticJSON" provider) to all VM's within an OpenStack deployment,
regardless of project or domain. For deployments of Queens or later regardless of project or domain. For deployments of Rocky or later
this value is ignored. Please set the corresponding value in the this value is ignored. Please set the corresponding value in the
nova-cloud-controller charm. nova-cloud-controller charm.
vendor-data-url: vendor-data-url:
@ -268,7 +268,7 @@ options:
(via "DynamicJSON" provider) to all VM's within an OpenStack deployment, (via "DynamicJSON" provider) to all VM's within an OpenStack deployment,
regardless of project or domain. regardless of project or domain.
. .
Only supported in OpenStack Newton and higher. For deployments of Queens or Only supported in OpenStack Newton and higher. For deployments of Rocky or
later this value is ignored. Please set the corresponding value in the later this value is ignored. Please set the corresponding value in the
nova-cloud-controller charm. nova-cloud-controller charm.
default-availability-zone: default-availability-zone:

View File

@ -172,21 +172,22 @@ class NovaMetadataContext(OSContextGenerator):
ctxt = {} ctxt = {}
cmp_os_release = CompareOpenStackReleases(os_release('neutron-common')) cmp_os_release = CompareOpenStackReleases(os_release('neutron-common'))
if cmp_os_release < 'rocky': if cmp_os_release < 'rocky':
ctxt['vendordata_providers'] = [] vdata_providers = []
vdata = config('vendor-data') vdata = config('vendor-data')
vdata_url = config('vendor-data-url') vdata_url = config('vendor-data-url')
if vdata: if vdata:
ctxt['vendor_data'] = True ctxt['vendor_data'] = True
ctxt['vendordata_providers'].append('StaticJSON') vdata_providers.append('StaticJSON')
if vdata_url: if vdata_url:
if cmp_os_release > 'mitaka': if cmp_os_release > 'mitaka':
ctxt['vendor_data_url'] = vdata_url ctxt['vendor_data_url'] = vdata_url
ctxt['vendordata_providers'].append('DynamicJSON') vdata_providers.append('DynamicJSON')
else: else:
log('Dynamic vendor data unsupported' log('Dynamic vendor data unsupported'
' for {}.'.format(cmp_os_release), level=ERROR) ' for {}.'.format(cmp_os_release), level=ERROR)
ctxt['vendordata_providers'] = ','.join(vdata_providers)
for rid in relation_ids(self.rel_name): for rid in relation_ids(self.rel_name):
for unit in related_units(rid): for unit in related_units(rid):
rdata = relation_get(rid=rid, unit=unit) rdata = relation_get(rid=rid, unit=unit)

View File

@ -459,7 +459,7 @@ class TestNovaMetadataContext(CharmTestCase):
ctxt = neutron_contexts.NovaMetadataContext()() ctxt = neutron_contexts.NovaMetadataContext()()
self.assertTrue(ctxt['vendor_data']) self.assertTrue(ctxt['vendor_data'])
self.assertEqual(ctxt['vendordata_providers'], ['StaticJSON']) self.assertEqual(ctxt['vendordata_providers'], 'StaticJSON')
@patch.object(neutron_contexts, 'get_local_ip') @patch.object(neutron_contexts, 'get_local_ip')
@patch.object(neutron_contexts, 'get_shared_secret') @patch.object(neutron_contexts, 'get_shared_secret')
@ -476,7 +476,7 @@ class TestNovaMetadataContext(CharmTestCase):
ctxt = neutron_contexts.NovaMetadataContext()() ctxt = neutron_contexts.NovaMetadataContext()()
self.assertEqual(ctxt['vendor_data_url'], _vdata_url) self.assertEqual(ctxt['vendor_data_url'], _vdata_url)
self.assertEqual(ctxt['vendordata_providers'], ['DynamicJSON']) self.assertEqual(ctxt['vendordata_providers'], 'DynamicJSON')
@patch.object(neutron_contexts, 'get_local_ip') @patch.object(neutron_contexts, 'get_local_ip')
@patch.object(neutron_contexts, 'get_shared_secret') @patch.object(neutron_contexts, 'get_shared_secret')
@ -496,8 +496,8 @@ class TestNovaMetadataContext(CharmTestCase):
self.assertTrue(ctxt['vendor_data']) self.assertTrue(ctxt['vendor_data'])
self.assertEqual(ctxt['vendor_data_url'], _vdata_url) self.assertEqual(ctxt['vendor_data_url'], _vdata_url)
self.assertEqual(ctxt['vendordata_providers'], ['StaticJSON', self.assertEqual(ctxt['vendordata_providers'],
'DynamicJSON']) 'StaticJSON,DynamicJSON')
@patch.object(neutron_contexts, 'get_local_ip') @patch.object(neutron_contexts, 'get_local_ip')
@patch.object(neutron_contexts, 'get_shared_secret') @patch.object(neutron_contexts, 'get_shared_secret')
@ -519,7 +519,7 @@ class TestNovaMetadataContext(CharmTestCase):
'nova_metadata_port': '8775', 'nova_metadata_port': '8775',
'nova_metadata_protocol': 'http', 'nova_metadata_protocol': 'http',
'shared_secret': 'asecret', 'shared_secret': 'asecret',
'vendordata_providers': []}) 'vendordata_providers': ''})
@patch.object(neutron_contexts, 'relation_get') @patch.object(neutron_contexts, 'relation_get')
@patch.object(neutron_contexts, 'related_units') @patch.object(neutron_contexts, 'related_units')
@ -542,7 +542,7 @@ class TestNovaMetadataContext(CharmTestCase):
'nova_metadata_port': '8775', 'nova_metadata_port': '8775',
'nova_metadata_protocol': 'http', 'nova_metadata_protocol': 'http',
'shared_secret': 'auuid', 'shared_secret': 'auuid',
'vendordata_providers': []}) 'vendordata_providers': ''})
@patch.object(neutron_contexts, 'get_local_ip') @patch.object(neutron_contexts, 'get_local_ip')
@patch.object(neutron_contexts, 'get_shared_secret') @patch.object(neutron_contexts, 'get_shared_secret')
@ -561,4 +561,4 @@ class TestNovaMetadataContext(CharmTestCase):
'nova_metadata_port': '8775', 'nova_metadata_port': '8775',
'nova_metadata_protocol': 'http', 'nova_metadata_protocol': 'http',
'shared_secret': 'buuid', 'shared_secret': 'buuid',
'vendordata_providers': []}) 'vendordata_providers': ''})