[dbus PATCH v2 4/9] Change DomainEvent argument from string to unsigned int

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

 



Modify the relevant tests to comply with the new signal.

Note: argument matching in connect_to_signal method is
only usable with string and thus had to be refactored.

Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx>
---
 data/org.libvirt.Connect.xml |  2 +-
 src/events.c                 | 26 +-------------------------
 tests/libvirttest.py         | 13 +++++++++++++
 tests/test_connect.py        | 12 ++++++++----
 tests/test_domain.py         | 30 ++++++++++++++++++++----------
 5 files changed, 43 insertions(+), 40 deletions(-)

diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index 7249fa4..386a7bb 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -170,7 +170,7 @@
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventCallback"/>
       <arg name="domain" type="o"/>
-      <arg name="event" type="s"/>
+      <arg name="event" type="u"/>
     </signal>
     <signal name="NetworkEvent">
       <annotation name="org.gtk.GDBus.DocString"
diff --git a/src/events.c b/src/events.c
index 7e9da08..601d898 100644
--- a/src/events.c
+++ b/src/events.c
@@ -4,26 +4,6 @@
 
 #include <libvirt/libvirt.h>
 
-VIRT_DBUS_ENUM_DECL(virtDBusEventsDomainEvent)
-VIRT_DBUS_ENUM_IMPL(virtDBusEventsDomainEvent,
-                    VIR_DOMAIN_EVENT_LAST,
-                    "Defined",
-                    "Undefined",
-                    "Started",
-                    "Suspended",
-                    "Resumed",
-                    "Stopped",
-                    "Shutdown",
-                    "PMSuspended",
-                    "Crashed")
-
-static const gchar *
-virtDBusEventsDomainEventToString(gint event)
-{
-    const gchar *str = virtDBusEventsDomainEventTypeToString(event);
-    return str ? str : "unknown";
-}
-
 static gint
 virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED,
                               virDomainPtr domain,
@@ -33,10 +13,6 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED,
 {
     virtDBusConnect *connect = opaque;
     g_autofree gchar *path = NULL;
-    const gchar *eventStr = virtDBusEventsDomainEventToString(event);
-
-    if (!eventStr)
-        return 0;
 
     path = virtDBusUtilBusPathForVirDomain(domain, connect->domainPath);
 
@@ -45,7 +21,7 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED,
                                   connect->connectPath,
                                   VIRT_DBUS_CONNECT_INTERFACE,
                                   "DomainEvent",
-                                  g_variant_new("(os)", path, eventStr),
+                                  g_variant_new("(ou)", path, event),
                                   NULL);
 
     return 0;
diff --git a/tests/libvirttest.py b/tests/libvirttest.py
index d1b71cc..f7f48ed 100644
--- a/tests/libvirttest.py
+++ b/tests/libvirttest.py
@@ -1,3 +1,4 @@
+from enum import IntEnum
 from dbus.mainloop.glib import DBusGMainLoop
 from gi.repository import GLib
 import dbus
@@ -85,3 +86,15 @@ class BaseTestClass():
         path = self.connect.ListNetworks(0)[0]
         obj = self.bus.get_object('org.libvirt', path)
         return path, obj
+
+
+class DomainEvent(IntEnum):
+    DEFINED = 0
+    UNDEFINED = 1
+    STARTED = 2
+    SUSPENDED = 3
+    RESUMED = 4
+    STOPPED = 5
+    SHUTDOWN = 6
+    PMSUSPENDED = 7
+    CRASHED = 8
diff --git a/tests/test_connect.py b/tests/test_connect.py
index 57f0658..41cc134 100755
--- a/tests/test_connect.py
+++ b/tests/test_connect.py
@@ -31,11 +31,13 @@ class TestConnect(libvirttest.BaseTestClass):
     '''
 
     def test_connect_domain_create_xml(self):
-        def domain_started(path, _event):
+        def domain_started(path, event):
+            if event != libvirttest.DomainEvent.STARTED:
+                return
             assert isinstance(path, dbus.ObjectPath)
             self.loop.quit()
 
-        self.connect.connect_to_signal('DomainEvent', domain_started, arg1='Started')
+        self.connect.connect_to_signal('DomainEvent', domain_started)
 
         path = self.connect.DomainCreateXML(self.minimal_domain_xml, 0)
         assert isinstance(path, dbus.ObjectPath)
@@ -43,11 +45,13 @@ class TestConnect(libvirttest.BaseTestClass):
         self.main_loop()
 
     def test_comnect_domain_define_xml(self):
-        def domain_defined(path, _event):
+        def domain_defined(path, event):
+            if event != libvirttest.DomainEvent.DEFINED:
+                return
             assert isinstance(path, dbus.ObjectPath)
             self.loop.quit()
 
-        self.connect.connect_to_signal('DomainEvent', domain_defined, arg1='Defined')
+        self.connect.connect_to_signal('DomainEvent', domain_defined)
 
         path = self.connect.DomainDefineXML(self.minimal_domain_xml)
         assert isinstance(path, dbus.ObjectPath)
diff --git a/tests/test_domain.py b/tests/test_domain.py
index 0e83f72..2def6c1 100755
--- a/tests/test_domain.py
+++ b/tests/test_domain.py
@@ -47,11 +47,13 @@ class TestDomain(libvirttest.BaseTestClass):
         assert autostart_current == dbus.Boolean(autostart_expected)
 
     def test_domain_managed_save(self):
-        def domain_stopped(path, _event):
+        def domain_stopped(path, event):
+            if event != libvirttest.DomainEvent.STOPPED:
+                return
             assert isinstance(path, dbus.ObjectPath)
             self.loop.quit()
 
-        self.connect.connect_to_signal('DomainEvent', domain_stopped, arg1='Stopped')
+        self.connect.connect_to_signal('DomainEvent', domain_stopped)
 
         obj, domain = self.domain()
         domain.ManagedSave(0)
@@ -72,11 +74,13 @@ class TestDomain(libvirttest.BaseTestClass):
         assert description_expected == domain.GetMetadata(metadata_description, "", 0)
 
     def test_resume(self):
-        def domain_resumed(path, _event):
+        def domain_resumed(path, event):
+            if event != libvirttest.DomainEvent.RESUMED:
+                return
             assert isinstance(path, dbus.ObjectPath)
             self.loop.quit()
 
-        self.connect.connect_to_signal('DomainEvent', domain_resumed, arg1='Resumed')
+        self.connect.connect_to_signal('DomainEvent', domain_resumed)
 
         obj, domain = self.domain()
         domain.Suspend()
@@ -88,11 +92,13 @@ class TestDomain(libvirttest.BaseTestClass):
         self.main_loop()
 
     def test_shutdown(self):
-        def domain_stopped(path, _event):
+        def domain_stopped(path, event):
+            if event != libvirttest.DomainEvent.STOPPED:
+                return
             assert isinstance(path, dbus.ObjectPath)
             self.loop.quit()
 
-        self.connect.connect_to_signal('DomainEvent', domain_stopped, arg1='Stopped')
+        self.connect.connect_to_signal('DomainEvent', domain_stopped)
 
         obj, domain = self.domain()
         domain.Shutdown(0)
@@ -103,11 +109,13 @@ class TestDomain(libvirttest.BaseTestClass):
         self.main_loop()
 
     def test_suspend(self):
-        def domain_suspended(path, _event):
+        def domain_suspended(path, event):
+            if event != libvirttest.DomainEvent.SUSPENDED:
+                return
             assert isinstance(path, dbus.ObjectPath)
             self.loop.quit()
 
-        self.connect.connect_to_signal('DomainEvent', domain_suspended, arg1='Suspended')
+        self.connect.connect_to_signal('DomainEvent', domain_suspended)
 
         obj, domain = self.domain()
         domain.Suspend()
@@ -118,11 +126,13 @@ class TestDomain(libvirttest.BaseTestClass):
         self.main_loop()
 
     def test_undefine(self):
-        def domain_undefined(path, _event):
+        def domain_undefined(path, event):
+            if event != libvirttest.DomainEvent.UNDEFINED:
+                return
             assert isinstance(path, dbus.ObjectPath)
             self.loop.quit()
 
-        self.connect.connect_to_signal('DomainEvent', domain_undefined, arg1='Undefined')
+        self.connect.connect_to_signal('DomainEvent', domain_undefined)
 
         _, domain = self.domain()
         domain.Shutdown(0)
-- 
2.15.0

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