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

Proposed by Javier Collado
Status: Merged
Approved by: Javier Collado
Approved revision: 803
Merged at revision: 804
Proposed branch: lp:~javier.collado/utah/bug1101189
Merge into: lp:utah
Diff against target: 42 lines (+21/-10)
1 file modified
utah/provisioning/baremetal/cobbler.py (+21/-10)
To merge this branch: bzr merge lp:~javier.collado/utah/bug1101189
Reviewer Review Type Date Requested Status
Joe Talbott (community) Approve
Review via email: mp+143890@code.launchpad.net

Description of the change

This branch captures cobbler log using a `tail -f` subprocess against
`/var/log/cobbler/cobbler.log` (this file name is hard coded, since I'm not
sure if it's worth to make it configurable). The subprocess output is read in a
finally clause, so it's executed whatever happens in the cobbler command
(exception raised or value returned).

An example using the python interpreter follows. Note that the command succeeds
in the shell (return code 0), but in the cobbler log there's an internal error.
This is the kind of problem that this merge is attempting to make easier to
detect:

m._cobble(['system', 'add', '--name=a_name'])
rovisioning.baremetal.cobbler.CobblerMachine object at 0x357cf90>> ignored
DEBUG:root:Running command: sudo cobbler system add --name=a_name
DEBUG:root:Output follows:
DEBUG:root:
DEBUG:root:Return code: 0
DEBUG:root:Cobbler log follows:
Fri Jan 18 15:12:13 2013 - DEBUG | REMOTE CLI Authorized; user(?)
Fri Jan 18 15:12:13 2013 - DEBUG | get_item; ['system', 'a_name']
Fri Jan 18 15:12:13 2013 - DEBUG | done with get_item; ['system', 'a_name']
Fri Jan 18 15:12:13 2013 - INFO | Exception occured: <class 'cobbler.cexceptions.CX'>
Fri Jan 18 15:12:13 2013 - INFO | Exception value: 'internal error, unknown system name a_name'
Fri Jan 18 15:12:13 2013 - INFO | Exception Info:
  File "/usr/lib/python2.7/dist-packages/cobbler/remote.py", line 862, in xapi_object_edit
    handle = self.get_item_handle(object_type, object_name)
   File "/usr/lib/python2.7/dist-packages/cobbler/remote.py", line 655, in get_item_handle
    raise CX("internal error, unknown %s name %s" % (what,name))

Fri Jan 18 15:12:13 2013 - INFO | REMOTE new_item(system); user(<DIRECT>)
Fri Jan 18 15:12:13 2013 - DEBUG | REMOTE CLI Authorized; user(?)
Fri Jan 18 15:12:13 2013 - INFO | REMOTE modify_item(system); user(<DIRECT>); object_id(___NEW___system::V22dUEnj9W4rovypns4Wm5
QUlDbzbVIAAQ==); attribute(in_place)
Fri Jan 18 15:12:13 2013 - DEBUG | REMOTE CLI Authorized; user(?)
Fri Jan 18 15:12:13 2013 - INFO | REMOTE modify_item(system); user(<DIRECT>); object_id(___NEW___system::V22dUEnj9W4rovypns4Wm5
QUlDbzbVIAAQ==); attribute(name)
Fri Jan 18 15:12:13 2013 - DEBUG | REMOTE CLI Authorized; user(?)
Fri Jan 18 15:12:13 2013 - INFO | REMOTE modify_item(system); user(<DIRECT>); object_id(___NEW___system::V22dUEnj9W4rovypns4Wm5
QUlDbzbVIAAQ==); attribute(modify_interface)
Fri Jan 18 15:12:13 2013 - DEBUG | REMOTE CLI Authorized; user(?)
Fri Jan 18 15:12:13 2013 - INFO | REMOTE save_item(system); user(<DIRECT>); object_id(___NEW___system::V22dUEnj9W4rovypns4Wm5QU
lDbzbVIAAQ==)
Fri Jan 18 15:12:13 2013 - DEBUG | REMOTE CLI Authorized; user(?)
Fri Jan 18 15:12:13 2013 - INFO | add_item(system); ['a_name']
Fri Jan 18 15:12:13 2013 - DEBUG | get_items; ['system']
Fri Jan 18 15:12:13 2013 - DEBUG | done with get_items; ['system']

To post a comment you must log in.
Revision history for this message
Joe Talbott (joetalbott) wrote :

This looks good to me.

review: Approve
lp:~javier.collado/utah/bug1101189 updated
803. By Javier Collado

Fixed typo

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utah/provisioning/baremetal/cobbler.py'
2--- utah/provisioning/baremetal/cobbler.py 2012-12-12 18:56:13 +0000
3+++ utah/provisioning/baremetal/cobbler.py 2013-01-18 18:31:22 +0000
4@@ -213,17 +213,28 @@
5 Pull out all cobbler commands so that we can later support changing
6 users, remote login, not sudo, etc.
7 """
8- retcode = self._runargs(['sudo', 'cobbler'] + cmd)
9- if retcode != 0:
10- error_msg = 'Cobbler command failed: ' + ' '.join(cmd)
11- if failok:
12- self.logger.debug(error_msg)
13+ tail_process = \
14+ subprocess.Popen(['tail', '-n0', '-f',
15+ '/var/log/cobbler/cobbler.log'],
16+ stdout=subprocess.PIPE)
17+ try:
18+ retcode = self._runargs(['sudo', 'cobbler'] + cmd)
19+ if retcode != 0:
20+ error_msg = 'Cobbler command failed: ' + ' '.join(cmd)
21+ if failok:
22+ self.logger.debug(error_msg)
23+ return retcode
24+ else:
25+ self.logger.error(error_msg)
26+ raise UTAHBMProvisioningException(error_msg)
27+ else:
28 return retcode
29- else:
30- self.logger.error(error_msg)
31- raise UTAHBMProvisioningException(error_msg)
32- else:
33- return retcode
34+ finally:
35+ # tail process will wait forever because of the -f/--follow option,
36+ # so it has to be terminated in order to read from stdout.
37+ tail_process.terminate()
38+ self.logger.debug('Cobbler log follows:\n'
39+ '{}'.format(tail_process.stdout.read()))
40
41 def _start(self):
42 """

Subscribers

People subscribed via source and target branches