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
=== modified file 'utah/provisioning/baremetal/cobbler.py'
--- utah/provisioning/baremetal/cobbler.py 2012-12-12 18:56:13 +0000
+++ utah/provisioning/baremetal/cobbler.py 2013-01-18 18:31:22 +0000
@@ -213,17 +213,28 @@
213 Pull out all cobbler commands so that we can later support changing213 Pull out all cobbler commands so that we can later support changing
214 users, remote login, not sudo, etc.214 users, remote login, not sudo, etc.
215 """215 """
216 retcode = self._runargs(['sudo', 'cobbler'] + cmd)216 tail_process = \
217 if retcode != 0:217 subprocess.Popen(['tail', '-n0', '-f',
218 error_msg = 'Cobbler command failed: ' + ' '.join(cmd)218 '/var/log/cobbler/cobbler.log'],
219 if failok:219 stdout=subprocess.PIPE)
220 self.logger.debug(error_msg)220 try:
221 retcode = self._runargs(['sudo', 'cobbler'] + cmd)
222 if retcode != 0:
223 error_msg = 'Cobbler command failed: ' + ' '.join(cmd)
224 if failok:
225 self.logger.debug(error_msg)
226 return retcode
227 else:
228 self.logger.error(error_msg)
229 raise UTAHBMProvisioningException(error_msg)
230 else:
221 return retcode231 return retcode
222 else:232 finally:
223 self.logger.error(error_msg)233 # tail process will wait forever because of the -f/--follow option,
224 raise UTAHBMProvisioningException(error_msg)234 # so it has to be terminated in order to read from stdout.
225 else:235 tail_process.terminate()
226 return retcode236 self.logger.debug('Cobbler log follows:\n'
237 '{}'.format(tail_process.stdout.read()))
227238
228 def _start(self):239 def _start(self):
229 """240 """

Subscribers

People subscribed via source and target branches