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

Proposed by Bilal Baqar
Status: Merged
Merged at revision: 27
Proposed branch: lp:~bbaqar/charms/trusty/plumgrid-director/ip-sort
Merge into: lp:~plumgrid-team/charms/trusty/plumgrid-director/trunk
Diff against target: 312 lines (+106/-37)
6 files modified
hooks/pg_dir_context.py (+11/-7)
hooks/pg_dir_hooks.py (+13/-1)
hooks/pg_dir_utils.py (+71/-22)
templates/kilo/hosts (+1/-1)
unit_tests/test_pg_dir_context.py (+8/-5)
unit_tests/test_pg_dir_hooks.py (+2/-1)
To merge this branch: bzr merge lp:~bbaqar/charms/trusty/plumgrid-director/ip-sort
Reviewer Review Type Date Requested Status
Abdullah Khan Wazir Approve
Nabeel Afzal Approve
Review via email: mp+288564@code.launchpad.net

Description of the change

Sorted the director IPs.
Ticket: [CFB-829]

To post a comment you must log in.
Revision history for this message
Nabeel Afzal (nabeel-afzal) :
review: Approve
Revision history for this message
Abdullah Khan Wazir (abdullah-khan) wrote :

Looks good.

review: Approve
22. By Bilal Baqar

Fixing sleep

23. By Bilal Baqar

Fixing sleep

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hooks/pg_dir_context.py'
--- hooks/pg_dir_context.py 2016-01-26 18:44:19 +0000
+++ hooks/pg_dir_context.py 2016-03-13 03:51:15 +0000
@@ -3,6 +3,10 @@
3# This file contains the class that generates context3# This file contains the class that generates context
4# for PLUMgrid template files.4# for PLUMgrid template files.
55
6import re
7from charmhelpers.contrib.openstack import context
8from charmhelpers.contrib.openstack.utils import get_host_ip
9from charmhelpers.contrib.network.ip import get_address_in_network
6from charmhelpers.core.hookenv import (10from charmhelpers.core.hookenv import (
7 config,11 config,
8 unit_get,12 unit_get,
@@ -12,12 +16,10 @@
12 related_units,16 related_units,
13 relation_get,17 relation_get,
14)18)
15from charmhelpers.contrib.openstack import context19from socket import (
16from charmhelpers.contrib.openstack.utils import get_host_ip20 gethostname,
17from charmhelpers.contrib.network.ip import get_address_in_network21 getfqdn
1822)
19import re
20from socket import gethostname as get_unit_hostname
2123
2224
23def _pg_dir_ips():25def _pg_dir_ips():
@@ -71,6 +73,7 @@
71 pg_dir_ips = _pg_dir_ips()73 pg_dir_ips = _pg_dir_ips()
72 pg_dir_ips.append(str(get_address_in_network(network=None,74 pg_dir_ips.append(str(get_address_in_network(network=None,
73 fallback=get_host_ip(unit_get('private-address')))))75 fallback=get_host_ip(unit_get('private-address')))))
76 pg_dir_ips = sorted(pg_dir_ips)
74 pg_ctxt['director_ips'] = pg_dir_ips77 pg_ctxt['director_ips'] = pg_dir_ips
75 pg_dir_ips_string = ''78 pg_dir_ips_string = ''
76 single_ip = True79 single_ip = True
@@ -82,8 +85,9 @@
82 pg_dir_ips_string = pg_dir_ips_string + ',' + str(ip)85 pg_dir_ips_string = pg_dir_ips_string + ',' + str(ip)
83 pg_ctxt['director_ips_string'] = pg_dir_ips_string86 pg_ctxt['director_ips_string'] = pg_dir_ips_string
84 pg_ctxt['virtual_ip'] = conf['plumgrid-virtual-ip']87 pg_ctxt['virtual_ip'] = conf['plumgrid-virtual-ip']
85 unit_hostname = get_unit_hostname()88 unit_hostname = gethostname()
86 pg_ctxt['pg_hostname'] = unit_hostname89 pg_ctxt['pg_hostname'] = unit_hostname
90 pg_ctxt['pg_fqdn'] = getfqdn()
87 from pg_dir_utils import get_mgmt_interface, get_fabric_interface91 from pg_dir_utils import get_mgmt_interface, get_fabric_interface
88 pg_ctxt['interface'] = get_mgmt_interface()92 pg_ctxt['interface'] = get_mgmt_interface()
89 pg_ctxt['fabric_interface'] = get_fabric_interface()93 pg_ctxt['fabric_interface'] = get_fabric_interface()
9094
=== modified file 'hooks/pg_dir_hooks.py'
--- hooks/pg_dir_hooks.py 2016-01-14 12:39:52 +0000
+++ hooks/pg_dir_hooks.py 2016-03-13 03:51:15 +0000
@@ -7,6 +7,7 @@
77
8import sys8import sys
9import time9import time
10
10from charmhelpers.core.hookenv import (11from charmhelpers.core.hookenv import (
11 Hooks,12 Hooks,
12 UnregisteredHookError,13 UnregisteredHookError,
@@ -30,7 +31,8 @@
30 ensure_mtu,31 ensure_mtu,
31 add_lcm_key,32 add_lcm_key,
32 post_pg_license,33 post_pg_license,
33 fabric_interface_changed34 fabric_interface_changed,
35 load_iptables
34)36)
3537
36hooks = Hooks()38hooks = Hooks()
@@ -42,6 +44,7 @@
42 '''44 '''
43 Install hook is run when the charm is first deployed on a node.45 Install hook is run when the charm is first deployed on a node.
44 '''46 '''
47 load_iptables()
45 configure_sources(update=True)48 configure_sources(update=True)
46 pkgs = determine_packages()49 pkgs = determine_packages()
47 for pkg in pkgs:50 for pkg in pkgs:
@@ -109,6 +112,15 @@
109 time.sleep(15)112 time.sleep(15)
110113
111114
115@hooks.hook('upgrade-charm')
116def upgrade_charm():
117 '''
118 This hook is run when the charm is upgraded
119 '''
120 load_iptables()
121 CONFIGS.write_all()
122
123
112@hooks.hook('stop')124@hooks.hook('stop')
113def stop():125def stop():
114 '''126 '''
115127
=== modified file 'hooks/pg_dir_utils.py'
--- hooks/pg_dir_utils.py 2016-03-03 20:56:40 +0000
+++ hooks/pg_dir_utils.py 2016-03-13 03:51:15 +0000
@@ -2,8 +2,18 @@
22
3# This file contains functions used by the hooks to deploy PLUMgrid Director.3# This file contains functions used by the hooks to deploy PLUMgrid Director.
44
5import pg_dir_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.openstack import templating
15from charmhelpers.core.host import set_nic_mtu
16from charmhelpers.contrib.storage.linux.ceph import modprobe
7from charmhelpers.core.hookenv import (17from charmhelpers.core.hookenv import (
8 log,18 log,
9 config,19 config,
@@ -17,32 +27,22 @@
17 is_address_in_network,27 is_address_in_network,
18 get_iface_addr28 get_iface_addr
19)29)
30from charmhelpers.core.host import (
31 service_start,
32 service_stop,
33)
20from charmhelpers.fetch import (34from charmhelpers.fetch import (
21 apt_cache35 apt_cache,
36 apt_install
22)37)
23from charmhelpers.contrib.openstack import templating
24from charmhelpers.core.host import set_nic_mtu
25from collections import OrderedDict
26from charmhelpers.contrib.storage.linux.ceph import modprobe
27from charmhelpers.contrib.openstack.utils import (38from charmhelpers.contrib.openstack.utils import (
28 os_release,39 os_release,
29)40)
30from charmhelpers.core.host import (
31 service_start,
32 service_stop,
33)
34from socket import gethostname as get_unit_hostname
35import pg_dir_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'
44PG_LXC_PATH = '/var/lib/libvirt/filesystems/plumgrid'45PG_LXC_PATH = '/var/lib/libvirt/filesystems/plumgrid'
45
46PG_CONF = '%s/conf/pg/plumgrid.conf' % PG_LXC_DATA_PATH46PG_CONF = '%s/conf/pg/plumgrid.conf' % PG_LXC_DATA_PATH
47PG_KA_CONF = '%s/conf/etc/keepalived.conf' % PG_LXC_DATA_PATH47PG_KA_CONF = '%s/conf/etc/keepalived.conf' % PG_LXC_DATA_PATH
48PG_DEF_CONF = '%s/conf/pg/nginx.conf' % PG_LXC_DATA_PATH48PG_DEF_CONF = '%s/conf/pg/nginx.conf' % PG_LXC_DATA_PATH
@@ -52,7 +52,6 @@
52AUTH_KEY_PATH = '%s/root/.ssh/authorized_keys' % PG_LXC_DATA_PATH52AUTH_KEY_PATH = '%s/root/.ssh/authorized_keys' % PG_LXC_DATA_PATH
53TEMP_LICENSE_FILE = '/tmp/license'53TEMP_LICENSE_FILE = '/tmp/license'
5454
55
56BASE_RESOURCE_MAP = OrderedDict([55BASE_RESOURCE_MAP = OrderedDict([
57 (PG_KA_CONF, {56 (PG_KA_CONF, {
58 'services': ['plumgrid'],57 'services': ['plumgrid'],
@@ -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(2)
146 _exec_cmd(cmd=['iptables', '-F'])
147 service_start('plumgrid')144 service_start('plumgrid')
148 time.sleep(5)145 time.sleep(5)
149146
@@ -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
@@ -341,3 +338,55 @@
341 log('No change in PLUMgrid License')338 log('No change in PLUMgrid License')
342 return 0339 return 0
343 return 1340 return 1
341
342
343def load_iptables():
344 '''
345 Loads iptables rules to allow all PLUMgrid communication.
346 '''
347 network = get_cidr_from_iface(get_mgmt_interface())
348 if network:
349 _exec_cmd(['sudo', 'iptables', '-A', 'INPUT', '-p', 'tcp',
350 '-j', 'ACCEPT', '-s', network, '-d',
351 network, '-m', 'state', '--state', 'NEW'])
352 _exec_cmd(['sudo', 'iptables', '-A', 'INPUT', '-p', 'udp', '-j',
353 'ACCEPT', '-s', network, '-d', network,
354 '-m', 'state', '--state', 'NEW'])
355 _exec_cmd(['sudo', 'iptables', '-I', 'INPUT', '-s', network,
356 '-d', '224.0.0.18/32', '-j', 'ACCEPT'])
357 _exec_cmd(['sudo', 'iptables', '-I', 'INPUT', '-p', 'vrrp', '-j',
358 'ACCEPT'])
359 _exec_cmd(['sudo', 'iptables', '-A', 'INPUT', '-p', 'tcp', '-j',
360 'ACCEPT', '-d', config('plumgrid-virtual-ip'), '-m',
361 'state', '--state', 'NEW'])
362 apt_install('iptables-persistent')
363
364
365def get_cidr_from_iface(interface):
366 '''
367 Determines Network CIDR from interface.
368 '''
369 if not interface:
370 return None
371 apt_install('ohai')
372 try:
373 os_info = subprocess.check_output(['ohai', '-l', 'fatal'])
374 except OSError:
375 log('Unable to get operating system information')
376 return None
377 try:
378 os_info_json = json.loads(os_info)
379 except ValueError:
380 log('Unable to determine network')
381 return None
382 device = os_info_json['network']['interfaces'].get(interface)
383 if device is not None:
384 if device.get('routes'):
385 routes = device['routes']
386 for net in routes:
387 if 'scope' in net:
388 return net.get('destination')
389 else:
390 return None
391 else:
392 return None
344393
=== added symlink 'hooks/upgrade-charm'
=== target is u'pg_dir_hooks.py'
=== modified file 'templates/kilo/hosts'
--- templates/kilo/hosts 2015-07-29 18:11:14 +0000
+++ templates/kilo/hosts 2016-03-13 03:51:15 +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_dir_context.py'
--- unit_tests/test_pg_dir_context.py 2016-01-26 22:08:24 +0000
+++ unit_tests/test_pg_dir_context.py 2016-03-13 03:51:15 +0000
@@ -8,7 +8,8 @@
8 'config',8 'config',
9 'unit_get',9 'unit_get',
10 'get_host_ip',10 'get_host_ip',
11 'get_unit_hostname',11 'gethostname',
12 'getfqdn'
12]13]
1314
1415
@@ -71,7 +72,8 @@
71 _npa.side_effect = mock_npa72 _npa.side_effect = mock_npa
72 _unit_get.return_value = '192.168.100.201'73 _unit_get.return_value = '192.168.100.201'
73 _unit_priv_ip.return_value = '192.168.100.201'74 _unit_priv_ip.return_value = '192.168.100.201'
74 self.get_unit_hostname.return_value = 'node0'75 self.gethostname.return_value = 'node0'
76 self.getfqdn.return_value = 'node0.maas'
75 self.get_host_ip.return_value = '192.168.100.201'77 self.get_host_ip.return_value = '192.168.100.201'
76 _pg_dir_ips.return_value = ['192.168.100.202', '192.168.100.203']78 _pg_dir_ips.return_value = ['192.168.100.202', '192.168.100.203']
77 _mgmt_int.return_value = 'juju-br0'79 _mgmt_int.return_value = 'juju-br0'
@@ -87,14 +89,15 @@
87 'neutron_url': 'https://None:9696',89 'neutron_url': 'https://None:9696',
88 'virtual_ip': '192.168.100.250',90 'virtual_ip': '192.168.100.250',
89 'pg_hostname': 'node0',91 'pg_hostname': 'node0',
92 'pg_fqdn': 'node0.maas',
90 'interface': 'juju-br0',93 'interface': 'juju-br0',
91 'fabric_interface': 'juju-br0',94 'fabric_interface': 'juju-br0',
92 'label': 'node0',95 'label': 'node0',
93 'fabric_mode': 'host',96 'fabric_mode': 'host',
94 'virtual_router_id': '250',97 'virtual_router_id': '250',
95 'director_ips': ['192.168.100.202', '192.168.100.203',98 'director_ips': ['192.168.100.201', '192.168.100.202',
96 '192.168.100.201'],99 '192.168.100.203'],
97 'director_ips_string':100 'director_ips_string':
98 '192.168.100.202,192.168.100.203,192.168.100.201',101 '192.168.100.201,192.168.100.202,192.168.100.203',
99 }102 }
100 self.assertEquals(expect, napi_ctxt())103 self.assertEquals(expect, napi_ctxt())
101104
=== modified file 'unit_tests/test_pg_dir_hooks.py'
--- unit_tests/test_pg_dir_hooks.py 2016-03-03 20:56:40 +0000
+++ unit_tests/test_pg_dir_hooks.py 2016-03-13 03:51:15 +0000
@@ -31,7 +31,8 @@
31 'add_lcm_key',31 'add_lcm_key',
32 'determine_packages',32 'determine_packages',
33 'post_pg_license',33 'post_pg_license',
34 'config'34 'config',
35 'load_iptables'
35]36]
36NEUTRON_CONF_DIR = "/etc/neutron"37NEUTRON_CONF_DIR = "/etc/neutron"
3738

Subscribers

People subscribed via source and target branches