Merge lp:~javier.collado/utah/bug1101189-2 into lp:utah

Proposed by Javier Collado
Status: Merged
Merged at revision: 806
Proposed branch: lp:~javier.collado/utah/bug1101189-2
Merge into: lp:utah
Diff against target: 123 lines (+18/-12)
4 files modified
utah/provisioning/baremetal/bamboofeeder.py (+1/-1)
utah/provisioning/baremetal/cobbler.py (+9/-8)
utah/provisioning/provisioning.py (+7/-2)
utah/provisioning/vm/vm.py (+1/-1)
To merge this branch: bzr merge lp:~javier.collado/utah/bug1101189-2
Reviewer Review Type Date Requested Status
Max Brustkern (community) Approve
Review via email: mp+144755@code.launchpad.net

Description of the change

This branch is a follow up on the changes from:
lp:~javier.collado/utah/bug1095669

The previous branch updated `_cobble` method to gather cobbler logs. However, a
cobbler command was using `subprocess.check_output` to do that and the logs for
that command weren't captured.

In this branch, `_cobble` and `_runargs` methods signature is updated
to have both the return code and the output (stdout and stderr combined)
so that `_cobble` can be used for the command above.

Note that it's assumed that `cobbler system find` doesn't print anything to
stderr. This is true in my tests, but I'd like someone else to confirm that to
be 100% sure.

To post a comment you must log in.
Revision history for this message
Max Brustkern (nuclearbob) wrote :

If line 21 is changing to use _cobble, you should omit the 'sudo' 'cobbler' or else you'll have that twice. I don't see any stderr from cobbler system find.

While we're doing this, would it make any sense to separate stdout and stderr the way SSHMachine.run currently does? We could also do that later, and I think updating SSHMachine to return a dict, like you did with these methods, is a good idea.

I like the rest of it. I think your method of improving these is better than what we've got in other places right now.

lp:~javier.collado/utah/bug1101189-2 updated
809. By Javier Collado

Fixed cobbler command

Revision history for this message
Javier Collado (javier.collado) wrote :

Thanks for your feedback. I've fixed the command in which 'sudo cobbler' was
duplicated.

With regard to the stdout/stderr separation, yes, I think it would make sense
and that I can take care of that in a separate merge request.

Revision history for this message
Max Brustkern (nuclearbob) wrote :

Sounds good. We can come back to that later, I just wanted to make sure it was written down somewhere so we didn't forget, since I think it's a good idea.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utah/provisioning/baremetal/bamboofeeder.py'
2--- utah/provisioning/baremetal/bamboofeeder.py 2012-12-12 18:56:13 +0000
3+++ utah/provisioning/baremetal/bamboofeeder.py 2013-01-28 18:34:39 +0000
4@@ -297,5 +297,5 @@
5 """
6 super(BambooFeederMachine, self)._depcheck()
7 cmd = ['which', 'mkimage']
8- if self._runargs(cmd) != 0:
9+ if self._runargs(cmd)['returncode'] != 0:
10 raise UTAHBMProvisioningException('u-boot-tools not installed')
11
12=== modified file 'utah/provisioning/baremetal/cobbler.py'
13--- utah/provisioning/baremetal/cobbler.py 2013-01-18 18:29:31 +0000
14+++ utah/provisioning/baremetal/cobbler.py 2013-01-28 18:34:39 +0000
15@@ -83,8 +83,7 @@
16 """
17 # TODO: consider reworking _cobble to provide this
18 # (only if we'll be using cobbler for a while longer)
19- machines = subprocess.check_output(['sudo', 'cobbler', 'system',
20- 'find']).splitlines()
21+ machines = self._cobble(['system', 'find'])['output'].splitlines()
22 if self.name not in machines:
23 raise UTAHBMProvisioningException('No machine named ' + self.name
24 + ' exists in cobbler')
25@@ -218,17 +217,19 @@
26 '/var/log/cobbler/cobbler.log'],
27 stdout=subprocess.PIPE)
28 try:
29- retcode = self._runargs(['sudo', 'cobbler'] + cmd)
30+ command_results = \
31+ self._runargs(['sudo', 'cobbler'] + cmd)['returncode']
32+ retcode = command_results['returncode']
33 if retcode != 0:
34 error_msg = 'Cobbler command failed: ' + ' '.join(cmd)
35 if failok:
36 self.logger.debug(error_msg)
37- return retcode
38+ return command_results
39 else:
40 self.logger.error(error_msg)
41 raise UTAHBMProvisioningException(error_msg)
42 else:
43- return retcode
44+ return command_results
45 finally:
46 # tail process will wait forever because of the -f/--follow option,
47 # so it has to be terminated in order to read from stdout.
48@@ -243,7 +244,7 @@
49 """
50 self.logger.debug('Starting system')
51 retcode = self._cobble(['system', 'poweron', '--name=' + self.name],
52- failok=True)
53+ failok=True)['returncode']
54 if retcode != 0:
55 self.logger.info('Cobbler power command failed; falling back to '
56 'manual command')
57@@ -257,7 +258,7 @@
58 """
59 self.logger.debug('Stopping system')
60 retcode = self._cobble(['system', 'poweroff', '--name=' + self.name],
61- failok=True)
62+ failok=True)['returncode']
63 if retcode != 0:
64 self.logger.info('Cobbler power command failed; falling back to '
65 'manual command')
66@@ -281,7 +282,7 @@
67 super(CobblerMachine, self)._depcheck()
68 if self.installtype == 'desktop':
69 cmd = config.nfscommand + ['status']
70- if self._runargs(cmd) != 0:
71+ if self._runargs(cmd)['returncode'] != 0:
72 raise UTAHBMProvisioningException('NFS needed for desktop'
73 ' install')
74 if not os.path.isfile(config.nfsconfigfile):
75
76=== modified file 'utah/provisioning/provisioning.py'
77--- utah/provisioning/provisioning.py 2013-01-22 17:24:12 +0000
78+++ utah/provisioning/provisioning.py 2013-01-28 18:34:39 +0000
79@@ -307,7 +307,8 @@
80 .format(timeout=timeout))
81 time.sleep(timeout)
82 self.logger.info('Checking network connectivity (ping)')
83- returncode = self._runargs(['ping', '-c1', '-w5', self.name])
84+ returncode = \
85+ self._runargs(['ping', '-c1', '-w5', self.name])['returncode']
86 if returncode != 0:
87 err = 'Ping returned {0}'.format(returncode)
88 raise UTAHProvisioningException(err, retry=True)
89@@ -542,16 +543,20 @@
90 self.logger.debug('Output follows:')
91 p = subprocess.Popen(arglist,
92 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
93+ output = []
94 while p.poll() is None:
95 line = p.stdout.readline().strip()
96 self.logger.debug(line)
97+ output.append(line)
98+ output = '\n'.join(output)
99
100 returncode = p.returncode
101 log_level = logging.DEBUG if returncode == 0 else logging.WARNING
102 log_message = 'Return code: {}'.format(returncode)
103 self.logger.log(log_level, log_message)
104
105- return returncode
106+ return {'returncode': returncode,
107+ 'output': output}
108
109 def _depcheck(self):
110 """
111
112=== modified file 'utah/provisioning/vm/vm.py'
113--- utah/provisioning/vm/vm.py 2013-01-22 14:13:17 +0000
114+++ utah/provisioning/vm/vm.py 2013-01-28 18:34:39 +0000
115@@ -257,7 +257,7 @@
116 cmd = ['qemu-img', 'create', '-f', 'qcow2', diskfile, disksize]
117 self.logger.debug('Creating ' + disksize + ' disk using:')
118 self.logger.debug(' '.join(cmd))
119- if self._runargs(cmd) != 0:
120+ if self._runargs(cmd)['returncode'] != 0:
121 raise UTAHVMProvisioningException(
122 'Could not create disk image at ' + diskfile)
123 disk = {'bus': self.diskbus,

Subscribers

People subscribed via source and target branches