From patchwork Mon Jul 11 06:18:44 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amos Kong X-Patchwork-Id: 963382 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6B6GRib025501 for ; Mon, 11 Jul 2011 06:16:27 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757019Ab1GKGQY (ORCPT ); Mon, 11 Jul 2011 02:16:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54037 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756510Ab1GKGQY (ORCPT ); Mon, 11 Jul 2011 02:16:24 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6B6GM5x003347 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 11 Jul 2011 02:16:23 -0400 Received: from [127.0.0.1] (dhcp-8-167.nay.redhat.com [10.66.8.167]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p6B6GK7v011974; Mon, 11 Jul 2011 02:16:21 -0400 Subject: [PATCH] KVM-test: Add subtest cdrom To: autotest@test.kernel.org From: Amos Kong Cc: lmr@redhat.com, fyang@redhat.com, kvm@vger.kernel.org Date: Mon, 11 Jul 2011 14:18:44 +0800 Message-ID: <20110711061844.21058.97093.stgit@t> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 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.6 (demeter2.kernel.org [140.211.167.43]); Mon, 11 Jul 2011 06:16:27 +0000 (UTC) Test cdrom about mount/format/copy/md5sum, change iso file by monitor command, create iso files by pre_command, clean temporary file by post_command. Signed-off-by: Amos Kong --- client/tests/kvm/tests/cdrom.py | 131 ++++++++++++++++++++++++++++++++ client/tests/kvm/tests_base.cfg.sample | 11 +++ 2 files changed, 142 insertions(+), 0 deletions(-) create mode 100644 client/tests/kvm/tests/cdrom.py -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/client/tests/kvm/tests/cdrom.py b/client/tests/kvm/tests/cdrom.py new file mode 100644 index 0000000..be5e4cd --- /dev/null +++ b/client/tests/kvm/tests/cdrom.py @@ -0,0 +1,131 @@ +import logging, re, time +from autotest_lib.client.common_lib import error +from autotest_lib.client.virt import virt_utils + +def run_cdrom(test, params, env): + """ + KVM cdrom test: + 1) Boot up a VM with one iso + 2) Check if VM identify iso file + 3) Eject cdrom and change with another iso for many times + 4) Try to fromat cdrom and check the return string + 5) Mount cdrom device to /mnt + 6) Copy file from cdrom and compare files by diff + 7) Umount and mount many times + + @param test: kvm test object + @param params: Dictionary with the test parameters + @param env: Dictionary with test environment. + """ + def get_cdrom_info(): + o = vm.monitor.info("block") + try: + device = re.findall("(ide\d+-cd\d+): .*", o)[0] + except IndexError: + device = None + try: + file = re.findall("ide\d+-cd\d+: .*file=(\S*) ", o)[0] + except IndexError: + file = None + logging.debug("Device name: %s, ISO: %s" % (device, file)) + return (device, file) + + def check_cdrom_locked(cdrom): + blocks_info = vm.monitor.info("block") + if isinstance(blocks_info, str): + lock_str = "locked=1" + for block in blocks_info.splitlines(): + if cdrom in block and lock_str in block: + return True + else: + for block in blocks_info: + if 'inserted' in block.keys() and\ + block['inserted']['file'] == cdrom: + return block['locked'] + return False + + + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() + + session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) + cdrom_orig = params.get("cdrom_cd1") + cdrom_new = params.get("new_iso") + cdrom = cdrom_orig + output = session.get_command_output("ls /dev/cdrom*") + cdrom_dev_list = re.findall("/dev/cdrom-\w+|/dev/cdrom\d*", output) + logging.debug("cdrom_dev_list: %s" % cdrom_dev_list) + + cdrom_dev = "" + test_cmd = "dd if=%s of=/dev/null bs=1 count=1" + for d in cdrom_dev_list: + s, o = session.cmd_status_output(test_cmd % d) + if s == 0: + cdrom_dev = d + break + else: + raise error.TestFail("Could not find a valid cdrom device." + " dd returns: %d, output:\n%s" % (s, o)) + + logging.info("Detecting the existence of cdrom") + (device, file) = get_cdrom_info() + if file != cdrom: + raise error.TestError("%s does not realized" % cdrom) + + session.get_command_output("umount %s" % cdrom_dev) + if not virt_utils.wait_for(lambda: not check_cdrom_locked(file), 300): + raise error.TestError("%s could not become unlocked" % device) + + max_times = int(params.get("max_times", 100)) + logging.info("Eject the cdrom for %s times" % max_times) + max = max_times + while max > 0: + vm.monitor.cmd("eject %s" % device) + (device, file) = get_cdrom_info() + if file is not None: + raise error.TestFail("%s is not ejected" % cdrom) + + cdrom = cdrom_new + if max % 2 == 0: + cdrom = cdrom_orig + vm.monitor.cmd("change %s %s" % (device, cdrom)) + time.sleep(10) + (device, file) = get_cdrom_info() + if file != cdrom: + raise error.TestError("%s is not changed" % cdrom) + max -= 1 + + logging.info("Check whether the cdrom is read-only") + filename = params.get("filename") + dest_dir = "/mnt" + s, o = session.get_command_status_output("echo y|mkfs %s" % cdrom_dev) + if not "Read-only" in o: + logging.debug("Format cdrom doesn't return Read-only error") + if s == 0: + raise error.TestFail("Format %s unexpected success" % cdrom_dev) + + if not virt_utils.wait_for(lambda: session.get_command_status("mount %s %s" + % (cdrom_dev, dest_dir)) == 0, 30): + logging.debug(session.get_command_output("cat /etc/mtab")) + raise error.TestFail("Could not mount %s" % cdrom_dev) + + logging.info("File copying test") + cmd = "/bin/cp -f %s/%s /tmp/" + if session.get_command_status(cmd % (dest_dir, filename)) != 0: + raise error.TestFail("Fail to copy file from %s" % dest_dir) + cmd = "diff %s/%s /tmp/%s" % (dest_dir, filename, filename) + if session.get_command_status(cmd) != 0: + raise error.TestFail("Two file is different, cmd: %s" % cmd) + + logging.info("Mounting/Unmounting test") + max = max_times + while max > 0: + if session.get_command_status("umount %s" % cdrom_dev) != 0: + raise error.TestFail("Could not umount %s" % cdrom_dev) + cmd = "mount %s %s" % (cdrom_dev, dest_dir) + if session.get_command_status(cmd) != 0: + logging.debug(session.get_command_output("cat /etc/mtab")) + raise error.TestFail("Could not mount %s" % cdrom_dev) + max -= 1 + + session.close() diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index 65880d8..5d6227b 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -1101,6 +1101,17 @@ variants: kill_vm_gracefully = no # Do not define test variants below shutdown + - cdrom_test: install setup image_copy unattended_install.cdrom + type = cdrom + pre_command = "dd if=/dev/urandom of=orig bs=10M count=1 && dd if=/dev/urandom of=new bs=10M count=1 && mkisofs -o /tmp/kvm_autotest_root/orig.iso orig && mkisofs -o /tmp/kvm_autotest_root/new.iso new" + new_iso = /tmp/kvm_autotest_root/new.iso + cdrom_cd1 = orig.iso + max_times = 20 + filename = new + kill_vm = yes + post_command = rm -rf /tmp/kvm_autotest_root/orig.iso /tmp/kvm_autotest_root/new.iso orig new + only Linux + # NICs variants: