1import logging, time, os 2from autotest_lib.client.common_lib import error 3from autotest_lib.client.bin import utils 4 5 6@error.context_aware 7def run_floppy(test, params, env): 8 """ 9 Test virtual floppy of guest: 10 11 1) Create a floppy disk image on host 12 2) Start the guest with this floppy image. 13 3) Make a file system on guest virtual floppy. 14 4) Calculate md5sum value of a file and copy it into floppy. 15 5) Verify whether the md5sum does match. 16 17 @param test: KVM test object. 18 @param params: Dictionary with the test parameters. 19 @param env: Dictionary with test environment. 20 """ 21 def master_floppy(params): 22 error.context("creating test floppy") 23 floppy = os.path.abspath(params.get("floppy")) 24 utils.run("dd if=/dev/zero of=%s bs=512 count=2880" % floppy) 25 26 27 master_floppy(params) 28 vm = env.get_vm(params["main_vm"]) 29 vm.create() 30 31 timeout = int(params.get("login_timeout", 360)) 32 session = vm.wait_for_login(timeout=timeout) 33 34 dest_dir = params.get("mount_dir") 35 # If mount_dir specified, treat guest as a Linux OS 36 # Some Linux distribution does not load floppy at boot and Windows 37 # needs time to load and init floppy driver 38 if dest_dir: 39 status = session.cmd("modprobe floppy") 40 else: 41 time.sleep(20) 42 43 error.context("Formating floppy disk before using it") 44 format_cmd = params.get("format_floppy_cmd") 45 session.cmd(format_cmd, timeout=120) 46 logging.info("Floppy disk formatted successfully") 47 48 source_file = params.get("source_file") 49 dest_file = params.get("dest_file") 50 51 if dest_dir: 52 error.context("Mounting floppy") 53 session.cmd("mount /dev/fd0 %s" % dest_dir) 54 error.context("Testing floppy") 55 session.cmd(params.get("test_floppy_cmd")) 56 57 try: 58 error.context("Copying file to the floppy") 59 session.cmd("%s %s %s" % (params.get("copy_cmd"), source_file, 60 dest_file)) 61 logging.info("Succeed to copy file '%s' into floppy disk" % source_file) 62 63 error.context("Checking if the file is unchanged after copy") 64 session.cmd("%s %s %s" % (params.get("diff_file_cmd"), source_file, 65 dest_file)) 66 finally: 67 clean_cmd = "%s %s" % (params.get("clean_cmd"), dest_file) 68 session.cmd(clean_cmd) 69 if dest_dir: 70 session.cmd("umount %s" % dest_dir) 71 session.close() 72