Merge lp:~bbaqar/charms/trusty/plumgrid-director/ip-sort into lp:~plumgrid-team/charms/trusty/plumgrid-director/trunk
- Trusty Tahr (14.04)
- ip-sort
- Merge into 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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Abdullah Khan Wazir | Approve | ||
Nabeel Afzal | Approve | ||
Review via email: mp+288564@code.launchpad.net |
Commit message
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
- 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
1 | === modified file 'hooks/pg_dir_context.py' | |||
2 | --- hooks/pg_dir_context.py 2016-01-26 18:44:19 +0000 | |||
3 | +++ hooks/pg_dir_context.py 2016-03-13 03:51:15 +0000 | |||
4 | @@ -3,6 +3,10 @@ | |||
5 | 3 | # This file contains the class that generates context | 3 | # This file contains the class that generates context |
6 | 4 | # for PLUMgrid template files. | 4 | # for PLUMgrid template files. |
7 | 5 | 5 | ||
8 | 6 | import re | ||
9 | 7 | from charmhelpers.contrib.openstack import context | ||
10 | 8 | from charmhelpers.contrib.openstack.utils import get_host_ip | ||
11 | 9 | from charmhelpers.contrib.network.ip import get_address_in_network | ||
12 | 6 | from charmhelpers.core.hookenv import ( | 10 | from charmhelpers.core.hookenv import ( |
13 | 7 | config, | 11 | config, |
14 | 8 | unit_get, | 12 | unit_get, |
15 | @@ -12,12 +16,10 @@ | |||
16 | 12 | related_units, | 16 | related_units, |
17 | 13 | relation_get, | 17 | relation_get, |
18 | 14 | ) | 18 | ) |
25 | 15 | from charmhelpers.contrib.openstack import context | 19 | from socket import ( |
26 | 16 | from charmhelpers.contrib.openstack.utils import get_host_ip | 20 | gethostname, |
27 | 17 | from charmhelpers.contrib.network.ip import get_address_in_network | 21 | getfqdn |
28 | 18 | 22 | ) | |
23 | 19 | import re | ||
24 | 20 | from socket import gethostname as get_unit_hostname | ||
29 | 21 | 23 | ||
30 | 22 | 24 | ||
31 | 23 | def _pg_dir_ips(): | 25 | def _pg_dir_ips(): |
32 | @@ -71,6 +73,7 @@ | |||
33 | 71 | pg_dir_ips = _pg_dir_ips() | 73 | pg_dir_ips = _pg_dir_ips() |
34 | 72 | pg_dir_ips.append(str(get_address_in_network(network=None, | 74 | pg_dir_ips.append(str(get_address_in_network(network=None, |
35 | 73 | fallback=get_host_ip(unit_get('private-address'))))) | 75 | fallback=get_host_ip(unit_get('private-address'))))) |
36 | 76 | pg_dir_ips = sorted(pg_dir_ips) | ||
37 | 74 | pg_ctxt['director_ips'] = pg_dir_ips | 77 | pg_ctxt['director_ips'] = pg_dir_ips |
38 | 75 | pg_dir_ips_string = '' | 78 | pg_dir_ips_string = '' |
39 | 76 | single_ip = True | 79 | single_ip = True |
40 | @@ -82,8 +85,9 @@ | |||
41 | 82 | pg_dir_ips_string = pg_dir_ips_string + ',' + str(ip) | 85 | pg_dir_ips_string = pg_dir_ips_string + ',' + str(ip) |
42 | 83 | pg_ctxt['director_ips_string'] = pg_dir_ips_string | 86 | pg_ctxt['director_ips_string'] = pg_dir_ips_string |
43 | 84 | pg_ctxt['virtual_ip'] = conf['plumgrid-virtual-ip'] | 87 | pg_ctxt['virtual_ip'] = conf['plumgrid-virtual-ip'] |
45 | 85 | unit_hostname = get_unit_hostname() | 88 | unit_hostname = gethostname() |
46 | 86 | pg_ctxt['pg_hostname'] = unit_hostname | 89 | pg_ctxt['pg_hostname'] = unit_hostname |
47 | 90 | pg_ctxt['pg_fqdn'] = getfqdn() | ||
48 | 87 | from pg_dir_utils import get_mgmt_interface, get_fabric_interface | 91 | from pg_dir_utils import get_mgmt_interface, get_fabric_interface |
49 | 88 | pg_ctxt['interface'] = get_mgmt_interface() | 92 | pg_ctxt['interface'] = get_mgmt_interface() |
50 | 89 | pg_ctxt['fabric_interface'] = get_fabric_interface() | 93 | pg_ctxt['fabric_interface'] = get_fabric_interface() |
51 | 90 | 94 | ||
52 | === modified file 'hooks/pg_dir_hooks.py' | |||
53 | --- hooks/pg_dir_hooks.py 2016-01-14 12:39:52 +0000 | |||
54 | +++ hooks/pg_dir_hooks.py 2016-03-13 03:51:15 +0000 | |||
55 | @@ -7,6 +7,7 @@ | |||
56 | 7 | 7 | ||
57 | 8 | import sys | 8 | import sys |
58 | 9 | import time | 9 | import time |
59 | 10 | |||
60 | 10 | from charmhelpers.core.hookenv import ( | 11 | from charmhelpers.core.hookenv import ( |
61 | 11 | Hooks, | 12 | Hooks, |
62 | 12 | UnregisteredHookError, | 13 | UnregisteredHookError, |
63 | @@ -30,7 +31,8 @@ | |||
64 | 30 | ensure_mtu, | 31 | ensure_mtu, |
65 | 31 | add_lcm_key, | 32 | add_lcm_key, |
66 | 32 | post_pg_license, | 33 | post_pg_license, |
68 | 33 | fabric_interface_changed | 34 | fabric_interface_changed, |
69 | 35 | load_iptables | ||
70 | 34 | ) | 36 | ) |
71 | 35 | 37 | ||
72 | 36 | hooks = Hooks() | 38 | hooks = Hooks() |
73 | @@ -42,6 +44,7 @@ | |||
74 | 42 | ''' | 44 | ''' |
75 | 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. |
76 | 44 | ''' | 46 | ''' |
77 | 47 | load_iptables() | ||
78 | 45 | configure_sources(update=True) | 48 | configure_sources(update=True) |
79 | 46 | pkgs = determine_packages() | 49 | pkgs = determine_packages() |
80 | 47 | for pkg in pkgs: | 50 | for pkg in pkgs: |
81 | @@ -109,6 +112,15 @@ | |||
82 | 109 | time.sleep(15) | 112 | time.sleep(15) |
83 | 110 | 113 | ||
84 | 111 | 114 | ||
85 | 115 | @hooks.hook('upgrade-charm') | ||
86 | 116 | def upgrade_charm(): | ||
87 | 117 | ''' | ||
88 | 118 | This hook is run when the charm is upgraded | ||
89 | 119 | ''' | ||
90 | 120 | load_iptables() | ||
91 | 121 | CONFIGS.write_all() | ||
92 | 122 | |||
93 | 123 | |||
94 | 112 | @hooks.hook('stop') | 124 | @hooks.hook('stop') |
95 | 113 | def stop(): | 125 | def stop(): |
96 | 114 | ''' | 126 | ''' |
97 | 115 | 127 | ||
98 | === modified file 'hooks/pg_dir_utils.py' | |||
99 | --- hooks/pg_dir_utils.py 2016-03-03 20:56:40 +0000 | |||
100 | +++ hooks/pg_dir_utils.py 2016-03-13 03:51:15 +0000 | |||
101 | @@ -2,8 +2,18 @@ | |||
102 | 2 | 2 | ||
103 | 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. |
104 | 4 | 4 | ||
105 | 5 | import pg_dir_context | ||
106 | 6 | import subprocess | ||
107 | 7 | import time | ||
108 | 8 | import os | ||
109 | 9 | import json | ||
110 | 10 | from collections import OrderedDict | ||
111 | 11 | from socket import gethostname as get_unit_hostname | ||
112 | 12 | from copy import deepcopy | ||
113 | 5 | from charmhelpers.contrib.openstack.neutron import neutron_plugin_attribute | 13 | from charmhelpers.contrib.openstack.neutron import neutron_plugin_attribute |
115 | 6 | from copy import deepcopy | 14 | from charmhelpers.contrib.openstack import templating |
116 | 15 | from charmhelpers.core.host import set_nic_mtu | ||
117 | 16 | from charmhelpers.contrib.storage.linux.ceph import modprobe | ||
118 | 7 | from charmhelpers.core.hookenv import ( | 17 | from charmhelpers.core.hookenv import ( |
119 | 8 | log, | 18 | log, |
120 | 9 | config, | 19 | config, |
121 | @@ -17,32 +27,22 @@ | |||
122 | 17 | is_address_in_network, | 27 | is_address_in_network, |
123 | 18 | get_iface_addr | 28 | get_iface_addr |
124 | 19 | ) | 29 | ) |
125 | 30 | from charmhelpers.core.host import ( | ||
126 | 31 | service_start, | ||
127 | 32 | service_stop, | ||
128 | 33 | ) | ||
129 | 20 | from charmhelpers.fetch import ( | 34 | from charmhelpers.fetch import ( |
131 | 21 | apt_cache | 35 | apt_cache, |
132 | 36 | apt_install | ||
133 | 22 | ) | 37 | ) |
134 | 23 | from charmhelpers.contrib.openstack import templating | ||
135 | 24 | from charmhelpers.core.host import set_nic_mtu | ||
136 | 25 | from collections import OrderedDict | ||
137 | 26 | from charmhelpers.contrib.storage.linux.ceph import modprobe | ||
138 | 27 | from charmhelpers.contrib.openstack.utils import ( | 38 | from charmhelpers.contrib.openstack.utils import ( |
139 | 28 | os_release, | 39 | os_release, |
140 | 29 | ) | 40 | ) |
141 | 30 | from charmhelpers.core.host import ( | ||
142 | 31 | service_start, | ||
143 | 32 | service_stop, | ||
144 | 33 | ) | ||
145 | 34 | from socket import gethostname as get_unit_hostname | ||
146 | 35 | import pg_dir_context | ||
147 | 36 | import subprocess | ||
148 | 37 | import time | ||
149 | 38 | import os | ||
150 | 39 | import json | ||
151 | 40 | 41 | ||
152 | 41 | LXC_CONF = '/etc/libvirt/lxc.conf' | 42 | LXC_CONF = '/etc/libvirt/lxc.conf' |
153 | 42 | TEMPLATES = 'templates/' | 43 | TEMPLATES = 'templates/' |
154 | 43 | PG_LXC_DATA_PATH = '/var/lib/libvirt/filesystems/plumgrid-data' | 44 | PG_LXC_DATA_PATH = '/var/lib/libvirt/filesystems/plumgrid-data' |
155 | 44 | PG_LXC_PATH = '/var/lib/libvirt/filesystems/plumgrid' | 45 | PG_LXC_PATH = '/var/lib/libvirt/filesystems/plumgrid' |
156 | 45 | |||
157 | 46 | PG_CONF = '%s/conf/pg/plumgrid.conf' % PG_LXC_DATA_PATH | 46 | PG_CONF = '%s/conf/pg/plumgrid.conf' % PG_LXC_DATA_PATH |
158 | 47 | PG_KA_CONF = '%s/conf/etc/keepalived.conf' % PG_LXC_DATA_PATH | 47 | PG_KA_CONF = '%s/conf/etc/keepalived.conf' % PG_LXC_DATA_PATH |
159 | 48 | PG_DEF_CONF = '%s/conf/pg/nginx.conf' % PG_LXC_DATA_PATH | 48 | PG_DEF_CONF = '%s/conf/pg/nginx.conf' % PG_LXC_DATA_PATH |
160 | @@ -52,7 +52,6 @@ | |||
161 | 52 | AUTH_KEY_PATH = '%s/root/.ssh/authorized_keys' % PG_LXC_DATA_PATH | 52 | AUTH_KEY_PATH = '%s/root/.ssh/authorized_keys' % PG_LXC_DATA_PATH |
162 | 53 | TEMP_LICENSE_FILE = '/tmp/license' | 53 | TEMP_LICENSE_FILE = '/tmp/license' |
163 | 54 | 54 | ||
164 | 55 | |||
165 | 56 | BASE_RESOURCE_MAP = OrderedDict([ | 55 | BASE_RESOURCE_MAP = OrderedDict([ |
166 | 57 | (PG_KA_CONF, { | 56 | (PG_KA_CONF, { |
167 | 58 | 'services': ['plumgrid'], | 57 | 'services': ['plumgrid'], |
168 | @@ -141,9 +140,7 @@ | |||
169 | 141 | ''' | 140 | ''' |
170 | 142 | Stops and Starts PLUMgrid service after flushing iptables. | 141 | Stops and Starts PLUMgrid service after flushing iptables. |
171 | 143 | ''' | 142 | ''' |
175 | 144 | service_stop('plumgrid') | 143 | stop_pg() |
173 | 145 | time.sleep(2) | ||
174 | 146 | _exec_cmd(cmd=['iptables', '-F']) | ||
176 | 147 | service_start('plumgrid') | 144 | service_start('plumgrid') |
177 | 148 | time.sleep(5) | 145 | time.sleep(5) |
178 | 149 | 146 | ||
179 | @@ -168,7 +165,7 @@ | |||
180 | 168 | Removes iovisor kernel module. | 165 | Removes iovisor kernel module. |
181 | 169 | ''' | 166 | ''' |
182 | 170 | _exec_cmd(cmd=['rmmod', 'iovisor'], | 167 | _exec_cmd(cmd=['rmmod', 'iovisor'], |
184 | 171 | error_msg='Error Loading IOVisor Kernel Module') | 168 | error_msg='Error Removing IOVisor Kernel Module') |
185 | 172 | time.sleep(1) | 169 | time.sleep(1) |
186 | 173 | 170 | ||
187 | 174 | 171 | ||
188 | @@ -341,3 +338,55 @@ | |||
189 | 341 | log('No change in PLUMgrid License') | 338 | log('No change in PLUMgrid License') |
190 | 342 | return 0 | 339 | return 0 |
191 | 343 | return 1 | 340 | return 1 |
192 | 341 | |||
193 | 342 | |||
194 | 343 | def load_iptables(): | ||
195 | 344 | ''' | ||
196 | 345 | Loads iptables rules to allow all PLUMgrid communication. | ||
197 | 346 | ''' | ||
198 | 347 | network = get_cidr_from_iface(get_mgmt_interface()) | ||
199 | 348 | if network: | ||
200 | 349 | _exec_cmd(['sudo', 'iptables', '-A', 'INPUT', '-p', 'tcp', | ||
201 | 350 | '-j', 'ACCEPT', '-s', network, '-d', | ||
202 | 351 | network, '-m', 'state', '--state', 'NEW']) | ||
203 | 352 | _exec_cmd(['sudo', 'iptables', '-A', 'INPUT', '-p', 'udp', '-j', | ||
204 | 353 | 'ACCEPT', '-s', network, '-d', network, | ||
205 | 354 | '-m', 'state', '--state', 'NEW']) | ||
206 | 355 | _exec_cmd(['sudo', 'iptables', '-I', 'INPUT', '-s', network, | ||
207 | 356 | '-d', '224.0.0.18/32', '-j', 'ACCEPT']) | ||
208 | 357 | _exec_cmd(['sudo', 'iptables', '-I', 'INPUT', '-p', 'vrrp', '-j', | ||
209 | 358 | 'ACCEPT']) | ||
210 | 359 | _exec_cmd(['sudo', 'iptables', '-A', 'INPUT', '-p', 'tcp', '-j', | ||
211 | 360 | 'ACCEPT', '-d', config('plumgrid-virtual-ip'), '-m', | ||
212 | 361 | 'state', '--state', 'NEW']) | ||
213 | 362 | apt_install('iptables-persistent') | ||
214 | 363 | |||
215 | 364 | |||
216 | 365 | def get_cidr_from_iface(interface): | ||
217 | 366 | ''' | ||
218 | 367 | Determines Network CIDR from interface. | ||
219 | 368 | ''' | ||
220 | 369 | if not interface: | ||
221 | 370 | return None | ||
222 | 371 | apt_install('ohai') | ||
223 | 372 | try: | ||
224 | 373 | os_info = subprocess.check_output(['ohai', '-l', 'fatal']) | ||
225 | 374 | except OSError: | ||
226 | 375 | log('Unable to get operating system information') | ||
227 | 376 | return None | ||
228 | 377 | try: | ||
229 | 378 | os_info_json = json.loads(os_info) | ||
230 | 379 | except ValueError: | ||
231 | 380 | log('Unable to determine network') | ||
232 | 381 | return None | ||
233 | 382 | device = os_info_json['network']['interfaces'].get(interface) | ||
234 | 383 | if device is not None: | ||
235 | 384 | if device.get('routes'): | ||
236 | 385 | routes = device['routes'] | ||
237 | 386 | for net in routes: | ||
238 | 387 | if 'scope' in net: | ||
239 | 388 | return net.get('destination') | ||
240 | 389 | else: | ||
241 | 390 | return None | ||
242 | 391 | else: | ||
243 | 392 | return None | ||
244 | 344 | 393 | ||
245 | === added symlink 'hooks/upgrade-charm' | |||
246 | === target is u'pg_dir_hooks.py' | |||
247 | === modified file 'templates/kilo/hosts' | |||
248 | --- templates/kilo/hosts 2015-07-29 18:11:14 +0000 | |||
249 | +++ templates/kilo/hosts 2016-03-13 03:51:15 +0000 | |||
250 | @@ -1,5 +1,5 @@ | |||
251 | 1 | 127.0.0.1 localhost | 1 | 127.0.0.1 localhost |
253 | 2 | 127.0.1.1 {{ pg_hostname }} | 2 | 127.0.1.1 {{ pg_fqdn }} {{ pg_hostname }} |
254 | 3 | 3 | ||
255 | 4 | # The following lines are desirable for IPv6 capable hosts | 4 | # The following lines are desirable for IPv6 capable hosts |
256 | 5 | ::1 ip6-localhost ip6-loopback | 5 | ::1 ip6-localhost ip6-loopback |
257 | 6 | 6 | ||
258 | === modified file 'unit_tests/test_pg_dir_context.py' | |||
259 | --- unit_tests/test_pg_dir_context.py 2016-01-26 22:08:24 +0000 | |||
260 | +++ unit_tests/test_pg_dir_context.py 2016-03-13 03:51:15 +0000 | |||
261 | @@ -8,7 +8,8 @@ | |||
262 | 8 | 'config', | 8 | 'config', |
263 | 9 | 'unit_get', | 9 | 'unit_get', |
264 | 10 | 'get_host_ip', | 10 | 'get_host_ip', |
266 | 11 | 'get_unit_hostname', | 11 | 'gethostname', |
267 | 12 | 'getfqdn' | ||
268 | 12 | ] | 13 | ] |
269 | 13 | 14 | ||
270 | 14 | 15 | ||
271 | @@ -71,7 +72,8 @@ | |||
272 | 71 | _npa.side_effect = mock_npa | 72 | _npa.side_effect = mock_npa |
273 | 72 | _unit_get.return_value = '192.168.100.201' | 73 | _unit_get.return_value = '192.168.100.201' |
274 | 73 | _unit_priv_ip.return_value = '192.168.100.201' | 74 | _unit_priv_ip.return_value = '192.168.100.201' |
276 | 74 | self.get_unit_hostname.return_value = 'node0' | 75 | self.gethostname.return_value = 'node0' |
277 | 76 | self.getfqdn.return_value = 'node0.maas' | ||
278 | 75 | self.get_host_ip.return_value = '192.168.100.201' | 77 | self.get_host_ip.return_value = '192.168.100.201' |
279 | 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'] |
280 | 77 | _mgmt_int.return_value = 'juju-br0' | 79 | _mgmt_int.return_value = 'juju-br0' |
281 | @@ -87,14 +89,15 @@ | |||
282 | 87 | 'neutron_url': 'https://None:9696', | 89 | 'neutron_url': 'https://None:9696', |
283 | 88 | 'virtual_ip': '192.168.100.250', | 90 | 'virtual_ip': '192.168.100.250', |
284 | 89 | 'pg_hostname': 'node0', | 91 | 'pg_hostname': 'node0', |
285 | 92 | 'pg_fqdn': 'node0.maas', | ||
286 | 90 | 'interface': 'juju-br0', | 93 | 'interface': 'juju-br0', |
287 | 91 | 'fabric_interface': 'juju-br0', | 94 | 'fabric_interface': 'juju-br0', |
288 | 92 | 'label': 'node0', | 95 | 'label': 'node0', |
289 | 93 | 'fabric_mode': 'host', | 96 | 'fabric_mode': 'host', |
290 | 94 | 'virtual_router_id': '250', | 97 | 'virtual_router_id': '250', |
293 | 95 | 'director_ips': ['192.168.100.202', '192.168.100.203', | 98 | 'director_ips': ['192.168.100.201', '192.168.100.202', |
294 | 96 | '192.168.100.201'], | 99 | '192.168.100.203'], |
295 | 97 | 'director_ips_string': | 100 | 'director_ips_string': |
297 | 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', |
298 | 99 | } | 102 | } |
299 | 100 | self.assertEquals(expect, napi_ctxt()) | 103 | self.assertEquals(expect, napi_ctxt()) |
300 | 101 | 104 | ||
301 | === modified file 'unit_tests/test_pg_dir_hooks.py' | |||
302 | --- unit_tests/test_pg_dir_hooks.py 2016-03-03 20:56:40 +0000 | |||
303 | +++ unit_tests/test_pg_dir_hooks.py 2016-03-13 03:51:15 +0000 | |||
304 | @@ -31,7 +31,8 @@ | |||
305 | 31 | 'add_lcm_key', | 31 | 'add_lcm_key', |
306 | 32 | 'determine_packages', | 32 | 'determine_packages', |
307 | 33 | 'post_pg_license', | 33 | 'post_pg_license', |
309 | 34 | 'config' | 34 | 'config', |
310 | 35 | 'load_iptables' | ||
311 | 35 | ] | 36 | ] |
312 | 36 | NEUTRON_CONF_DIR = "/etc/neutron" | 37 | NEUTRON_CONF_DIR = "/etc/neutron" |
313 | 37 | 38 |
Looks good.