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
1=== modified file 'hooks/nova_compute_context.py'
2--- hooks/nova_compute_context.py 2015-03-12 10:07:02 +0000
3+++ hooks/nova_compute_context.py 2015-03-27 16:21:32 +0000
4@@ -390,6 +390,19 @@
5 return ctxt
6
7
8+class MetadataServiceContext(context.OSContextGenerator):
9+
10+ def __call__(self):
11+ ctxt = {}
12+ for rid in relation_ids('neutron-plugin'):
13+ for unit in related_units(rid):
14+ rdata = relation_get(rid=rid, unit=unit)
15+ if 'metadata-shared-secret' in rdata:
16+ ctxt['metadata_shared_secret'] = \
17+ rdata['metadata-shared-secret']
18+ return ctxt
19+
20+
21 class NeutronComputeContext(context.NeutronContext):
22 interfaces = []
23
24
25=== modified file 'hooks/nova_compute_hooks.py'
26--- hooks/nova_compute_hooks.py 2015-02-24 11:33:01 +0000
27+++ hooks/nova_compute_hooks.py 2015-03-27 16:21:32 +0000
28@@ -21,6 +21,7 @@
29
30 from charmhelpers.fetch import (
31 apt_install,
32+ apt_purge,
33 apt_update,
34 filter_installed_packages,
35 )
36@@ -324,6 +325,18 @@
37 nrpe_setup.write()
38
39
40+@hooks.hook('neutron-plugin-relation-changed')
41+@restart_on_change(restart_map())
42+def neutron_plugin_changed():
43+ settings = relation_get()
44+ if 'metadata-shared-secret' in settings:
45+ apt_update()
46+ apt_install('nova-api-metadata', fatal=True)
47+ else:
48+ apt_purge('nova-api-metadata', fatal=True)
49+ CONFIGS.write(NOVA_CONF)
50+
51+
52 def main():
53 try:
54 hooks.execute(sys.argv)
55
56=== modified file 'hooks/nova_compute_utils.py'
57--- hooks/nova_compute_utils.py 2015-03-12 10:07:02 +0000
58+++ hooks/nova_compute_utils.py 2015-03-27 16:21:32 +0000
59@@ -39,6 +39,7 @@
60
61 from nova_compute_context import (
62 CloudComputeContext,
63+ MetadataServiceContext,
64 NovaComputeLibvirtContext,
65 NovaComputeCephContext,
66 NeutronComputeContext,
67@@ -94,6 +95,7 @@
68 service='nova',
69 config_file=NOVA_CONF),
70 InstanceConsoleContext(),
71+ MetadataServiceContext(),
72 HostIPContext()],
73 },
74 }
75@@ -203,6 +205,8 @@
76 }
77 resource_map.update(CEPH_RESOURCES)
78
79+ if enable_nova_metadata():
80+ resource_map[NOVA_CONF]['services'].append('nova-api-metadata')
81 return resource_map
82
83
84@@ -271,6 +275,8 @@
85 except KeyError:
86 log('Unsupported virt-type configured: %s' % virt_type)
87 raise
88+ if enable_nova_metadata():
89+ packages.append('nova-api-metadata')
90
91 return packages
92
93@@ -488,3 +494,8 @@
94 if lsb_release()['DISTRIB_CODENAME'].lower() < "trusty":
95 raise Exception("IPv6 is not supported in the charms for Ubuntu "
96 "versions less than Trusty 14.04")
97+
98+
99+def enable_nova_metadata():
100+ ctxt = MetadataServiceContext()()
101+ return 'metadata_shared_secret' in ctxt
102
103=== modified file 'templates/juno/nova.conf'
104--- templates/juno/nova.conf 2014-12-15 10:28:47 +0000
105+++ templates/juno/nova.conf 2015-03-27 16:21:32 +0000
106@@ -31,6 +31,11 @@
107 glance_api_servers = {{ glance_api_servers }}
108 {% endif -%}
109
110+{% if metadata_shared_secret -%}
111+neutron_metadata_proxy_shared_secret = {{ metadata_shared_secret }}
112+service_neutron_metadata_proxy=True
113+{% endif -%}
114+
115 {% if console_vnc_type -%}
116 vnc_enabled = True
117 novnc_enabled = True
118
119=== modified file 'unit_tests/test_nova_compute_contexts.py'
120--- unit_tests/test_nova_compute_contexts.py 2015-02-16 09:53:45 +0000
121+++ unit_tests/test_nova_compute_contexts.py 2015-03-27 16:21:32 +0000
122@@ -228,3 +228,11 @@
123 self.assertEquals(
124 {'host_ip': '172.24.0.79'}, host_ip())
125 self.unit_get.assert_called_with('private-address')
126+
127+ def test_metadata_service_ctxt(self):
128+ self.relation_ids.return_value = 'neutron-plugin:0'
129+ self.related_units.return_value = 'neutron-openvswitch/0'
130+ self.test_relation.set({'metadata-shared-secret': 'shared_secret'})
131+ metadatactxt = context.MetadataServiceContext()
132+ self.assertEqual(metadatactxt(), {'metadata_shared_secret':
133+ 'shared_secret'})
134
135=== modified file 'unit_tests/test_nova_compute_hooks.py'
136--- unit_tests/test_nova_compute_hooks.py 2015-02-09 21:30:33 +0000
137+++ unit_tests/test_nova_compute_hooks.py 2015-03-27 16:21:32 +0000
138@@ -378,3 +378,12 @@
139 call('/etc/nova/nova.conf'),
140 ]
141 self.assertEquals(ex, configs.write.call_args_list)
142+
143+ @patch.object(hooks, 'CONFIGS')
144+ def test_neutron_plugin_changed(self, configs):
145+ self.relation_get.return_value = {'metadata-shared-secret':
146+ 'sharedsecret'}
147+ hooks.neutron_plugin_changed()
148+ self.assertTrue(self.apt_update.called)
149+ self.apt_install.assert_called_with('nova-api-metadata', fatal=True)
150+ configs.write.assert_called_with('/etc/nova/nova.conf')
151
152=== modified file 'unit_tests/test_nova_compute_utils.py'
153--- unit_tests/test_nova_compute_utils.py 2015-02-06 18:09:18 +0000
154+++ unit_tests/test_nova_compute_utils.py 2015-03-27 16:21:32 +0000
155@@ -24,7 +24,8 @@
156 'relation_ids',
157 'relation_get',
158 'mkdir',
159- 'install_alternative'
160+ 'install_alternative',
161+ 'MetadataServiceContext',
162 ]
163
164 OVS_PKGS = [
165@@ -41,8 +42,10 @@
166 super(NovaComputeUtilsTests, self).setUp(utils, TO_PATCH)
167 self.config.side_effect = self.test_config.get
168
169+ @patch.object(utils, 'enable_nova_metadata')
170 @patch.object(utils, 'network_manager')
171- def test_determine_packages_nova_network(self, net_man):
172+ def test_determine_packages_nova_network(self, net_man, en_meta):
173+ en_meta.return_value = False
174 net_man.return_value = 'flatdhcpmanager'
175 self.relation_ids.return_value = []
176 result = utils.determine_packages()
177@@ -53,9 +56,11 @@
178 ]
179 self.assertEquals(ex, result)
180
181+ @patch.object(utils, 'enable_nova_metadata')
182 @patch.object(utils, 'neutron_plugin')
183 @patch.object(utils, 'network_manager')
184- def test_determine_packages_quantum(self, net_man, n_plugin):
185+ def test_determine_packages_quantum(self, net_man, n_plugin, en_meta):
186+ en_meta.return_value = False
187 self.neutron_plugin_attribute.return_value = OVS_PKGS
188 net_man.return_value = 'quantum'
189 n_plugin.return_value = 'ovs'
190@@ -64,9 +69,11 @@
191 ex = utils.BASE_PACKAGES + OVS_PKGS_FLAT + ['nova-compute-kvm']
192 self.assertEquals(ex, result)
193
194+ @patch.object(utils, 'enable_nova_metadata')
195 @patch.object(utils, 'neutron_plugin')
196 @patch.object(utils, 'network_manager')
197- def test_determine_packages_quantum_ceph(self, net_man, n_plugin):
198+ def test_determine_packages_quantum_ceph(self, net_man, n_plugin, en_meta):
199+ en_meta.return_value = False
200 self.neutron_plugin_attribute.return_value = OVS_PKGS
201 net_man.return_value = 'quantum'
202 n_plugin.return_value = 'ovs'
203@@ -76,6 +83,18 @@
204 ['ceph-common', 'nova-compute-kvm'])
205 self.assertEquals(ex, result)
206
207+ @patch.object(utils, 'enable_nova_metadata')
208+ @patch.object(utils, 'neutron_plugin')
209+ @patch.object(utils, 'network_manager')
210+ def test_determine_packages_metadata(self, net_man, n_plugin, en_meta):
211+ en_meta.return_value = True
212+ self.neutron_plugin_attribute.return_value = OVS_PKGS
213+ net_man.return_value = 'bob'
214+ n_plugin.return_value = 'ovs'
215+ self.relation_ids.return_value = []
216+ result = utils.determine_packages()
217+ self.assertTrue('nova-api-metadata' in result)
218+
219 @patch.object(utils, 'network_manager')
220 def test_resource_map_nova_network_no_multihost(self, net_man):
221 self.skipTest('skipped until contexts are properly mocked')
222@@ -172,6 +191,17 @@
223 result = utils.resource_map()
224 self.assertTrue('/etc/neutron/neutron.conf' not in result)
225
226+ @patch.object(utils, 'enable_nova_metadata')
227+ @patch.object(utils, 'neutron_plugin')
228+ @patch.object(utils, 'network_manager')
229+ def test_resource_map_metadata(self, net_man, _plugin, _metadata):
230+ _metadata.return_value = True
231+ net_man.return_value = 'bob'
232+ _plugin.return_value = 'ovs'
233+ self.relation_ids.return_value = []
234+ result = utils.resource_map()['/etc/nova/nova.conf']['services']
235+ self.assertTrue('nova-api-metadata' in result)
236+
237 def fake_user(self, username='foo'):
238 user = MagicMock()
239 user.pw_dir = '/home/' + username
240@@ -375,3 +405,17 @@
241 'secret-set-value', '--secret',
242 compute_context.CEPH_SECRET_UUID,
243 '--base64', key])
244+
245+ def test_enable_nova_metadata(self):
246+ class DummyContext():
247+
248+ def __init__(self, return_value):
249+ self.return_value = return_value
250+
251+ def __call__(self):
252+ return self.return_value
253+
254+ self.MetadataServiceContext.return_value = \
255+ DummyContext(return_value={'metadata_shared_secret':
256+ 'sharedsecret'})
257+ self.assertEqual(utils.enable_nova_metadata(), True)

Subscribers

People subscribed via source and target branches