Re: [libvirt-dbus] [PATCH 2/2] Implement snapshots APIs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Oct 07, 2019 at 05:22:34PM +0200, Simon Kobyda wrote:
Signed-off-by: Simon Kobyda <skobyda@xxxxxxxxxx>
---
data/org.libvirt.Domain.xml         |  26 ++++
data/org.libvirt.DomainSnapshot.xml |  34 +++++
src/domain.c                        | 158 +++++++++++++++++++++
src/domainsnapshot.c                | 204 +++++++++++++++++++++++++++-
tests/Makefile.am                   |   1 +
tests/libvirttest.py                |  14 ++
tests/test_domain.py                |   8 ++
tests/test_snapshot.py              |  43 ++++++
tests/xmldata.py                    |   6 +
9 files changed, 493 insertions(+), 1 deletion(-)
create mode 100755 tests/test_snapshot.py

diff --git a/src/domainsnapshot.c b/src/domainsnapshot.c
index 590cbef..4bffe5d 100644
--- a/src/domainsnapshot.c
+++ b/src/domainsnapshot.c
@@ -1,14 +1,216 @@
static virtDBusGDBusMethodTable virtDBusDomainSnapshotMethodTable[] = {
-    { 0 }
+    { "Delete", virtDBusDomainSnapshotDelete },
+    { "GetParent", virtDBusDomainSnapshotGetParent },
+    { "GetXMLDesc", virtDBusDomainSnapshotGetXMLDesc },
+    { "IsCurrent", virtDBusDomainSnapshotIsCurrent }, // Needs to be method since it takes 'flags' parameter

/* ... */ is the prevailing comment style, however there are no rules
for that.

+    { "ListChildren", virtDBusDomainSnapshotListAllChildren },
+    { "Revert", virtDBusDomainSnapshotRevert },
};

static gchar **
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cd1fbd7..7757429 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -14,6 +14,7 @@ test_programs = \
	test_interface.py \
	test_network.py \
	test_nodedev.py \
+	test_snapshot.py \
	test_storage.py \
	$(NULL)

diff --git a/tests/libvirttest.py b/tests/libvirttest.py
index a442196..8462fc3 100644
--- a/tests/libvirttest.py
+++ b/tests/libvirttest.py
@@ -112,6 +112,20 @@ class BaseTestClass():
        """
        return self.node_device_create()

+    @pytest.fixture
+    def snapshot_create(self):
+        """ Fixture to create simple snapshot the test driver
+
+        This fixture should be used in the setup of every test manipulating
+        with snaphots.
+        """
+        _, test_domain = self.get_test_domain()
+        interface_obj = dbus.Interface(test_domain, 'org.libvirt.Domain')
+        path = interface_obj.SnapshotCreateXML(xmldata.minimal_snapshot_xml, 0)
+        obj = self.bus.get_object('org.libvirt', path)
+        interface_obj = dbus.Interface(obj, 'org.libvirt.DomainSnapshot')
+        return interface_obj
+
    @pytest.fixture
    def storage_volume_create(self):
        """ Fixture to create dummy storage volume on the test driver
diff --git a/tests/test_domain.py b/tests/test_domain.py
index b5879b4..fdb5aa4 100755
--- a/tests/test_domain.py
+++ b/tests/test_domain.py
@@ -2,6 +2,7 @@

import dbus
import libvirttest
+import xmldata

DBUS_EXCEPTION_MISSING_FUNCTION = 'this function is not supported by the connection driver'

@@ -160,6 +161,13 @@ class TestDomain(libvirttest.BaseTestClass):
        pinInfo = domain.GetVcpuPinInfo(0)
        assert pinInfo == pinInfo_expected

+    def test_snapshot(self):
+        obj, domain = self.get_test_domain()
+        domain.SnapshotCreateXML(xmldata.minimal_snapshot_xml, 0)
+        assert isinstance(domain.SnapshotCurrent(0), dbus.ObjectPath)
+        assert isinstance(domain.SnapshotLookupByName("my_snapshot", 0), dbus.ObjectPath)
+        assert isinstance(domain.ListDomainSnapshots(0), dbus.Array)

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

syntax-check fails with 'flake8' installed:

$ make syntax-check
/usr/bin/flake8 --show-source --ignore=E501 .
./tests/test_domain.py:171:1: E305 expected 2 blank lines after class or function definition, found 1
if __name__ == '__main__':
^
./tests/test_domain.py:173:1: W391 blank line at end of file

^
./tests/test_snapshot.py:9:1: E302 expected 2 blank lines, found 1
@pytest.mark.usefixtures("snapshot_create")
^
./tests/test_snapshot.py:42:1: E305 expected 2 blank lines after class or function definition, found 1
if __name__ == '__main__':
^
make: *** [Makefile:906: flake8] Error 1

Jano

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux