From: Lucas Meneghel Rodrigues <lmr@redhat.com>
To: autotest@test.kernel.org
Cc: kvm@vger.kernel.org, Amos Kong <akong@redhat.com>
Subject: [PATCH 1/2] KVM-test: Add mount utility functions
Date: Wed, 29 Dec 2010 12:35:47 -0200 [thread overview]
Message-ID: <1293633348-7188-2-git-send-email-lmr@redhat.com> (raw)
In-Reply-To: <1293633348-7188-1-git-send-email-lmr@redhat.com>
From: Amos Kong <akong@redhat.com>
Add mount and umount function, you can assign source, mount_point, type
and permission.
Changes from v1:
- Make better use of autotest API to control subprocesses
Signed-off-by: Amos Kong <akong@redhat.com>
---
client/tests/kvm/kvm_utils.py | 55 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index 8805449..de362d5 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -1536,3 +1536,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
+ try:
+ utils.system(umount_cmd)
+ return True
+ except error.CmdError:
+ return False
+ else:
+ logging.debug("%s is not mounted under %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)
+ try:
+ utils.system(mount_cmd)
+ except error.CmdError:
+ 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("Can't find mounted NFS share - /etc/mtab contents \n%s" %
+ file("/etc/mtab").read())
+ return False
--
1.7.2.3
next prev parent reply other threads:[~2010-12-29 14:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-29 14:35 [PATCH 0/2] KVM test: Image copy test v2 Lucas Meneghel Rodrigues
2010-12-29 14:35 ` Lucas Meneghel Rodrigues [this message]
2010-12-29 14:35 ` [PATCH 2/2] KVM-test: Add image_copy subtest to prepare images Lucas Meneghel Rodrigues
2010-12-29 15:24 ` [PATCH 0/2] KVM test: Image copy test v2 Lucas Meneghel Rodrigues
-- strict thread matches above, loose matches on Subject: below --
2010-12-22 13:27 [PATCH 1/2] KVM-test: Add mount utility functions Amos Kong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1293633348-7188-2-git-send-email-lmr@redhat.com \
--to=lmr@redhat.com \
--cc=akong@redhat.com \
--cc=autotest@test.kernel.org \
--cc=kvm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox