Merge lp:~junaidali/charms/trusty/plumgrid-director/custom-lxc into lp:charms/trusty/plumgrid-director

Proposed by Junaid Ali
Status: Merged
Merged at revision: 20
Proposed branch: lp:~junaidali/charms/trusty/plumgrid-director/custom-lxc
Merge into: lp:charms/trusty/plumgrid-director
Diff against target: 343 lines (+143/-25)
7 files modified
actions.yaml (+2/-0)
actions/actions.py (+40/-0)
config.yaml (+1/-12)
hooks/pg_dir_hooks.py (+15/-3)
hooks/pg_dir_utils.py (+80/-9)
templates/kilo/00-pg.conf (+2/-1)
templates/kilo/plumgrid.conf (+3/-0)
To merge this branch: bzr merge lp:~junaidali/charms/trusty/plumgrid-director/custom-lxc
Reviewer Review Type Date Requested Status
Review Queue (community) automated testing Needs Fixing
David Ames Pending
Review via email: mp+304250@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Review Queue (review-queue) wrote :

This item has failed automated testing! Results available here http://juju-ci.vapour.ws/job/charm-bundle-test-lxc/5469/

review: Needs Fixing (automated testing)
Revision history for this message
Review Queue (review-queue) wrote :

This item has failed automated testing! Results available here http://juju-ci.vapour.ws/job/charm-bundle-test-aws/5570/

review: Needs Fixing (automated testing)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'actions'
2=== added file 'actions.yaml'
3--- actions.yaml 1970-01-01 00:00:00 +0000
4+++ actions.yaml 2016-08-29 12:05:04 +0000
5@@ -0,0 +1,2 @@
6+restart:
7+ description: Restart the plumgrid-director unit. This action will restart related services.
8
9=== added file 'actions/actions.py'
10--- actions/actions.py 1970-01-01 00:00:00 +0000
11+++ actions/actions.py 2016-08-29 12:05:04 +0000
12@@ -0,0 +1,40 @@
13+#!/usr/bin/python
14+
15+import os
16+import sys
17+
18+sys.path.append('hooks/')
19+
20+from charmhelpers.core.hookenv import action_fail
21+from pg_dir_utils import (
22+ restart_pg
23+)
24+
25+
26+def restart(args):
27+ """Pause the Ceilometer services.
28+ @raises Exception should the service fail to stop.
29+ """
30+ restart_pg('lxc')
31+
32+
33+# A dictionary of all the defined actions to callables (which take
34+# parsed arguments).
35+ACTIONS = {"restart": restart}
36+
37+
38+def main(args):
39+ action_name = os.path.basename(args[0])
40+ try:
41+ action = ACTIONS[action_name]
42+ except KeyError:
43+ return "Action %s undefined" % action_name
44+ else:
45+ try:
46+ action(args)
47+ except Exception as e:
48+ action_fail(str(e))
49+
50+
51+if __name__ == "__main__":
52+ sys.exit(main(sys.argv))
53
54=== added symlink 'actions/restart'
55=== target is u'actions.py'
56=== modified file 'config.yaml'
57--- config.yaml 2016-05-04 06:47:43 +0000
58+++ config.yaml 2016-08-29 12:05:04 +0000
59@@ -17,24 +17,13 @@
60 description: Public SSH key of PLUMgrid LCM which is running PG-Tools.
61 mgmt-interface:
62 type: string
63- default: 'juju-br0'
64 description: The interface connected to PLUMgrid Managment network.
65- os-data-network:
66- type: string
67- default:
68- description: |
69- The IP address and netmask of the OpenStack Data network (e.g.,
70- 192.168.0.0/24)
71- .
72- This network will be used for tenant network traffic in overlay
73- networks.
74 fabric-interfaces:
75 default: 'MANAGEMENT'
76 type: string
77 description: |
78 Interfaces that will provide fabric connectivity on the director nodes.
79- Provided in form of json in a string. These interfaces have to be connected
80- to the os-data-network specified in the config. Default value is MANAGEMENT which
81+ Provided in form of json in a string. Default value is MANAGEMENT which
82 will configure the management interface as the fabric interface on each
83 director.
84 network-device-mtu:
85
86=== modified file 'hooks/pg_dir_hooks.py'
87--- hooks/pg_dir_hooks.py 2016-05-04 13:24:55 +0000
88+++ hooks/pg_dir_hooks.py 2016-08-29 12:05:04 +0000
89@@ -40,7 +40,9 @@
90 fabric_interface_changed,
91 load_iptables,
92 restart_on_change,
93- director_cluster_ready
94+ director_cluster_ready,
95+ disable_apparmor_libvirt,
96+ configure_pg_sources
97 )
98
99 hooks = Hooks()
100@@ -61,6 +63,7 @@
101 apt_install(pkg, options=['--force-yes'], fatal=True)
102 load_iovisor()
103 ensure_mtu()
104+ disable_apparmor_libvirt()
105 CONFIGS.write_all()
106
107
108@@ -73,6 +76,7 @@
109 if director_cluster_ready():
110 ensure_mtu()
111 CONFIGS.write_all()
112+ restart_pg('lxc')
113
114
115 @hooks.hook('plumgrid-relation-joined')
116@@ -135,6 +139,8 @@
117 charm_config.changed('iovisor-build')):
118 status_set('maintenance', 'Upgrading apt packages')
119 stop_pg()
120+ if charm_config.changed('install_sources'):
121+ configure_pg_sources()
122 configure_sources(update=True)
123 pkgs = determine_packages()
124 for pkg in pkgs:
125@@ -148,7 +154,7 @@
126 ensure_mtu()
127 CONFIGS.write_all()
128 if not service_running('plumgrid'):
129- restart_pg()
130+ restart_pg('lxc')
131
132
133 @hooks.hook('start')
134@@ -156,13 +162,18 @@
135 '''
136 This hook is run when the charm is started.
137 '''
138+ restart_pg('lxc')
139+ time.sleep(15)
140 if config('plumgrid-license-key') is not None:
141 count = 0
142- while (count < 10):
143+ while (count < 15):
144 if post_pg_license():
145 break
146 count += 1
147 time.sleep(15)
148+ if count == 15:
149+ raise ValueError("Error occurred while posting plumgrid license"
150+ "key. Please check plumgrid services.")
151
152
153 @hooks.hook('upgrade-charm')
154@@ -173,6 +184,7 @@
155 '''
156 ensure_mtu()
157 CONFIGS.write_all()
158+ restart_pg('lxc')
159
160
161 @hooks.hook('stop')
162
163=== modified file 'hooks/pg_dir_utils.py'
164--- hooks/pg_dir_utils.py 2016-05-01 02:16:59 +0000
165+++ hooks/pg_dir_utils.py 2016-08-29 12:05:04 +0000
166@@ -7,6 +7,7 @@
167 import time
168 import os
169 import json
170+import shlex
171 from collections import OrderedDict
172 from socket import gethostname as get_unit_hostname
173 from copy import deepcopy
174@@ -24,11 +25,10 @@
175 get_bridges,
176 get_bridge_nics,
177 is_ip,
178- is_address_in_network,
179- get_iface_addr
180 )
181 from charmhelpers.core.host import (
182 service_start,
183+ service_restart,
184 service_stop,
185 service_running,
186 path_hash,
187@@ -42,6 +42,7 @@
188 os_release,
189 )
190
191+SOURCES_LIST = '/etc/apt/sources.list'
192 LXC_CONF = '/etc/libvirt/lxc.conf'
193 TEMPLATES = 'templates/'
194 PG_LXC_DATA_PATH = '/var/lib/libvirt/filesystems/plumgrid-data'
195@@ -88,6 +89,22 @@
196 ])
197
198
199+def configure_pg_sources():
200+ '''
201+ Returns true if install sources is updated in sources.list file
202+ '''
203+ try:
204+ with open(SOURCES_LIST, 'r+') as sources:
205+ all_lines = sources.readlines()
206+ sources.seek(0)
207+ for i in (line for line in all_lines if "plumgrid" not in line):
208+ sources.write(i)
209+ sources.truncate()
210+ sources.close()
211+ except IOError:
212+ log('Unable to update /etc/apt/sources.list')
213+
214+
215 def determine_packages():
216 '''
217 Returns list of packages required by PLUMgrid director as specified
218@@ -144,7 +161,31 @@
219 return {cfg: rscs['services'] for cfg, rscs in resource_map().iteritems()}
220
221
222-def restart_pg():
223+def start_gateway():
224+ '''
225+ Brings up PE-gateway interface. Initial hack but will be solved when docker
226+ plumgrid-director package will be used.
227+ '''
228+ count = 0
229+ while (count < 7):
230+ cmd = 'ps aux | grep launch_metadata_helper'
231+ output = subprocess.check_output([cmd], shell=True)
232+ roots = 0
233+ v = shlex.split(output)
234+ for i in v:
235+ if i == 'root':
236+ roots += 1
237+ if roots < 3:
238+ stop_pg()
239+ time.sleep(3)
240+ service_start('plumgrid')
241+ else:
242+ break
243+ count += 1
244+ time.sleep(20)
245+
246+
247+def restart_pg(gateway=None):
248 '''
249 Stops and Starts PLUMgrid service after flushing iptables.
250 '''
251@@ -162,6 +203,8 @@
252 raise ValueError("plumgrid service couldn't be started")
253 else:
254 raise ValueError("libvirt-bin service couldn't be started")
255+ if gateway:
256+ start_gateway()
257 status_set('active', 'Unit is ready')
258
259
260@@ -207,7 +250,9 @@
261 Returns the managment interface.
262 '''
263 mgmt_interface = config('mgmt-interface')
264- if interface_exists(mgmt_interface):
265+ if not mgmt_interface:
266+ return get_iface_from_addr(unit_get('private-address'))
267+ elif mgmt_interface and interface_exists(mgmt_interface):
268 return mgmt_interface
269 else:
270 log('Provided managment interface %s does not exist'
271@@ -251,11 +296,7 @@
272 else:
273 raise ValueError('No fabric interface provided for node')
274 if interface_exists(node_fabric_interface):
275- if is_address_in_network(config('os-data-network'),
276- get_iface_addr(node_fabric_interface)[0]):
277- return node_fabric_interface
278- else:
279- raise ValueError('Fabric interface not in fabric network')
280+ return node_fabric_interface
281 else:
282 log('Provided fabric interface %s does not exist'
283 % node_fabric_interface)
284@@ -276,6 +317,36 @@
285 set_nic_mtu(fabric_interface, interface_mtu)
286
287
288+def disable_apparmor_libvirt():
289+ '''
290+ Disables Apparmor profile of libvirtd.
291+ '''
292+ apt_install('apparmor-utils')
293+ apt_install('cgroup-bin')
294+ _exec_cmd(['sudo', 'aa-disable', '/usr/sbin/libvirtd'],
295+ error_msg='Error disabling AppArmor profile of libvirtd')
296+ disable_apparmor()
297+ service_restart('libvirt-bin')
298+
299+
300+def disable_apparmor():
301+ '''
302+ Disables Apparmor security for lxc.
303+ '''
304+ try:
305+ f = open(LXC_CONF, 'r')
306+ except IOError:
307+ log('Libvirt not installed yet')
308+ return 0
309+ filedata = f.read()
310+ f.close()
311+ newdata = filedata.replace("security_driver = \"apparmor\"",
312+ "#security_driver = \"apparmor\"")
313+ f = open(LXC_CONF, 'w')
314+ f.write(newdata)
315+ f.close()
316+
317+
318 def _exec_cmd(cmd=None, error_msg='Command exited with ERRORs', fatal=False):
319 '''
320 Function to execute any bash command on the node.
321
322=== modified file 'templates/kilo/00-pg.conf'
323--- templates/kilo/00-pg.conf 2016-04-06 16:27:37 +0000
324+++ templates/kilo/00-pg.conf 2016-08-29 12:05:04 +0000
325@@ -1,2 +1,3 @@
326 $template ls_json,"{{'{'}}{{'%'}}timestamp:::date-rfc3339,jsonf:@timestamp%,%source:::jsonf:@source_host%,%msg:::json%}"
327-:syslogtag,isequal,"pg:" @{{ opsvm_ip }}:6000;ls_json
328+if $syslogtag == 'pg:' and not ($msg contains 'dht_cli_') then @{{ opsvm_ip }}:6000;ls_json
329+:msg, contains, "VM Interface Stats" ~
330
331=== modified file 'templates/kilo/plumgrid.conf'
332--- templates/kilo/plumgrid.conf 2015-08-10 10:06:33 +0000
333+++ templates/kilo/plumgrid.conf 2016-08-29 12:05:04 +0000
334@@ -5,6 +5,9 @@
335 plumgrid_rsync_port=2222
336 plumgrid_rest_addr=0.0.0.0:9180
337 fabric_mode={{ fabric_mode }}
338+plumgrid_syslog_ng_ip={{ plumgrid_syslog_ng_ip }}
339+plumgrid_syslog_ng_port={{ plumgrid_syslog_ng_port }}
340+plumgrid_monitor_interval={{ plumgrid_monitor_interval }}
341 start_plumgrid_iovisor=yes
342 start_plumgrid=`/opt/pg/scripts/pg_is_director.sh $plumgrid_ip`
343 location=

Subscribers

People subscribed via source and target branches

to all changes: