rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
logging.info("File transfer is not ended, start a round of migration ...")
logging.info("File transfer is not ended, start a round of" "migration ...")
def transfer_test(vm, host_path, guest_path, timeout=120): """ vm.copy_files_to does not raise exception, so we need a wrapper in order to make it to be used by BackgroundTest. """ if not vm.copy_files_to(host_path, guest_path, timeout=timeout): raise error.TestError("Fail to do the file transfer!")
utils.run("rm -rf /tmp/zero")
if os.path.isfile("/tmp/zero"): os.remove("/tmp/zero")
def transfer_test(vm, host_path, guest_path, timeout=120): """ vm.copy_files_to does not raise exception, so we need a wrapper in order to make it to be used by BackgroundTest. """ if not vm.copy_files_to(host_path, guest_path, timeout=timeout): raise error.TestError("Fail to do the file transfer!")
mac, ip = kvm_utils.get_mac_ip_pair_from_dict(nic_params)
if "address_index" in nic_params: mac, ip = kvm_utils.get_mac_ip_pair_from_dict(nic_params) else: mac = vm.get_mac_address(nic_index) nic_index += 1
def chk_fmt_model(device, fmt_model, info_cmd, str): f_fail = 0 devices = kvm_utils.get_sub_dict_names(params, device) for chk_device in devices: expected = kvm_utils.get_sub_dict(params, chk_device).get(fmt_model) if not expected: expected = "rtl8139" try: o = vm.monitor.info(info_cmd) except kvm_monitor.MonitorError,...
slot_id = "0" + add_output.split(",")[2].split()[1] cmd = "pci_del pci_addr=%s" % slot_id
result_domain, bus, slot, function = add_output.split(',') domain = int(result_domain.split()[2]) bus = int(bus.split()[1]) slot = int(slot.split()[1]) pci_addr = "%x:%x:%x" % (domain, bus, slot) cmd = "pci_del pci_addr=%s" % pci_addr
def pci_del(ignore_failure=False): if cmd_type == "pci_add": slot_id = "0" + add_output.split(",")[2].split()[1] cmd = "pci_del pci_addr=%s" % slot_id elif cmd_type == "device_add": cmd = "device_del %s" % id # This should be replaced by a proper monitor method call vm.monitor.cmd(cmd)
elif pa_type is not None and pa_type != "no":
elif pa_type and pa_type != "no":
def create(self, name=None, params=None, root_dir=None, for_migration=False, timeout=5.0): """ Start the VM by running a qemu command. All parameters are optional. The following applies to all parameters but for_migration: If a parameter is not supplied, the corresponding value stored in the class attributes is used, a...
except Exception as inst:
except Exception, inst:
def _open(self, in_files): """ Open devices and return array of descriptors
except Exception as inst:
except Exception, inst:
def blocking(self, port, mode=False): """ Set port function mode blocking/nonblocking
print ("PASS: set blocking mode to %s mode" % ("blocking" if mode else "nonblocking"))
if mode: print "PASS: set to blocking mode" else: print "PASS: set to nonblocking mode"
def blocking(self, port, mode=False): """ Set port function mode blocking/nonblocking
except Exception as inst:
except Exception, inst:
def close(self, file): """ Close open port.
except Exception as inst:
except Exception, inst:
def open(self, in_file): """ Direct open devices.
except Exception as inst:
except Exception, inst:
def send(self, port, length=1, mode=True): """ Send a data of some length
except Exception as inst:
except Exception, inst:
def recv(self, port, length=1, buffer=1024, mode=True): """ Recv a data of some length
session = self.remote_login() if session: cmd = self.params.get("cpu_chk_cmd") s, count = session.get_command_status_output(cmd) if s == 0: return int(count)
cmd = self.params.get("cpu_chk_cmd") s, count = session.get_command_status_output(cmd) if s == 0: return int(count)
def get_cpu_count(self): """ Get the cpu count of the VM. """ try: session = self.remote_login() if session: cmd = self.params.get("cpu_chk_cmd") s, count = session.get_command_status_output(cmd) if s == 0: return int(count) return None finally: session.close()
if dict.get("run_kvm_stat") == "yes": profile = True else: profile = None if profile: job.profilers.add('kvm_stat')
profilers = dict.get("profilers", "").split() for profiler in profilers: job.profilers.add(profiler)
def run_tests(test_list, job): """ Runs the sequence of KVM tests based on the list of dictionaries generated by the configuration system, handling dependencies. @param test_list: List with all dictionary test parameters. @param job: Autotest job object. @return: True, if all tests ran passed, False if any of them fa...
profile_only=profile) if profile: job.profilers.delete('kvm_stat')
profile_only= bool(profilers) or None) for profiler in profilers: job.profilers.delete(profiler)
def run_tests(test_list, job): """ Runs the sequence of KVM tests based on the list of dictionaries generated by the configuration system, handling dependencies. @param test_list: List with all dictionary test parameters. @param job: Autotest job object. @return: True, if all tests ran passed, False if any of them fa...
raise error.TestFail("Could not log into guest %s using %s connection", vm.name, type)
raise error.TestFail("Could not log into guest %s using %s connection" % (vm.name, type))
def wait_for_login(vm, nic_index=0, timeout=240, start=0, step=2, serial=None): """ Try logging into a VM repeatedly. Stop on success or when timeout expires. @param vm: VM object. @param nic_index: Index of NIC to access in the VM. @param timeout: Time to wait before giving up. @param serial: Whether to use a serial...
if start_vm and not vm.create(name, params, test.bindir, for_migration): raise error.TestError("Could not start VM")
if start_vm: if not vm.create(name, params, test.bindir, for_migration): raise error.TestError("Could not start VM") else: vm.params = params
def preprocess_vm(test, params, env, name): """ Preprocess a single VM object according to the instructions in params. Start the VM if requested and get a screendump. @param test: An Autotest test object. @param params: A dict containing VM preprocessing parameters. @param env: The environment (a dict-like object). @p...
def add_nic(help, vlan, model=None, mac=None, netdev_id=None): if has_option(help, "netdev"): cmd = " -net nic,netdev=%s" % netdev_id
def add_nic(help, vlan, model=None, mac=None, netdev_id=None, nic_extra_params=None): if has_option(help, "device"): if model == "virtio": model="virtio-net-pci" if not model: model= "rtl8139" cmd = " -device %s" % model if mac: cmd += ",mac=%s" % mac if has_option(help, "netdev"): cmd += ",netdev=%s" % netdev_id else:...
def add_nic(help, vlan, model=None, mac=None, netdev_id=None): if has_option(help, "netdev"): cmd = " -net nic,netdev=%s" % netdev_id else: cmd = " -net nic,vlan=%d" % vlan if model: cmd += ",model=%s" % model if mac: cmd += ",macaddr='%s'" % mac return cmd
cmd = " -net nic,vlan=%d" % vlan if model: cmd += ",model=%s" % model if mac: cmd += ",macaddr='%s'" % mac
if has_option(help, "netdev"): cmd = " -net nic,netdev=%s" % netdev_id else: cmd = " -net nic,vlan=%d" % vlan if model: cmd += ",model=%s" % model if mac: cmd += ",macaddr='%s'" % mac
def add_nic(help, vlan, model=None, mac=None, netdev_id=None): if has_option(help, "netdev"): cmd = " -net nic,netdev=%s" % netdev_id else: cmd = " -net nic,vlan=%d" % vlan if model: cmd += ",model=%s" % model if mac: cmd += ",macaddr='%s'" % mac return cmd
self.netdev_id[vlan])
self.netdev_id[vlan], nic_params.get("nic_extra_params"))
def add_no_hpet(help): if has_option(help, "no-hpet"): return " -no-hpet" else: return ""
def __init__(self, exitevent, in_files, out_files, cachesize=1): """ @param exitevent: Event to end switch. @param in_files: Array of input files. @param out_files: Array of output files. @param cachesize: Block to receive and send. """ Thread.__init__(self) self.in_files = in_files self.out_files = out_files self.ca...
class th_send(Thread): """ Random data sender thread. """ def __init__(self, port, length, buffers, blocklen=32): """ @param port: Destination port. @param length: Amount of data we want to send. @param buffers: Buffers for the control data (FIFOs). @param blocklen: Block length. """ Thread.__init__(self) self.ExitStat...
def __init__(self, exitevent, in_files, out_files, cachesize=1): """ @param exitevent: Event to end switch. @param in_files: Array of input files. @param out_files: Array of output files. @param cachesize: Block to receive and send. """ Thread.__init__(self)
files[name] = os.open(name, os.O_RDWR) if (ports[item[0]]["is_console"] == "yes"): print os.system("stty -F %s raw -echo" % (ports[item[0]]["path"])) print os.system("stty -F %s -a" % ports[item[0]]["path"]) f.append(files[name]) except Exception as inst: print "FAIL: Failed to open file %s" % name raise inst return f ...
f = open("/proc/stat", "r") tmp = f.readlines(200) f.close() except: logging.critical("Error reading /proc/stat") error.TestFail("average_cpu_load: Error reading /proc/stat") for line in tmp: if line[0:4] == "cpu ": reg = re.compile('[0-9]+') load_values = reg.findall(line) load = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] f...
def open_device(in_files, ports): """ Open devices and return an array of descriptors. @param in_files: files array @return: array of descriptors """ f = [] for item in in_files: name = ports[item[0]]["path"] if (not item[1] == ports[item[0]]["is_console"]): print ports print "FAIL: Host console is not like console o...
logging.debug("Checking KSM status...") ksm_flag = 0 for line in os.popen('ksmctl info').readlines(): if line.startswith('flags'): ksm_flag = int(line.split(' ')[1].split(',')[0]) if int(ksm_flag) != 1: logging.info("KSM module is not loaded! Trying to load module and " "start ksmctl...") try: utils.run("modprobe ksm")...
def split_parallel(): """ Parallel page spliting """ logging.info("Phase 1: parallel page spliting") # We have to wait until allocator is finished (it waits 5 seconds to # clean the socket
tftp_root = os.environ.get('KVM_TEST_tftp', '') if tftp_root: self.tftp_root = os.path.join(kvm_test_dir, tftp_root) if not os.path.isdir(self.tftp_root): os.makedirs(self.tftp_root) else: self.tftp_root = tftp_root self.kernel_args = os.environ.get('KVM_TEST_kernel_args', '') self.finish_program = os.environ.get('KVM...
attributes = ['kernel_args', 'finish_program', 'cdrom_cd1', 'unattended_file', 'medium', 'url', 'kernel', 'initrd', 'nfs_server', 'nfs_dir', 'pxe_dir', 'pxe_image', 'pxe_initrd', 'install_virtio', 'tftp', 'qemu_img_binary', 'floppy'] for a in attributes: self._setattr(a) if self.install_virtio == 'yes': v_attributes =...
def __init__(self): """ Gets params from environment variables and sets class attributes. """ script_dir = os.path.dirname(sys.modules[__name__].__file__) kvm_test_dir = os.path.abspath(os.path.join(script_dir, "..")) images_dir = os.path.join(kvm_test_dir, 'images') self.deps_dir = os.path.join(kvm_test_dir, 'deps') s...
self.nfs_mount = tempfile.mkdtemp(prefix='nfs_', dir='/tmp') floppy_name = os.environ['KVM_TEST_floppy'] self.floppy_img = os.path.join(kvm_test_dir, floppy_name) floppy_dir = os.path.dirname(self.floppy_img) if not os.path.isdir(floppy_dir): os.makedirs(floppy_dir) self.pxe_dir = os.environ.get('KVM_TEST_pxe_dir', ''...
if self.medium == 'nfs': self.nfs_mount = tempfile.mkdtemp(prefix='nfs_', dir='/tmp') self.floppy = os.path.join(kvm_test_dir, self.floppy) if not os.path.isdir(os.path.dirname(self.floppy)): os.makedirs(os.path.dirname(self.floppy))
def __init__(self): """ Gets params from environment variables and sets class attributes. """ script_dir = os.path.dirname(sys.modules[__name__].__file__) kvm_test_dir = os.path.abspath(os.path.join(script_dir, "..")) images_dir = os.path.join(kvm_test_dir, 'images') self.deps_dir = os.path.join(kvm_test_dir, 'deps') s...
if os.path.exists(self.floppy_img): os.remove(self.floppy_img) c_cmd = '%s create -f raw %s 1440k' % (self.qemu_img_bin, self.floppy_img)
if os.path.exists(self.floppy): os.remove(self.floppy) c_cmd = '%s create -f raw %s 1440k' % (self.qemu_img_binary, self.floppy)
def create_boot_floppy(self): """ Prepares a boot floppy by creating a floppy image file, mounting it and copying an answer file (kickstarts for RH based distros, answer files for windows) to it. After that the image is umounted. """ print "Creating boot floppy"
f_cmd = 'mkfs.msdos -s 1 %s' % self.floppy_img
f_cmd = 'mkfs.msdos -s 1 %s' % self.floppy
def create_boot_floppy(self): """ Prepares a boot floppy by creating a floppy image file, mounting it and copying an answer file (kickstarts for RH based distros, answer files for windows) to it. After that the image is umounted. """ print "Creating boot floppy"
m_cmd = 'mount -o loop,rw %s %s' % (self.floppy_img,
m_cmd = 'mount -o loop,rw %s %s' % (self.floppy,
def create_boot_floppy(self): """ Prepares a boot floppy by creating a floppy image file, mounting it and copying an answer file (kickstarts for RH based distros, answer files for windows) to it. After that the image is umounted. """ print "Creating boot floppy"
if self.install_virtio:
if self.install_virtio == "yes":
def create_boot_floppy(self): """ Prepares a boot floppy by creating a floppy image file, mounting it and copying an answer file (kickstarts for RH based distros, answer files for windows) to it. After that the image is umounted. """ print "Creating boot floppy"
if self.tftp_root is '':
if not self.tftp:
def create_boot_floppy(self): """ Prepares a boot floppy by creating a floppy image file, mounting it and copying an answer file (kickstarts for RH based distros, answer files for windows) to it. After that the image is umounted. """ print "Creating boot floppy"
unattended_contents = re.sub(dummy_medium_re, content, unattended_contents) dummy_path = "C:" dummy_storage_re = r'\bKVM_TEST_STORAGE_DRIVER_PATH\b' storage_driver = os.environ.get('KVM_TEST_virtio_storage_path', '') if re.search(dummy_storage_re, unattended_contents): if self.install_virtio: unattended_contents = re...
unattended_contents = re.sub(dummy_medium_re, content, unattended_contents) def replace_virtio_key(contents, dummy_re, env): """ Replace a virtio dummy string with contents. If install_virtio is not set, replace it with a dummy string. @param contents: Contents of the unattended file @param dummy_re: Regular express...
def create_boot_floppy(self): """ Prepares a boot floppy by creating a floppy image file, mounting it and copying an answer file (kickstarts for RH based distros, answer files for windows) to it. After that the image is umounted. """ print "Creating boot floppy"
os.chmod(self.floppy_img, 0755)
os.chmod(self.floppy, 0755)
def create_boot_floppy(self): """ Prepares a boot floppy by creating a floppy image file, mounting it and copying an answer file (kickstarts for RH based distros, answer files for windows) to it. After that the image is umounted. """ print "Creating boot floppy"
print "Setting up PXE boot using TFTP root %s" % self.tftp_root
print "Setting up PXE boot using TFTP root %s" % self.tftp
def setup_pxe_boot(self): """ Sets up a PXE boot environment using the built in qemu TFTP server. Copies the PXE Linux bootloader pxelinux.0 from the host (needs the pxelinux package or equivalent for your distro), and vmlinuz and initrd.img files from the CD to a directory that qemu will serve trough TFTP to the VM. "...
pxe_dest = os.path.join(self.tftp_root, 'pxelinux.0')
pxe_dest = os.path.join(self.tftp, 'pxelinux.0')
def setup_pxe_boot(self): """ Sets up a PXE boot environment using the built in qemu TFTP server. Copies the PXE Linux bootloader pxelinux.0 from the host (needs the pxelinux package or equivalent for your distro), and vmlinuz and initrd.img files from the CD to a directory that qemu will serve trough TFTP to the VM. "...
m_cmd = 'mount -t iso9660 -v -o loop,ro %s %s' % (self.cdrom_iso,
m_cmd = 'mount -t iso9660 -v -o loop,ro %s %s' % (self.cdrom_cd1,
def setup_pxe_boot(self): """ Sets up a PXE boot environment using the built in qemu TFTP server. Copies the PXE Linux bootloader pxelinux.0 from the host (needs the pxelinux package or equivalent for your distro), and vmlinuz and initrd.img files from the CD to a directory that qemu will serve trough TFTP to the VM. "...
self.cdrom_iso)
self.cdrom_cd1)
def setup_pxe_boot(self): """ Sets up a PXE boot environment using the built in qemu TFTP server. Copies the PXE Linux bootloader pxelinux.0 from the host (needs the pxelinux package or equivalent for your distro), and vmlinuz and initrd.img files from the CD to a directory that qemu will serve trough TFTP to the VM. "...
tftp_image = os.path.join(self.tftp_root, 'vmlinuz') tftp_initrd = os.path.join(self.tftp_root, 'initrd.img')
tftp_image = os.path.join(self.tftp, 'vmlinuz') tftp_initrd = os.path.join(self.tftp, 'initrd.img')
def setup_pxe_boot(self): """ Sets up a PXE boot environment using the built in qemu TFTP server. Copies the PXE Linux bootloader pxelinux.0 from the host (needs the pxelinux package or equivalent for your distro), and vmlinuz and initrd.img files from the CD to a directory that qemu will serve trough TFTP to the VM. "...
pxe_config_dir = os.path.join(self.tftp_root, 'pxelinux.cfg')
pxe_config_dir = os.path.join(self.tftp, 'pxelinux.cfg')
def setup_pxe_boot(self): """ Sets up a PXE boot environment using the built in qemu TFTP server. Copies the PXE Linux bootloader pxelinux.0 from the host (needs the pxelinux package or equivalent for your distro), and vmlinuz and initrd.img files from the CD to a directory that qemu will serve trough TFTP to the VM. "...
print " medium: " + str(self.medium) print " qemu_img_bin: " + str(self.qemu_img_bin) print " cdrom iso: " + str(self.cdrom_iso) print " unattended_file: " + str(self.unattended_file) print " kernel_args: " + str(self.kernel_args) print " tftp_root: " + str(self.tftp_root) print " floppy_mount: " +...
for member in inspect.getmembers(self): name, value = member attribute = getattr(self, name) if not (name.startswith("__") or callable(attribute) or not value): print " %s: %s" % (name, value) print if self.unattended_file and self.floppy is not None:
def setup(self): print "Starting unattended install setup"
if self.tftp_root:
if self.tftp:
def setup(self): print "Starting unattended install setup"
self.netdev_id[vlan], nic_params.get("nic_extra_params"))
netdev_id, nic_params.get("nic_extra_params"))
def add_no_hpet(help): if has_option(help, "no-hpet"): return " -no-hpet" else: return ""
nic_params.get("bootp"), redirs, self.netdev_id[vlan],
nic_params.get("bootp"), redirs, netdev_id,
def add_no_hpet(help): if has_option(help, "no-hpet"): return " -no-hpet" else: return ""
nic_dicts = [kvm_utils.get_sub_dict(self.params, nic) for nic in nics] macs = [kvm_utils.get_mac_ip_pair_from_dict(dict)[0] for dict in nic_dicts] macs.append(mac)
macs = [self.get_mac_address(i) for i in range(len(nics))]
def get_address(self, index=0): """ Return the address of a NIC of the guest, in host space.
test.do_test(tmulti_open, [vm, send_pt], True)
test.do_test(tmulti_open, [vm, send_pt])
def test_smoke(test, vm, consoles, params): """ Virtio console smoke test.
test.do_test(tbasic_loopback, [vm, send_pt, recv_pt], data)
test.do_test(tbasic_loopback, [vm, send_pt, recv_pt, data], True)
def test_smoke(test, vm, consoles, params): """ Virtio console smoke test.
self.mount = tempfile.mkdtemp(prefix='cdrom_unattended', dir='/tmp')
self.mount = tempfile.mkdtemp(prefix='cdrom_unattended_', dir='/tmp')
def __init__(self, path): print "Creating ISO unattended image %s" % path self.mount = tempfile.mkdtemp(prefix='cdrom_unattended', dir='/tmp') self.path = path clean_old_image(path) if not os.path.isdir(os.path.dirname(path)): os.makedirs(os.path.dirname(path))
self.cdrom_mount = tempfile.mkdtemp(prefix='cdrom_', dir='/tmp')
self.cdrom_cd1_mount = tempfile.mkdtemp(prefix='cdrom_cd1_', dir='/tmp')
def __init__(self): """ Gets params from environment variables and sets class attributes. """ images_dir = os.path.join(KVM_TEST_DIR, 'images') self.deps_dir = os.path.join(KVM_TEST_DIR, 'deps') self.unattended_dir = os.path.join(KVM_TEST_DIR, 'unattended')
self.cdrom_mount)
self.cdrom_cd1_mount)
def setup_pxe_boot(self): """ Sets up a PXE boot environment using the built in qemu TFTP server. Copies the PXE Linux bootloader pxelinux.0 from the host (needs the pxelinux package or equivalent for your distro), and vmlinuz and initrd.img files from the CD to a directory that qemu will serve trough TFTP to the VM. "...
pxe_dir = os.path.join(self.cdrom_mount, self.pxe_dir)
pxe_dir = os.path.join(self.cdrom_cd1_mount, self.pxe_dir)
def setup_pxe_boot(self): """ Sets up a PXE boot environment using the built in qemu TFTP server. Copies the PXE Linux bootloader pxelinux.0 from the host (needs the pxelinux package or equivalent for your distro), and vmlinuz and initrd.img files from the CD to a directory that qemu will serve trough TFTP to the VM. "...
u_cmd = 'umount %s' % self.cdrom_mount if os.system(u_cmd): raise SetupError('Could not unmount CD at %s.' % self.cdrom_mount) self.cleanup(self.cdrom_mount)
cleanup(self.cdrom_cd1_mount)
def setup_pxe_boot(self): """ Sets up a PXE boot environment using the built in qemu TFTP server. Copies the PXE Linux bootloader pxelinux.0 from the host (needs the pxelinux package or equivalent for your distro), and vmlinuz and initrd.img files from the CD to a directory that qemu will serve trough TFTP to the VM. "...
u_cmd = "umount %s" % self.nfs_mount if os.system(u_cmd): raise SetupError("Could not unmont nfs at %s" % self.nfs_mount) self.cleanup(self.nfs_mount) def cleanup(self, mount): """ Clean up a previously used mountpoint. @param mount: Mountpoint to be cleaned up. """ if os.path.isdir(mount): if os.path.ismount(mount)...
cleanup(self.nfs_mount)
def setup_nfs(self): """ Copy the vmlinuz and initrd.img from nfs. """ print "Copying the vmlinuz and initrd.img from nfs"
self.kernel, self.image_path))
os.path.basename(self.kernel), self.image_path))
def setup_nfs(self): """ Copy the vmlinuz and initrd.img from nfs. """ print "Copying the vmlinuz and initrd.img from nfs"
self.initrd, self.image_path))
os.path.basename(self.initrd), self.image_path))
def setup_nfs(self): """ Copy the vmlinuz and initrd.img from nfs. """ print "Copying the vmlinuz and initrd.img from nfs"
iso = params.get("cdrom") if iso: iso = kvm_utils.get_path(root_dir, iso) if not os.path.exists(iso): logging.error("ISO file not found: %s" % iso) return False compare = False if params.get("md5sum_1m"): logging.debug("Comparing expected MD5 sum with MD5 sum of " "first MB of ISO file...") actual_hash = utils.hash_fil...
for cdrom in kvm_utils.get_sub_dict_names(params, "cdroms"): cdrom_params = kvm_utils.get_sub_dict(params, cdrom) iso = cdrom_params.get("cdrom") if iso: iso = kvm_utils.get_path(root_dir, iso) if not os.path.exists(iso): logging.error("ISO file not found: %s" % iso)
def create(self, name=None, params=None, root_dir=None, timeout=5.0, migration_mode=None, mac_source=None): """ Start the VM by running a qemu command. All parameters are optional. If name, params or root_dir are not supplied, the respective values stored as class attributes are used.
for k in params.keys():
for k in params:
def process_command(test, params, env, command, command_timeout, command_noncritical): """ Pre- or post- custom commands to be executed before/after a test is run @param test: An Autotest test object. @param params: A dict containing all VM and image parameters. @param env: The environment (a dict-like object). @param...
for key in env:
for key in env.keys():
def preprocess(test, params, env): """ Preprocess all VMs and images according to the instructions in params. Also, collect some host information, such as the KVM version. @param test: An Autotest test object. @param params: A dict containing all VM and image parameters. @param env: The environment (a dict-like object...
self.results = []
self.results = None
def initialize(self): self.job.require_gcc() self.results = []
self.results.append(utils.system_output(cmd, retain_output=True))
raw_output = utils.system_output(cmd, retain_output=True) self.results = raw_output path = os.path.join(self.resultsdir, 'raw_output_%s' % self.iteration) raw_output_file = open(path, 'w') raw_output_file.write(raw_output) raw_output_file.close()
def run_once(self, num_groups=90): hackbench_bin = os.path.join(self.srcdir, 'hackbench') cmd = '%s %s' % (hackbench_bin, num_groups) self.results.append(utils.system_output(cmd, retain_output=True))
def setup_virtio_win2003(self, virtio_floppy):
def setup_virtio_win2003(self, virtio_floppy, virtio_oemsetup_id):
def setup_virtio_win2003(self, virtio_floppy): """ Setup the install floppy with the virtio storage drivers, win2003 style.
if default_driver != self.virtio_oemsetup_identifier: parser.set('Defaults', 'SCSI', self.virtio_oemsetup_identifier)
if default_driver != virtio_oemsetup_id: parser.set('Defaults', 'SCSI', virtio_oemsetup_id)
def setup_virtio_win2003(self, virtio_floppy): """ Setup the install floppy with the virtio storage drivers, win2003 style.
boot_disk.setup_virtio_win2003(self.virtio_floppy)
boot_disk.setup_virtio_win2003(self.virtio_floppy, self.virtio_oemsetup_id)
def setup_boot_disk(self): answer_contents = self.render_answer_file()
s, o = session.get_command_status_output(e_cmd)
s, o = session.get_command_status_output(e_cmd, timeout=120)
def extract(vm, remote_path, dest_dir="."): """ Extract a .tar.bz2 file on the guest.
netdev_id=None, vhost=False):
netdev_id=None, netdev_extra_params=None):
def add_net(help, vlan, mode, ifname=None, script=None, downscript=None, tftp=None, bootfile=None, hostfwd=[], netdev_id=None, vhost=False): if has_option(help, "netdev"): cmd = " -netdev %s,id=%s" % (mode, netdev_id) if vhost: cmd += ",vhost=on" else: cmd = " -net %s,vlan=%d" % (mode, vlan) if mode == "tap": if ifname...
if vhost: cmd += ",vhost=on"
if netdev_extra_params: cmd += ",%s" % netdev_extra_params
def add_net(help, vlan, mode, ifname=None, script=None, downscript=None, tftp=None, bootfile=None, hostfwd=[], netdev_id=None, vhost=False): if has_option(help, "netdev"): cmd = " -netdev %s,id=%s" % (mode, netdev_id) if vhost: cmd += ",vhost=on" else: cmd = " -net %s,vlan=%d" % (mode, vlan) if mode == "tap": if ifname...
nic_params.get("vhost")=="yes")
nic_params.get("netdev_extra_params"))
def add_no_hpet(help): if has_option(help, "no-hpet"): return " -no-hpet" else: return ""
for nic in params.get("nics").split(): self.netdev_id.append(kvm_utils.generate_random_id())
def __init__(self, name, params, root_dir, address_cache): """ Initialize the object and set a few attributes.
utils.system('patch -p1 < ../0001-fix-ctcs2-build.patch')
p1 = 'patch -p1 < ../0001-Fix-CTCS2-Build.patch' utils.system(p1)
def setup(self, tarball='ctcs2.tar.bz2', length='4h', tc_opt='-k', tcf_contents=None): """ Builds the test suite, and sets up the control file that is going to be processed by the ctcs2 engine. @param tarball: CTCS2 tarball @param length: The amount of time we'll run the test suite @param tcf_contents: If the user want...
output = os.popen('uname -i').read() if output.find('x86_64') != -1: utils.system('patch -p1 < ../0002-compile-on-64bit.patch')
if utils.get_cpu_arch() == 'x86_64': p2 = 'patch -p1 < ../0002-Fix-CTCS2-build-in-64-bit-boxes.patch' utils.system(p2)
def setup(self, tarball='ctcs2.tar.bz2', length='4h', tc_opt='-k', tcf_contents=None): """ Builds the test suite, and sets up the control file that is going to be processed by the ctcs2 engine. @param tarball: CTCS2 tarball @param length: The amount of time we'll run the test suite @param tcf_contents: If the user want...
utils.system('./configure')
if 'CBUILD' in os.environ and 'CHOST' in os.environ: config_params = '--build=%s --host=%s' % (os.environ['CBUILD'], os.environ['CHOST']) else: config_params = '' utils.system('./configure %s' % config_params)
def setup(self, tarball='dbench-3.04.tar.gz'): tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) utils.extract_tarball_to_dir(tarball, self.srcdir) os.chdir(self.srcdir)
config_file_list = ["address_pools.cfg", "build.cfg", "cdkeys.cfg", "tests_base.cfg", "tests.cfg", "unittests.cfg"]
config_file_list = ["build.cfg", "cdkeys.cfg", "tests_base.cfg", "tests.cfg", "unittests.cfg"]
def check_iso(url, destination, hash): """ Verifies if ISO that can be find on url is on destination with right hash. This function will verify the SHA1 hash of the ISO image. If the file turns out to be missing or corrupted, let the user know we can download it. @param url: URL where the ISO file can be found. @para...
except Exception as e:
except Exception, e:
def get_time(session, time_command, time_filter_re, time_format): """ Return the host time and guest time. If the guest time cannot be fetched a TestError exception is raised. Note that the shell session should be ready to receive commands (i.e. should "display" a command prompt and should be done with all previous c...
utils.system('./tiobench.pl --dir %s %s' %(self.dir, self.args))
results = utils.system_output('./tiobench.pl --dir %s %s' % (self.dir, self.args)) logging.info(results) results_path = os.path.join(self.resultsdir, 'raw_output_%s' % self.iteration) utils.open_write_close(results_path, results)
def run_once(self, dir = None, args = None): if not dir: self.dir = self.tmpdir else: self.dir = dir if not args: self.args = '--block=4096 --block=8192 --threads=10 --size=1024 --numruns=2' else: self.args = args
test_name = test_name.split("kvm.")[1]
test_name = test_name[4:]
def parse_results(text): """ Parse text containing Autotest results. @return: A list of result 4-tuples. """ result_list = [] start_time_list = [] info_list = [] lines = text.splitlines() for line in lines: line = line.strip() parts = line.split("\t") # Found a START line -- get start time if (line.startswith("START...
script = nic_params.get("script") downscript = nic_params.get("downscript")
script = nic_params.get("nic_script") downscript = nic_params.get("nic_downscript")
def add_pcidevice(help, host): return " -pcidevice host=%s" % host
def __init__(self, type="nic_vf", driver=None, driver_option=None,
def __init__(self, type="vf", driver=None, driver_option=None,
def __init__(self, type="nic_vf", driver=None, driver_option=None, names=None, devices_requested=None): """ Initialize parameter 'type' which could be: nic_vf: Virtual Functions nic_pf: Physical Function (actual hardware) mixed: Both includes VFs and PFs
nic_vf: Virtual Functions nic_pf: Physical Function (actual hardware)
vf: Virtual Functions pf: Physical Function (actual hardware)
def __init__(self, type="nic_vf", driver=None, driver_option=None, names=None, devices_requested=None): """ Initialize parameter 'type' which could be: nic_vf: Virtual Functions nic_pf: Physical Function (actual hardware) mixed: Both includes VFs and PFs
if self.type == "nic_vf":
if self.type == "vf":
def get_devs(self, count): """ Check out all devices' PCI IDs according to their name.
elif self.type == "nic_pf":
elif self.type == "pf":
def get_devs(self, count): """ Check out all devices' PCI IDs according to their name.
flopy_name = os.environ['KVM_TEST_floppy'] self.floppy_img = os.path.join(kvm_test_dir, flopy_name)
self.nfs_mount = tempfile.mkdtemp(prefix='nfs_', dir='/tmp') floppy_name = os.environ['KVM_TEST_floppy'] self.floppy_img = os.path.join(kvm_test_dir, floppy_name)
def __init__(self): """ Gets params from environment variables and sets class attributes. """ script_dir = os.path.dirname(sys.modules[__name__].__file__) kvm_test_dir = os.path.abspath(os.path.join(script_dir, "..")) images_dir = os.path.join(kvm_test_dir, 'images') self.deps_dir = os.path.join(kvm_test_dir, 'deps') s...
dummy_re = r'\bKVM_TEST_MEDIUM\b' if self.medium == "cdrom": content = "cdrom" elif self.medium == "url": content = "url --url %s" % self.url elif self.medium == "nfs": content = "nfs --server=%s --dir=%s" % (self.nfs_server, self.nfs_dir) else: raise SetupError("Unexpected installation medium %s" % self.url) unattend...
def create_boot_floppy(self): """ Prepares a boot floppy by creating a floppy image file, mounting it and copying an answer file (kickstarts for RH based distros, answer files for windows) to it. After that the image is umounted. """ print "Creating boot floppy"
self.create_boot_floppy() if self.tftp_root: self.setup_pxe_boot()
print " url: " + str(self.url) print " kernel: " + str(self.kernel) print " initrd: " + str(self.initrd) print " nfs_server: " + str(self.nfs_server) print " nfs_dir: " + str(self.nfs_dir) print " nfs_mount: " + str(self.nfs_mount) if self.unattended_file and self.floppy_img is not None: self.create_...
def setup(self): print "Starting unattended install setup"
def run_once(self, seconds=1):
def run_once(self): """ Set hwclock back to a date in 1980 and verify if the changes took effect in the system. """ logging.info('Setting hwclock to 2/2/80 03:04:00')
def run_once(self, seconds=1): utils.system('/sbin/hwclock --set --date "2/2/80 03:04:00"') date = utils.system_output('/sbin/hwclock') if not re.match('Sat *Feb *2 *03:04:.. 1980', date): raise error.TestFail('Failed to set hwclock back to the eighties')
date = utils.system_output('/sbin/hwclock')
date = utils.system_output('LC_ALL=C /sbin/hwclock')
def run_once(self, seconds=1): utils.system('/sbin/hwclock --set --date "2/2/80 03:04:00"') date = utils.system_output('/sbin/hwclock') if not re.match('Sat *Feb *2 *03:04:.. 1980', date): raise error.TestFail('Failed to set hwclock back to the eighties')
raise error.TestFail('Failed to set hwclock back to the eighties')
raise error.TestFail("Failed to set hwclock back to the eighties. " "Output of hwclock is '%s'" % date)
def run_once(self, seconds=1): utils.system('/sbin/hwclock --set --date "2/2/80 03:04:00"') date = utils.system_output('/sbin/hwclock') if not re.match('Sat *Feb *2 *03:04:.. 1980', date): raise error.TestFail('Failed to set hwclock back to the eighties')
if mig_protocol == "tcp": uri = "tcp:localhost:%d" % dest_vm.migration_port elif mig_protocol == "unix": uri = "unix:%s" % dest_vm.migration_file elif mig_protocol == "exec": uri = '"exec:nc localhost %s"' % dest_vm.migration_port if offline: vm.monitor.cmd("stop") vm.monitor.migrate(uri) if mig_cancel: time.sleep(2)...
try: if mig_protocol == "tcp": uri = "tcp:localhost:%d" % dest_vm.migration_port elif mig_protocol == "unix": uri = "unix:%s" % dest_vm.migration_file elif mig_protocol == "exec": uri = '"exec:nc localhost %s"' % dest_vm.migration_port
def wait_for_migration(): if not kvm_utils.wait_for(mig_finished, mig_timeout, 2, 2, "Waiting for migration to finish..."): raise error.TestFail("Timeout expired while waiting for migration " "to finish")
vm.monitor.cmd("cont") dest_vm.destroy(gracefully=False) return vm else: wait_for_migration() if stable_check: save_path = None or "/tmp" save1 = os.path.join(save_path, "src") save2 = os.path.join(save_path, "dst") vm.save_to_file(save1) dest_vm.save_to_file(save2) md5_save1 = utils.hash_file(save1) md5_save2 = uti...
vm.monitor.cmd("stop") vm.monitor.migrate(uri) if mig_cancel: time.sleep(2) vm.monitor.cmd("migrate_cancel") if not kvm_utils.wait_for(mig_cancelled, 60, 2, 2, "Waiting for migration " "cancellation"): raise error.TestFail("Failed to cancel migration") if offline: vm.monitor.cmd("cont") dest_vm.destroy(gracefully=Fals...
def wait_for_migration(): if not kvm_utils.wait_for(mig_finished, mig_timeout, 2, 2, "Waiting for migration to finish..."): raise error.TestFail("Timeout expired while waiting for migration " "to finish")
def run_once(self, qemu_path='', options='', testlist=''):
def run_once(self, options='', testlist=''):
def run_once(self, qemu_path='', options='', testlist=''): """ Passes the appropriate parameters to the testsuite.
if qemu_path: os.environ['PATH'] = qemu_path + ":" + os.environ['PATH']
def run_once(self, qemu_path='', options='', testlist=''): """ Passes the appropriate parameters to the testsuite.
result = utils.run(cmd, ignore_status=True)
def run_once(self, qemu_path='', options='', testlist=''): """ Passes the appropriate parameters to the testsuite.
msg = re.findall("Failures: .*", result.stdout)[0] if msg: self.failed_cases = re.findall("(\d+)", msg) raise error.TestFail("Failed cases: %s" % self.failed_cases) def postprocess_iteration(self): """ Copies the log files to the results dir. """ src = os.path.join(self.srcdir, "check.log") dest = os.path.join(self.r...
try: try: result = utils.system(cmd) except error.CmdError, e: failed_cases = re.findall("Failures: (\d+)", str(e)) for num in failed_cases: failed_name = num + ".out.bad" src = os.path.join(self.srcdir, failed_name) dest = os.path.join(self.resultsdir, failed_name) utils.get_file(src, dest) if failed_cases: e_msg = ("...
def run_once(self, qemu_path='', options='', testlist=''): """ Passes the appropriate parameters to the testsuite.
OS install. Optionally, sets up a PXE install server using qemu built in TFTP and DHCP servers to install a particular operating system. The parameters to the script are retrieved from environment variables.
OS install. The parameters to the script are retrieved from environment variables.
def close(self): g_cmd = ('mkisofs -o %s -max-iso9660-filenames ' '-relaxed-filenames -D --input-charset iso8859-1 ' '%s' % (self.path, self.mount)) run(g_cmd, info='Could not generate iso with answer file')
'nfs_server', 'nfs_dir', 'pxe_dir', 'pxe_image', 'pxe_initrd', 'install_virtio', 'tftp', 'floppy', 'cdrom_unattended']
'nfs_server', 'nfs_dir', 'install_virtio', 'floppy', 'cdrom_unattended', 'boot_path', 'extra_params']
def __init__(self): """ Gets params from environment variables and sets class attributes. """ images_dir = os.path.join(KVM_TEST_DIR, 'images') self.deps_dir = os.path.join(KVM_TEST_DIR, 'deps') self.unattended_dir = os.path.join(KVM_TEST_DIR, 'unattended')
self.tftp = self.tftp if self.tftp: self.tftp = os.path.join(KVM_TEST_DIR, self.tftp) if not os.path.isdir(self.tftp): os.makedirs(self.tftp)
def __init__(self): """ Gets params from environment variables and sets class attributes. """ images_dir = os.path.join(KVM_TEST_DIR, 'images') self.deps_dir = os.path.join(KVM_TEST_DIR, 'deps') self.unattended_dir = os.path.join(KVM_TEST_DIR, 'unattended')
self.image_path = KVM_TEST_DIR self.kernel_path = os.path.join(self.image_path, self.kernel) self.initrd_path = os.path.join(self.image_path, self.initrd)
self.image_path = os.path.dirname(self.kernel)
def __init__(self): """ Gets params from environment variables and sets class attributes. """ images_dir = os.path.join(KVM_TEST_DIR, 'images') self.deps_dir = os.path.join(KVM_TEST_DIR, 'deps') self.unattended_dir = os.path.join(KVM_TEST_DIR, 'unattended')
if self.tftp:
if "autoyast" in self.extra_params:
def setup_boot_disk(self): answer_contents = self.render_answer_file()
def setup_pxe_boot(self): """ Sets up a PXE boot environment using the built in qemu TFTP server. Copies the PXE Linux bootloader pxelinux.0 from the host (needs the pxelinux package or equivalent for your distro), and vmlinuz and initrd.img files from the CD to a directory that qemu will serve trough TFTP to the VM. "...
def setup_cdrom(self): """ Mount cdrom and copy vmlinuz and initrd.img. """ print "Copying vmlinuz and initrd.img from cdrom" m_cmd = ('mount -t iso9660 -v -o loop,ro %s %s' % (self.cdrom_cd1, self.cdrom_cd1_mount)) run(m_cmd, info='Could not mount CD image %s.' % self.cdrom_cd1)
def setup_pxe_boot(self): """ Sets up a PXE boot environment using the built in qemu TFTP server. Copies the PXE Linux bootloader pxelinux.0 from the host (needs the pxelinux package or equivalent for your distro), and vmlinuz and initrd.img files from the CD to a directory that qemu will serve trough TFTP to the VM. "...
m_cmd = ('mount -t iso9660 -v -o loop,ro %s %s' % (self.cdrom_cd1, self.cdrom_cd1_mount)) run(m_cmd, info='Could not mount CD image %s.' % self.cdrom_cd1) pxe_dir = os.path.join(self.cdrom_cd1_mount, self.pxe_dir) pxe_image = os.path.join(pxe_dir, self.pxe_image) pxe_initrd = os.path.join(pxe_dir, self.pxe_initrd) if...
img_path_cmd = ("mkdir -p %s" % self.image_path) run(img_path_cmd, info=("Could not create image path dir %s" % self.image_path)) kernel_fetch_cmd = ("cp %s/%s/%s %s" % (self.cdrom_cd1_mount, self.boot_path, os.path.basename(self.kernel), self.kernel)) run(kernel_fetch_cmd, info=("Could not copy the vmlinuz from %s" % ...
def setup_pxe_boot(self): """ Sets up a PXE boot environment using the built in qemu TFTP server. Copies the PXE Linux bootloader pxelinux.0 from the host (needs the pxelinux package or equivalent for your distro), and vmlinuz and initrd.img files from the CD to a directory that qemu will serve trough TFTP to the VM. "...
pxe_config_dir = os.path.join(self.tftp, 'pxelinux.cfg') if not os.path.isdir(pxe_config_dir): os.makedirs(pxe_config_dir) pxe_config_path = os.path.join(pxe_config_dir, 'default') pxe_config = open(pxe_config_path, 'w') pxe_config.write('DEFAULT pxeboot\n') pxe_config.write('TIMEOUT 20\n') pxe_config.write('PROMPT 0\...
def setup_pxe_boot(self): """ Sets up a PXE boot environment using the built in qemu TFTP server. Copies the PXE Linux bootloader pxelinux.0 from the host (needs the pxelinux package or equivalent for your distro), and vmlinuz and initrd.img files from the CD to a directory that qemu will serve trough TFTP to the VM. "...
print "Downloading the vmlinuz and initrd.img"
print "Downloading vmlinuz and initrd.img from URL"
def setup_url(self): """ Download the vmlinuz and initrd.img from URL. """ print "Downloading the vmlinuz and initrd.img" os.chdir(self.image_path)
kernel_fetch_cmd = "wget -q %s/isolinux/%s" % (self.url, self.kernel) initrd_fetch_cmd = "wget -q %s/isolinux/%s" % (self.url, self.initrd)
kernel_fetch_cmd = "wget -q %s/%s/%s" % (self.url, self.boot_path, os.path.basename(self.kernel)) initrd_fetch_cmd = "wget -q %s/%s/%s" % (self.url, self.boot_path, os.path.basename(self.initrd))
def setup_url(self): """ Download the vmlinuz and initrd.img from URL. """ print "Downloading the vmlinuz and initrd.img" os.chdir(self.image_path)