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
=== modified file 'hooks/pg_gw_context.py'
--- hooks/pg_gw_context.py 2016-03-12 21:55:39 +0000
+++ hooks/pg_gw_context.py 2016-03-27 15:36:55 +0000
@@ -16,16 +16,23 @@
16)16)
1717
1818
19def _pg_dir_settings():19def _pg_dir_context():
20 '''20 '''
21 Inspects relation with PLUMgrid director.21 Inspects relation with PLUMgrid director.
22 '''22 '''
23 director_ips = []23 ctxt = {
24 'opsvm_ip': '127.0.0.1',
25 'director_ips': [],
26 }
24 for rid in relation_ids('plumgrid'):27 for rid in relation_ids('plumgrid'):
25 for unit in related_units(rid):28 for unit in related_units(rid):
26 rdata = relation_get(rid=rid, unit=unit)29 rdata = relation_get(rid=rid, unit=unit)
27 director_ips.append(str(get_host_ip(rdata['private-address'])))30 ctxt['director_ips'
28 return director_ips31 ].append(str(get_host_ip(rdata['private-address'])))
32 if "opsvm_ip" in rdata:
33 ctxt['opsvm_ip'] = \
34 rdata['opsvm_ip']
35 return ctxt
2936
3037
31class PGGwContext(context.NeutronContext):38class PGGwContext(context.NeutronContext):
@@ -62,16 +69,16 @@
62 if not pg_ctxt:69 if not pg_ctxt:
63 return {}70 return {}
6471
65 pg_dir_ips = ''72 pg_dir_context = _pg_dir_context()
66 pg_dir_settings = sorted(_pg_dir_settings())73 pg_dir_ips = sorted(pg_dir_context['director_ips'])
67 single_ip = True74 dir_count = len(pg_dir_ips)
68 for ip in pg_dir_settings:75 pg_ctxt['director_ips_string'] = (str(pg_dir_ips[0]) + ',' +
69 if single_ip:76 str(pg_dir_ips[1]) + ',' +
70 pg_dir_ips = str(ip)77 str(pg_dir_ips[2])
71 single_ip = False78 if dir_count == 3 else
72 else:79 str(pg_dir_ips[0])
73 pg_dir_ips = pg_dir_ips + ',' + str(ip)80 if dir_count == 1 else
74 pg_ctxt['local_ip'] = pg_dir_ips81 '')
75 unit_hostname = gethostname()82 unit_hostname = gethostname()
76 pg_ctxt['pg_hostname'] = unit_hostname83 pg_ctxt['pg_hostname'] = unit_hostname
77 pg_ctxt['pg_fqdn'] = getfqdn()84 pg_ctxt['pg_fqdn'] = getfqdn()
@@ -85,5 +92,6 @@
85 pg_ctxt['label'] = unit_hostname92 pg_ctxt['label'] = unit_hostname
86 pg_ctxt['fabric_mode'] = 'host'93 pg_ctxt['fabric_mode'] = 'host'
87 pg_ctxt['ext_interfaces'] = get_gw_interfaces()94 pg_ctxt['ext_interfaces'] = get_gw_interfaces()
95 pg_ctxt['opsvm_ip'] = pg_dir_context['opsvm_ip']
8896
89 return pg_ctxt97 return pg_ctxt
9098
=== modified file 'hooks/pg_gw_hooks.py'
--- hooks/pg_gw_hooks.py 2016-03-25 17:33:22 +0000
+++ hooks/pg_gw_hooks.py 2016-03-27 15:36:55 +0000
@@ -18,7 +18,6 @@
1818
19from charmhelpers.fetch import (19from charmhelpers.fetch import (
20 apt_install,20 apt_install,
21 apt_purge,
22 configure_sources,21 configure_sources,
23)22)
2423
@@ -26,6 +25,7 @@
26 register_configs,25 register_configs,
27 ensure_files,26 ensure_files,
28 restart_pg,27 restart_pg,
28 restart_map,
29 stop_pg,29 stop_pg,
30 determine_packages,30 determine_packages,
31 load_iovisor,31 load_iovisor,
@@ -34,6 +34,8 @@
34 add_lcm_key,34 add_lcm_key,
35 fabric_interface_changed,35 fabric_interface_changed,
36 load_iptables,36 load_iptables,
37 restart_on_change,
38 director_cluster_ready
37)39)
3840
39hooks = Hooks()41hooks = Hooks()
@@ -56,18 +58,16 @@
56 add_lcm_key()58 add_lcm_key()
5759
5860
59@hooks.hook('plumgrid-relation-joined')
60@hooks.hook('plumgrid-relation-changed')61@hooks.hook('plumgrid-relation-changed')
61def plumgrid_joined():62@restart_on_change(restart_map())
63def plumgrid_changed():
62 '''64 '''
63 This hook is run when relation between plumgrid-gateway and65 This hook is run when relation between plumgrid-gateway and
64 plumgrid-director is made.66 plumgrid-director is made.
65 '''67 '''
66 ensure_mtu()68 if director_cluster_ready():
67 ensure_files()69 ensure_mtu()
68 add_lcm_key()70 CONFIGS.write_all()
69 CONFIGS.write_all()
70 restart_pg()
7171
7272
73@hooks.hook('config-changed')73@hooks.hook('config-changed')
@@ -105,12 +105,10 @@
105105
106106
107@hooks.hook('upgrade-charm')107@hooks.hook('upgrade-charm')
108@restart_on_change(restart_map())
108def upgrade_charm():109def upgrade_charm():
109 load_iptables()
110 ensure_mtu()110 ensure_mtu()
111 ensure_files()
112 CONFIGS.write_all()111 CONFIGS.write_all()
113 restart_pg()
114112
115113
116@hooks.hook('stop')114@hooks.hook('stop')
@@ -119,10 +117,6 @@
119 This hook is run when the charm is destroyed.117 This hook is run when the charm is destroyed.
120 '''118 '''
121 stop_pg()119 stop_pg()
122 remove_iovisor()
123 pkgs = determine_packages()
124 for pkg in pkgs:
125 apt_purge(pkg, fatal=False)
126120
127121
128def main():122def main():
129123
=== modified file 'hooks/pg_gw_utils.py'
--- hooks/pg_gw_utils.py 2016-03-21 18:46:01 +0000
+++ hooks/pg_gw_utils.py 2016-03-27 15:36:55 +0000
@@ -12,7 +12,6 @@
12from copy import deepcopy12from copy import deepcopy
13from charmhelpers.contrib.openstack.neutron import neutron_plugin_attribute13from charmhelpers.contrib.openstack.neutron import neutron_plugin_attribute
14from charmhelpers.contrib.storage.linux.ceph import modprobe14from charmhelpers.contrib.storage.linux.ceph import modprobe
15from charmhelpers.core.host import set_nic_mtu
16from charmhelpers.contrib.openstack import templating15from charmhelpers.contrib.openstack import templating
17from charmhelpers.core.hookenv import (16from charmhelpers.core.hookenv import (
18 log,17 log,
@@ -30,7 +29,9 @@
30 write_file,29 write_file,
31 service_start,30 service_start,
32 service_stop,31 service_stop,
33 service_running32 service_running,
33 path_hash,
34 set_nic_mtu
34)35)
35from charmhelpers.fetch import (36from charmhelpers.fetch import (
36 apt_cache,37 apt_cache,
@@ -47,6 +48,7 @@
47PG_HN_CONF = '%s/conf/etc/hostname' % PG_LXC_DATA_PATH48PG_HN_CONF = '%s/conf/etc/hostname' % PG_LXC_DATA_PATH
48PG_HS_CONF = '%s/conf/etc/hosts' % PG_LXC_DATA_PATH49PG_HS_CONF = '%s/conf/etc/hosts' % PG_LXC_DATA_PATH
49PG_IFCS_CONF = '%s/conf/pg/ifcs.conf' % PG_LXC_DATA_PATH50PG_IFCS_CONF = '%s/conf/pg/ifcs.conf' % PG_LXC_DATA_PATH
51OPS_CONF = '%s/conf/etc/00-pg.conf' % PG_LXC_DATA_PATH
50AUTH_KEY_PATH = '%s/root/.ssh/authorized_keys' % PG_LXC_DATA_PATH52AUTH_KEY_PATH = '%s/root/.ssh/authorized_keys' % PG_LXC_DATA_PATH
51IFC_LIST_GW = '/var/run/plumgrid/lxc/ifc_list_gateway'53IFC_LIST_GW = '/var/run/plumgrid/lxc/ifc_list_gateway'
52SUDOERS_CONF = '/etc/sudoers.d/ifc_ctl_sudoers'54SUDOERS_CONF = '/etc/sudoers.d/ifc_ctl_sudoers'
@@ -64,6 +66,10 @@
64 'services': ['plumgrid'],66 'services': ['plumgrid'],
65 'contexts': [pg_gw_context.PGGwContext()],67 'contexts': [pg_gw_context.PGGwContext()],
66 }),68 }),
69 (OPS_CONF, {
70 'services': ['plumgrid'],
71 'contexts': [pg_gw_context.PGGwContext()],
72 }),
67 (PG_IFCS_CONF, {73 (PG_IFCS_CONF, {
68 'services': [],74 'services': [],
69 'contexts': [pg_gw_context.PGGwContext()],75 'contexts': [pg_gw_context.PGGwContext()],
@@ -161,7 +167,7 @@
161 Stops PLUMgrid service.167 Stops PLUMgrid service.
162 '''168 '''
163 service_stop('plumgrid')169 service_stop('plumgrid')
164 time.sleep(30)170 time.sleep(2)
165171
166172
167def load_iovisor():173def load_iovisor():
@@ -380,3 +386,24 @@
380 return None386 return None
381 else:387 else:
382 return None388 return None
389
390
391def director_cluster_ready():
392 dirs_count = len(pg_gw_context._pg_dir_context()['director_ips'])
393 return True if dirs_count == 1 or dirs_count == 3 else False
394
395
396def restart_on_change(restart_map):
397 """
398 Restart services based on configuration files changing
399 """
400 def wrap(f):
401 def wrapped_f(*args, **kwargs):
402 checksums = {path: path_hash(path) for path in restart_map}
403 f(*args, **kwargs)
404 for path in restart_map:
405 if path_hash(path) != checksums[path]:
406 restart_pg()
407 break
408 return wrapped_f
409 return wrap
383410
=== removed symlink 'hooks/plumgrid-relation-joined'
=== target was u'pg_gw_hooks.py'
=== added file 'templates/kilo/00-pg.conf'
--- templates/kilo/00-pg.conf 1970-01-01 00:00:00 +0000
+++ templates/kilo/00-pg.conf 2016-03-27 15:36:55 +0000
@@ -0,0 +1,1 @@
1$template ls_json,"{{'{'}}{{'%'}}timestamp:::date-rfc3339,jsonf:@timestamp%,%source:::jsonf:@source_host%,%msg:::json%}":syslogtag,isequal,"pg:" @{{ opsvm_ip }}:6000;ls_json
02
=== modified file 'templates/kilo/plumgrid.conf'
--- templates/kilo/plumgrid.conf 2015-07-29 18:23:55 +0000
+++ templates/kilo/plumgrid.conf 2016-03-27 15:36:55 +0000
@@ -1,4 +1,4 @@
1plumgrid_ip={{ local_ip }}1plumgrid_ip={{ director_ips_string }}
2plumgrid_port=80012plumgrid_port=8001
3mgmt_dev={{ interface }}3mgmt_dev={{ interface }}
4label={{ label}}4label={{ label}}
55
=== modified file 'unit_tests/test_pg_gw_context.py'
--- unit_tests/test_pg_gw_context.py 2016-03-12 21:55:39 +0000
+++ unit_tests/test_pg_gw_context.py 2016-03-27 15:36:55 +0000
@@ -35,14 +35,14 @@
35 @patch.object(charmhelpers.contrib.openstack.context,35 @patch.object(charmhelpers.contrib.openstack.context,
36 'config_flags_parser')36 'config_flags_parser')
37 @patch.object(context.PGGwContext, '_save_flag_file')37 @patch.object(context.PGGwContext, '_save_flag_file')
38 @patch.object(context, '_pg_dir_settings')38 @patch.object(context, '_pg_dir_context')
39 @patch.object(charmhelpers.contrib.openstack.context,39 @patch.object(charmhelpers.contrib.openstack.context,
40 'neutron_plugin_attribute')40 'neutron_plugin_attribute')
41 @patch.object(utils, 'get_mgmt_interface')41 @patch.object(utils, 'get_mgmt_interface')
42 @patch.object(utils, 'get_fabric_interface')42 @patch.object(utils, 'get_fabric_interface')
43 @patch.object(utils, 'get_gw_interfaces')43 @patch.object(utils, 'get_gw_interfaces')
44 def test_neutroncc_context_api_rel(self, _gw_int, _fabric_int,44 def test_neutroncc_context_api_rel(self, _gw_int, _fabric_int,
45 _mgmt_int, _npa, _pg_dir_settings,45 _mgmt_int, _npa, _pg_dir_context,
46 _save_flag_file, _config_flag,46 _save_flag_file, _config_flag,
47 _unit_get, _unit_priv_ip, _config,47 _unit_get, _unit_priv_ip, _config,
48 _is_clus, _https, _ens_pkgs):48 _is_clus, _https, _ens_pkgs):
@@ -54,13 +54,14 @@
5454
55 self.maxDiff = None55 self.maxDiff = None
56 _npa.side_effect = mock_npa56 _npa.side_effect = mock_npa
57 _unit_get.return_value = '192.168.100.201'57 _unit_get.return_value = '192.168.100.203'
58 _unit_priv_ip.return_value = '192.168.100.201'58 _unit_priv_ip.return_value = '192.168.100.203'
59 self.gethostname.return_value = 'node0'59 self.gethostname.return_value = 'node0'
60 self.getfqdn.return_value = 'node0'60 self.getfqdn.return_value = 'node0'
61 _is_clus.return_value = False61 _is_clus.return_value = False
62 _config_flag.return_value = False62 _config_flag.return_value = False
63 _pg_dir_settings.return_value = {'pg_dir_ip': '192.168.100.201'}63 _pg_dir_context.return_value = {'director_ips': ['192.168.100.201'],
64 'opsvm_ip': '127.0.0.1'}
64 _mgmt_int.return_value = 'juju-br0'65 _mgmt_int.return_value = 'juju-br0'
65 _fabric_int.return_value = 'juju-br0'66 _fabric_int.return_value = 'juju-br0'
66 _gw_int.return_value = ['eth1']67 _gw_int.return_value = ['eth1']
@@ -69,11 +70,12 @@
69 'ext_interfaces': ['eth1'],70 'ext_interfaces': ['eth1'],
70 'config': 'neutron.randomconfig',71 'config': 'neutron.randomconfig',
71 'core_plugin': 'neutron.randomdriver',72 'core_plugin': 'neutron.randomdriver',
72 'local_ip': 'pg_dir_ip',73 'local_ip': '192.168.100.203',
74 'director_ips_string': '192.168.100.201',
73 'network_manager': 'neutron',75 'network_manager': 'neutron',
74 'neutron_plugin': 'plumgrid',76 'neutron_plugin': 'plumgrid',
75 'neutron_security_groups': None,77 'neutron_security_groups': None,
76 'neutron_url': 'https://192.168.100.201:9696',78 'neutron_url': 'https://192.168.100.203:9696',
77 'pg_hostname': 'node0',79 'pg_hostname': 'node0',
78 'pg_fqdn': 'node0',80 'pg_fqdn': 'node0',
79 'interface': 'juju-br0',81 'interface': 'juju-br0',
@@ -81,5 +83,6 @@
81 'label': 'node0',83 'label': 'node0',
82 'fabric_mode': 'host',84 'fabric_mode': 'host',
83 'neutron_alchemy_flags': False,85 'neutron_alchemy_flags': False,
86 'opsvm_ip': '127.0.0.1',
84 }87 }
85 self.assertEquals(expect, napi_ctxt())88 self.assertEquals(expect, napi_ctxt())
8689
=== modified file 'unit_tests/test_pg_gw_hooks.py'
--- unit_tests/test_pg_gw_hooks.py 2016-03-24 13:12:00 +0000
+++ unit_tests/test_pg_gw_hooks.py 2016-03-27 15:36:55 +0000
@@ -30,7 +30,8 @@
30 'ensure_mtu',30 'ensure_mtu',
31 'add_lcm_key',31 'add_lcm_key',
32 'determine_packages',32 'determine_packages',
33 'load_iptables'33 'load_iptables',
34 'director_cluster_ready'
34]35]
35NEUTRON_CONF_DIR = "/etc/neutron"36NEUTRON_CONF_DIR = "/etc/neutron"
3637
@@ -62,17 +63,12 @@
62 self.ensure_files.assert_called_with()63 self.ensure_files.assert_called_with()
63 self.add_lcm_key.assert_called_with()64 self.add_lcm_key.assert_called_with()
6465
65 def test_plumgrid_joined(self):66 def test_plumgrid_changed(self):
66 self._call_hook('plumgrid-relation-joined')67 self._call_hook('plumgrid-relation-changed')
68 self.director_cluster_ready.return_value = True
67 self.ensure_mtu.assert_called_with()69 self.ensure_mtu.assert_called_with()
68 self.ensure_files.assert_called_with()
69 self.add_lcm_key.assert_called_with()
70 self.CONFIGS.write_all.assert_called_with()70 self.CONFIGS.write_all.assert_called_with()
71 self.restart_pg.assert_called_with()
7271
73 def test_stop(self):72 def test_stop(self):
74 _pkgs = ['plumgrid-lxc', 'iovisor-dkms']
75 self._call_hook('stop')73 self._call_hook('stop')
76 self.stop_pg.assert_called_with()74 self.stop_pg.assert_called_with()
77 self.remove_iovisor.assert_called_with()
78 self.determine_packages.return_value = _pkgs
7975
=== modified file 'unit_tests/test_pg_gw_utils.py'
--- unit_tests/test_pg_gw_utils.py 2015-08-24 16:24:20 +0000
+++ unit_tests/test_pg_gw_utils.py 2016-03-27 15:36:55 +0000
@@ -53,7 +53,8 @@
53 confs = [nutils.PG_CONF,53 confs = [nutils.PG_CONF,
54 nutils.PG_HN_CONF,54 nutils.PG_HN_CONF,
55 nutils.PG_HS_CONF,55 nutils.PG_HS_CONF,
56 nutils.PG_IFCS_CONF]56 nutils.PG_IFCS_CONF,
57 nutils.OPS_CONF]
57 self.assertItemsEqual(_regconfs.configs, confs)58 self.assertItemsEqual(_regconfs.configs, confs)
5859
59 def test_resource_map(self):60 def test_resource_map(self):
@@ -69,6 +70,7 @@
69 (nutils.PG_CONF, ['plumgrid']),70 (nutils.PG_CONF, ['plumgrid']),
70 (nutils.PG_HN_CONF, ['plumgrid']),71 (nutils.PG_HN_CONF, ['plumgrid']),
71 (nutils.PG_HS_CONF, ['plumgrid']),72 (nutils.PG_HS_CONF, ['plumgrid']),
73 (nutils.OPS_CONF, ['plumgrid']),
72 (nutils.PG_IFCS_CONF, []),74 (nutils.PG_IFCS_CONF, []),
73 ])75 ])
74 self.assertEqual(expect, _restart_map)76 self.assertEqual(expect, _restart_map)

Subscribers

People subscribed via source and target branches