Merge lp:~mvo/click/lp1346723-chroot into lp:click/devel

Proposed by Michael Vogt on 2014-07-22
Status: Merged
Merged at revision: 524
Proposed branch: lp:~mvo/click/lp1346723-chroot
Merge into: lp:click/devel
Diff against target: 36 lines (+20/-6)
1 file modified
click/chroot.py (+20/-6)
To merge this branch: bzr merge lp:~mvo/click/lp1346723-chroot
Reviewer Review Type Date Requested Status
Colin Watson 2014-07-22 Approve on 2014-09-29
PS Jenkins bot (community) continuous-integration Approve on 2014-07-22
Review via email: mp+227686@code.launchpad.net

Commit message

Make click destroy more robust by umnounting any mounted filesystem inside the schroot first.

Description of the change

This branch makes the removal of a click schroot more robust. Before shutil.rmtree() it tries to umount all mounted filesystems inside this schroot. I also removed the check for "exists()" to make it possible to remvoe chroots where the config is gone but the chroot itself is still there.

To post a comment you must log in.
lp:~mvo/click/lp1346723-chroot updated on 2014-07-22
491. By Michael Vogt on 2014-07-22

fix pep8 error

Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'click/chroot.py'
2--- click/chroot.py 2014-07-03 11:03:24 +0000
3+++ click/chroot.py 2014-07-22 09:40:42 +0000
4@@ -519,12 +519,26 @@
5 return self.clean()
6
7 def destroy(self):
8- if not self.exists():
9- raise ClickChrootDoesNotExistException(
10- "Chroot %s does not exist" % self.full_name)
11- os.remove(self.chroot_config)
12- mount = "%s/%s" % (self.chroots_dir, self.full_name)
13- shutil.rmtree(mount)
14+ # remove config
15+ if os.path.exists(self.chroot_config):
16+ os.remove(self.chroot_config)
17+ # find all schroot mount points, this is actually quite complicated
18+ mount_dir = os.path.abspath(
19+ os.path.join(self.chroots_dir, "..", "mount"))
20+ needle = os.path.join(mount_dir, self.full_name)
21+ all_mounts = []
22+ with open("/proc/mounts") as f:
23+ for line in f.readlines():
24+ mp = line.split()[1]
25+ if mp.startswith(needle):
26+ all_mounts.append(mp)
27+ # reverse order is important in case of submounts
28+ for mp in sorted(all_mounts, key=len, reverse=True):
29+ subprocess.call(["umount", mp])
30+ # now remove the rest
31+ chroot_dir = "%s/%s" % (self.chroots_dir, self.full_name)
32+ if os.path.exists(chroot_dir):
33+ shutil.rmtree(chroot_dir)
34 return 0
35
36 def begin_session(self):

Subscribers

People subscribed via source and target branches

to all changes: