def test_init_stop_on_reboot(make_capabilities): """ Test virt.init to add the on_reboot=destroy flag """ make_capabilities() with patch.dict(virt.os.__dict__, { "chmod": MagicMock(), "makedirs": MagicMock() }): with patch.dict(virt.__salt__, {"cmd.run": MagicMock()}): virt.init("test_vm", 2, 2048, stop_on_reboot=True, start=False) define_mock = virt.libvirt.openAuth().defineXML setxml = ET.fromstring(define_mock.call_args[0][0]) assert "destroy" == setxml.find("./on_reboot").text
def test_init_hostdev_usb(make_capabilities, make_mock_device): """ Test virt.init with USB host device passed through """ make_capabilities() make_mock_device(""" <device> <name>usb_3_1_3</name> <path>/sys/devices/pci0000:00/0000:00:1d.6/0000:06:00.0/0000:07:02.0/0000:3e:00.0/usb3/3-1/3-1.3</path> <devnode type='dev'>/dev/bus/usb/003/004</devnode> <parent>usb_3_1</parent> <driver> <name>usb</name> </driver> <capability type='usb_device'> <bus>3</bus> <device>4</device> <product id='0x6006'>AUKEY PC-LM1E Camera</product> <vendor id='0x0458'>KYE Systems Corp. (Mouse Systems)</vendor> </capability> </device> """) with patch.dict(virt.os.__dict__, { "chmod": MagicMock(), "makedirs": MagicMock() }): with patch.dict(virt.__salt__, {"cmd.run": MagicMock()}): virt.init("test_vm", 2, 2048, host_devices=["usb_3_1_3"], start=False) define_mock = virt.libvirt.openAuth().defineXML setxml = ET.fromstring(define_mock.call_args[0][0]) expected_xml = strip_xml(""" <hostdev mode='subsystem' type='usb'> <source> <vendor id='0x0458'/> <product id='0x6006'/> </source> </hostdev> """) assert expected_xml == strip_xml( ET.tostring(setxml.find("./devices/hostdev")))
def test_init_hostdev_pci(make_capabilities, make_mock_device): """ Test virt.init with PCI host device passed through """ make_capabilities() make_mock_device(""" <device> <name>pci_1002_71c4</name> <parent>pci_8086_27a1</parent> <capability type='pci'> <class>0xffffff</class> <domain>0</domain> <bus>1</bus> <slot>0</slot> <function>0</function> <product id='0x71c4'>M56GL [Mobility FireGL V5200]</product> <vendor id='0x1002'>ATI Technologies Inc</vendor> <numa node='1'/> </capability> </device> """) with patch.dict(virt.os.__dict__, { "chmod": MagicMock(), "makedirs": MagicMock() }): with patch.dict(virt.__salt__, {"cmd.run": MagicMock()}): virt.init("test_vm", 2, 2048, host_devices=["pci_1002_71c4"], start=False) define_mock = virt.libvirt.openAuth().defineXML setxml = ET.fromstring(define_mock.call_args[0][0]) expected_xml = strip_xml(""" <hostdev mode='subsystem' type='pci' managed='yes'> <source> <address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> </source> </hostdev> """) assert expected_xml == strip_xml( ET.tostring(setxml.find("./devices/hostdev")))