From patchwork Wed Dec 29 14:35:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 439531 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 oBUMBEjo000490 for ; Thu, 30 Dec 2010 22:11:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752925Ab0L2Of4 (ORCPT ); Wed, 29 Dec 2010 09:35:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:31680 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752301Ab0L2Ofz (ORCPT ); Wed, 29 Dec 2010 09:35:55 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oBTEZr9d014000 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 29 Dec 2010 09:35:54 -0500 Received: from freedom.redhat.com (vpn-8-145.rdu.redhat.com [10.11.8.145]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oBTEZn9x009850; Wed, 29 Dec 2010 09:35:52 -0500 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Amos Kong Subject: [PATCH 1/2] KVM-test: Add mount utility functions Date: Wed, 29 Dec 2010 12:35:47 -0200 Message-Id: <1293633348-7188-2-git-send-email-lmr@redhat.com> In-Reply-To: <1293633348-7188-1-git-send-email-lmr@redhat.com> References: <1293633348-7188-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 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]); Thu, 30 Dec 2010 22:11:29 +0000 (UTC) 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