1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2024-10-26 07:55:06 +03:00

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>
This commit is contained in:
Daniel P. Berrangé 2020-10-06 11:01:42 +01:00
parent 613411502d
commit 1f44167510
7 changed files with 109 additions and 0 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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()

15
tests/test_interface.py Normal file
View File

@ -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")

15
tests/test_network.py Normal file
View File

@ -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")

15
tests/test_nodedev.py Normal file
View File

@ -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")

24
tests/test_storage.py Normal file
View File

@ -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)