Merge lp:~bbaqar/charms/trusty/plumgrid-edge/opsvm into lp:~plumgrid-team/charms/trusty/plumgrid-edge/trunk

Proposed by Bilal Baqar
Status: Merged
Merged at revision: 25
Proposed branch: lp:~bbaqar/charms/trusty/plumgrid-edge/opsvm
Merge into: lp:~plumgrid-team/charms/trusty/plumgrid-edge/trunk
Diff against target: 363 lines (+79/-50)
8 files modified
hooks/pg_edge_context.py (+22/-14)
hooks/pg_edge_hooks.py (+10/-17)
hooks/pg_edge_utils.py (+28/-1)
templates/kilo/00-pg.conf (+1/-0)
templates/kilo/plumgrid.conf (+1/-1)
unit_tests/test_pg_edge_context.py (+10/-7)
unit_tests/test_pg_edge_hooks.py (+5/-10)
unit_tests/test_pg_edge_utils.py (+2/-0)
To merge this branch: bzr merge lp:~bbaqar/charms/trusty/plumgrid-edge/opsvm
Reviewer Review Type Date Requested Status
Junaid Ali Approve
Javeria Khan Approve
Review via email: mp+290148@code.launchpad.net

Commit message

OPSVM Changes
Ticket: [SOL-830]

Description of the change

- Getting OPSVM IP from director relation
- Making OPSVM specific changes
- Cleaned code in various functions
- Added restart_on_change decorater function that restarts plumgrid service only when there has been any change in the configuration files
- Removed restart of plumgrid service when only two directors are available
- Fixed unit tests accordingly

To post a comment you must log in.
25. By Bilal Baqar

Cleaned code

26. By Bilal Baqar

restart_on_changed

27. By Bilal Baqar

Fixed lint and unit_tests

28. By Bilal Baqar

Improved dir ips string

29. By Bilal Baqar

Removed pkg purge in stop hook

30. By Bilal Baqar

fixing unit_test

Revision history for this message
Javeria Khan (javeria-ak) wrote :

Looks good to me functionally.

review: Approve
Revision history for this message
Junaid Ali (junaidali) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/pg_edge_context.py'
2--- hooks/pg_edge_context.py 2016-03-12 21:32:55 +0000
3+++ hooks/pg_edge_context.py 2016-03-28 14:31:59 +0000
4@@ -16,16 +16,23 @@
5 )
6
7
8-def _pg_dir_settings():
9+def _pg_dir_context():
10 '''
11 Inspects relation with PLUMgrid director.
12 '''
13- director_ips = []
14+ ctxt = {
15+ 'opsvm_ip': '127.0.0.1',
16+ 'director_ips': [],
17+ }
18 for rid in relation_ids('plumgrid'):
19 for unit in related_units(rid):
20 rdata = relation_get(rid=rid, unit=unit)
21- director_ips.append(str(get_host_ip(rdata['private-address'])))
22- return director_ips
23+ ctxt['director_ips'
24+ ].append(str(get_host_ip(rdata['private-address'])))
25+ if "opsvm_ip" in rdata:
26+ ctxt['opsvm_ip'] = \
27+ rdata['opsvm_ip']
28+ return ctxt
29
30
31 class PGEdgeContext(context.NeutronContext):
32@@ -62,16 +69,16 @@
33 if not pg_ctxt:
34 return {}
35
36- pg_dir_ips = ''
37- pg_dir_settings = sorted(_pg_dir_settings())
38- single_ip = True
39- for ip in pg_dir_settings:
40- if single_ip:
41- pg_dir_ips = str(ip)
42- single_ip = False
43- else:
44- pg_dir_ips = pg_dir_ips + ',' + str(ip)
45- pg_ctxt['local_ip'] = pg_dir_ips
46+ pg_dir_context = _pg_dir_context()
47+ pg_dir_ips = sorted(pg_dir_context['director_ips'])
48+ dir_count = len(pg_dir_ips)
49+ pg_ctxt['director_ips_string'] = (str(pg_dir_ips[0]) + ',' +
50+ str(pg_dir_ips[1]) + ',' +
51+ str(pg_dir_ips[2])
52+ if dir_count == 3 else
53+ str(pg_dir_ips[0])
54+ if dir_count == 1 else
55+ '')
56 unit_hostname = gethostname()
57 pg_ctxt['pg_hostname'] = unit_hostname
58 pg_ctxt['pg_fqdn'] = getfqdn()
59@@ -80,5 +87,6 @@
60 pg_ctxt['fabric_interface'] = get_fabric_interface()
61 pg_ctxt['label'] = unit_hostname
62 pg_ctxt['fabric_mode'] = 'host'
63+ pg_ctxt['opsvm_ip'] = pg_dir_context['opsvm_ip']
64
65 return pg_ctxt
66
67=== modified file 'hooks/pg_edge_hooks.py'
68--- hooks/pg_edge_hooks.py 2016-03-25 16:57:36 +0000
69+++ hooks/pg_edge_hooks.py 2016-03-28 14:31:59 +0000
70@@ -19,7 +19,6 @@
71
72 from charmhelpers.fetch import (
73 apt_install,
74- apt_purge,
75 configure_sources,
76 )
77
78@@ -27,6 +26,7 @@
79 register_configs,
80 ensure_files,
81 restart_pg,
82+ restart_map,
83 stop_pg,
84 determine_packages,
85 load_iovisor,
86@@ -34,7 +34,9 @@
87 ensure_mtu,
88 add_lcm_key,
89 fabric_interface_changed,
90- load_iptables
91+ load_iptables,
92+ restart_on_change,
93+ director_cluster_ready
94 )
95
96 hooks = Hooks()
97@@ -57,18 +59,16 @@
98 add_lcm_key()
99
100
101-@hooks.hook('plumgrid-relation-joined')
102 @hooks.hook('plumgrid-relation-changed')
103-def director_joined():
104+@restart_on_change(restart_map())
105+def director_changed():
106 '''
107 This hook is run when relation between plumgrid-edge and
108 plumgrid-director is made or changed.
109 '''
110- ensure_mtu()
111- ensure_files()
112- add_lcm_key()
113- CONFIGS.write_all()
114- restart_pg()
115+ if director_cluster_ready():
116+ ensure_mtu()
117+ CONFIGS.write_all()
118
119
120 @hooks.hook('neutron-plugin-relation-joined')
121@@ -103,7 +103,6 @@
122 charm_config.changed('plumgrid-build') or
123 charm_config.changed('install_keys') or
124 charm_config.changed('iovisor-build')):
125- ensure_files()
126 stop_pg()
127 configure_sources(update=True)
128 pkgs = determine_packages()
129@@ -124,12 +123,10 @@
130
131
132 @hooks.hook('upgrade-charm')
133+@restart_on_change(restart_map())
134 def upgrade_charm():
135- load_iptables()
136 ensure_mtu()
137- ensure_files()
138 CONFIGS.write_all()
139- restart_pg()
140
141
142 @hooks.hook('stop')
143@@ -138,10 +135,6 @@
144 This hook is run when the charm is destroyed.
145 '''
146 stop_pg()
147- remove_iovisor()
148- pkgs = determine_packages()
149- for pkg in pkgs:
150- apt_purge(pkg, fatal=False)
151
152
153 def main():
154
155=== modified file 'hooks/pg_edge_utils.py'
156--- hooks/pg_edge_utils.py 2016-03-21 18:59:43 +0000
157+++ hooks/pg_edge_utils.py 2016-03-28 14:31:59 +0000
158@@ -12,7 +12,6 @@
159 from copy import deepcopy
160 from charmhelpers.contrib.openstack.neutron import neutron_plugin_attribute
161 from charmhelpers.contrib.storage.linux.ceph import modprobe
162-from charmhelpers.core.host import set_nic_mtu
163 from charmhelpers.contrib.openstack import templating
164 from charmhelpers.core.hookenv import (
165 log,
166@@ -32,6 +31,8 @@
167 service_start,
168 service_stop,
169 service_running,
170+ path_hash,
171+ set_nic_mtu
172 )
173 from charmhelpers.fetch import (
174 apt_cache,
175@@ -49,6 +50,7 @@
176 PG_HN_CONF = '%s/conf/etc/hostname' % PG_LXC_DATA_PATH
177 PG_HS_CONF = '%s/conf/etc/hosts' % PG_LXC_DATA_PATH
178 PG_IFCS_CONF = '%s/conf/pg/ifcs.conf' % PG_LXC_DATA_PATH
179+OPS_CONF = '%s/conf/etc/00-pg.conf' % PG_LXC_DATA_PATH
180 AUTH_KEY_PATH = '%s/root/.ssh/authorized_keys' % PG_LXC_DATA_PATH
181 SUDOERS_CONF = '/etc/sudoers.d/ifc_ctl_sudoers'
182 FILTERS_CONF_DIR = '/etc/nova/rootwrap.d'
183@@ -67,6 +69,10 @@
184 'services': ['plumgrid'],
185 'contexts': [pg_edge_context.PGEdgeContext()],
186 }),
187+ (OPS_CONF, {
188+ 'services': ['plumgrid'],
189+ 'contexts': [pg_edge_context.PGEdgeContext()],
190+ }),
191 (PG_IFCS_CONF, {
192 'services': [],
193 'contexts': [pg_edge_context.PGEdgeContext()],
194@@ -410,3 +416,24 @@
195 return None
196 else:
197 return None
198+
199+
200+def director_cluster_ready():
201+ dirs_count = len(pg_edge_context._pg_dir_context()['director_ips'])
202+ return True if dirs_count == 1 or dirs_count == 3 else False
203+
204+
205+def restart_on_change(restart_map):
206+ """
207+ Restart services based on configuration files changing
208+ """
209+ def wrap(f):
210+ def wrapped_f(*args, **kwargs):
211+ checksums = {path: path_hash(path) for path in restart_map}
212+ f(*args, **kwargs)
213+ for path in restart_map:
214+ if path_hash(path) != checksums[path]:
215+ restart_pg()
216+ break
217+ return wrapped_f
218+ return wrap
219
220=== removed symlink 'hooks/plumgrid-relation-joined'
221=== target was u'pg_edge_hooks.py'
222=== added file 'templates/kilo/00-pg.conf'
223--- templates/kilo/00-pg.conf 1970-01-01 00:00:00 +0000
224+++ templates/kilo/00-pg.conf 2016-03-28 14:31:59 +0000
225@@ -0,0 +1,1 @@
226+$template ls_json,"{{'{'}}{{'%'}}timestamp:::date-rfc3339,jsonf:@timestamp%,%source:::jsonf:@source_host%,%msg:::json%}":syslogtag,isequal,"pg:" @{{ opsvm_ip }}:6000;ls_json
227
228=== modified file 'templates/kilo/plumgrid.conf'
229--- templates/kilo/plumgrid.conf 2015-07-29 18:19:18 +0000
230+++ templates/kilo/plumgrid.conf 2016-03-28 14:31:59 +0000
231@@ -1,4 +1,4 @@
232-plumgrid_ip={{ local_ip }}
233+plumgrid_ip={{ director_ips_string }}
234 plumgrid_port=8001
235 mgmt_dev={{ interface }}
236 label={{ label}}
237
238=== modified file 'unit_tests/test_pg_edge_context.py'
239--- unit_tests/test_pg_edge_context.py 2016-03-12 20:58:04 +0000
240+++ unit_tests/test_pg_edge_context.py 2016-03-28 14:31:59 +0000
241@@ -35,13 +35,13 @@
242 @patch.object(charmhelpers.contrib.openstack.context,
243 'config_flags_parser')
244 @patch.object(context.PGEdgeContext, '_save_flag_file')
245- @patch.object(context, '_pg_dir_settings')
246+ @patch.object(context, '_pg_dir_context')
247 @patch.object(charmhelpers.contrib.openstack.context,
248 'neutron_plugin_attribute')
249 @patch.object(utils, 'get_mgmt_interface')
250 @patch.object(utils, 'get_fabric_interface')
251 def test_neutroncc_context_api_rel(self, _fabric_int, _mgmt_int,
252- _npa, _pg_dir_settings,
253+ _npa, _pg_dir_context,
254 _save_flag_file, _config_flag,
255 _unit_get, _unit_priv_ip, _config,
256 _is_clus, _https, _ens_pkgs):
257@@ -61,24 +61,26 @@
258
259 self.maxDiff = None
260 _npa.side_effect = mock_npa
261- _unit_get.return_value = '192.168.100.201'
262- _unit_priv_ip.return_value = '192.168.100.201'
263+ _unit_get.return_value = '192.168.100.203'
264+ _unit_priv_ip.return_value = '192.168.100.203'
265 self.gethostname.return_value = 'node0'
266 self.getfqdn.return_value = 'node0.maas'
267 _is_clus.return_value = False
268 _config_flag.return_value = False
269- _pg_dir_settings.return_value = {'pg_dir_ip': '192.168.100.201'}
270+ _pg_dir_context.return_value = {'director_ips': ['192.168.100.201'],
271+ 'opsvm_ip': '127.0.0.1'}
272 _mgmt_int.return_value = 'juju-br0'
273 _fabric_int.return_value = 'juju-br0'
274 napi_ctxt = context.PGEdgeContext()
275 expect = {
276 'config': 'neutron.randomconfig',
277 'core_plugin': 'neutron.randomdriver',
278- 'local_ip': 'pg_dir_ip',
279+ 'local_ip': '192.168.100.203',
280+ 'director_ips_string': '192.168.100.201',
281 'network_manager': 'neutron',
282 'neutron_plugin': 'plumgrid',
283 'neutron_security_groups': None,
284- 'neutron_url': 'https://192.168.100.201:9696',
285+ 'neutron_url': 'https://192.168.100.203:9696',
286 'pg_hostname': 'node0',
287 'pg_fqdn': 'node0.maas',
288 'interface': 'juju-br0',
289@@ -86,5 +88,6 @@
290 'label': 'node0',
291 'fabric_mode': 'host',
292 'neutron_alchemy_flags': False,
293+ 'opsvm_ip': '127.0.0.1',
294 }
295 self.assertEquals(expect, napi_ctxt())
296
297=== modified file 'unit_tests/test_pg_edge_hooks.py'
298--- unit_tests/test_pg_edge_hooks.py 2016-03-24 12:36:29 +0000
299+++ unit_tests/test_pg_edge_hooks.py 2016-03-28 14:31:59 +0000
300@@ -18,7 +18,6 @@
301 TO_PATCH = [
302 'remove_iovisor',
303 'apt_install',
304- 'apt_purge',
305 'CONFIGS',
306 'log',
307 'configure_sources',
308@@ -32,7 +31,8 @@
309 'config',
310 'relation_set',
311 'relation_ids',
312- 'load_iptables'
313+ 'load_iptables',
314+ 'director_cluster_ready'
315 ]
316 NEUTRON_CONF_DIR = "/etc/neutron"
317
318@@ -64,13 +64,11 @@
319 self.ensure_files.assert_called_with()
320 self.add_lcm_key.assert_called_with()
321
322- def test_plumgrid_joined(self):
323- self._call_hook('plumgrid-relation-joined')
324+ def test_plumgrid_changed(self):
325+ self._call_hook('plumgrid-relation-changed')
326+ self.director_cluster_ready.return_value = True
327 self.ensure_mtu.assert_called_with()
328- self.ensure_files.assert_called_with()
329- self.add_lcm_key.assert_called_with()
330 self.CONFIGS.write_all.assert_called_with()
331- self.restart_pg.assert_called_with()
332
333 def test_neutron_plugin_joined(self):
334 self.test_config.set('metadata-shared-key', 'plumgrid')
335@@ -84,8 +82,5 @@
336 )
337
338 def test_stop(self):
339- _pkgs = ['plumgrid-lxc', 'iovisor-dkms']
340 self._call_hook('stop')
341 self.stop_pg.assert_called_with()
342- self.remove_iovisor.assert_called_with()
343- self.determine_packages.return_value = _pkgs
344
345=== modified file 'unit_tests/test_pg_edge_utils.py'
346--- unit_tests/test_pg_edge_utils.py 2015-08-24 16:22:15 +0000
347+++ unit_tests/test_pg_edge_utils.py 2016-03-28 14:31:59 +0000
348@@ -54,6 +54,7 @@
349 nutils.PG_HN_CONF,
350 nutils.PG_HS_CONF,
351 nutils.PG_IFCS_CONF,
352+ nutils.OPS_CONF,
353 '/etc/nova/rootwrap.d/network.filters']
354 self.assertItemsEqual(_regconfs.configs, confs)
355
356@@ -70,6 +71,7 @@
357 (nutils.PG_CONF, ['plumgrid']),
358 (nutils.PG_HN_CONF, ['plumgrid']),
359 (nutils.PG_HS_CONF, ['plumgrid']),
360+ (nutils.OPS_CONF, ['plumgrid']),
361 (nutils.PG_IFCS_CONF, []),
362 (nutils.FILTERS_CONF, []),
363 ])

Subscribers

People subscribed via source and target branches