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

Proposed by Bilal Baqar
Status: Merged
Merged at revision: 22
Proposed branch: lp:~bbaqar/charms/trusty/plumgrid-gateway/ip-sort
Merge into: lp:~plumgrid-team/charms/trusty/plumgrid-gateway/trunk
Diff against target: 276 lines (+89/-28)
6 files modified
hooks/pg_gw_context.py (+9/-5)
hooks/pg_gw_hooks.py (+12/-1)
hooks/pg_gw_utils.py (+61/-19)
templates/kilo/hosts (+1/-1)
unit_tests/test_pg_gw_context.py (+5/-2)
unit_tests/test_pg_gw_hooks.py (+1/-0)
To merge this branch: bzr merge lp:~bbaqar/charms/trusty/plumgrid-gateway/ip-sort
Reviewer Review Type Date Requested Status
Abdullah Khan Wazir Approve
Review via email: mp+288719@code.launchpad.net

Description of the change

Sorted the director IPs and setting required iptables rules
Ticket: [CFB-829]

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

Local commit

20. By Bilal Baqar

Adding restart in upgrade hook

Revision history for this message
Abdullah Khan Wazir (abdullah-khan) :
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 2015-11-22 03:26:23 +0000
+++ hooks/pg_gw_context.py 2016-03-14 04:18:28 +0000
@@ -3,14 +3,17 @@
3# This file contains the class that generates context for3# This file contains the class that generates context for
4# PLUMgrid template files.4# PLUMgrid template files.
55
6from charmhelpers.contrib.openstack import context
7from charmhelpers.contrib.openstack.utils import get_host_ip
6from charmhelpers.core.hookenv import (8from charmhelpers.core.hookenv import (
7 relation_ids,9 relation_ids,
8 related_units,10 related_units,
9 relation_get,11 relation_get,
10)12)
11from charmhelpers.contrib.openstack import context13from socket import (
12from charmhelpers.contrib.openstack.utils import get_host_ip14 gethostname,
13from socket import gethostname as get_unit_hostname15 getfqdn
16)
1417
1518
16def _pg_dir_settings():19def _pg_dir_settings():
@@ -60,7 +63,7 @@
60 return {}63 return {}
6164
62 pg_dir_ips = ''65 pg_dir_ips = ''
63 pg_dir_settings = _pg_dir_settings()66 pg_dir_settings = sorted(_pg_dir_settings())
64 single_ip = True67 single_ip = True
65 for ip in pg_dir_settings:68 for ip in pg_dir_settings:
66 if single_ip:69 if single_ip:
@@ -69,8 +72,9 @@
69 else:72 else:
70 pg_dir_ips = pg_dir_ips + ',' + str(ip)73 pg_dir_ips = pg_dir_ips + ',' + str(ip)
71 pg_ctxt['local_ip'] = pg_dir_ips74 pg_ctxt['local_ip'] = pg_dir_ips
72 unit_hostname = get_unit_hostname()75 unit_hostname = gethostname()
73 pg_ctxt['pg_hostname'] = unit_hostname76 pg_ctxt['pg_hostname'] = unit_hostname
77 pg_ctxt['pg_fqdn'] = getfqdn()
74 from pg_gw_utils import (78 from pg_gw_utils import (
75 get_mgmt_interface,79 get_mgmt_interface,
76 get_gw_interfaces,80 get_gw_interfaces,
7781
=== modified file 'hooks/pg_gw_hooks.py'
--- hooks/pg_gw_hooks.py 2015-11-22 03:26:23 +0000
+++ hooks/pg_gw_hooks.py 2016-03-14 04:18:28 +0000
@@ -30,7 +30,8 @@
30 remove_iovisor,30 remove_iovisor,
31 ensure_mtu,31 ensure_mtu,
32 add_lcm_key,32 add_lcm_key,
33 fabric_interface_changed33 fabric_interface_changed,
34 load_iptables,
34)35)
3536
36hooks = Hooks()37hooks = Hooks()
@@ -42,6 +43,7 @@
42 '''43 '''
43 Install hook is run when the charm is first deployed on a node.44 Install hook is run when the charm is first deployed on a node.
44 '''45 '''
46 load_iptables()
45 configure_sources(update=True)47 configure_sources(update=True)
46 pkgs = determine_packages()48 pkgs = determine_packages()
47 for pkg in pkgs:49 for pkg in pkgs:
@@ -98,6 +100,15 @@
98 restart_pg()100 restart_pg()
99101
100102
103@hooks.hook('upgrade-charm')
104def upgrade_charm():
105 load_iptables()
106 ensure_mtu()
107 ensure_files()
108 CONFIGS.write_all()
109 restart_pg()
110
111
101@hooks.hook('stop')112@hooks.hook('stop')
102def stop():113def stop():
103 '''114 '''
104115
=== modified file 'hooks/pg_gw_utils.py'
--- hooks/pg_gw_utils.py 2015-11-22 03:26:23 +0000
+++ hooks/pg_gw_utils.py 2016-03-14 04:18:28 +0000
@@ -2,8 +2,18 @@
22
3# This file contains functions used by the hooks to deploy PLUMgrid Gateway.3# This file contains functions used by the hooks to deploy PLUMgrid Gateway.
44
5import pg_gw_context
6import subprocess
7import time
8import os
9import json
10from collections import OrderedDict
11from socket import gethostname as get_unit_hostname
12from copy import deepcopy
5from charmhelpers.contrib.openstack.neutron import neutron_plugin_attribute13from charmhelpers.contrib.openstack.neutron import neutron_plugin_attribute
6from copy import deepcopy14from charmhelpers.contrib.storage.linux.ceph import modprobe
15from charmhelpers.core.host import set_nic_mtu
16from charmhelpers.contrib.openstack import templating
7from charmhelpers.core.hookenv import (17from charmhelpers.core.hookenv import (
8 log,18 log,
9 config,19 config,
@@ -22,33 +32,22 @@
22 service_stop,32 service_stop,
23)33)
24from charmhelpers.fetch import (34from charmhelpers.fetch import (
25 apt_cache35 apt_cache,
36 apt_install
26)37)
27from charmhelpers.contrib.storage.linux.ceph import modprobe
28from charmhelpers.core.host import set_nic_mtu
29from charmhelpers.contrib.openstack import templating
30from collections import OrderedDict
31from charmhelpers.contrib.openstack.utils import (38from charmhelpers.contrib.openstack.utils import (
32 os_release,39 os_release,
33)40)
34from socket import gethostname as get_unit_hostname
35import pg_gw_context
36import subprocess
37import time
38import os
39import json
4041
41LXC_CONF = "/etc/libvirt/lxc.conf"42LXC_CONF = "/etc/libvirt/lxc.conf"
42TEMPLATES = 'templates/'43TEMPLATES = 'templates/'
43PG_LXC_DATA_PATH = '/var/lib/libvirt/filesystems/plumgrid-data'44PG_LXC_DATA_PATH = '/var/lib/libvirt/filesystems/plumgrid-data'
44
45PG_CONF = '%s/conf/pg/plumgrid.conf' % PG_LXC_DATA_PATH45PG_CONF = '%s/conf/pg/plumgrid.conf' % PG_LXC_DATA_PATH
46PG_HN_CONF = '%s/conf/etc/hostname' % PG_LXC_DATA_PATH46PG_HN_CONF = '%s/conf/etc/hostname' % PG_LXC_DATA_PATH
47PG_HS_CONF = '%s/conf/etc/hosts' % PG_LXC_DATA_PATH47PG_HS_CONF = '%s/conf/etc/hosts' % PG_LXC_DATA_PATH
48PG_IFCS_CONF = '%s/conf/pg/ifcs.conf' % PG_LXC_DATA_PATH48PG_IFCS_CONF = '%s/conf/pg/ifcs.conf' % PG_LXC_DATA_PATH
49AUTH_KEY_PATH = '%s/root/.ssh/authorized_keys' % PG_LXC_DATA_PATH49AUTH_KEY_PATH = '%s/root/.ssh/authorized_keys' % PG_LXC_DATA_PATH
50IFC_LIST_GW = '/var/run/plumgrid/lxc/ifc_list_gateway'50IFC_LIST_GW = '/var/run/plumgrid/lxc/ifc_list_gateway'
51
52SUDOERS_CONF = '/etc/sudoers.d/ifc_ctl_sudoers'51SUDOERS_CONF = '/etc/sudoers.d/ifc_ctl_sudoers'
5352
54BASE_RESOURCE_MAP = OrderedDict([53BASE_RESOURCE_MAP = OrderedDict([
@@ -141,9 +140,7 @@
141 '''140 '''
142 Stops and Starts PLUMgrid service after flushing iptables.141 Stops and Starts PLUMgrid service after flushing iptables.
143 '''142 '''
144 service_stop('plumgrid')143 stop_pg()
145 time.sleep(30)
146 _exec_cmd(cmd=['iptables', '-F'])
147 service_start('plumgrid')144 service_start('plumgrid')
148 time.sleep(30)145 time.sleep(30)
149146
@@ -153,7 +150,7 @@
153 Stops PLUMgrid service.150 Stops PLUMgrid service.
154 '''151 '''
155 service_stop('plumgrid')152 service_stop('plumgrid')
156 time.sleep(2)153 time.sleep(30)
157154
158155
159def load_iovisor():156def load_iovisor():
@@ -168,7 +165,7 @@
168 Removes iovisor kernel module.165 Removes iovisor kernel module.
169 '''166 '''
170 _exec_cmd(cmd=['rmmod', 'iovisor'],167 _exec_cmd(cmd=['rmmod', 'iovisor'],
171 error_msg='Error Loading Iovisor Kernel Module')168 error_msg='Error Removing IOVisor Kernel Module')
172 time.sleep(1)169 time.sleep(1)
173170
174171
@@ -327,3 +324,48 @@
327 fa.write('\n')324 fa.write('\n')
328 fa.close()325 fa.close()
329 return 1326 return 1
327
328
329def load_iptables():
330 '''
331 Loads iptables rules to allow all PLUMgrid communication.
332 '''
333 network = get_cidr_from_iface(get_mgmt_interface())
334 if network:
335 _exec_cmd(['sudo', 'iptables', '-A', 'INPUT', '-p', 'tcp',
336 '-j', 'ACCEPT', '-s', network, '-d',
337 network, '-m', 'state', '--state', 'NEW'])
338 _exec_cmd(['sudo', 'iptables', '-A', 'INPUT', '-p', 'udp', '-j',
339 'ACCEPT', '-s', network, '-d', network,
340 '-m', 'state', '--state', 'NEW'])
341 apt_install('iptables-persistent')
342
343
344def get_cidr_from_iface(interface):
345 '''
346 Determines Network CIDR from interface.
347 '''
348 if not interface:
349 return None
350 apt_install('ohai')
351 try:
352 os_info = subprocess.check_output(['ohai', '-l', 'fatal'])
353 except OSError:
354 log('Unable to get operating system information')
355 return None
356 try:
357 os_info_json = json.loads(os_info)
358 except ValueError:
359 log('Unable to determine network')
360 return None
361 device = os_info_json['network']['interfaces'].get(interface)
362 if device is not None:
363 if device.get('routes'):
364 routes = device['routes']
365 for net in routes:
366 if 'scope' in net:
367 return net.get('destination')
368 else:
369 return None
370 else:
371 return None
330372
=== added symlink 'hooks/upgrade-charm'
=== target is u'pg_gw_hooks.py'
=== modified file 'templates/kilo/hosts'
--- templates/kilo/hosts 2015-07-29 18:23:55 +0000
+++ templates/kilo/hosts 2016-03-14 04:18:28 +0000
@@ -1,5 +1,5 @@
1127.0.0.1 localhost1127.0.0.1 localhost
2127.0.1.1 {{ pg_hostname }}2127.0.1.1 {{ pg_fqdn }} {{ pg_hostname }}
33
4# The following lines are desirable for IPv6 capable hosts4# The following lines are desirable for IPv6 capable hosts
5::1 ip6-localhost ip6-loopback5::1 ip6-localhost ip6-loopback
66
=== modified file 'unit_tests/test_pg_gw_context.py'
--- unit_tests/test_pg_gw_context.py 2015-11-22 03:26:23 +0000
+++ unit_tests/test_pg_gw_context.py 2016-03-14 04:18:28 +0000
@@ -5,7 +5,8 @@
5import charmhelpers5import charmhelpers
66
7TO_PATCH = [7TO_PATCH = [
8 'get_unit_hostname',8 'gethostname',
9 'getfqdn'
9]10]
1011
1112
@@ -55,7 +56,8 @@
55 _npa.side_effect = mock_npa56 _npa.side_effect = mock_npa
56 _unit_get.return_value = '192.168.100.201'57 _unit_get.return_value = '192.168.100.201'
57 _unit_priv_ip.return_value = '192.168.100.201'58 _unit_priv_ip.return_value = '192.168.100.201'
58 self.get_unit_hostname.return_value = 'node0'59 self.gethostname.return_value = 'node0'
60 self.getfqdn.return_value = 'node0'
59 _is_clus.return_value = False61 _is_clus.return_value = False
60 _config_flag.return_value = False62 _config_flag.return_value = False
61 _pg_dir_settings.return_value = {'pg_dir_ip': '192.168.100.201'}63 _pg_dir_settings.return_value = {'pg_dir_ip': '192.168.100.201'}
@@ -73,6 +75,7 @@
73 'neutron_security_groups': None,75 'neutron_security_groups': None,
74 'neutron_url': 'https://192.168.100.201:9696',76 'neutron_url': 'https://192.168.100.201:9696',
75 'pg_hostname': 'node0',77 'pg_hostname': 'node0',
78 'pg_fqdn': 'node0',
76 'interface': 'juju-br0',79 'interface': 'juju-br0',
77 'fabric_interface': 'juju-br0',80 'fabric_interface': 'juju-br0',
78 'label': 'node0',81 'label': 'node0',
7982
=== modified file 'unit_tests/test_pg_gw_hooks.py'
--- unit_tests/test_pg_gw_hooks.py 2016-03-03 21:49:53 +0000
+++ unit_tests/test_pg_gw_hooks.py 2016-03-14 04:18:28 +0000
@@ -30,6 +30,7 @@
30 'ensure_mtu',30 'ensure_mtu',
31 'add_lcm_key',31 'add_lcm_key',
32 'determine_packages',32 'determine_packages',
33 'load_iptables'
33]34]
34NEUTRON_CONF_DIR = "/etc/neutron"35NEUTRON_CONF_DIR = "/etc/neutron"
3536

Subscribers

People subscribed via source and target branches