Merge lp:~hopem/maas-deployer/lp1487146 into lp:~maas-deployers/maas-deployer/next

Proposed by Edward Hope-Morley
Status: Merged
Merged at revision: 19
Proposed branch: lp:~hopem/maas-deployer/lp1487146
Merge into: lp:~maas-deployers/maas-deployer/next
Diff against target: 106 lines (+37/-40)
1 file modified
maas_deployer/vmaas/engine.py (+37/-40)
To merge this branch: bzr merge lp:~hopem/maas-deployer/lp1487146
Reviewer Review Type Date Requested Status
Ante Karamatić (community) Approve
Review via email: mp+268634@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ante Karamatić (ivoks) :
review: Approve
lp:~hopem/maas-deployer/lp1487146 updated
20. By Edward Hope-Morley

fix lint issue

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'maas_deployer/vmaas/engine.py'
2--- maas_deployer/vmaas/engine.py 2015-08-14 17:11:59 +0000
3+++ maas_deployer/vmaas/engine.py 2015-08-21 14:09:33 +0000
4@@ -9,11 +9,12 @@
5 import json
6 import logging
7 import os
8-import subprocess
9-from subprocess import CalledProcessError
10 import sys
11 import time
12
13+from subprocess import CalledProcessError
14+
15+
16 from maas_deployer.vmaas import (
17 vm,
18 util,
19@@ -140,53 +141,49 @@
20 time.sleep(1)
21 continue
22
23+ def _get_api_key_from_cloudinit(self, user, addr):
24+ # Now get the api key
25+ rcmd = [r'grep "+ apikey=" %s| tail -n 1| sed -r "s/.+=(.+)/\1/"' %
26+ ('/var/log/cloud-init-output.log')]
27+ cmd = self.get_ssh_cmd(user, addr, remote_cmd=rcmd)
28+ stdout, _ = util.execc(cmd=cmd)
29+ self.api_key = stdout
30+
31+ @util.retry_on_exception(exc_tuple=[CalledProcessError])
32+ def wait_for_cloudinit_finished(self, maas_config, maas_ip):
33+ log.debug("Logging into maas host '%s'", (maas_ip))
34+ # Now get the api key
35+ msg = "MAAS controller is now configured"
36+ cloudinitlog = '/var/log/cloud-init-output.log'
37+ rcmd = ['grep "%s" %s' %
38+ (msg, cloudinitlog)]
39+ cmd = self.get_ssh_cmd(maas_config['user'], maas_ip,
40+ remote_cmd=rcmd)
41+ out, err = util.execc(cmd=cmd, fatal=False)
42+ if out and not err:
43+ self._get_api_key_from_cloudinit(maas_config['user'], maas_ip)
44+ return
45+
46+ log.info("Waiting for cloud-init to complete - this usual takes "
47+ "several minutes")
48+ rcmd = ['grep -m 1 "%s" <(sudo tail -n 1 -F %s)' %
49+ (msg, cloudinitlog)]
50+ cmd = self.get_ssh_cmd(maas_config['user'], maas_ip,
51+ remote_cmd=rcmd)
52+ util.execc(cmd=cmd)
53+ self._get_api_key_from_cloudinit(maas_config['user'], maas_ip)
54+
55 def wait_for_maas_installation(self, maas_config):
56 """
57 Polls the ssh console to wait for the MAAS installation to
58 complete.
59 """
60- finished = False
61-
62 log.debug("Waiting for MAAS vm to come up for ssh..")
63 maas_ip = self._get_maas_ip_address(maas_config)
64
65 self.ip_addr = maas_ip
66-
67- try:
68- curr_action = "Installing MAAS via cloud-init"
69- spinner = itertools.cycle(['|', '/', '-', '\\'])
70-
71- self.wait_for_vm_ready(maas_config['user'], maas_ip)
72- log.debug("Logging into maas host '%s'", (maas_ip))
73-
74- remote_cmd = ['sudo', 'tail', '-F',
75- '/var/log/cloud-init-output.log']
76- cmd = self.get_ssh_cmd(maas_config['user'], maas_ip,
77- remote_cmd=remote_cmd)
78- process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
79- for c in iter(lambda: process.stdout.readline(), ''):
80- c = c.strip()
81- if c.startswith('+ apikey='):
82- self.api_key = c.split('=')[1]
83-
84- if c.find('MAAS controller is now configured') >= 0:
85- sys.stdout.write(' %s ... Done\r\n' % curr_action)
86- sys.stdout.flush()
87- finished = True
88- process.terminate()
89- break
90-
91- # Display a spinner to show that progress is being made.
92- sys.stdout.write(' %s ... %s' % (curr_action,
93- spinner.next()))
94- sys.stdout.flush()
95- sys.stdout.write('\r')
96- except CalledProcessError as e:
97- # An exception when process.terminate() is invoked because
98- # virsh console will return -1. A pty is required to
99- # gracefully exit, so we work around it
100- if not finished:
101- raise e
102+ self.wait_for_vm_ready(maas_config['user'], maas_ip)
103+ self.wait_for_cloudinit_finished(maas_config, maas_ip)
104
105 def _get_maas_ip_address(self, maas_config):
106 """Attempts to get the IP address from the maas_config dict.

Subscribers

People subscribed via source and target branches