test_nodedev.py 1.93 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#!/usr/bin/env python3

import dbus
import libvirttest
import pytest


@pytest.mark.usefixtures("node_device_create")
class TestNodeDevice(libvirttest.BaseTestClass):
    """ Tests for methods and properties of the NodeDevice interface
    """

    def test_node_device_destroy(self):
        def node_device_deleted(path, event, _detail):
            if event != libvirttest.NodeDeviceEvent.DELETED:
                return
            assert isinstance(path, dbus.ObjectPath)
            self.loop.quit()

        self.connect.connect_to_signal('NodeDeviceEvent', node_device_deleted)

        test_node_device_path = self.node_device_create()
        obj = self.bus.get_object('org.libvirt', test_node_device_path)
        interface_obj = dbus.Interface(obj, 'org.libvirt.NodeDevice')
        interface_obj.Destroy()

        self.main_loop()

29 30 31 32 33 34
    def test_node_device_get_xml_description(self):
        test_node_device_path = self.node_device_create()
        obj = self.bus.get_object('org.libvirt', test_node_device_path)
        interface_obj = dbus.Interface(obj, 'org.libvirt.NodeDevice')
        assert isinstance(interface_obj.GetXMLDesc(0), dbus.String)

35 36 37 38 39 40
    def test_node_device_list_caps(self):
        test_node_device_path = self.node_device_create()
        obj = self.bus.get_object('org.libvirt', test_node_device_path)
        interface_obj = dbus.Interface(obj, 'org.libvirt.NodeDevice')
        assert isinstance(interface_obj.ListCaps(), dbus.Array)

41 42 43 44 45 46 47
    def test_node_device_properties_type(self):
        """ Ensure correct return type for NodeDevice properties
        """
        test_node_device_path = self.node_device_create()
        obj = self.bus.get_object('org.libvirt', test_node_device_path)
        props = obj.GetAll('org.libvirt.NodeDevice', dbus_interface=dbus.PROPERTIES_IFACE)
        assert isinstance(props['Name'], dbus.String)
48
        assert isinstance(props['Parent'], dbus.String)
49

50 51 52

if __name__ == '__main__':
    libvirttest.run()