diff options
author | Daniel P. Berrangé <berrange@redhat.com> | 2020-10-06 11:01:42 +0100 |
---|---|---|
committer | Daniel P. Berrangé <berrange@redhat.com> | 2020-10-06 12:25:14 +0100 |
commit | 1f441675108ef5e7566e84b546339a1d1ee9af4c (patch) | |
tree | 919aca586b4ab009e29fde05937bc6c8f987311e /tests | |
parent | 613411502d2cdf3541837710239409044a376b0a (diff) | |
download | libvirt-python-1f441675108ef5e7566e84b546339a1d1ee9af4c.tar.gz |
tests: start basic unit tests for more APIs
To prevent regressions, especially with generated code, we need to have
test coverage of more APIs. This starts off with coverage for object
creation for all object types supported by the test driver
currently. This exercises constructors which have been broken several
times in the past.
Related https://gitlab.com/libvirt/libvirt-python/-/issues/4
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_domain.py | 6 | ||||
-rw-r--r-- | tests/test_domain_checkpoint.py | 18 | ||||
-rw-r--r-- | tests/test_domain_snapshot.py | 16 | ||||
-rw-r--r-- | tests/test_interface.py | 15 | ||||
-rw-r--r-- | tests/test_network.py | 15 | ||||
-rw-r--r-- | tests/test_nodedev.py | 15 | ||||
-rw-r--r-- | tests/test_storage.py | 24 |
7 files changed, 109 insertions, 0 deletions
diff --git a/tests/test_domain.py b/tests/test_domain.py index 2b3710b..17fd7b3 100644 --- a/tests/test_domain.py +++ b/tests/test_domain.py @@ -17,3 +17,9 @@ class TestLibvirtDomain(unittest.TestCase): self.assertTrue("weight" in params) params["weight"] = 100 self.dom.setSchedulerParameters(params) + + @unittest.skipIf(libvirt.getVersion() == 4000000, + "test driver screenshot broken in 4.0.0") + def testScreenshot(self): + stream = self.conn.newStream() + ss = self.dom.screenshot(stream, 0, 0) diff --git a/tests/test_domain_checkpoint.py b/tests/test_domain_checkpoint.py new file mode 100644 index 0000000..97cbde6 --- /dev/null +++ b/tests/test_domain_checkpoint.py @@ -0,0 +1,18 @@ +import unittest +import libvirt + + +class TestLibvirtDomainCheckpoint(unittest.TestCase): + def setUp(self): + self.conn = libvirt.open("test:///default") + self.dom = self.conn.lookupByName("test") + + def tearDown(self): + self.dom = None + self.conn = None + + @unittest.skipUnless(hasattr(libvirt.virDomain, "checkpointCreateXML"), + "checkpoints not supported in this libvirt") + def testCheckpointCreate(self): + cp = self.dom.checkpointCreateXML("<domaincheckpoint/>") + cp.delete() diff --git a/tests/test_domain_snapshot.py b/tests/test_domain_snapshot.py new file mode 100644 index 0000000..a90833e --- /dev/null +++ b/tests/test_domain_snapshot.py @@ -0,0 +1,16 @@ +import unittest +import libvirt + + +class TestLibvirtDomainSnapshot(unittest.TestCase): + def setUp(self): + self.conn = libvirt.open("test:///default") + self.dom = self.conn.lookupByName("test") + + def tearDown(self): + self.dom = None + self.conn = None + + def testSnapCreate(self): + snap = self.dom.snapshotCreateXML("<domainsnapshot/>") + snap.delete() diff --git a/tests/test_interface.py b/tests/test_interface.py new file mode 100644 index 0000000..2d7f7ec --- /dev/null +++ b/tests/test_interface.py @@ -0,0 +1,15 @@ +import unittest +import libvirt + + +class TestLibvirtInterface(unittest.TestCase): + def setUp(self): + self.conn = libvirt.open("test:///default") + self.iface = self.conn.interfaceLookupByName("eth1") + + def tearDown(self): + self.iface = None + self.conn = None + + def testAttr(self): + self.assertEqual(self.iface.name(), "eth1") diff --git a/tests/test_network.py b/tests/test_network.py new file mode 100644 index 0000000..3d47f35 --- /dev/null +++ b/tests/test_network.py @@ -0,0 +1,15 @@ +import unittest +import libvirt + + +class TestLibvirtNetwork(unittest.TestCase): + def setUp(self): + self.conn = libvirt.open("test:///default") + self.net = self.conn.networkLookupByName("default") + + def tearDown(self): + self.net = None + self.conn = None + + def testAttr(self): + self.assertEqual(self.net.name(), "default") diff --git a/tests/test_nodedev.py b/tests/test_nodedev.py new file mode 100644 index 0000000..7cf1274 --- /dev/null +++ b/tests/test_nodedev.py @@ -0,0 +1,15 @@ +import unittest +import libvirt + + +class TestLibvirtNodeDev(unittest.TestCase): + def setUp(self): + self.conn = libvirt.open("test:///default") + self.nodedev = self.conn.nodeDeviceLookupByName("computer") + + def tearDown(self): + self.nodedev = None + self.conn = None + + def testAttr(self): + self.assertEqual(self.nodedev.name(), "computer") diff --git a/tests/test_storage.py b/tests/test_storage.py new file mode 100644 index 0000000..ba20e53 --- /dev/null +++ b/tests/test_storage.py @@ -0,0 +1,24 @@ +import unittest +import libvirt + + +class TestLibvirtStorage(unittest.TestCase): + def setUp(self): + self.conn = libvirt.open("test:///default") + self.pool = self.conn.storagePoolLookupByName("default-pool") + + def tearDown(self): + self.pool = None + self.conn = None + + def testAttr(self): + self.assertEqual(self.pool.name(), "default-pool") + + def testVol(self): + volxml = '''<volume type="file"> + <name>raw.img</name> + <allocation unit="M">10</allocation> + <capacity unit="M">1000</capacity> +</volume>''' + + vol = self.pool.createXML(volxml) |