def undo_mounts(self, rootdir, fatal=True): self.logger.debug("Unmounting runroot mounts") mounts = {} fn = "%s/tmp/runroot_mounts" % rootdir if os.path.exists(fn): fslog = file(fn, "r") for line in fslog: mounts.setdefault(line.strip(), 1) fslog.close() # also, check /proc/mounts just in case for dir in scan_mounts(rootdir): mounts.setdefault(dir, 1) mounts = mounts.keys() # deeper directories first mounts.sort() mounts.reverse() failed = [] self.logger.info("Unmounting (runroot): %s" % mounts) for dir in mounts: (rv, output) = commands.getstatusoutput("umount -l '%s'" % dir) if rv != 0: failed.append("%s: %s" % (dir, output)) if failed: msg = "Unable to unmount: %s" % ", ".join(failed) self.logger.warn(msg) if fatal: raise koji.GenericError, msg else: # remove the mount list when everything is unmounted try: os.unlink(fn) except OSError: pass
def undo_mounts(self, rootdir, fatal=True): self.logger.debug("Unmounting runroot mounts") mounts = {} fn = '%s/tmp/runroot_mounts' % rootdir if os.path.exists(fn): fslog = open(fn, 'r') for line in fslog.readlines(): mounts.setdefault(line.strip(), 1) fslog.close() #also, check /proc/mounts just in case for dir in scan_mounts(rootdir): mounts.setdefault(dir, 1) mounts = sorted(mounts.keys()) # deeper directories first mounts.reverse() failed = [] self.logger.info("Unmounting (runroot): %s" % mounts) for dir in mounts: (rv, output) = commands.getstatusoutput("umount -l '%s'" % dir) if rv != 0: failed.append("%s: %s" % (dir, output)) if failed: msg = "Unable to unmount: %s" % ', '.join(failed) self.logger.warn(msg) if fatal: raise koji.GenericError(msg) else: # remove the mount list when everything is unmounted try: os.unlink(fn) except OSError: pass
def undo_mounts(self, rootdir, fatal=True): self.logger.debug("Unmounting runroot mounts") mounts = set() fn = '%s/tmp/runroot_mounts' % rootdir if os.path.exists(fn): with open(fn, 'r') as fslog: for line in fslog.readlines(): mounts.add(line.strip()) #also, check /proc/mounts just in case mounts |= set(scan_mounts(rootdir)) mounts = sorted(mounts) # deeper directories first mounts.reverse() failed = [] self.logger.info("Unmounting (runroot): %s" % mounts) for dir in mounts: proc = subprocess.Popen(["umount", "-l", dir], stdout=subprocess.PIPE, stderr=subprocess.PIPE) if proc.wait() != 0: output = proc.stdout.read() output += proc.stderr.read() failed.append("%s: %s" % (dir, output)) if failed: msg = "Unable to unmount: %s" % ', '.join(failed) self.logger.warn(msg) if fatal: raise koji.GenericError(msg) else: # remove the mount list when everything is unmounted try: os.unlink(fn) except OSError: pass
def test_scan_mounts_no_results(self): """ Tests the scan_mounts function with a mocked /proc/mounts file. An argument of /nonexistent/path to the function should return an empty list. """ fake_mounts_file_contents = get_fake_mounts_file() with patch('koji.tasks.open', return_value=fake_mounts_file_contents, create=True): self.assertEquals(scan_mounts('/nonexistent/path'), [])
def test_scan_mounts_results(self): """ Tests the scan_mounts function with a mocked /proc/mounts file. A list containing mount points starting with /dev are expected to be returned from the function based on the function input of /dev. """ fake_mounts_file_contents = get_fake_mounts_file() with patch('koji.tasks.open', return_value=fake_mounts_file_contents, create=True): self.assertIn(scan_mounts('/dev'), [['/dev/shm', '/dev/pts', '/dev/mqueue', '/dev/hugepages', '/dev']])
def test_scan_mounts_no_results(self): """ Tests the scan_mounts function with a mocked /proc/mounts file. An argument of /nonexistent/path to the function should return an empty list. """ fake_mounts_file_contents = get_fake_mounts_file() with patch('{0}.open'.format(__name__), return_value=fake_mounts_file_contents, create=True): self.assertEquals(scan_mounts('/nonexistent/path'), [])
def test_scan_mounts_results(self): """ Tests the scan_mounts function with a mocked /proc/mounts file. A list containing mount points starting with /dev are expected to be returned from the function based on the function input of /dev. """ fake_mounts_file_contents = get_fake_mounts_file() with patch('{0}.open'.format(__name__), return_value=fake_mounts_file_contents, create=True): self.assertEquals(scan_mounts('/dev'), ['/dev/shm', '/dev/pts', '/dev/mqueue', '/dev/hugepages', '/dev'])