diff --git a/selftests/unit/test_libvirt_xml.py b/selftests/unit/test_libvirt_xml.py index b4d134dc4c1..96075750ea1 100644 --- a/selftests/unit/test_libvirt_xml.py +++ b/selftests/unit/test_libvirt_xml.py @@ -9,6 +9,7 @@ import six from avocado.utils import process +from avocado.utils import data_factory try: @@ -22,7 +23,7 @@ if os.path.isdir(os.path.join(basedir, 'virttest')): sys.path.append(basedir) -from virttest import xml_utils, utils_misc, data_dir +from virttest import xml_utils, data_dir from virttest.libvirt_xml import accessors, vm_xml, xcepts, network_xml, base from virttest.libvirt_xml import nodedev_xml from virttest.libvirt_xml.devices import librarian @@ -814,10 +815,10 @@ def test_arbitrart_attributes(self): channel = librarian.get('channel')(virsh_instance=self.dummy_virsh) console = librarian.get('console')(virsh_instance=self.dummy_virsh) for chardev in (parallel, serial, channel, console): - attribute1 = utils_misc.generate_random_string(10) - value1 = utils_misc.generate_random_string(10) - attribute2 = utils_misc.generate_random_string(10) - value2 = utils_misc.generate_random_string(10) + attribute1 = data_factory.generate_random_string(10) + value1 = data_factory.generate_random_string(10) + attribute2 = data_factory.generate_random_string(10) + value2 = data_factory.generate_random_string(10) chardev.add_source(**{attribute1: value1, attribute2: value2}) chardev.add_target(**{attribute1: value1, attribute2: value2}) self.assertEqual(chardev.sources, chardev.targets) diff --git a/selftests/unit/test_utils_env.py b/selftests/unit/test_utils_env.py index e54cddc2c8a..1ca96ab4bca 100644 --- a/selftests/unit/test_utils_env.py +++ b/selftests/unit/test_utils_env.py @@ -11,9 +11,10 @@ if os.path.isdir(os.path.join(basedir, 'virttest')): sys.path.append(basedir) +from avocado.utils import data_factory + from virttest import utils_env from virttest import utils_params -from virttest import utils_misc class FakeVm(object): @@ -25,7 +26,7 @@ def __init__(self, vm_name, params): self.driver_type = self.params.get('driver_type') self.instance = ("%s-%s" % ( time.strftime("%Y%m%d-%H%M%S"), - utils_misc.generate_random_string(16))) + data_factory.generate_random_string(16))) def get_params(self): return self.params @@ -39,7 +40,7 @@ class FakeSyncListenServer(object): def __init__(self, address='', port=123, tmpdir=None): self.instance = ("%s-%s" % ( time.strftime("%Y%m%d-%H%M%S"), - utils_misc.generate_random_string(16))) + data_factory.generate_random_string(16))) self.port = port def close(self): @@ -203,8 +204,8 @@ def _update_env(env, key, value): if "changing_dict" not in env: env["changing_dict"] = {} while True: - key = "%s" % utils_misc.generate_random_string(length=10) - value = "%s" % utils_misc.generate_random_string(length=10) + key = "%s" % data_factory.generate_random_string(length=10) + value = "%s" % data_factory.generate_random_string(length=10) _update_env(env, key, value) if termination_event.isSet(): break diff --git a/selftests/unit/test_utils_net.py b/selftests/unit/test_utils_net.py index 122387ffda6..46209278813 100644 --- a/selftests/unit/test_utils_net.py +++ b/selftests/unit/test_utils_net.py @@ -10,6 +10,7 @@ import shelve from avocado.utils import process +from avocado.utils import data_factory from six.moves import xrange @@ -21,7 +22,6 @@ from virttest.unittest_utils import mock from virttest import utils_net -from virttest import utils_misc from virttest import cartesian_config from virttest import utils_params from virttest import propcan @@ -40,7 +40,7 @@ def __init__(self, vm_name, params): self.driver_type = self.params.get('driver_type') self.instance = ("%s-%s" % ( time.strftime("%Y%m%d-%H%M%S"), - utils_misc.generate_random_string(16))) + data_factory.generate_random_string(16))) def get_params(self): return self.params @@ -152,7 +152,7 @@ def what_func(propertea): half_prop_end = (len(self.VirtIface.__all_slots__) // 2) + 1 props = {} for propertea in self.VirtIface.__all_slots__[0:half_prop_end]: - props[propertea] = utils_misc.generate_random_string(16) + props[propertea] = data_factory.generate_random_string(16) virtiface = self.VirtIface(props) self.loop_assert(virtiface, list(props.keys()), what_func) @@ -161,7 +161,7 @@ def what_func(propertea): return props[propertea] props = {} for propertea in self.VirtIface.__all_slots__: - props[propertea] = utils_misc.generate_random_string(16) + props[propertea] = data_factory.generate_random_string(16) virtiface = self.VirtIface(props) self.loop_assert(virtiface, list(props.keys()), what_func) @@ -173,11 +173,11 @@ def what_func(propertea): return props[propertea] props = {} for propertea in self.VirtIface.__all_slots__: - props[propertea] = utils_misc.generate_random_string(16) + props[propertea] = data_factory.generate_random_string(16) more_props = {} for _ in xrange(0, 16): - key = utils_misc.generate_random_string(16) - value = utils_misc.generate_random_string(16) + key = data_factory.generate_random_string(16) + value = data_factory.generate_random_string(16) more_props[key] = value # Keep separated for testing apendex_set = {} @@ -225,15 +225,15 @@ def get_style(self, vm_type, driver_type): return utils_net.VMNetStyle.get_style(vm_type, driver_type) def test_default_default(self): - style = self.get_style(utils_misc.generate_random_string(16), - utils_misc.generate_random_string(16)) + style = self.get_style(data_factory.generate_random_string(16), + data_factory.generate_random_string(16)) self.assertEqual(style['mac_prefix'], '9a') self.assertEqual(style['container_class'], utils_net.QemuIface) self.assert_(issubclass(style['container_class'], utils_net.VirtIface)) def test_libvirt(self): style = self.get_style('libvirt', - utils_misc.generate_random_string(16)) + data_factory.generate_random_string(16)) self.assertEqual(style['container_class'], utils_net.LibvirtIface) self.assert_(issubclass(style['container_class'], utils_net.VirtIface)) diff --git a/virttest/env_process.py b/virttest/env_process.py index d7fb6b9d44d..8675ff51f7b 100644 --- a/virttest/env_process.py +++ b/virttest/env_process.py @@ -20,6 +20,7 @@ from avocado.utils import path from avocado.utils import distro from avocado.utils import cpu as cpu_utils +from avocado.utils import data_factory from avocado.core import exceptions import six @@ -354,7 +355,7 @@ def check_image(test, params, image_name, vm_process_status=None): # It should before image check. if params.get("save_image", "no") == "yes": if vm_process_status == "dead": - hsh = utils_misc.generate_random_string(4) + hsh = data_factory.generate_random_string(4) name = ("JOB-%s-TEST-%s-%s-%s.%s" % ( test.job.unique_id[:7], str(test.name.uid), image_name, hsh, image.image_format)) @@ -1526,7 +1527,7 @@ def _take_screendumps(test, params, env): os.makedirs(temp_dir) except OSError: pass - random_id = utils_misc.generate_random_string(6) + random_id = data_factory.generate_random_string(6) temp_filename = "scrdump-%s-iter%s.ppm" % (random_id, test.iteration) temp_filename = os.path.join(temp_dir, temp_filename) delay = float(params.get("screendump_delay", 5)) diff --git a/virttest/libvirt_vm.py b/virttest/libvirt_vm.py index 4e1b494bd75..7fba5a999b0 100644 --- a/virttest/libvirt_vm.py +++ b/virttest/libvirt_vm.py @@ -18,6 +18,8 @@ import aexpect from avocado.utils import process from avocado.utils import crypto +from avocado.utils import data_factory +from avocado.utils import wait from avocado.core import exceptions from virttest import error_context @@ -1361,7 +1363,7 @@ def get_serial_console_filename(self, name): :param name: The serial port name. """ return "serial-%s-%s-%s.log" % (name, self.name, - utils_misc.generate_random_string(4)) + data_factory.generate_random_string(4)) def get_serial_console_filenames(self): """ @@ -2016,9 +2018,9 @@ def create(self, name=None, params=None, root_dir=None, timeout=5.0, # some other problem happened, raise normally raise # Wait for the domain to be created - utils_misc.wait_for(func=self.is_alive, timeout=60, - text=("waiting for domain %s to start" % - self.name)) + wait.wait_for(func=self.is_alive, timeout=60, + text=("waiting for domain %s to start" % + self.name)) result = virsh.domuuid(self.name, uri=self.connect_uri) self.uuid = results_stdout_52lts(result).strip() # Create isa serial ports. @@ -2159,7 +2161,7 @@ def destroy(self, gracefully=True, free_mac_addresses=True): self.params.get("shutdown_command")) logging.debug("Shutdown command sent; waiting for VM " "to go down...") - if utils_misc.wait_for(self.is_dead, 60, 1, 1): + if wait.wait_for(self.is_dead, 60, 1, 1): logging.debug("VM is down") return finally: @@ -2391,9 +2393,9 @@ def reboot(self, session=None, method="shell", nic_index=0, timeout=240, raise virt_vm.VMRebootError("Unknown reboot method: %s" % method) error_context.context("waiting for guest to go down", logging.info) - if not utils_misc.wait_for(lambda: not - session.is_responsive(timeout=30), - 120, 0, 1): + if not wait.wait_for(lambda: not + session.is_responsive(timeout=30), + 120, 0, 1): raise virt_vm.VMRebootError("Guest refuses to go down") session.close() @@ -2418,9 +2420,9 @@ def start(self, autoconsole=True): result = virsh.start(self.name, uri=self.connect_uri) if not result.exit_status: # Wait for the domain to be created - has_started = utils_misc.wait_for(func=self.is_alive, timeout=60, - text=("waiting for domain %s " - "to start" % self.name)) + has_started = wait.wait_for(func=self.is_alive, timeout=60, + text=("waiting for domain %s " + "to start" % self.name)) if has_started is None: raise virt_vm.VMStartError(self.name, "libvirt domain not " "active after start") @@ -2962,10 +2964,10 @@ def _stop_ga(): _stop_ga() # Check qemu-guest-agent status if start: - if not utils_misc.wait_for(_is_ga_running, timeout=60): + if not wait.wait_for(_is_ga_running, timeout=60): raise virt_vm.VMError("qemu-guest-agent is not running.") else: - if not utils_misc.wait_for(_is_ga_finished, timeout=60): + if not wait.wait_for(_is_ga_finished, timeout=60): raise virt_vm.VMError("qemu-guest-agent is running") finally: session.close() diff --git a/virttest/qemu_devices/qdevices.py b/virttest/qemu_devices/qdevices.py index b442754bddd..25a36466b6f 100644 --- a/virttest/qemu_devices/qdevices.py +++ b/virttest/qemu_devices/qdevices.py @@ -12,6 +12,8 @@ from collections import OrderedDict from functools import reduce +from avocado.utils import data_factory + from virttest import qemu_monitor from virttest import utils_misc from virttest.qemu_devices.utils import DeviceError @@ -43,7 +45,7 @@ def _build_cmd(cmd, args=None, q_id=None): if args is not None: obj["arguments"] = args if q_id is True: - obj["id"] = utils_misc.generate_random_string(8) + obj["id"] = data_factory.generate_random_string(8) elif q_id is not None: obj["id"] = q_id return obj diff --git a/virttest/qemu_io.py b/virttest/qemu_io.py index 685e309c5c0..03b731d0ab4 100644 --- a/virttest/qemu_io.py +++ b/virttest/qemu_io.py @@ -2,6 +2,7 @@ import aexpect from avocado.utils import process +from avocado.utils import data_factory from virttest import utils_misc from virttest import error_context @@ -27,7 +28,7 @@ def __init__(self, test, params, image_name, blkdebug_cfg="", log_func=None): self.type = "" if log_filename: - log_filename += "-" + utils_misc.generate_random_string(4) + log_filename += "-" + data_factory.generate_random_string(4) self.output_func = utils_misc.log_line self.output_params = (log_filename,) else: diff --git a/virttest/qemu_monitor.py b/virttest/qemu_monitor.py index dd0fe9dec28..ce08b9e522e 100644 --- a/virttest/qemu_monitor.py +++ b/virttest/qemu_monitor.py @@ -22,6 +22,9 @@ logging.warning("Could not import json module. " "QMP monitor functionality disabled.") +from avocado.utils import wait +from avocado.utils import data_factory + from . import passfd_setup from . import utils_misc from . import cartesian_config @@ -1914,7 +1917,7 @@ def cmd(self, cmd, args=None, timeout=CMD_TIMEOUT, debug=True, fd=None): # Read any data that might be available self._read_objects() # Send command - q_id = utils_misc.generate_random_string(8) + q_id = data_factory.generate_random_string(8) cmdobj = self._build_cmd(cmd, args, q_id) if debug: logging.debug("Send command: %s" % cmdobj) @@ -2247,7 +2250,7 @@ def system_reset(self): self.verify_supported_cmd(cmd) self.clear_event(event) ret = self.cmd(cmd=cmd) - if not utils_misc.wait_for(lambda: self.get_event(event), timeout=120): + if not wait.wait_for(lambda: self.get_event(event), timeout=120): raise QMPEventError(cmd, event, self.vm.name, self.name) return ret @@ -2593,7 +2596,7 @@ def system_wakeup(self): # Send a system_wakeup monitor command self.cmd(cmd) # Look for WAKEUP QMP event - if not utils_misc.wait_for(lambda: self.get_event(qmp_event), 120): + if not wait.wait_for(lambda: self.get_event(qmp_event), 120): raise QMPEventError(cmd, qmp_event, self.vm.name, self.name) logging.info("%s QMP event received" % qmp_event) @@ -2835,7 +2838,7 @@ def balloon(self, size): # Send a balloon monitor command self.send_args_cmd("%s value=%s" % (cmd, size)) # Look for BALLOON QMP events - if not utils_misc.wait_for(lambda: self.get_event(qmp_event), 120): + if not wait.wait_for(lambda: self.get_event(qmp_event), 120): raise QMPEventError(cmd, qmp_event, self.vm.name, self.name) logging.info("%s QMP event received" % qmp_event) @@ -3014,7 +3017,7 @@ def system_powerdown(self): # Send a powerdown monitor command self.cmd(cmd) # Look for POWERDOWN QMP events - if not utils_misc.wait_for(lambda: self.get_event(qmp_event), 120): + if not wait.wait_for(lambda: self.get_event(qmp_event), 120): raise QMPEventError(cmd, qmp_event, self.vm.name, self.name) logging.info("%s QMP event received" % qmp_event) diff --git a/virttest/qemu_vm.py b/virttest/qemu_vm.py index 53e9debb21b..3d5abc766f3 100644 --- a/virttest/qemu_vm.py +++ b/virttest/qemu_vm.py @@ -21,6 +21,8 @@ from avocado.utils import process from avocado.utils import crypto from avocado.utils import linux_modules +from avocado.utils import data_factory +from avocado.utils import wait import six from six.moves import xrange @@ -861,7 +863,7 @@ def set_dev_params(dev, dev_params, dev.set_param(pro[:-idx], val) if dev_backend: dev.set_param("backend", dev_backend) - dev_id = utils_misc.generate_random_string(8) + dev_id = data_factory.generate_random_string(8) dev_id = "%s-%s" % (backend_type, dev_id) dev.set_param("id", dev_id) @@ -2351,8 +2353,8 @@ def _nic_tap_remove_helper(self, nic): os.close(int(i)) if nic.ifname: deletion_time = max(5, math.ceil(int(nic.queues) / 8)) - if utils_misc.wait_for(lambda: nic.ifname not in utils_net.get_net_if(), - deletion_time): + if wait.wait_for(lambda: nic.ifname not in utils_net.get_net_if(), + deletion_time): self._del_port_from_bridge(nic) except TypeError: pass @@ -2963,8 +2965,8 @@ def wait_for_status(self, status, timeout, first=0.0, step=1.0, text=None): :return: True in case the status has changed before timeout, otherwise return None. """ - return utils_misc.wait_for(lambda: self.monitor.verify_status(status), - timeout, first, step, text) + return wait.wait_for(lambda: self.monitor.verify_status(status), + timeout, first, step, text) def wait_until_paused(self, timeout): """ @@ -2987,7 +2989,7 @@ def wait_until_dead(self, timeout, first=0.0, step=1.0): :param first: Time to sleep before first attempt :param steps: Time to sleep between attempts in seconds """ - return utils_misc.wait_for(self.is_dead, timeout, first, step) + return wait.wait_for(self.is_dead, timeout, first, step) def wait_for_shutdown(self, timeout=60): """ @@ -3105,7 +3107,7 @@ def _cleanup(self, free_mac_addresses): if port_mapping: queues_num = sum([int(_.queues) for _ in port_mapping.values()]) deletion_time = max(5, math.ceil(queues_num / 8)) - utils_misc.wait_for(lambda: set(port_mapping.keys()).isdisjoint( + wait.wait_for(lambda: set(port_mapping.keys()).isdisjoint( utils_net.get_net_if()), deletion_time) for inactive_port in set(port_mapping.keys()).difference(utils_net.get_net_if()): nic = port_mapping.pop(inactive_port) @@ -3673,9 +3675,9 @@ def deactivate_nic(self, nic_index_or_name, wait=20): logging.info("waiting for the guest to finish the unplug") nic_eigenvalue = r'dev:\s+%s,\s+id\s+"%s"' % (nic.nic_model, nic.nic_name) - if not utils_misc.wait_for(lambda: nic_eigenvalue not in - self.monitor.info("qtree"), - wait, 5, 1): + if not wait.wait_for(lambda: nic_eigenvalue not in + self.monitor.info("qtree"), + wait, 5, 1): raise virt_vm.VMDelNicError("Device is not unplugged by " "guest, please check whether the " "hotplug module was loaded in " @@ -3796,8 +3798,8 @@ def mig_cancelled(self): return self._mig_cancelled(o) def wait_for_migration(self, timeout): - if not utils_misc.wait_for(self.mig_finished, timeout, 2, 2, - "Waiting for migration to complete"): + if not wait.wait_for(self.mig_finished, timeout, 2, 2, + "Waiting for migration to complete"): raise virt_vm.VMMigrateTimeoutError("Timeout expired while waiting" " for migration to finish") @@ -4062,9 +4064,9 @@ def migrate(self, timeout=virt_vm.BaseVM.MIGRATE_TIMEOUT, protocol="tcp", cancel_delay, logging.info) time.sleep(cancel_delay) self.monitor.cmd("migrate_cancel") - if not utils_misc.wait_for(self.mig_cancelled, 60, 2, 2, - "Waiting for migration " - "cancellation"): + if not wait.wait_for(self.mig_cancelled, 60, 2, 2, + "Waiting for migration " + "cancellation"): raise virt_vm.VMMigrateCancelError( "Cannot cancel migration") return @@ -4228,7 +4230,7 @@ def _shell_reboot(session, timeout): # TODO detect and handle guest crash? _reboot() error_context.context("waiting for guest to go down", logging.info) - if not utils_misc.wait_for(_check_go_down, timeout=timeout): + if not wait.wait_for(_check_go_down, timeout=timeout): raise virt_vm.VMRebootError("Guest refuses to go down") finally: if session: @@ -4283,7 +4285,7 @@ def save_to_file(self, path): logging.debug("Saving VM %s to %s" % (self.name, path)) # Can only check status if background migration self.monitor.migrate("exec:cat>%s" % path, wait=False) - utils_misc.wait_for( + wait.wait_for( # no monitor.migrate-status method lambda: re.search("(status.*completed)", diff --git a/virttest/utils_net.py b/virttest/utils_net.py index 41b693c1b05..d4e69814baf 100644 --- a/virttest/utils_net.py +++ b/virttest/utils_net.py @@ -20,6 +20,8 @@ from avocado.core import exceptions from avocado.utils import path as utils_path from avocado.utils import process +from avocado.utils import data_factory +from avocado.utils import wait import six from six.moves import xrange @@ -3186,7 +3188,7 @@ def generate_ifname(self, nic_index_or_name): """ nic_index = self.nic_name_index(self[nic_index_or_name].nic_name) prefix = "t%d-" % nic_index - postfix = utils_misc.generate_random_string(6) + postfix = data_factory.generate_random_string(6) # Ensure interface name doesn't excede 11 characters self[nic_index_or_name].ifname = (prefix + postfix)[-11:] self.update_db() @@ -3309,11 +3311,11 @@ def __verify_neigh(ip, macs, dev, timeout, session=None, **dargs): verify_func = __verify_neigh if ip_ver == 6 else __arping for dev in devs: # VM might take some time to respond after migration - return bool(utils_misc.wait_for(lambda: verify_func(ip, macs, dev, - timeout, - session=session, **dargs), - timeout, - text="Retry verifying IP address")) + return bool(wait.wait_for(lambda: verify_func(ip, macs, dev, + timeout, + session=session, **dargs), + timeout, + text="Retry verifying IP address")) def generate_mac_address_simple(): @@ -4008,9 +4010,9 @@ def _check_file_size_unchanged(): return False return True - utils_misc.wait_for(lambda: _check_file_size_unchanged(), - timeout=timeout, - step=10.0) + wait.wait_for(lambda: _check_file_size_unchanged(), + timeout=timeout, + step=10.0) kill_cmd = "taskkill /im traceview.exe" session.cmd(kill_cmd) diff --git a/virttest/utils_test/__init__.py b/virttest/utils_test/__init__.py index c22fe4f71ff..c8f00fa0491 100755 --- a/virttest/utils_test/__init__.py +++ b/virttest/utils_test/__init__.py @@ -39,6 +39,8 @@ from avocado.utils import crypto from avocado.utils import path from avocado.utils import archive +from avocado.utils import wait +from avocado.utils import data_factory from six.moves import xrange @@ -51,6 +53,7 @@ from virttest import remote from virttest import scan_autotest_results from virttest import storage +from virttest import utils_disk from virttest import utils_misc from virttest import utils_net from virttest import virt_vm @@ -584,7 +587,7 @@ def run_image_copy(test, params, env): mount_dest_dir) error_context.context("Mount the NFS share directory") - if not utils_misc.mount(src, mount_dest_dir, 'nfs', 'ro'): + if not utils_disk.mount(src, mount_dest_dir, 'nfs', 'ro'): raise exceptions.TestError('Could not mount NFS share %s to %s' % (src, mount_dest_dir)) @@ -651,7 +654,7 @@ def run_file_transfer(test, params, env): guest_path = tempfile.mktemp(prefix="transferred-", dir=tmp_dir) else: tmp_dir = params.get("tmp_dir", "c:\\") - guest_path = "\\".join([tmp_dir, utils_misc.generate_random_string(8)]) + guest_path = "\\".join([tmp_dir, data_factory.generate_random_string(8)]) guest_path = "\\".join(filter(None, re.split(r"\\+", guest_path))) cmd = "dd if=/dev/zero of=%s bs=10M count=%d" % (host_path, count) try: @@ -803,9 +806,9 @@ def transfer_data(session, host_cmd, guest_cmd, n_time, timeout, count = int(filesize) host_data_file = os.path.join(dir_name, - "tmp-%s" % utils_misc.generate_random_string(8)) + "tmp-%s" % data_factory.generate_random_string(8)) guest_data_file = os.path.join(tmp_dir, - "tmp-%s" % utils_misc.generate_random_string(8)) + "tmp-%s" % data_factory.generate_random_string(8)) if sender == "host" or sender == "both": cmd = "dd if=/dev/zero of=%s bs=1M count=%d" % (host_data_file, count) @@ -2138,9 +2141,9 @@ def load_stress_tool(self): except aexpect.ShellTimeoutError: self.cmd_launch('') # wait for stress to start and then check, if not raise TestError - if not utils_misc.wait_for(self.app_running, self.stress_wait_for_timeout, first=2.0, - text="wait for stress app to start", - step=1.0): + if not wait.wait_for(self.app_running, self.stress_wait_for_timeout, first=2.0, + text="wait for stress app to start", + step=1.0): raise exceptions.TestError("Stress app does not " "running as expected") @@ -2156,8 +2159,8 @@ def _unload_stress(): return False logging.info("stop stress app in guest/host/remote host") - utils_misc.wait_for(_unload_stress, self.stress_wait_for_timeout, first=2.0, - text="wait stress app quit", step=1.0) + wait.wait_for(_unload_stress, self.stress_wait_for_timeout, first=2.0, + text="wait stress app quit", step=1.0) def app_running(self): """ diff --git a/virttest/utils_test/qemu/migration.py b/virttest/utils_test/qemu/migration.py index 24b993ec39d..8b83c58408b 100644 --- a/virttest/utils_test/qemu/migration.py +++ b/virttest/utils_test/qemu/migration.py @@ -23,6 +23,7 @@ from avocado.utils import data_factory from avocado.utils import path as utils_path from avocado.utils import process +from avocado.utils import wait from avocado.utils.data_structures import DataSize from virttest import data_dir @@ -128,8 +129,8 @@ def mig_cancelled(): o.get("status") == "canceled") def wait_for_migration(): - if not utils_misc.wait_for(mig_finished, mig_timeout, 2, 2, - "Waiting for migration to finish"): + if not wait.wait_for(mig_finished, mig_timeout, 2, 2, + "Waiting for migration to finish"): raise exceptions.TestFail("Timeout expired while waiting for migration " "to finish") @@ -163,9 +164,9 @@ def wait_for_migration(): if mig_cancel: time.sleep(2) vm.monitor.cmd("migrate_cancel") - if not utils_misc.wait_for(mig_cancelled, 60, 2, 2, - "Waiting for migration " - "cancellation"): + if not wait.wait_for(mig_cancelled, 60, 2, 2, + "Waiting for migration " + "cancellation"): raise exceptions.TestFail("Failed to cancel migration") if offline: vm.resume() @@ -1646,7 +1647,7 @@ def check_running(): return session.cmd_status(self.check_running_cmd) == 0 if self.check_running_cmd: - if not utils_misc.wait_for(check_running, timeout=360): + if not wait.wait_for(check_running, timeout=360): raise exceptions.TestFail("Failed to start %s in guest." % self.bg_stress_test) diff --git a/virttest/virt_vm.py b/virttest/virt_vm.py index 540380bc930..ab90042064c 100644 --- a/virttest/virt_vm.py +++ b/virttest/virt_vm.py @@ -11,6 +11,8 @@ from aexpect.exceptions import ShellError from aexpect.exceptions import ExpectError from avocado.core import exceptions +from avocado.utils import data_factory +from avocado.utils import wait import six from six.moves import xrange @@ -590,7 +592,7 @@ def _generate_unique_id(self): """ while True: self.instance = (time.strftime("%Y%m%d-%H%M%S-") + - utils_misc.generate_random_string(8)) + data_factory.generate_random_string(8)) if not glob.glob(os.path.join(data_dir.get_tmp_dir(), "*%s" % self.instance)): break @@ -886,7 +888,7 @@ def _get_address(): except (VMIPAddressMissingError, VMAddressVerificationError) as e: return False - ipaddr = utils_misc.wait_for(_get_address, timeout, step=interval) + ipaddr = wait.wait_for(_get_address, timeout, step=interval) if not ipaddr: # Read guest address via serial console and update VM address # cache to avoid get out-dated address. @@ -1075,7 +1077,7 @@ def login(self, nic_index=0, timeout=LOGIN_TIMEOUT, port = self.get_port(int(self.params.get("shell_port"))) log_filename = ("session-%s-%s-%s.log" % (self.name, time.strftime("%m-%d-%H-%M-%S"), - utils_misc.generate_random_string(4))) + data_factory.generate_random_string(4))) session = remote.remote_login(client, address, port, username, password, prompt, linesep, log_filename, timeout, @@ -1236,7 +1238,7 @@ def copy_files_to(self, host_path, guest_path, nic_index=0, limit="", port = self.get_port(int(self.params.get("file_transfer_port"))) log_filename = ("transfer-%s-to-%s-%s.log" % (self.name, address, - utils_misc.generate_random_string(4))) + data_factory.generate_random_string(4))) remote.copy_files_to(address, client, username, password, port, host_path, guest_path, limit, log_filename, verbose, timeout, interface=neigh_attach_if, @@ -1272,7 +1274,7 @@ def copy_files_from(self, guest_path, host_path, nic_index=0, limit="", port = self.get_port(int(self.params.get("file_transfer_port"))) log_filename = ("transfer-%s-from-%s-%s.log" % (self.name, address, - utils_misc.generate_random_string(4))) + data_factory.generate_random_string(4))) remote.copy_files_from(address, client, username, password, port, guest_path, host_path, limit, log_filename, verbose, timeout, interface=neigh_attach_if,