Merge lp:~nuclearbob/utah/cobbler-cleanup into lp:utah

Proposed by Max Brustkern
Status: Merged
Approved by: Javier Collado
Approved revision: 705
Merged at revision: 705
Proposed branch: lp:~nuclearbob/utah/cobbler-cleanup
Merge into: lp:utah
Diff against target: 62 lines (+20/-13)
1 file modified
utah/provisioning/baremetal/cobbler.py (+20/-13)
To merge this branch: bzr merge lp:~nuclearbob/utah/cobbler-cleanup
Reviewer Review Type Date Requested Status
Javier Collado (community) Approve
Max Brustkern (community) Needs Resubmitting
Review via email: mp+128792@code.launchpad.net

Description of the change

This branch should more aggressively clean up tmp directories in case of failures so we don't get left with tons of directories cluttering up the system.

To post a comment you must log in.
Revision history for this message
Javier Collado (javier.collado) wrote :

I think that in the _cleanuptmpdir method is confusing to use a variable
that is named `filename` when it could be both a filename or a dirname.
I'd prefer something like `name`, but since that's already used in the
loop for the relative name, maybe `absolute_name` is a good choice
(also `path`, `absolute_path` might be good alternatives).

lp:~nuclearbob/utah/cobbler-cleanup updated
704. By Max Brustkern

Changed variable name per Javier's comments, and added a check to make sure the directory exists

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

Good point. I've also added a check to make sure the directory exists so that if the method gets called during provisioning and during __del__, it doesn't blow up.

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

The variable renaming introduced a few errors that I'm pasting below:
./utah/provisioning/baremetal/cobbler.py:281: W806 local variable 'absolute_name' is assigned to but never used
./utah/provisioning/baremetal/cobbler.py:282: W802 undefined name 'absoulte_name'
./utah/provisioning/baremetal/cobbler.py:284: W802 undefined name 'filename'
./utah/provisioning/baremetal/cobbler.py:285: W802 undefined name 'absoulte_name'

review: Needs Fixing
lp:~nuclearbob/utah/cobbler-cleanup updated
705. By Nuclear Bob <max@daedelus>

Fixed typos

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

Thanks, I really should be checking these better. New changes should be pushed now.

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

Looks good now. Merging.

review: Approve

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-10-04 15:14:41 +0000
+++ utah/provisioning/baremetal/cobbler.py 2012-10-10 20:36:19 +0000
@@ -182,24 +182,16 @@
182 + ' seconds')182 + ' seconds')
183 retry(self.sshcheck, checktimeout, logmethod=self.logger.info)183 retry(self.sshcheck, checktimeout, logmethod=self.logger.info)
184184
185 if self.installtype == 'desktop':
186 self.logger.info('Removing NFS share')
187 self._removenfs()
188
185 if self.debug:189 if self.debug:
186 self.logger.info('Leaving temp directory '190 self.logger.info('Leaving temp directory '
187 'because debug is enabled: ' + self.tmpdir)191 'because debug is enabled: ' + self.tmpdir)
188 else:192 else:
189 self.logger.info('Cleaning up temp directory')193 self.logger.info('Cleaning up temp directory')
190 if self.installtype == 'desktop':194 self._cleanuptmpdir()
191 self.logger.info('Removing NFS share')
192 self._removenfs()
193 # Cribbed from http://svn.python.org
194 # /projects/python/trunk/Mac/BuildScript/build-installer.py
195 for dirpath, dirnames, filenames in os.walk(self.tmpdir):
196 for name in (dirnames + filenames):
197 filename = os.path.join(dirpath, name)
198 if not os.path.islink(filename):
199 self.logger.debug('Changing permissions of '
200 + filename)
201 os.chmod(filename, 0775)
202 shutil.rmtree(self.tmpdir)
203195
204 self.provisioned = True196 self.provisioned = True
205 self.active = True197 self.active = True
@@ -268,6 +260,8 @@
268 """260 """
269 if self.installtype == 'desktop':261 if self.installtype == 'desktop':
270 self._removenfs()262 self._removenfs()
263 if not self.debug:
264 self._cleanuptmpdir()
271 if self.inventory is not None:265 if self.inventory is not None:
272 self.inventory.release(machine=self)266 self.inventory.release(machine=self)
273267
@@ -277,6 +271,19 @@
277 '/d', '-i', config.nfsconfigfile])271 '/d', '-i', config.nfsconfigfile])
278 self.logger.debug('Reloading NFS config')272 self.logger.debug('Reloading NFS config')
279 self._runargs(config.nfscommand)273 self._runargs(config.nfscommand)
274
275 def _cleanuptmpdir(self):
276 if os.path.isdir(self.tmpdir):
277 # Cribbed from http://svn.python.org
278 # /projects/python/trunk/Mac/BuildScript/build-installer.py
279 for dirpath, dirnames, filenames in os.walk(self.tmpdir):
280 for name in (dirnames + filenames):
281 absolute_name = os.path.join(dirpath, name)
282 if not os.path.islink(absolute_name):
283 self.logger.debug('Changing permissions of '
284 + absolute_name)
285 os.chmod(absolute_name, 0775)
286 shutil.rmtree(self.tmpdir)
280287
281 def activecheck(self):288 def activecheck(self):
282 """289 """

Subscribers

People subscribed via source and target branches