コード例 #1
0
def setup_reset_nvram(guest_xml, params, virsh_func, test, *args):
    """
    Setup for the tests, including
    1. Configure os firmware attribute
    2. Create nvram file and make its size invalid

    :param guest_xml: the guest xml
    :param params: dict for parameters of the tests
    :param virsh_func: virsh function will be invoked
    :param args:  tuple, virsh function uses
    """
    test.log.info("Config guest xml with firmware efi")
    vm_name = params.get("main_vm", "avocado-vt-vm1")
    os_attrs = eval(params.get('os_attrs'))
    if os_attrs:
        osxml = vm_xml.VMOSXML()
        osxml.setup_attrs(**os_attrs)
        guest_xml.os = osxml
        guest_xml.sync()
    test.log.debug("After configuration, vm xml:\n%s",
                   vm_xml.VMXML.new_from_inactive_dumpxml(vm_name))
    test.log.info("Start vm to create %s_VARS.fd file" % vm_name)
    virsh.start(vm_name)
    test.log.info("Modify the nvram file to make it invalid")
    cmd = 'echo > /var/lib/libvirt/qemu/nvram/%s_VARS.fd' % vm_name
    process.run(cmd, ignore_status=False, shell=True)
    test.log.debug("Prepare the required vm state")
    if len(args) > 1:
        virsh_func(args[0], args[1], ignore_status=False)
    else:
        virsh_func(args[0], ignore_status=False)
コード例 #2
0
ファイル: iface_network.py プロジェクト: wkf31156/tp-libvirt
    def modify_iface_xml():
        """
        Modify interface xml options
        """
        vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
        if pxe_boot:
            # Config boot console for pxe boot
            osxml = vm_xml.VMOSXML()
            osxml.type = vmxml.os.type
            osxml.arch = vmxml.os.arch
            osxml.machine = vmxml.os.machine
            osxml.loader = "/usr/share/seabios/bios.bin"
            osxml.bios_useserial = "yes"
            osxml.bios_reboot_timeout = "-1"
            osxml.boots = ['network']
            del vmxml.os
            vmxml.os = osxml

        xml_devices = vmxml.devices
        iface_index = xml_devices.index(
            xml_devices.by_device_tag("interface")[0])
        iface = xml_devices[iface_index]
        iface_bandwidth = {}
        iface_inbound = ast.literal_eval(iface_bandwidth_inbound)
        iface_outbound = ast.literal_eval(iface_bandwidth_outbound)
        if iface_inbound:
            iface_bandwidth["inbound"] = iface_inbound
        if iface_outbound:
            iface_bandwidth["outbound"] = iface_outbound
        if iface_bandwidth:
            bandwidth = iface.new_bandwidth(**iface_bandwidth)
            iface.bandwidth = bandwidth

        iface_type = params.get("iface_type", "network")
        iface.type_name = iface_type
        source = ast.literal_eval(iface_source)
        if not source:
            source = {"network": "default"}
        net_ifs = utils_net.get_net_if(state="UP")
        # Check source device is valid or not,
        # if it's not in host interface list, try to set
        # source device to first active interface of host
        if (iface.type_name == "direct" and
            source.has_key('dev') and
                source['dev'] not in net_ifs):
            logging.warn("Source device %s is not a interface"
                         " of host, reset to %s",
                         source['dev'], net_ifs[0])
            source['dev'] = net_ifs[0]
        del iface.source
        iface.source = source
        iface_model = params.get("iface_model", "virtio")
        iface.model = iface_model
        logging.debug("New interface xml file: %s", iface)
        vmxml.devices = xml_devices
        vmxml.xmltreefile.write()
        vmxml.sync()
コード例 #3
0
ファイル: iface_network.py プロジェクト: ldoktor/tp-libvirt
    def modify_iface_xml():
        """
        Modify interface xml options
        """
        vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
        if pxe_boot:
            # Config boot console for pxe boot
            osxml = vm_xml.VMOSXML()
            osxml.type = vmxml.os.type
            osxml.arch = vmxml.os.arch
            osxml.machine = vmxml.os.machine
            osxml.loader = "/usr/share/seabios/bios.bin"
            osxml.bios_useserial = "yes"
            osxml.bios_reboot_timeout = "-1"
            osxml.boots = ['network']
            del vmxml.os
            vmxml.os = osxml

        xml_devices = vmxml.devices
        iface_index = xml_devices.index(
            xml_devices.by_device_tag("interface")[0])
        iface = xml_devices[iface_index]
        iface_bandwidth = {}
        iface_inbound = eval(iface_bandwidth_inbound)
        iface_outbound = eval(iface_bandwidth_outbound)
        if iface_inbound:
            iface_bandwidth["inbound"] = iface_inbound
        if iface_outbound:
            iface_bandwidth["outbound"] = iface_outbound
        if iface_bandwidth:
            bandwidth = iface.new_bandwidth(**iface_bandwidth)
            iface.bandwidth = bandwidth

        iface_source = params.get("iface_source")
        if iface_source:
            source = eval(iface_source)
            if source:
                iface.source = source
        logging.debug("New interface xml file: %s", iface)
        vmxml.devices = xml_devices
        vmxml.xmltreefile.write()
        vmxml.sync()
コード例 #4
0
 def generate_container_xml():
     """
     Generate container xml
     """
     vmxml = vm_xml.VMXML(dom_type)
     vmxml.vm_name = vm_name
     vmxml.max_mem = max_mem
     vmxml.current_mem = current_mem
     vmxml.vcpu = vcpu
     # Generate os
     vm_os = vm_xml.VMOSXML()
     vm_os.type = os_type
     vm_os.arch = os_arch
     vm_os.init = os_init
     vmxml.os = vm_os
     # Generate emulator
     emulator = Emulator()
     emulator.path = emulator_path
     # Generate console
     console = Console()
     filesystem = Filesystem()
     filesystem.accessmode = fs_accessmode
     filesystem.source = {'dir': install_root}
     filesystem.target = {'dir': fs_target}
     # Add emulator and console in devices
     devices = vm_xml.VMXMLDevices()
     devices.append(emulator)
     devices.append(console)
     devices.append(filesystem)
     # Add network device
     network = Interface(type_name=interface_type)
     network.mac_address = utils_net.generate_mac_address_simple()
     network.source = {interface_type: net_name}
     devices.append(network)
     vmxml.set_devices(devices)
     return vmxml
コード例 #5
0
            if hotplug:
                disks_xml.append(disk_xml)
            else:
                vmxml.add_device(disk_xml)

        # If we want to test with bootdisk.
        # just edit the bootdisk xml.
        if test_with_boot_disk:
            xml_devices = vmxml.devices
            disk_index = xml_devices.index(
                xml_devices.by_device_tag("disk")[0])
            disk = xml_devices[disk_index]
            if bootorder != "":
                disk.boot = bootorder
                osxml = vm_xml.VMOSXML()
                osxml.type = vmxml.os.type
                osxml.arch = vmxml.os.arch
                osxml.machine = vmxml.os.machine
                if test_boot_console:
                    osxml.loader = "/usr/share/seabios/bios.bin"
                    osxml.bios_useserial = "yes"
                    osxml.bios_reboot_timeout = "-1"

                del vmxml.os
                vmxml.os = osxml
            driver_dict = {
                "name": disk.driver["name"],
                "type": disk.driver["type"]
            }
            if bootdisk_driver != "":
コード例 #6
0
    def modify_iface_xml(sync=True):
        """
        Modify interface xml options

        :param sync: whether or not sync vmxml after the iface xml modified,
                    default to be True
        """
        vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
        if pxe_boot:
            # Config boot console for pxe boot
            osxml = vm_xml.VMOSXML()
            osxml.type = vmxml.os.type
            osxml.arch = vmxml.os.arch
            osxml.machine = vmxml.os.machine
            osxml.loader = "/usr/share/seabios/bios.bin"
            osxml.bios_useserial = "yes"
            if utils_misc.compare_qemu_version(4, 0, 0, False):
                osxml.bios_reboot_timeout = "-1"
            osxml.boots = ['network']
            del vmxml.os
            vmxml.os = osxml

        xml_devices = vmxml.devices
        iface_index = xml_devices.index(
            xml_devices.by_device_tag("interface")[0])
        iface = xml_devices[iface_index]
        if not sync:
            params.setdefault('original_iface', vmxml.devices[iface_index])
        iface_bandwidth = {}
        iface_inbound = ast.literal_eval(iface_bandwidth_inbound)
        iface_outbound = ast.literal_eval(iface_bandwidth_outbound)
        if iface_inbound:
            iface_bandwidth["inbound"] = iface_inbound
        if iface_outbound:
            iface_bandwidth["outbound"] = iface_outbound
        if iface_bandwidth:
            bandwidth = iface.new_bandwidth(**iface_bandwidth)
            iface.bandwidth = bandwidth

        iface_type = params.get("iface_type", "network")
        iface.type_name = iface_type
        source = ast.literal_eval(iface_source)
        if not source:
            source = {"network": "default"}
        net_ifs = utils_net.get_net_if(state="UP")
        # Check source device is valid or not,
        # if it's not in host interface list, try to set
        # source device to first active interface of host
        if (iface.type_name == "direct" and
                'dev' in source and
                source['dev'] not in net_ifs):
            logging.warning("Source device %s is not a interface of host, reset to %s",
                            source['dev'], net_ifs[0])
            source['dev'] = net_ifs[0]
        del iface.source
        iface.source = source
        if iface_model:
            iface.model = get_iface_model(iface_model, host_arch)
        if iface_rom:
            iface.rom = eval(iface_rom)
        if iface_boot:
            vmxml.remove_all_boots()
            iface.boot = iface_boot
        logging.debug("New interface xml file: %s", iface)
        if sync:
            vmxml.devices = xml_devices
            vmxml.xmltreefile.write()
            vmxml.sync()
        else:
            return iface