Merge lp:~gnuoy/charms/trusty/nova-compute/dvr-support into lp:~openstack-charmers-archive/charms/trusty/nova-compute/next

Proposed by Liam Young
Status: Merged
Merged at revision: 111
Proposed branch: lp:~gnuoy/charms/trusty/nova-compute/dvr-support
Merge into: lp:~openstack-charmers-archive/charms/trusty/nova-compute/next
Diff against target: 257 lines (+107/-4)
7 files modified
hooks/nova_compute_context.py (+13/-0)
hooks/nova_compute_hooks.py (+13/-0)
hooks/nova_compute_utils.py (+11/-0)
templates/juno/nova.conf (+5/-0)
unit_tests/test_nova_compute_contexts.py (+8/-0)
unit_tests/test_nova_compute_hooks.py (+9/-0)
unit_tests/test_nova_compute_utils.py (+48/-4)
To merge this branch: bzr merge lp:~gnuoy/charms/trusty/nova-compute/dvr-support
Reviewer Review Type Date Requested Status
OpenStack Charmers Pending
Review via email: mp+254423@code.launchpad.net
To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #2919 nova-compute-next for gnuoy mp254423
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/2919/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #2710 nova-compute-next for gnuoy mp254423
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/2710/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hooks/nova_compute_context.py'
--- hooks/nova_compute_context.py 2015-03-12 10:07:02 +0000
+++ hooks/nova_compute_context.py 2015-03-27 16:21:32 +0000
@@ -390,6 +390,19 @@
390 return ctxt390 return ctxt
391391
392392
393class MetadataServiceContext(context.OSContextGenerator):
394
395 def __call__(self):
396 ctxt = {}
397 for rid in relation_ids('neutron-plugin'):
398 for unit in related_units(rid):
399 rdata = relation_get(rid=rid, unit=unit)
400 if 'metadata-shared-secret' in rdata:
401 ctxt['metadata_shared_secret'] = \
402 rdata['metadata-shared-secret']
403 return ctxt
404
405
393class NeutronComputeContext(context.NeutronContext):406class NeutronComputeContext(context.NeutronContext):
394 interfaces = []407 interfaces = []
395408
396409
=== modified file 'hooks/nova_compute_hooks.py'
--- hooks/nova_compute_hooks.py 2015-02-24 11:33:01 +0000
+++ hooks/nova_compute_hooks.py 2015-03-27 16:21:32 +0000
@@ -21,6 +21,7 @@
2121
22from charmhelpers.fetch import (22from charmhelpers.fetch import (
23 apt_install,23 apt_install,
24 apt_purge,
24 apt_update,25 apt_update,
25 filter_installed_packages,26 filter_installed_packages,
26)27)
@@ -324,6 +325,18 @@
324 nrpe_setup.write()325 nrpe_setup.write()
325326
326327
328@hooks.hook('neutron-plugin-relation-changed')
329@restart_on_change(restart_map())
330def neutron_plugin_changed():
331 settings = relation_get()
332 if 'metadata-shared-secret' in settings:
333 apt_update()
334 apt_install('nova-api-metadata', fatal=True)
335 else:
336 apt_purge('nova-api-metadata', fatal=True)
337 CONFIGS.write(NOVA_CONF)
338
339
327def main():340def main():
328 try:341 try:
329 hooks.execute(sys.argv)342 hooks.execute(sys.argv)
330343
=== modified file 'hooks/nova_compute_utils.py'
--- hooks/nova_compute_utils.py 2015-03-12 10:07:02 +0000
+++ hooks/nova_compute_utils.py 2015-03-27 16:21:32 +0000
@@ -39,6 +39,7 @@
3939
40from nova_compute_context import (40from nova_compute_context import (
41 CloudComputeContext,41 CloudComputeContext,
42 MetadataServiceContext,
42 NovaComputeLibvirtContext,43 NovaComputeLibvirtContext,
43 NovaComputeCephContext,44 NovaComputeCephContext,
44 NeutronComputeContext,45 NeutronComputeContext,
@@ -94,6 +95,7 @@
94 service='nova',95 service='nova',
95 config_file=NOVA_CONF),96 config_file=NOVA_CONF),
96 InstanceConsoleContext(),97 InstanceConsoleContext(),
98 MetadataServiceContext(),
97 HostIPContext()],99 HostIPContext()],
98 },100 },
99}101}
@@ -203,6 +205,8 @@
203 }205 }
204 resource_map.update(CEPH_RESOURCES)206 resource_map.update(CEPH_RESOURCES)
205207
208 if enable_nova_metadata():
209 resource_map[NOVA_CONF]['services'].append('nova-api-metadata')
206 return resource_map210 return resource_map
207211
208212
@@ -271,6 +275,8 @@
271 except KeyError:275 except KeyError:
272 log('Unsupported virt-type configured: %s' % virt_type)276 log('Unsupported virt-type configured: %s' % virt_type)
273 raise277 raise
278 if enable_nova_metadata():
279 packages.append('nova-api-metadata')
274280
275 return packages281 return packages
276282
@@ -488,3 +494,8 @@
488 if lsb_release()['DISTRIB_CODENAME'].lower() < "trusty":494 if lsb_release()['DISTRIB_CODENAME'].lower() < "trusty":
489 raise Exception("IPv6 is not supported in the charms for Ubuntu "495 raise Exception("IPv6 is not supported in the charms for Ubuntu "
490 "versions less than Trusty 14.04")496 "versions less than Trusty 14.04")
497
498
499def enable_nova_metadata():
500 ctxt = MetadataServiceContext()()
501 return 'metadata_shared_secret' in ctxt
491502
=== modified file 'templates/juno/nova.conf'
--- templates/juno/nova.conf 2014-12-15 10:28:47 +0000
+++ templates/juno/nova.conf 2015-03-27 16:21:32 +0000
@@ -31,6 +31,11 @@
31glance_api_servers = {{ glance_api_servers }}31glance_api_servers = {{ glance_api_servers }}
32{% endif -%}32{% endif -%}
3333
34{% if metadata_shared_secret -%}
35neutron_metadata_proxy_shared_secret = {{ metadata_shared_secret }}
36service_neutron_metadata_proxy=True
37{% endif -%}
38
34{% if console_vnc_type -%}39{% if console_vnc_type -%}
35vnc_enabled = True40vnc_enabled = True
36novnc_enabled = True41novnc_enabled = True
3742
=== modified file 'unit_tests/test_nova_compute_contexts.py'
--- unit_tests/test_nova_compute_contexts.py 2015-02-16 09:53:45 +0000
+++ unit_tests/test_nova_compute_contexts.py 2015-03-27 16:21:32 +0000
@@ -228,3 +228,11 @@
228 self.assertEquals(228 self.assertEquals(
229 {'host_ip': '172.24.0.79'}, host_ip())229 {'host_ip': '172.24.0.79'}, host_ip())
230 self.unit_get.assert_called_with('private-address')230 self.unit_get.assert_called_with('private-address')
231
232 def test_metadata_service_ctxt(self):
233 self.relation_ids.return_value = 'neutron-plugin:0'
234 self.related_units.return_value = 'neutron-openvswitch/0'
235 self.test_relation.set({'metadata-shared-secret': 'shared_secret'})
236 metadatactxt = context.MetadataServiceContext()
237 self.assertEqual(metadatactxt(), {'metadata_shared_secret':
238 'shared_secret'})
231239
=== modified file 'unit_tests/test_nova_compute_hooks.py'
--- unit_tests/test_nova_compute_hooks.py 2015-02-09 21:30:33 +0000
+++ unit_tests/test_nova_compute_hooks.py 2015-03-27 16:21:32 +0000
@@ -378,3 +378,12 @@
378 call('/etc/nova/nova.conf'),378 call('/etc/nova/nova.conf'),
379 ]379 ]
380 self.assertEquals(ex, configs.write.call_args_list)380 self.assertEquals(ex, configs.write.call_args_list)
381
382 @patch.object(hooks, 'CONFIGS')
383 def test_neutron_plugin_changed(self, configs):
384 self.relation_get.return_value = {'metadata-shared-secret':
385 'sharedsecret'}
386 hooks.neutron_plugin_changed()
387 self.assertTrue(self.apt_update.called)
388 self.apt_install.assert_called_with('nova-api-metadata', fatal=True)
389 configs.write.assert_called_with('/etc/nova/nova.conf')
381390
=== modified file 'unit_tests/test_nova_compute_utils.py'
--- unit_tests/test_nova_compute_utils.py 2015-02-06 18:09:18 +0000
+++ unit_tests/test_nova_compute_utils.py 2015-03-27 16:21:32 +0000
@@ -24,7 +24,8 @@
24 'relation_ids',24 'relation_ids',
25 'relation_get',25 'relation_get',
26 'mkdir',26 'mkdir',
27 'install_alternative'27 'install_alternative',
28 'MetadataServiceContext',
28]29]
2930
30OVS_PKGS = [31OVS_PKGS = [
@@ -41,8 +42,10 @@
41 super(NovaComputeUtilsTests, self).setUp(utils, TO_PATCH)42 super(NovaComputeUtilsTests, self).setUp(utils, TO_PATCH)
42 self.config.side_effect = self.test_config.get43 self.config.side_effect = self.test_config.get
4344
45 @patch.object(utils, 'enable_nova_metadata')
44 @patch.object(utils, 'network_manager')46 @patch.object(utils, 'network_manager')
45 def test_determine_packages_nova_network(self, net_man):47 def test_determine_packages_nova_network(self, net_man, en_meta):
48 en_meta.return_value = False
46 net_man.return_value = 'flatdhcpmanager'49 net_man.return_value = 'flatdhcpmanager'
47 self.relation_ids.return_value = []50 self.relation_ids.return_value = []
48 result = utils.determine_packages()51 result = utils.determine_packages()
@@ -53,9 +56,11 @@
53 ]56 ]
54 self.assertEquals(ex, result)57 self.assertEquals(ex, result)
5558
59 @patch.object(utils, 'enable_nova_metadata')
56 @patch.object(utils, 'neutron_plugin')60 @patch.object(utils, 'neutron_plugin')
57 @patch.object(utils, 'network_manager')61 @patch.object(utils, 'network_manager')
58 def test_determine_packages_quantum(self, net_man, n_plugin):62 def test_determine_packages_quantum(self, net_man, n_plugin, en_meta):
63 en_meta.return_value = False
59 self.neutron_plugin_attribute.return_value = OVS_PKGS64 self.neutron_plugin_attribute.return_value = OVS_PKGS
60 net_man.return_value = 'quantum'65 net_man.return_value = 'quantum'
61 n_plugin.return_value = 'ovs'66 n_plugin.return_value = 'ovs'
@@ -64,9 +69,11 @@
64 ex = utils.BASE_PACKAGES + OVS_PKGS_FLAT + ['nova-compute-kvm']69 ex = utils.BASE_PACKAGES + OVS_PKGS_FLAT + ['nova-compute-kvm']
65 self.assertEquals(ex, result)70 self.assertEquals(ex, result)
6671
72 @patch.object(utils, 'enable_nova_metadata')
67 @patch.object(utils, 'neutron_plugin')73 @patch.object(utils, 'neutron_plugin')
68 @patch.object(utils, 'network_manager')74 @patch.object(utils, 'network_manager')
69 def test_determine_packages_quantum_ceph(self, net_man, n_plugin):75 def test_determine_packages_quantum_ceph(self, net_man, n_plugin, en_meta):
76 en_meta.return_value = False
70 self.neutron_plugin_attribute.return_value = OVS_PKGS77 self.neutron_plugin_attribute.return_value = OVS_PKGS
71 net_man.return_value = 'quantum'78 net_man.return_value = 'quantum'
72 n_plugin.return_value = 'ovs'79 n_plugin.return_value = 'ovs'
@@ -76,6 +83,18 @@
76 ['ceph-common', 'nova-compute-kvm'])83 ['ceph-common', 'nova-compute-kvm'])
77 self.assertEquals(ex, result)84 self.assertEquals(ex, result)
7885
86 @patch.object(utils, 'enable_nova_metadata')
87 @patch.object(utils, 'neutron_plugin')
88 @patch.object(utils, 'network_manager')
89 def test_determine_packages_metadata(self, net_man, n_plugin, en_meta):
90 en_meta.return_value = True
91 self.neutron_plugin_attribute.return_value = OVS_PKGS
92 net_man.return_value = 'bob'
93 n_plugin.return_value = 'ovs'
94 self.relation_ids.return_value = []
95 result = utils.determine_packages()
96 self.assertTrue('nova-api-metadata' in result)
97
79 @patch.object(utils, 'network_manager')98 @patch.object(utils, 'network_manager')
80 def test_resource_map_nova_network_no_multihost(self, net_man):99 def test_resource_map_nova_network_no_multihost(self, net_man):
81 self.skipTest('skipped until contexts are properly mocked')100 self.skipTest('skipped until contexts are properly mocked')
@@ -172,6 +191,17 @@
172 result = utils.resource_map()191 result = utils.resource_map()
173 self.assertTrue('/etc/neutron/neutron.conf' not in result)192 self.assertTrue('/etc/neutron/neutron.conf' not in result)
174193
194 @patch.object(utils, 'enable_nova_metadata')
195 @patch.object(utils, 'neutron_plugin')
196 @patch.object(utils, 'network_manager')
197 def test_resource_map_metadata(self, net_man, _plugin, _metadata):
198 _metadata.return_value = True
199 net_man.return_value = 'bob'
200 _plugin.return_value = 'ovs'
201 self.relation_ids.return_value = []
202 result = utils.resource_map()['/etc/nova/nova.conf']['services']
203 self.assertTrue('nova-api-metadata' in result)
204
175 def fake_user(self, username='foo'):205 def fake_user(self, username='foo'):
176 user = MagicMock()206 user = MagicMock()
177 user.pw_dir = '/home/' + username207 user.pw_dir = '/home/' + username
@@ -375,3 +405,17 @@
375 'secret-set-value', '--secret',405 'secret-set-value', '--secret',
376 compute_context.CEPH_SECRET_UUID,406 compute_context.CEPH_SECRET_UUID,
377 '--base64', key])407 '--base64', key])
408
409 def test_enable_nova_metadata(self):
410 class DummyContext():
411
412 def __init__(self, return_value):
413 self.return_value = return_value
414
415 def __call__(self):
416 return self.return_value
417
418 self.MetadataServiceContext.return_value = \
419 DummyContext(return_value={'metadata_shared_secret':
420 'sharedsecret'})
421 self.assertEqual(utils.enable_nova_metadata(), True)

Subscribers

People subscribed via source and target branches