From patchwork Wed Dec 22 13:27:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amos Kong X-Patchwork-Id: 427211 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBMDQXww023451 for ; Wed, 22 Dec 2010 13:26:33 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752738Ab0LVN0a (ORCPT ); Wed, 22 Dec 2010 08:26:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40725 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751826Ab0LVN0a (ORCPT ); Wed, 22 Dec 2010 08:26:30 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oBMDQSRq011892 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 22 Dec 2010 08:26:28 -0500 Received: from dhcp-91-173.nay.redhat.com (dhcp-91-173.nay.redhat.com [10.66.91.173]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oBMDQQWl001671; Wed, 22 Dec 2010 08:26:27 -0500 Subject: [PATCH 1/2] KVM-test: Add mount utility functions To: autotest@test.kernel.org From: Amos Kong Cc: lmr@redhat.com, kvm@vger.kernel.org Date: Wed, 22 Dec 2010 21:27:14 +0800 Message-ID: <20101222132714.29867.325.stgit@dhcp-91-173.nay.redhat.com> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Wed, 22 Dec 2010 13:26:33 +0000 (UTC) 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