1import logging 2from autotest_lib.client.common_lib import error 3 4def run_fillup_disk(test, params, env): 5 """ 6 Fillup guest disk (root mount point) using dd if=/dev/zero, 7 and then clean up (rm the big file). The main purpose of this case is to 8 expand the qcow2 file to its max size. 9 10 Suggest to test rebooting vm after this test. 11 12 @param test: kvm test object 13 @param params: Dictionary with the test parameters 14 @param env: Dictionary with test environment. 15 """ 16 vm = env.get_vm(params["main_vm"]) 17 vm.verify_alive() 18 timeout = int(params.get("login_timeout", 360)) 19 session = vm.wait_for_login(timeout=timeout) 20 21 fillup_timeout = int(params.get("fillup_timeout")) 22 fillup_size = int(params.get("fillup_size")) 23 fill_dir = params.get("guest_testdir","/tmp") 24 filled = False 25 number = 0 26 27 try: 28 logging.info("Start filling the disk in %s" % fill_dir) 29 cmd = params.get("fillup_cmd") 30 while not filled: 31 # As we want to test the backing file, so bypass the cache 32 tmp_cmd = cmd % (fill_dir, number, fillup_size) 33 logging.debug(tmp_cmd) 34 s, o = session.cmd_status_output(tmp_cmd, timeout=fillup_timeout) 35 if "No space left on device" in o: 36 logging.debug("Successfully filled up the disk") 37 filled = True; 38 elif s != 0: 39 raise error.TestFail("Command dd failed to execute: %s" % o) 40 number += 1 41 finally: 42 logging.info("Cleaning the temporary files...") 43 while number >= 0: 44 cmd = "rm -f /%s/fillup.%d" % (fill_dir, number) 45 logging.debug(cmd) 46 s, o = session.cmd_status_output(cmd) 47 if s != 0: 48 logging.error(o) 49 raise error.TestFail("Failed to remove file %s: %s;" 50 "guest may be unresponsive or " 51 "command timeout" % (number, o)) 52 number -= 1 53 session.close() 54