[libvirt] [dbus PATCH v2 5/6] virtDBusDomainDestroy: Use virDomainDestroyFlags instead of virDomainDestroy

Katerina Koukiou posted 6 patches 7 years, 1 month ago
[libvirt] [dbus PATCH v2 5/6] virtDBusDomainDestroy: Use virDomainDestroyFlags instead of virDomainDestroy
Posted by Katerina Koukiou 7 years, 1 month ago
We need to catch Exceptions when testing this API call, since virDomainDestroyFlags
will be supported in test-driver in 4.2.0 libvirt release.

Better version checks for unsupported API calls need to be done in all tests,
but it's not relevant to this commit.
When virConnectGetVersion will be supported we can move to better implementation,
and python logging should be used to provide proper warnings for skipped tests.

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com>
---
 data/org.libvirt.Domain.xml | 4 +++-
 src/domain.c                | 5 ++++-
 test/test_domain.py         | 7 ++++++-
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml
index 187f604..e79fb5e 100644
--- a/data/org.libvirt.Domain.xml
+++ b/data/org.libvirt.Domain.xml
@@ -27,7 +27,9 @@
     <method name="Shutdown">
       <arg name="flags" type="u" direction="in"/>
     </method>
-    <method name="Destroy"/>
+    <method name="Destroy">
+      <arg name="flags" type="u" direction="in"/>
+    </method>
     <method name="Reboot">
       <arg name="flags" type="u" direction="in"/>
     </method>
diff --git a/src/domain.c b/src/domain.c
index fd6609c..3c09351 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -344,12 +344,15 @@ virtDBusDomainDestroy(GVariant *inArgs G_GNUC_UNUSED,
 {
     virtDBusConnect *connect = userData;
     g_autoptr(virDomain) domain = NULL;
+    guint flags;
+
+    g_variant_get(inArgs, "(u)", &flags);
 
     domain = virtDBusDomainGetVirDomain(connect, objectPath, error);
     if (!domain)
         return;
 
-    if (virDomainDestroy(domain) < 0)
+    if (virDomainDestroyFlags(domain, flags) < 0)
         virtDBusUtilSetLastVirtError(error);
 }
 
diff --git a/test/test_domain.py b/test/test_domain.py
index 8cd0d6a..73737d7 100755
--- a/test/test_domain.py
+++ b/test/test_domain.py
@@ -3,6 +3,7 @@
 import dbus
 import libvirttest
 
+DBUS_EXCEPTION_MISSING_FUNCTION = 'this function is not supported by the connection driver'
 
 class TestDomain(libvirttest.BaseTestClass):
     def domain(self):
@@ -34,7 +35,11 @@ class TestDomain(libvirttest.BaseTestClass):
         domain.Reboot(0)
         domain.Shutdown(0)
         domain.Create(0)
-        domain.Destroy()
+        try:
+            domain.Destroy(0)
+        except dbus.exceptions.DBusException as e:
+            if not any(DBUS_EXCEPTION_MISSING_FUNCTION in arg for arg in e.args):
+                raise e
         domain.Undefine(0)
 
     def test_shutdown(self):
-- 
2.15.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [dbus PATCH v2 5/6] virtDBusDomainDestroy: Use virDomainDestroyFlags instead of virDomainDestroy
Posted by Pavel Hrdina 7 years, 1 month ago
On Fri, Mar 23, 2018 at 05:58:03PM +0100, Katerina Koukiou wrote:
> We need to catch Exceptions when testing this API call, since virDomainDestroyFlags
> will be supported in test-driver in 4.2.0 libvirt release.
> 
> Better version checks for unsupported API calls need to be done in all tests,
> but it's not relevant to this commit.
> When virConnectGetVersion will be supported we can move to better implementation,
> and python logging should be used to provide proper warnings for skipped tests.

Long lines in commit message, the unwritten rule (suggestion) is to
keep it under 72 characters per line.

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