diff mbox

[1/2] KVM-test: Add mount utility functions

Message ID 20101222132714.29867.325.stgit@dhcp-91-173.nay.redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Amos Kong Dec. 22, 2010, 1:27 p.m. UTC
None
diff mbox

Patch

diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index 5496e06..175b128 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -1456,3 +1456,58 @@  class KojiDownloader(object):
                 rpm_paths.append(r)
 
         return rpm_paths
+
+def umount(src, mount_point, type):
+    """
+    Umount the src mounted in mount_point.
+
+    @src: mount source
+    @mount_point: mount point
+    @type: file system type
+    """
+
+    mount_string = "%s %s %s" % (src, mount_point, type)
+    if mount_string in file("/etc/mtab").read():
+        umount_cmd = "umount %s" % mount_point
+        s, o = commands.getstatusoutput(umount_cmd)
+        if s != 0:
+            logging.error("Fail to umount: %s" % o)
+            return False
+        else:
+            return True
+    else:
+        logging.debug("%s is not mount in %s" % (src, mount_point))
+        return True
+
+def mount(src, mount_point, type, perm="rw"):
+    """
+    Mount the src into mount_point of the host.
+
+    @src: mount source
+    @mount_point: mount point
+    @type: file system type
+    @perm: mount premission
+    """
+    umount(src, mount_point, type)
+    mount_string = "%s %s %s %s" % (src, mount_point, type, perm)
+
+    if mount_string in file("/etc/mtab").read():
+        logging.debug("%s is already mounted in %s with %s" % \
+                      (src, mount_point, perm))
+        return True
+
+    mount_cmd = "mount -t %s %s %s -o %s" % (type, src, mount_point, perm)
+    logging.debug(mount_cmd)
+    s, o = commands.getstatusoutput(mount_cmd)
+    if s != 0:
+        logging.error("Fail to mount: %s " % o)
+        return False
+
+    logging.debug("Verify the mount through /etc/mtab")
+    if mount_string in file("/etc/mtab").read():
+        logging.debug("%s is successfully mounted" % src)
+        return True
+    else:
+        logging.error("Mounting verification failed: %s" % \
+                      file("/etc/mtab").read())
+        return False