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

Proposed by Bilal Baqar
Status: Merged
Merged at revision: 24
Proposed branch: lp:~bbaqar/charms/trusty/plumgrid-gateway/opsvm
Merge into: lp:~plumgrid-team/charms/trusty/plumgrid-gateway/trunk
Diff against target: 355 lines (+81/-50)
8 files modified
hooks/pg_gw_context.py (+22/-14)
hooks/pg_gw_hooks.py (+9/-15)
hooks/pg_gw_utils.py (+30/-3)
templates/kilo/00-pg.conf (+1/-0)
templates/kilo/plumgrid.conf (+1/-1)
unit_tests/test_pg_gw_context.py (+10/-7)
unit_tests/test_pg_gw_hooks.py (+5/-9)
unit_tests/test_pg_gw_utils.py (+3/-1)
To merge this branch: bzr merge lp:~bbaqar/charms/trusty/plumgrid-gateway/opsvm
Reviewer Review Type Date Requested Status
Junaid Ali Approve
Javeria Khan Approve
Review via email: mp+290180@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.
Revision history for this message
Javeria Khan (javeria-ak) wrote :

Looks good functionally.

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

Looks good to me.

review: Approve

Preview Diff

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

Subscribers

People subscribed via source and target branches