本文整理汇总了Python中virttest.libvirt_xml.vm_xml.VMXML类的典型用法代码示例。如果您正苦于以下问题:Python VMXML类的具体用法?Python VMXML怎么用?Python VMXML使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VMXML类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: configure_serial_console
def configure_serial_console(vm_name):
"""Configure serial console"""
# Check the primary serial and set it to pty.
VMXML.set_primary_serial(vm_name, 'pty', '0', None)
# Configure VM pty console.
vm_pty_xml = VMXML.new_from_inactive_dumpxml(vm_name)
vm_pty_xml.remove_all_device_by_type('console')
console = Console()
console.target_port = '0'
console.target_type = 'serial'
vm_pty_xml.add_device(console)
vm_pty_xml.sync()
开发者ID:lento-sun,项目名称:tp-libvirt,代码行数:13,代码来源:set_virtlogd.py
示例2: _find_comm_paths
def _find_comm_paths(session):
if source_path is None:
host_path = _get_autopath()
else:
host_path = source_path
name_port_map = {}
base_path = '/sys/class/virtio-ports'
vports = session.cmd_output('ls %s' % base_path).split()
status = session.cmd_status('ls %s/*/name' % base_path)
if status == 0:
for vport in vports:
vport_path = os.path.join(base_path, vport)
name_path = os.path.join(vport_path, 'name')
name = session.cmd_output('cat %s' % name_path).strip()
name_port_map[name] = vport
if expect_name not in name_port_map:
raise error.TestFail("Expect get vport name %s, got %s" %
(expect_name, name_port_map))
vport = name_port_map[expect_name]
else:
active_xml = VMXML.new_from_dumpxml(vm_name)
port_number = active_xml.xmltreefile.find(
'/devices/channel/address').get('port')
vport = 'vport1p%s' % port_number
guest_path = '/dev/%s' % vport
return guest_path, host_path
开发者ID:bssrikanth,项目名称:tp-libvirt,代码行数:28,代码来源:channel_functional.py
示例3: run_mix_boot_order_os_boot
def run_mix_boot_order_os_boot(params, libvirtd, vm):
"""
Define a domain mixing boot device and disk boot order.
"""
vm_name = vm.name
vm_xml = VMXML.new_from_inactive_dumpxml(vm_name)
vm_xml_backup = vm_xml.copy()
try:
if not vm_xml.os.boots:
os_xml = vm_xml.os
os_xml.boots = {'dev': 'hd'}
vm_xml.os = os_xml
else:
logging.debug(vm_xml.os.boots)
order = 0
devices = vm_xml.devices
for device in devices:
if device.device_tag == 'disk':
device.boot = order
order += 1
vm_xml.devices = devices
try:
vm_xml.sync()
except LibvirtXMLError:
pass
finally:
vm_xml_backup.sync()
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:29,代码来源:crash_regression.py
示例4: run
def run(test, params, env):
"""
Test svirt in virt-clone.
"""
VIRT_CLONE = None
try:
VIRT_CLONE = utils_misc.find_command("virt-clone")
except ValueError:
raise error.TestNAError("No virt-clone command found.")
# Get general variables.
status_error = ('yes' == params.get("status_error", 'no'))
host_sestatus = params.get("svirt_virt_clone_host_selinux", "enforcing")
# Get variables about seclabel for VM.
sec_type = params.get("svirt_virt_clone_vm_sec_type", "dynamic")
sec_model = params.get("svirt_virt_clone_vm_sec_model", "selinux")
sec_label = params.get("svirt_virt_clone_vm_sec_label", None)
sec_relabel = params.get("svirt_virt_clone_vm_sec_relabel", "yes")
sec_dict = {'type': sec_type, 'model': sec_model, 'label': sec_label,
'relabel': sec_relabel}
# Get variables about VM and get a VM object and VMXML instance.
vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)
vmxml = VMXML.new_from_inactive_dumpxml(vm_name)
backup_xml = vmxml.copy()
# Get varialbles about image.
img_label = params.get('svirt_virt_clone_disk_label')
# Label the disks of VM with img_label.
disks = vm.get_disk_devices()
backup_labels_of_disks = {}
for disk in disks.values():
disk_path = disk['source']
backup_labels_of_disks[disk_path] = utils_selinux.get_context_of_file(
filename=disk_path)
utils_selinux.set_context_of_file(filename=disk_path,
context=img_label)
# Set selinux of host.
backup_sestatus = utils_selinux.get_status()
utils_selinux.set_status(host_sestatus)
# Set the context of the VM.
vmxml.set_seclabel([sec_dict])
vmxml.sync()
clone_name = ("%s-clone" % vm.name)
try:
cmd = ("%s --original %s --name %s --auto-clone" %
(VIRT_CLONE, vm.name, clone_name))
cmd_result = utils.run(cmd, ignore_status=True)
if cmd_result.exit_status:
raise error.TestFail("Failed to execute virt-clone command."
"Detail: %s." % cmd_result)
finally:
# clean up
for path, label in backup_labels_of_disks.items():
utils_selinux.set_context_of_file(filename=path, context=label)
backup_xml.sync()
utils_selinux.set_status(backup_sestatus)
if not virsh.domstate(clone_name).exit_status:
libvirt_vm.VM(clone_name, params, None, None).remove_with_storage()
开发者ID:Antique,项目名称:tp-libvirt,代码行数:60,代码来源:svirt_virt_clone.py
示例5: run
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()
开发者ID:CongLi,项目名称:tp-libvirt,代码行数:58,代码来源:libvirt_usb_hotplug_controller.py
示例6: _check_xml
def _check_xml():
"""
Check defined XML against expectation
"""
expected_channel = Channel(channel_type)
try:
source_dict = channel.source
except LibvirtXMLNotFoundError:
source_dict = {}
if channel_type == 'pty':
source_dict = {}
elif channel_type == 'unix':
if source_mode is None:
if source_path:
source_dict['mode'] = 'connect'
else:
source_dict['mode'] = 'bind'
if source_path is None:
source_dict['path'] = _get_autopath()
if source_autopath:
del source_dict['autopath']
target_dict = {}
if target_type == 'virtio':
expected_channel.address = {
'bus': '0',
'controller': '0',
'port': '1',
'type': 'virtio-serial',
}
if 'type' in channel.target:
target_dict['type'] = channel.target['type']
if 'name' in channel.target:
target_dict['name'] = channel.target['name']
elif target_type == 'guestfwd':
if 'type' in channel.target:
target_dict['type'] = channel.target['type']
if 'address' in channel.target:
target_dict['address'] = channel.target['address']
if 'port' in channel.target:
target_dict['port'] = channel.target['port']
if source_dict:
expected_channel.source = source_dict
if target_dict:
expected_channel.target = target_dict
current_xml = VMXML.new_from_dumpxml(vm_name)
channel_elem = current_xml.xmltreefile.find('devices/channel')
cur_channel = Channel.new_from_element(channel_elem)
if not (expected_channel == cur_channel):
raise error.TestFail("Expect generate channel:\n%s\nBut got:\n%s" %
(expected_channel, cur_channel))
开发者ID:bssrikanth,项目名称:tp-libvirt,代码行数:55,代码来源:channel_functional.py
示例7: run
def run(test, params, env):
"""
Test of libvirt SPICE related features.
1) Block specified ports if required;
2) Setup SPICE TLS certification if required;
3) Setup graphics tag in VM;
4) Try to start VM;
5) Parse and check result with expected.
6) Clean up environment.
"""
vm_name = params.get("main_vm", "virt-tests-vm1")
spice_xml = params.get("spice_xml", "no") == 'yes'
vnc_xml = params.get("vnc_xml", "no") == 'yes'
vm = env.get_vm(vm_name)
if vm.is_alive():
vm.destroy()
sockets = block_ports(params)
networks = setup_networks(params)
expected_result = get_expected_results(params, networks)
env_state = EnvState(params, expected_result)
vm_xml = VMXML.new_from_inactive_dumpxml(vm_name)
vm_xml_backup = vm_xml.copy()
try:
vm_xml.remove_all_graphics()
if spice_xml:
spice_graphic = generate_spice_graphic_xml(params, expected_result)
logging.debug('Test SPICE XML is: %s', spice_graphic)
vm_xml.devices = vm_xml.devices.append(spice_graphic)
if vnc_xml:
vnc_graphic = generate_vnc_graphic_xml(params, expected_result)
logging.debug('Test VNC XML is: %s', vnc_graphic)
vm_xml.devices = vm_xml.devices.append(vnc_graphic)
vm_xml.sync()
all_ips = utils_net.get_all_ips()
fail_patts = expected_result['fail_patts']
try:
vm.start()
except virt_vm.VMStartError, detail:
if not fail_patts:
raise error.TestFail(
"Expect VM can be started, but failed with: %s" % detail)
for patt in fail_patts:
if re.search(patt, str(detail)):
return
raise error.TestFail(
"Expect fail with error in %s, but failed with: %s"
% (fail_patts, detail))
else:
开发者ID:uni-peter-zheng,项目名称:tp-libvirt,代码行数:54,代码来源:graphics_functional.py
示例8: check_dumpxml
def check_dumpxml():
"""
Check whether the added devices are shown in the guest xml
"""
pattern = "<sound model=\"%s\">" % sound_model
# Check sound model
xml_after_adding_device = VMXML.new_from_dumpxml(vm_name)
if pattern not in str(xml_after_adding_device):
test.fail("Can not find the %s sound device xml "
"in the guest xml file." % sound_model)
# Check codec type
if codec_type:
pattern = "<codec type=\"%s\" />" % codec_type
if pattern not in str(xml_after_adding_device):
test.fail("Can not find the %s codec xml for sound dev "
"in the guest xml file." % codec_type)
开发者ID:nasastry,项目名称:tp-libvirt,代码行数:16,代码来源:sound_device.py
示例9: run_invalid_interface
def run_invalid_interface(params, libvirtd, vm):
"""
Define a domain with an invalid interface device.
"""
vm_name = vm.name
vm_xml = VMXML.new_from_inactive_dumpxml(vm_name)
vm_xml_backup = vm_xml.copy()
try:
iface_xml = interface.Interface('bridge')
iface_xml.set_target({'dev': 'vnet'})
devices = vm_xml.devices
devices.append(iface_xml)
vm_xml.devices = devices
try:
vm_xml.sync()
except LibvirtXMLError:
pass
finally:
vm_xml_backup.sync()
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:20,代码来源:crash_regression.py
示例10: run
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))
开发者ID:uni-peter-zheng,项目名称:tp-libvirt,代码行数:41,代码来源:libvirt_usb_hotplug_device.py
示例11: get_controller_addr
def get_controller_addr(cntlr_type=None, model=None, index=None):
"""
Get the address of testing controller from VM XML as a string with
format "bus:slot.function".
"""
cur_vm_xml = VMXML.new_from_dumpxml(vm_name)
addr = None
for elem in cur_vm_xml.xmltreefile.findall('/devices/controller'):
if (
(cntlr_type is None or elem.get('type') == cntlr_type) and
(model is None or elem.get('model') == model) and
(index is None or elem.get('index') == index)):
addr_elem = elem.find('./address')
if addr_elem is not None:
addr = Address.new_from_element(addr_elem).attrs
if addr is not None:
bus = int(addr['bus'], 0)
slot = int(addr['slot'], 0)
func = int(addr['function'], 0)
addr_str = '%02d:%02d.%1d' % (bus, slot, func)
logging.debug("String for address element %s is %s", addr, addr_str)
return addr_str
开发者ID:Chenditang,项目名称:tp-libvirt,代码行数:23,代码来源:controller_functional.py
示例12: run_pm_test
def run_pm_test(params, libvirtd, vm):
"""
Destroy VM after executed a series of operations about S3 and save restore
"""
vm_name = vm.name
vm_xml = VMXML.new_from_inactive_dumpxml(vm_name)
vm_xml_backup = vm_xml.copy()
save_path = os.path.join(data_dir.get_tmp_dir(), 'tmp.save')
try:
pm_xml = VMPMXML()
pm_xml.mem_enabled = 'yes'
vm_xml.pm = pm_xml
vm_xml.sync()
vm.prepare_guest_agent()
virsh.dompmsuspend(vm.name, 'mem')
virsh.dompmwakeup(vm.name)
virsh.save(vm.name, save_path)
virsh.restore(save_path)
virsh.dompmsuspend(vm.name, 'mem')
virsh.save(vm.name, save_path)
virsh.destroy(vm.name)
finally:
vm_xml_backup.sync()
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:24,代码来源:crash_regression.py
示例13: run
def run(test, params, env):
"""
Test for PCI device passthrough to libvirt guest.
a). NIC:
1. Get params.
2. Get the pci device for specific net_name.
3. Attach pci device to guest.
4. Start guest and set the ip of guest.
5. Ping the server_ip of from guest
to verify the new network device.
b). STORAGE:
1. Get params.
2. Get the pci device for specific storage_dev_name.
3. Store the result of 'fdisk -l' on guest.
3. Attach pci device to guest.
4. Start guest and get the result of 'fdisk -l' on guest.
5. Compare the result of 'fdisk -l' before and after
attaching storage pci device to guest.
"""
# get the params from params
vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)
sriov = ('yes' == params.get("libvirt_pci_SRIOV", 'no'))
device_type = params.get("libvirt_pci_device_type", "NIC")
net_name = params.get("libvirt_pci_net_name", "eth0")
server_ip = params.get("libvirt_pci_server_ip")
storage_dev_name = params.get("libvirt_pci_storage_dev_name", "/dev/sdb")
fdisk_list_before = None
vmxml = VMXML.new_from_inactive_dumpxml(vm_name)
backup_xml = vmxml.copy()
pci_address = None
if device_type == "NIC":
# Find the pci device for given network device.
result = virsh.nodedev_list(cap="net")
nodedev_nets = result.stdout.strip().splitlines()
device = None
for nodedev in nodedev_nets:
netxml = NodedevXML.new_from_dumpxml(nodedev)
if netxml.cap.interface == net_name:
device = nodedev
break
if not device:
raise error.TestNAError("There is no network device name of %s." %
net_name)
pci_dev = netxml.parent
if sriov:
# set the parameter max_vfs of igb module to 7. Then we can use
# the virtual function pci device for network device.
# command 'modprobe -r igb' to unload igb module
# command '&& modprobe igb max_vfs=7' to load it again
# with max_vfs=7
# command '|| echo 'FAIL' > output_file' is a flag to mean
# modprobe igb with max_vfs=7 failed.
# command '|| modprobe igb' is a handler of error occured
# when we load igb again. If command 2 failed,
# this command will be executed to recover network.
output_file = os.path.join(test.tmpdir, "output")
if os.path.exists(output_file):
os.remove(output_file)
mod_cmd = ("modprobe -r igb && modprobe igb max_vfs=7 ||"
"echo 'FAIL' > %s && modprobe igb &" % output_file)
result = utils.run(mod_cmd, ignore_status=True)
if os.path.exists(output_file):
raise error.TestError("Failed to modprobe igb with max_vfs=7.")
# Get the virtual function pci device which was generated above.
pci_xml = NodedevXML.new_from_dumpxml(pci_dev)
virt_functions = pci_xml.cap.virt_functions
if not virt_functions:
raise error.TestError("Init virtual function failed.")
pci_address = virt_functions[0]
pci_dev = utils_test.libvirt.pci_label_from_address(pci_address,
radix=16)
# Find the network name (ethX) is using this pci device.
network_service = service.Factory.create_service("network")
network_service.restart()
result = virsh.nodedev_list("net")
nodedev_nets = result.stdout.strip().splitlines()
device = None
for nodedev in nodedev_nets:
netxml = NodedevXML.new_from_dumpxml(nodedev)
if netxml.parent == pci_dev:
device = nodedev
break
if not device:
raise error.TestNAError("There is no network name is using "
"Virtual Function PCI device %s." %
pci_dev)
pci_xml = NodedevXML.new_from_dumpxml(pci_dev)
pci_address = pci_xml.cap.get_address_dict()
#.........这里部分代码省略.........
开发者ID:libvirt-qe,项目名称:tp-libvirt,代码行数:101,代码来源:libvirt_pci_passthrough.py
示例14: run
def run(test, params, env):
"""
Test svirt in adding disk to VM.
(1).Init variables for test.
(2).Config qemu conf if need
(3).Label the VM and disk with proper label.
(4).Start VM and check the context.
(5).Destroy VM and check the context.
"""
# Get general variables.
status_error = ('yes' == params.get("status_error", 'no'))
host_sestatus = params.get("svirt_start_destroy_host_selinux", "enforcing")
# Get variables about seclabel for VM.
sec_type = params.get("svirt_start_destroy_vm_sec_type", "dynamic")
sec_model = params.get("svirt_start_destroy_vm_sec_model", "selinux")
sec_label = params.get("svirt_start_destroy_vm_sec_label", None)
sec_baselabel = params.get("svirt_start_destroy_vm_sec_baselabel", None)
security_driver = params.get("security_driver", None)
security_default_confined = params.get("security_default_confined", None)
security_require_confined = params.get("security_require_confined", None)
no_sec_model = 'yes' == params.get("no_sec_model", 'no')
sec_relabel = params.get("svirt_start_destroy_vm_sec_relabel", "yes")
sec_dict = {'type': sec_type, 'relabel': sec_relabel}
sec_dict_list = []
def _set_sec_model(model):
"""
Set sec_dict_list base on given sec model type
"""
sec_dict_copy = sec_dict.copy()
sec_dict_copy['model'] = model
if sec_type != "none":
if sec_type == "dynamic" and sec_baselabel:
sec_dict_copy['baselabel'] = sec_baselabel
else:
sec_dict_copy['label'] = sec_label
sec_dict_list.append(sec_dict_copy)
if not no_sec_model:
if "," in sec_model:
sec_models = sec_model.split(",")
for model in sec_models:
_set_sec_model(model)
else:
_set_sec_model(sec_model)
else:
sec_dict_list.append(sec_dict)
logging.debug("sec_dict_list is: %s" % sec_dict_list)
poweroff_with_destroy = ("destroy" == params.get(
"svirt_start_destroy_vm_poweroff", "destroy"))
# Get variables about VM and get a VM object and VMXML instance.
vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)
vmxml = VMXML.new_from_inactive_dumpxml(vm_name)
backup_xml = vmxml.copy()
# Get varialbles about image.
img_label = params.get('svirt_start_destroy_disk_label')
# Backup disk Labels.
disks = vm.get_disk_devices()
backup_labels_of_disks = {}
backup_ownership_of_disks = {}
for disk in disks.values():
disk_path = disk['source']
backup_labels_of_disks[disk_path] = utils_selinux.get_context_of_file(
filename=disk_path)
f = os.open(disk_path, 0)
stat_re = os.fstat(f)
backup_ownership_of_disks[disk_path] = "%s:%s" % (stat_re.st_uid,
stat_re.st_gid)
# Backup selinux of host.
backup_sestatus = utils_selinux.get_status()
qemu_conf = utils_config.LibvirtQemuConfig()
libvirtd = utils_libvirtd.Libvirtd()
def _resolve_label(label_string):
labels = label_string.split(":")
label_type = labels[2]
if len(labels) == 4:
label_range = labels[3]
elif len(labels) > 4:
label_range = "%s:%s" % (labels[3], labels[4])
else:
label_range = None
return (label_type, label_range)
def _check_label_equal(label1, label2):
label1s = label1.split(":")
label2s = label2.split(":")
for i in range(len(label1s)):
if label1s[i] != label2s[i]:
return False
return True
try:
# Set disk label
(img_label_type, img_label_range) = _resolve_label(img_label)
#.........这里部分代码省略.........
开发者ID:Antique,项目名称:tp-libvirt,代码行数:101,代码来源:svirt_start_destroy.py
示例15: test_active_nodedev_reset
def test_active_nodedev_reset(device, vm, expect_succeed):
"""
Test nodedev-reset when the specified device is attached to a VM
:param devices : Specified node device to be tested.
:param vm : VM the device is to be attached to.
:param expect_succeed : 'yes' for expect command run successfully
and 'no' for fail.
:raise TestFail : If result doesn't meet expectation.
:raise TestError : If failed to recover environment.
"""
# Split device name such as `pci_0000_00_19_0` and fill the XML.
hostdev_xml = """
<hostdev mode='subsystem' type='%s' managed='yes'>
<source>
<address domain='0x%s' bus='0x%s' slot='0x%s' function='0x%s'/>
</source>
</hostdev>""" % tuple(device.split('_'))
try:
# The device need to be detached before attach to VM.
virsh.nodedev_detach(device)
try:
# Backup VM XML.
vmxml = VMXML.new_from_inactive_dumpxml(vm.name)
# Generate a temp file to store host device XML.
dev_fd, dev_fname = tempfile.mkstemp(dir=data_dir.get_tmp_dir())
os.close(dev_fd)
dev_file = open(dev_fname, 'w')
dev_file.write(hostdev_xml)
dev_file.close()
# Only live VM allows attach device.
if not vm.is_alive():
vm.start()
try:
result = virsh.attach_device(vm.name, dev_fname)
logging.debug(result)
test_nodedev_reset([device], expect_succeed)
finally:
# Detach device from VM.
result = virsh.detach_device(vm.name, dev_fname)
# Raise error when detach failed.
if result.exit_status:
raise error.TestError(
'Failed to dettach device %s from %s. Result:\n %s'
% (device, vm.name, result))
finally:
# Cleanup temp XML file and recover test VM.
os.remove(dev_fname)
vmxml.sync()
finally:
# Reattach node device
result = virsh.nodedev_reattach(device)
# Raise error when reattach failed.
if result.exit_status:
raise error.TestError(
'Failed to reattach nodedev %s. Result:\n %s'
% (device, result))
开发者ID:CongLi,项目名称:tp-libvirt,代码行数:63,代码来源:virsh_nodedev_reset.py
示例16: run
def run(test, params, env):
"""
Test virsh {at|de}tach-interface command.
1) Prepare test environment and its parameters
2) Operate virsh on one or more devices
3) Check functionality of each device
4) Check functionality of mmconfig option
5) Restore domain
6) Handle results
"""
dev_obj = params.get("vadu_dev_objs")
# Skip chardev hotplug on rhel6 host as it is not supported
if "Serial" in dev_obj:
if not libvirt_version.version_compare(1, 1, 0):
raise error.TestNAError("You libvirt version not supported"
" attach/detach Serial devices")
logging.info("Preparing initial VM state")
# Prepare test environment and its parameters
test_params = TestParams(params, env, test)
if test_params.start_vm:
# Make sure VM is working
test_params.main_vm.verify_alive()
test_params.main_vm.wait_for_login().close()
else: # VM not suppose to be started
if test_params.main_vm.is_alive():
test_params.main_vm.destroy(gracefully=True)
# Capture backup of original XML early in test
test_params.vmxml = VMXML.new_from_inactive_dumpxml(
test_params.main_vm.name)
# All devices should share same access state
test_params.virsh = virsh.Virsh(ignore_status=True)
logging.info("Creating %d test device instances", len(test_params.devs))
# Create test objects from cfg. class names via subclasses above
test_devices = [globals()[class_name](test_params) # instantiate
for class_name in test_params.devs] # vadu_dev_objs
operational_results = []
preboot_results = []
pstboot_results = []
try:
operational_action(test_params, test_devices, operational_results)
# Fail early if attach-device return value is not expected
analyze_results(test_params=test_params,
operational_results=operational_results)
# Can't do functional testing with a cold VM, only test hot-attach
preboot_action(test_params, test_devices, preboot_results)
logging.info("Preparing test VM state for post-boot functional testing")
if test_params.start_vm:
# Hard-reboot required
test_params.main_vm.destroy(gracefully=True,
free_mac_addresses=False)
try:
test_params.main_vm.start()
except virt_vm.VMStartError:
raise error.TestFail('VM Failed to start for some reason!')
# Signal devices reboot is finished
for test_device in test_devices:
test_device.booted = True
test_params.main_vm.wait_for_login().close()
postboot_action(test_params, test_devices, pstboot_results)
analyze_results(test_params=test_params,
preboot_results=preboot_results,
pstboot_results=pstboot_results)
finally:
logging.info("Restoring VM from backup, then checking results")
test_params.main_vm.destroy(gracefully=False,
free_mac_addresses=False)
test_params.vmxml.undefine()
test_params.vmxml.restore() # Recover the original XML
test_params.vmxml.define()
if not test_params.start_vm:
# Test began with not start_vm, shut it down.
test_params.main_vm.destroy(gracefully=True)
# Device cleanup can raise multiple exceptions, do it last:
logging.info("Cleaning up test devices")
test_params.cleanup(test_devices)
开发者ID:Antique,项目名称:tp-libvirt,代码行数:80,代码来源:virsh_attach_device.py
示例17: run
def run(test, params, env):
"""
Test DAC setting in both domain xml and qemu.conf.
(1) Init variables for test.
(2) Set VM xml and qemu.conf with proper DAC label, also set
monitor socket parent dir with propoer ownership and mode.
(3) Start VM and check the context.
"""
# Get general variables.
status_error = ('yes' == params.get("status_error", 'no'))
host_sestatus = params.get("host_selinux", "enforcing")
# Get variables about seclabel for VM.
sec_type = params.get("vm_sec_type", "dynamic")
vm_sec_model = params.get("vm_sec_model", "dac")
vm_sec_label = params.get("vm_sec_label", None)
vm_sec_relabel = params.get("vm_sec_relabel", "yes")
sec_dict = {'type': sec_type, 'model': vm_sec_model,
'relabel': vm_sec_relabel}
if vm_sec_label:
sec_dict['label'] = vm_sec_label
set_qemu_conf = "yes" == params.get("set_qemu_conf", "no")
# Get per-img seclabel variables
disk_type = params.get("disk_type")
disk_target = params.get('disk_target')
disk_src_protocol = params.get("disk_source_protocol")
vol_name = params.get("vol_name")
tmp_dir = data_dir.get_tmp_dir()
pool_name = params.get("pool_name", "gluster-pool")
brick_path = os.path.join(tmp_dir, pool_name)
invalid_label = 'yes' == params.get("invalid_label", "no")
relabel = params.get("per_img_sec_relabel")
sec_label = params.get("per_img_sec_label")
per_sec_model = params.get("per_sec_model", 'dac')
per_img_dict = {'sec_model': per_sec_model, 'relabel': relabel,
'sec_label': sec_label}
params.update(per_img_dict)
# Get qemu.conf config variables
qemu_user = params.get("qemu_user", 'qemu')
qemu_group = params.get("qemu_group", 'qemu')
dynamic_ownership = "yes" == params.get("dynamic_ownership", "yes")
# Get variables about VM and get a VM object and VMXML instance.
vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)
vmxml = VMXML.new_from_inactive_dumpxml(vm_name)
backup_xml = vmxml.copy()
# Set selinux of host.
backup_sestatus = utils_selinux.get_status()
utils_selinux.set_status(host_sestatus)
qemu_sock_mod = False
qemu_sock_path = '/var/lib/libvirt/qemu/'
qemu_conf = utils_config.LibvirtQemuConfig()
libvirtd = utils_libvirtd.Libvirtd()
try:
if set_qemu_conf:
# Set qemu.conf for user and group
if qemu_user:
qemu_conf.user = qemu_user
if qemu_group:
qemu_conf.group = qemu_group
if dynamic_ownership:
qemu_conf.dynamic_ownership = 1
else:
qemu_conf.dynamic_ownership = 0
logging.debug("the qemu.conf content is: %s" % qemu_conf)
libvirtd.restart()
st = os.stat(qemu_sock_path)
if not bool(st.st_mode & stat.S_IWGRP):
# chmod g+w
os.chmod(qemu_sock_path, st.st_mode | stat.S_IWGRP)
qemu_sock_mod = True
# Set the context of the VM.
logging.debug("sec_dict is %s" % sec_dict)
vmxml.set_seclabel([sec_dict])
vmxml.sync()
# Get per-image seclabel in id string
if sec_label:
per_img_usr, per_img_grp = sec_label.split(':')
sec_label_id = format_user_group_str(per_img_usr, per_img_grp)
# Start VM to check the qemu process and image.
try:
# Set per-img sec context and start vm
utlv.set_vm_disk(vm, params)
# Start VM successfully.
if status_error:
if invalid_label:
# invalid label should fail, more info in bug 1165485
raise error.TestNAError("The label or model not valid, "
"check more info in bug: https://"
"bugzilla.redhat.com/show_bug.cgi"
"?id=1165485")
else:
raise error.TestFail("Test succeeded in negative case.")
#.........这里部分代码省略.........
开发者ID:CongLi,项目名称:tp-libvirt,代码行数:101,代码来源:dac_vm_per_image_start.py
示例18: run
def run(test, params, env):
"""
Verify hotplug feature for char device
"""
vm_name = params.get("main_vm", "vm1")
status_error = "yes" == params.get("status_error", "no")
char_dev = params.get("char_dev", "file")
hotplug_type = params.get("hotplug_type", "qmp")
dup_charid = "yes" == params.get("dup_charid", "no")
dup_devid = "yes" == params.get("dup_devid", "no")
diff_devid = "yes" == params.get("diff_devid", "no")
tmp_dir = os.path.join(test.tmpdir, "hotplug_serial")
if not os.path.exists(tmp_dir):
os.mkdir(tmp_dir)
os.chmod(tmp_dir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
vm_xml = VMXML.new_from_inactive_dumpxml(vm_name)
vm_xml_backup = vm_xml.copy()
# add controller for each char device
devices = vm_xml.get_devices()
controllers = vm_xml.get_devices(device_type="controller")
for dev in controllers:
if dev.type == "virtio-serial":
devices.remove(dev)
controller = Controller("controller")
controller.type = "virtio-serial"
controller.index = 0
devices.append(controller)
vm_xml.set_devices(devices)
vm_xml.sync()
# start and login vm
vm = env.get_vm(vm_name)
vm.start()
session = vm.wait_for_login()
def prepare_channel_xml(to_file, char_type, id=0):
params = {}
mode = ''
if char_type == "file":
channel_type = char_type
channel_path = os.path.join(tmp_dir, char_type)
elif char_type == "socket":
channel_type = 'unix'
channel_path = os.path.join(tmp_dir, char_type)
mode = 'bind'
elif char_type == "pty":
channel_type = char_type
channel_path = ("/dev/pts/%s" % id)
params = {'channel_type_name': channel_type,
'source_path': channel_path,
'source_mode': mode,
'target_type': 'virtio',
'target_name': char_type}
channel_xml = utlv.create_channel_xml(params, alias=True, address=True)
shutil.copyfile(channel_xml.xml, to_file)
def hotplug_device(type, char_dev, id=0):
tmp_file = os.path.join(tmp_dir, char_dev)
if type == "qmp":
char_add_opt = "chardev-add "
dev_add_opt = "device_add virtserialport,chardev="
if char_dev == "file":
char_add_opt += "file,path=%s,id=file" % tmp_file
|
请发表评论