summaryrefslogtreecommitdiff
path: root/server/hosts
diff options
context:
space:
mode:
authormbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4>2009-02-17 15:51:55 +0000
committermbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4>2009-02-17 15:51:55 +0000
commitc4f004added0ec71f3e666af146c34042ce79272 (patch)
tree9eca3b68010708ec34d1fe1623c470a7d8e2ef16 /server/hosts
parent0459d99d59bfb4cf998bf5861014b29a935e5066 (diff)
Added client.bin.partition.get_unmounted_partition_list() function and
moved server.hosts.Host.check_partitions() logic into it. Exposed the internal open()-like functor from check_partitions() in the public API. Signed-off-by: Mihai Rusu <dizzy@google.com> git-svn-id: svn://test.kernel.org/autotest/trunk@2800 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'server/hosts')
-rw-r--r--server/hosts/base_classes.py60
1 files changed, 35 insertions, 25 deletions
diff --git a/server/hosts/base_classes.py b/server/hosts/base_classes.py
index e96bb837..7a21c599 100644
--- a/server/hosts/base_classes.py
+++ b/server/hosts/base_classes.py
@@ -194,6 +194,38 @@ class Host(object):
(free_space_gb, gb, path, self.hostname)
+ def get_open_func(self, use_cache=True):
+ """
+ Defines and returns a function that may be used instead of built-in
+ open() to open and read files. The returned function is implemented
+ by using self.run('cat <file>') and may cache the results for the same
+ filename.
+
+ @param use_cache Cache results of self.run('cat <filename>') for the
+ same filename
+
+ @return a function that can be used instead of built-in open()
+ """
+ cached_files = {}
+
+ def open_func(filename):
+ if not use_cache or filename not in cached_files:
+ output = self.run('cat \'%s\'' % filename,
+ stdout_tee=open('/dev/null', 'w')).stdout
+ fd = cStringIO.StringIO(output)
+
+ if not use_cache:
+ return fd
+
+ cached_files[filename] = fd
+ else:
+ cached_files[filename].seek(0)
+
+ return cached_files[filename]
+
+ return open_func
+
+
def check_partitions(self, root_part, filter_func=None):
"""" Compare the contents of /proc/partitions with those of
/proc/mounts and raise exception in case unmounted partitions are found
@@ -209,35 +241,13 @@ class Host(object):
Raise: error.AutoservHostError if unfiltered unmounted partition found
"""
- # cache these files because the same file contents is read for
- # each partition
- cached_files = {}
-
- def remote_open(filename):
- if filename not in cached_files:
- output = self.run('cat \'%s\'' % filename,
- stdout_tee=open('/dev/null', 'w')).stdout
- cached_files[filename] = cStringIO.StringIO(output)
- else:
- cached_files[filename].seek(0)
-
- return cached_files[filename]
-
-
print 'Checking if non-swap partitions are mounted...'
- partitions = partition.get_partition_list(None,
- filter_func=filter_func, open_func=remote_open)
-
- unmounted = []
- for part in partitions:
- if part.device != '/dev/' + root_part and \
- not part.get_mountpoint(open_func=remote_open):
- unmounted.append(part.device)
-
+ unmounted = partition.get_unmounted_partition_list(root_part,
+ filter_func=filter_func, open_func=self.get_open_func())
if unmounted:
raise error.AutoservHostError('Found unmounted partitions: %s' %
- unmounted)
+ [part.device for part in unmounted])
def repair_filesystem_only(self):