本文整理汇总了Python中virttest.libvirt_xml.devices.controller.Controller.model方法的典型用法代码示例。如果您正苦于以下问题:Python Controller.model方法的具体用法?Python Controller.model怎么用?Python Controller.model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类virttest.libvirt_xml.devices.controller.Controller
的用法示例。
在下文中一共展示了Controller.model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: recompose_xml
# 需要导入模块: from virttest.libvirt_xml.devices.controller import Controller [as 别名]
# 或者: from virttest.libvirt_xml.devices.controller.Controller import model [as 别名]
def recompose_xml(vm_name, scsi_disk):
"""
Add scsi disk, guest agent and scsi controller for guest
:param: vm_name: Name of domain
:param: scsi_disk: scsi_debug disk name
"""
# Get disk path of scsi_disk
path_cmd = "udevadm info --name %s | grep /dev/disk/by-path/ | " \
"cut -d' ' -f4" % scsi_disk
disk_path = utils.run(path_cmd).stdout.strip()
# Add qemu guest agent in guest xml
vm_xml.VMXML.set_agent_channel(vm_name)
vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
# Add scsi disk xml
scsi_disk = Disk(type_name="block")
scsi_disk.device = "lun"
scsi_disk.source = scsi_disk.new_disk_source(
**{'attrs': {'dev': disk_path}})
scsi_disk.target = {'dev': "sdb", 'bus': "scsi"}
vmxml.add_device(scsi_disk)
# Add scsi disk controller
scsi_controller = Controller("controller")
scsi_controller.type = "scsi"
scsi_controller.index = "0"
scsi_controller.model = "virtio-scsi"
vmxml.add_device(scsi_controller)
# Redefine guest
vmxml.sync()
示例2: recompose_xml
# 需要导入模块: from virttest.libvirt_xml.devices.controller import Controller [as 别名]
# 或者: from virttest.libvirt_xml.devices.controller.Controller import model [as 别名]
def recompose_xml(vm_name, scsi_disk):
"""
Add scsi disk, guest agent and scsi controller for guest
:param: vm_name: Name of domain
:param: scsi_disk: scsi_debug disk name
"""
vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
disk_path = scsi_disk
# Add scsi disk xml
scsi_disk = Disk(type_name="block")
scsi_disk.device = "lun"
scsi_disk.source = scsi_disk.new_disk_source(
**{'attrs': {'dev': disk_path}})
scsi_disk.target = {'dev': "sdb", 'bus': "scsi"}
find_scsi = "no"
controllers = vmxml.xmltreefile.findall("devices/controller")
for controller in controllers:
if controller.get("type") == "scsi":
find_scsi = "yes"
vmxml.add_device(scsi_disk)
# Add scsi disk controller
if find_scsi == "no":
scsi_controller = Controller("controller")
scsi_controller.type = "scsi"
scsi_controller.index = "0"
scsi_controller.model = "virtio-scsi"
vmxml.add_device(scsi_controller)
# Redefine guest
vmxml.sync()
示例3: run
# 需要导入模块: from virttest.libvirt_xml.devices.controller import Controller [as 别名]
# 或者: from virttest.libvirt_xml.devices.controller.Controller import model [as 别名]
def run(test, params, env):
"""
Test for adding controller for usb.
"""
# get the params from params
vm_name = params.get("main_vm", "avocado-vt-vm1")
vm = env.get_vm(vm_name)
index = params.get("index", "1")
index_conflict = "yes" == params.get("index_conflict", "no")
model = params.get("model", "nec-xhci")
status_error = "yes" == params.get("status_error", "no")
vm_xml = VMXML.new_from_inactive_dumpxml(vm_name)
vm_xml_backup = vm_xml.copy()
controllers = vm_xml.get_devices(device_type="controller")
devices = vm_xml.get_devices()
for dev in controllers:
if dev.type == "usb":
devices.remove(dev)
controller = Controller("controller")
controller.type = "usb"
controller.index = index
controller.model = model
devices.append(controller)
if index_conflict:
controller_1 = Controller("controller")
controller_1.type = "usb"
controller_1.index = index
devices.append(controller)
vm_xml.set_devices(devices)
try:
try:
vm_xml.sync()
vm.start()
if status_error:
raise error.TestFail("Add controller successfully in negative case.")
else:
try:
session = vm.wait_for_login()
except (LoginError, ShellError), e:
error_msg = "Test failed in positive case.\n error: %s\n" % e
raise error.TestFail(error_msg)
cmd = "dmesg -c | grep %s" % model.split('-')[-1]
stat_dmesg = session.cmd_status(cmd)
if stat_dmesg != 0:
raise error.TestNAError("Fail to run dmesg in guest")
session.close()
except (LibvirtXMLError, VMStartError), e:
if not status_error:
raise error.TestFail("Add controller failed. Detail: %s" % e)
finally:
vm_xml_backup.sync()
示例4: setup_controller_xml
# 需要导入模块: from virttest.libvirt_xml.devices.controller import Controller [as 别名]
# 或者: from virttest.libvirt_xml.devices.controller.Controller import model [as 别名]
def setup_controller_xml():
"""
Prepare controller devices of VM XML according to params.
"""
if cntlr_type is None:
return
ctrl = Controller(type_name=cntlr_type)
if model is not None:
ctrl.model = model
if pcihole is not None:
ctrl.pcihole64 = pcihole
if vectors is not None:
ctrl.vectors = vectors
if index is not None:
ctrl.index = index
if addr_str is not None:
match = re.match(r"(?P<bus>[0-9]*):(?P<slot>[0-9]*).(?P<function>[0-9])", addr_str)
if match:
addr_dict = match.groupdict()
addr_dict['bus'] = hex(int(addr_dict['bus']))
addr_dict['slot'] = hex(int(addr_dict['slot']))
addr_dict['function'] = hex(int(addr_dict['function']))
addr_dict['domain'] = '0x0000'
ctrl.address = ctrl.new_controller_address(attrs=addr_dict)
logging.debug("Controller XML is:%s", ctrl)
vm_xml.add_device(ctrl)
if usb_cntlr_model is not None:
ctrl = Controller(type_name='usb')
ctrl.model = usb_cntlr_model
if usb_cntlr_addr is not None:
match = re.match(r"(?P<bus>[0-9]*):(?P<slot>[0-9]*).(?P<function>[0-9])", usb_cntlr_addr)
if match:
addr_dict = match.groupdict()
addr_dict['bus'] = hex(int(addr_dict['bus']))
addr_dict['slot'] = hex(int(addr_dict['slot']))
addr_dict['function'] = hex(int(addr_dict['function']))
addr_dict['domain'] = '0x0000'
ctrl.address = ctrl.new_controller_address(attrs=addr_dict)
vm_xml.add_device(ctrl)
示例5: setup_controller
# 需要导入模块: from virttest.libvirt_xml.devices.controller import Controller [as 别名]
# 或者: from virttest.libvirt_xml.devices.controller.Controller import model [as 别名]
def setup_controller(nic_num, controller_index, ctl_models):
"""
Create controllers bond to numa node in the guest xml
:param nic_num: number of nic card bond to numa node
:param controller_index: index num used to create controllers
:param ctl_models: contoller topo for numa bond
"""
index = controller_index
if nic_num == 2:
ctl_models.append('pcie-switch-upstream-port')
ctl_models.append('pcie-switch-downstream-port')
ctl_models.append('pcie-switch-downstream-port')
for i in range(index):
controller = Controller("controller")
controller.type = "pci"
controller.index = i
if i == 0:
controller.model = 'pcie-root'
else:
controller.model = 'pcie-root-port'
vmxml.add_device(controller)
set_address = False
for model in ctl_models:
controller = Controller("controller")
controller.type = "pci"
controller.index = index
controller.model = model
if set_address or model == "pcie-switch-upstream-port":
attrs = {'type': 'pci', 'domain': '0', 'slot': '0',
'bus': index - 1, 'function': '0'}
controller.address = controller.new_controller_address(**{"attrs": attrs})
logging.debug(controller)
if controller.model == "pcie-expander-bus":
controller.node = "0"
controller.target = {'busNr': '100'}
set_address = True
else:
set_address = False
logging.debug(controller)
vmxml.add_device(controller)
index += 1
return index - 1
示例6: set_vm_controller_xml
# 需要导入模块: from virttest.libvirt_xml.devices.controller import Controller [as 别名]
# 或者: from virttest.libvirt_xml.devices.controller.Controller import model [as 别名]
def set_vm_controller_xml(vmxml):
"""
Set VM scsi controller xml.
:param vmxml. Domain xml object.
"""
# Add disk scsi controller
scsi_controller = Controller("controller")
scsi_controller.type = "scsi"
scsi_controller.index = "0"
scsi_controller.model = "virtio-scsi"
vmxml.add_device(scsi_controller)
# Redefine domain
vmxml.sync()
示例7: add_ctrls
# 需要导入模块: from virttest.libvirt_xml.devices.controller import Controller [as 别名]
# 或者: from virttest.libvirt_xml.devices.controller.Controller import model [as 别名]
def add_ctrls(vm_xml, dev_type="pci", dev_index="0", dev_model="pci-root"):
"""
Add multiple devices
:param dev_type: the type of the device to be added
:param dev_index: the maximum index of the device to be added
:param dev_model: the model of the device to be added
"""
for inx in range(0, int(dev_index) + 1):
newcontroller = Controller("controller")
newcontroller.type = dev_type
newcontroller.index = inx
newcontroller.model = dev_model
logging.debug("New device is added:\n%s", newcontroller)
vm_xml.add_device(newcontroller)
vm_xml.sync()
示例8: prepare_usb_controller
# 需要导入模块: from virttest.libvirt_xml.devices.controller import Controller [as 别名]
# 或者: from virttest.libvirt_xml.devices.controller.Controller import model [as 别名]
def prepare_usb_controller(vmxml, usb_models):
"""
Add usb controllers into vm's xml.
:param vmxml: The vm's xml.
:param usb_models: The usb models will be used in usb controller(s).
"""
if not usb_models:
test.error("No usb model provided.")
# Add disk usb controller(s)
for usb_model in usb_models:
usb_controller = Controller("controller")
usb_controller.type = "usb"
usb_controller.index = "0"
usb_controller.model = usb_model
vmxml.add_device(usb_controller)
# Redefine domain
vmxml.sync()
示例9: create_pci_device
# 需要导入模块: from virttest.libvirt_xml.devices.controller import Controller [as 别名]
# 或者: from virttest.libvirt_xml.devices.controller.Controller import model [as 别名]
def create_pci_device(pci_model, pci_model_name, **kwargs):
"""
Create a pci/pcie bridge
:param pci_model: model of pci controller device
:param pci_model_name: model name of pci controller device
:param kwargs: other k-w args that needed to create device
:return: the newly created device object
"""
pci_bridge = Controller('pci')
pci_bridge.model = pci_model
pci_bridge.model_name = {'name': pci_model_name}
if 'index' in kwargs:
pci_bridge.index = kwargs['index']
if 'address' in kwargs:
pci_bridge.address = pci_bridge.new_controller_address(
attrs=eval(kwargs['address']))
logging.debug('pci_bridge: %s', pci_bridge)
return pci_bridge
示例10: run
# 需要导入模块: from virttest.libvirt_xml.devices.controller import Controller [as 别名]
# 或者: from virttest.libvirt_xml.devices.controller.Controller import model [as 别名]
def run(test, params, env):
"""
Test for hotplug usb device.
"""
# get the params from params
vm_name = params.get("main_vm", "virt-tests-vm1")
vm = env.get_vm(vm_name)
usb_type = params.get("usb_type", "kbd")
attach_type = params.get("attach_type", "attach_device")
attach_count = int(params.get("attach_count", "1"))
if usb_type == "storage":
model = params.get("model", "nec-xhci")
index = params.get("index", "1")
status_error = "yes" == params.get("status_error", "no")
vm_xml = VMXML.new_from_inactive_dumpxml(vm_name)
vm_xml_backup = vm_xml.copy()
# Set selinux of host.
backup_sestatus = utils_selinux.get_status()
utils_selinux.set_status("permissive")
if usb_type == "storage":
controllers = vm_xml.get_devices(device_type="controller")
devices = vm_xml.get_devices()
for dev in controllers:
if dev.type == "usb" and dev.index == "1":
devices.remove(dev)
controller = Controller("controller")
controller.type = "usb"
controller.index = index
controller.model = model
devices.append(controller)
vm_xml.set_devices(devices)
try:
session = vm.wait_for_login()
except (LoginError, VMError, ShellError), e:
raise error.TestFail("Test failed: %s" % str(e))
示例11: run
# 需要导入模块: from virttest.libvirt_xml.devices.controller import Controller [as 别名]
# 或者: from virttest.libvirt_xml.devices.controller.Controller import model [as 别名]
def run(test, params, env):
# Get variables.
status_error = ('yes' == params.get("status_error", 'no'))
img_type = ('yes' == params.get("libvirt_scsi_img_type", "no"))
cdrom_type = ('yes' == params.get("libvirt_scsi_cdrom_type", "no"))
partition_type = ('yes' == params.get("libvirt_scsi_partition_type", "no"))
partition = params.get("libvirt_scsi_partition",
"ENTER.YOUR.AVAILABLE.PARTITION")
vm_name = params.get("main_vm", "avocado-vt-vm1")
# Init a VM instance and a VMXML instance.
vm = env.get_vm(vm_name)
vmxml = VMXML.new_from_inactive_dumpxml(vm_name)
# Keep a backup of xml to restore it in cleanup.
backup_xml = vmxml.copy()
# Add a scsi controller if there is not.
controller_devices = vmxml.get_devices("controller")
scsi_controllers = []
for device in controller_devices:
if device.type == "scsi":
scsi_controllers.append(device)
if not scsi_controllers:
scsi_controller = Controller("controller")
scsi_controller.type = "scsi"
scsi_controller.index = "0"
scsi_controller.model = "virtio-scsi"
vmxml.add_device(scsi_controller)
# Add disk with bus of scsi into vmxml.
if partition_type:
if partition.count("ENTER.YOUR"):
raise error.TestNAError("Partition for partition test "
"is not configured.")
partition_disk = Disk(type_name="block")
partition_disk.device = "disk"
partition_disk.target = {'dev': "vdg",
'bus': "scsi"}
partition_disk.source = partition_disk.new_disk_source(
**{'attrs': {'dev': partition}})
vmxml.add_device(partition_disk)
if img_type:
# Init a QemuImg instance.
img_name = "libvirt_scsi"
params['image_name'] = img_name
image = qemu_storage.QemuImg(params, data_dir.get_tmp_dir(), img_name)
# Create a image.
img_path, _ = image.create(params)
img_disk = Disk(type_name="file")
img_disk.device = "disk"
img_disk.source = img_disk.new_disk_source(
**{'attrs': {'file': img_path}})
img_disk.target = {'dev': "vde",
'bus': "scsi"}
vmxml.add_device(img_disk)
if cdrom_type:
# Init a CdromDisk instance.
cdrom_path = os.path.join(data_dir.get_tmp_dir(), "libvirt_scsi")
try:
cdrom = CdromDisk(cdrom_path, data_dir.get_tmp_dir())
cdrom.close()
except process.CmdError, detail:
raise error.TestNAError("Failed to create cdrom disk: %s" % detail)
cdrom_disk = Disk(type_name="file")
cdrom_disk.device = "cdrom"
cdrom_disk.target = {'dev': "vdf",
'bus': "scsi"}
cdrom_disk.source = cdrom_disk.new_disk_source(
**{'attrs': {'file': cdrom_path}})
vmxml.add_device(cdrom_disk)
示例12: run
# 需要导入模块: from virttest.libvirt_xml.devices.controller import Controller [as 别名]
# 或者: from virttest.libvirt_xml.devices.controller.Controller import model [as 别名]
#.........这里部分代码省略.........
def check_qemu_cmd():
"""
Check qemu-kvm command line options
"""
cmd = ("ps -ef | grep %s | grep -v grep " % vm_name)
if driver_iothread:
cmd += " | grep iothread=iothread%s" % driver_iothread
if process.system(cmd, ignore_status=True, shell=True):
test.fail("Can't see disk option '%s' "
"in command line" % cmd)
def check_auth_plaintext(vm_name, password):
"""
Check if libvirt passed the plaintext of the chap authentication
password to qemu.
:param vm_name: The name of vm to be checked.
:param password: The plaintext of password used for chap authentication.
:return: True if using plaintext, False if not.
"""
cmd = ("ps -ef | grep -v grep | grep qemu-kvm | grep %s | grep %s"
% (vm_name, password))
return process.system(cmd, ignore_status=True, shell=True) == 0
# Disk specific attributes.
device = params.get("virt_disk_device", "disk")
device_target = params.get("virt_disk_device_target", "vdd")
device_format = params.get("virt_disk_device_format", "raw")
device_type = params.get("virt_disk_device_type", "file")
device_bus = params.get("virt_disk_device_bus", "virtio")
# Controller specific attributes.
cntlr_type = params.get('controller_type', None)
cntlr_model = params.get('controller_model', None)
cntlr_index = params.get('controller_index', None)
controller_addr_options = params.get('controller_addr_options', None)
driver_iothread = params.get("driver_iothread")
# iscsi options.
iscsi_target = params.get("iscsi_target")
iscsi_host = params.get("iscsi_host")
iscsi_port = params.get("iscsi_port")
emulated_size = params.get("iscsi_image_size", "1")
uuid = params.get("uuid", "")
auth_uuid = "yes" == params.get("auth_uuid", "")
auth_usage = "yes" == params.get("auth_usage", "")
status_error = "yes" == params.get("status_error")
define_error = "yes" == params.get("define_error", "no")
test_save_snapshot = "yes" == params.get("test_save_snapshot", "no")
test_qemu_cmd = "yes" == params.get("test_qemu_cmd", "no")
check_partitions = "yes" == params.get("virt_disk_check_partitions", "yes")
secret_uuid = ""
# Start vm and get all partions in vm.
if vm.is_dead():
vm.start()
session = vm.wait_for_login()
old_parts = libvirt.get_parts_list(session)
session.close()
vm.destroy(gracefully=False)
# Back up xml file.
vmxml_backup = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
示例13: run
# 需要导入模块: from virttest.libvirt_xml.devices.controller import Controller [as 别名]
# 或者: from virttest.libvirt_xml.devices.controller.Controller import model [as 别名]
def run(test, params, env):
"""
Sriov basic test:
1.create max vfs;
2.Check the nodedev info;
3.Start a guest with vf;
4.Reboot a guest with vf;
5.suspend/resume a guest with vf
"""
def find_pf():
pci_address = ""
for pci in pci_dirs:
temp_iface_name = os.listdir("%s/net" % pci)[0]
operstate = utils_net.get_net_if_operstate(temp_iface_name)
if operstate == "up":
pf_iface_name = temp_iface_name
pci_address = pci
break
if pci_address == "":
return False
else:
return pci_address
def create_address_dict(pci_id):
"""
Use pci_xxxx_xx_xx_x to create address dict.
"""
device_domain = pci_id.split(':')[0]
device_domain = "0x%s" % device_domain
device_bus = pci_id.split(':')[1]
device_bus = "0x%s" % device_bus
device_slot = pci_id.split(':')[-1].split('.')[0]
device_slot = "0x%s" % device_slot
device_function = pci_id.split('.')[-1]
device_function = "0x%s" % device_function
attrs = {'type': 'pci', 'domain': device_domain, 'slot': device_slot,
'bus': device_bus, 'function': device_function}
return attrs
def addr_to_pci(addr):
"""
Convert address dict to pci address: xxxxx:xx.x.
"""
pci_domain = re.findall(r"0x(.+)", addr['domain'])[0]
pci_bus = re.findall(r"0x(.+)", addr['bus'])[0]
pci_slot = re.findall(r"0x(.+)", addr['slot'])[0]
pci_function = re.findall(r"0x(.+)", addr['function'])[0]
pci_addr = pci_domain + ":" + pci_bus + ":" + pci_slot + "." + pci_function
return pci_addr
def create_hostdev_interface(pci_id, managed, model):
"""
Create hostdev type interface xml.
"""
attrs = create_address_dict(pci_id)
new_iface = Interface('hostdev')
new_iface.managed = managed
if model != "":
new_iface.model = model
new_iface.mac_address = utils_net.generate_mac_address_simple()
new_iface.hostdev_address = new_iface.new_iface_address(**{"attrs": attrs})
chars = string.ascii_letters + string.digits + '-_'
alias_name = 'ua-' + ''.join(random.choice(chars) for _ in list(range(64)))
new_iface.alias = {'name': alias_name}
return new_iface
def create_vfs(vf_num):
"""
Create max vfs.
"""
net_device = []
net_name = []
test_res = process.run("echo 0 > %s/sriov_numvfs" % pci_address, shell=True)
pci_list = virsh.nodedev_list(cap='pci').stdout.strip().splitlines()
net_list = virsh.nodedev_list(cap='net').stdout.strip().splitlines()
pci_list_before = set(pci_list)
net_list_before = set(net_list)
test_res = process.run("echo %d > %s/sriov_numvfs" % (vf_num, pci_address), shell=True)
if test_res.exit_status != 0:
test.fail("Fail to create vfs")
pci_list_sriov = virsh.nodedev_list(cap='pci').stdout.strip().splitlines()
def _vf_init_completed():
try:
net_list_sriov = virsh.nodedev_list(cap='net').stdout.strip().splitlines()
net_list_sriov = set(net_list_sriov)
net_diff = list(net_list_sriov.difference(net_list_before))
if len(net_diff) != int(vf_num):
net_diff = []
return False
return net_diff
except process.CmdError:
raise test.fail("Get net list with 'virsh list' failed\n")
pci_list_sriov = set(pci_list_sriov)
pci_diff = list(pci_list_sriov.difference(pci_list_before))
net_diff = utils_misc.wait_for(_vf_init_completed, timeout=60)
if not net_diff:
test.fail("Get net list with 'virsh list' failed\n")
#.........这里部分代码省略.........
示例14: Controller
# 需要导入模块: from virttest.libvirt_xml.devices.controller import Controller [as 别名]
# 或者: from virttest.libvirt_xml.devices.controller.Controller import model [as 别名]
disk.target = {"dev": bootdisk_target, "bus": bootdisk_bus}
device_source = disk.source.attrs["file"]
del disk.address
vmxml.devices = xml_devices
vmxml.define()
# Add virtio_scsi controller.
if virtio_scsi_controller:
scsi_controller = Controller("controller")
scsi_controller.type = "scsi"
scsi_controller.index = "0"
ctl_model = params.get("virtio_scsi_controller_model")
if ctl_model:
scsi_controller.model = ctl_model
if virtio_scsi_controller_driver != "":
driver_dict = {}
for driver_option in virtio_scsi_controller_driver.split(','):
if driver_option != "":
d = driver_option.split('=')
driver_dict.update({d[0].strip(): d[1].strip()})
scsi_controller.driver = driver_dict
vmxml.del_controller("scsi")
vmxml.add_device(scsi_controller)
# Test usb devices.
usb_devices = {}
if add_usb_device:
# Delete all usb devices first.
controllers = vmxml.get_devices(device_type="controller")
示例15: run_libvirt_scsi
# 需要导入模块: from virttest.libvirt_xml.devices.controller import Controller [as 别名]
# 或者: from virttest.libvirt_xml.devices.controller.Controller import model [as 别名]
def run_libvirt_scsi(test, params, env):
# Get variables.
status_error = ('yes' == params.get("status_error", 'no'))
img_type = ('yes' == params.get("libvirt_scsi_img_type", "no"))
cdrom_type = ('yes' == params.get("libvirt_scsi_cdrom_type", "no"))
partition_type = ('yes' == params.get("libvirt_scsi_partition_type", "no"))
partition = params.get("libvirt_scsi_partition",
"ENTER.YOUR.AVAILIBLE.PARTITION")
vm_name = params.get("main_vm", "virt-tests-vm1")
# Init a VM instance and a VMXML instance.
vm = env.get_vm(vm_name)
vmxml = VMXML.new_from_dumpxml(vm_name)
# Keep a backup of xml to restore it in cleanup.
backup_xml = vmxml.copy()
# Add a scsi controller if there is not.
controller_devices = vmxml.get_devices("controller")
scsi_controller_exists = False
for device in controller_devices:
if device.type == "scsi":
scsi_controller_exists = True
break
if not scsi_controller_exists:
scsi_controller = Controller("controller")
scsi_controller.type = "scsi"
scsi_controller.index = "0"
scsi_controller.model = "virtio-scsi"
vmxml.add_device(scsi_controller)
# Add disk with bus of scsi into vmxml.
if img_type:
# Init a QemuImg instance.
img_name = "libvirt_scsi"
params['image_name'] = img_name
image = qemu_storage.QemuImg(params, data_dir.get_tmp_dir(), img_name)
# Create a image.
img_path, _ = image.create(params)
img_disk = Disk(type_name="file")
img_disk.device = "disk"
img_disk.source = img_disk.new_disk_source(
**{'attrs': {'file': img_path}})
img_disk.target = {'dev': "vde",
'bus': "scsi"}
vmxml.add_device(img_disk)
if cdrom_type:
# Init a CdromDisk instance.
cdrom_path = os.path.join(data_dir.get_tmp_dir(), "libvirt_scsi")
cdrom = CdromDisk(cdrom_path, data_dir.get_tmp_dir())
cdrom.close()
cdrom_disk = Disk(type_name="file")
cdrom_disk.device = "cdrom"
cdrom_disk.target = {'dev': "vdf",
'bus': "scsi"}
cdrom_disk.source = cdrom_disk.new_disk_source(
**{'attrs': {'file': cdrom_path}})
vmxml.add_device(cdrom_disk)
if partition_type:
if partition.count("ENTER.YOUR"):
raise error.TestNAError("Partition for partition test"
"is not configured.")
partition_disk = Disk(type_name="block")
partition_disk.device = "disk"
partition_disk.target = {'dev': "vdg",
'bus': "scsi"}
partition_disk.source = partition_disk.new_disk_source(
**{'attrs': {'dev': partition}})
vmxml.add_device(partition_disk)
# sync the vmxml with VM.
vmxml.sync()
# Check the result of scsi disk.
try:
try:
vm.start()
# Start VM successfully.
if status_error:
raise error.TestFail('Starting VM successed in negative case.')
except virt_vm.VMStartError, e:
# Starting VM failed.
if not status_error:
raise error.TestFail("Test failed in positive case."
"error: %s" % e)
finally:
# clean up.
backup_xml.sync()