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

2018-05-04 Thread Pavel Hrdina
On Fri, May 04, 2018 at 10:38:30AM +0200, Katerina Koukiou wrote:
> 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 
> ---
>  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(-)

Reviewed-by: Pavel Hrdina 


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

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

2018-05-04 Thread Katerina Koukiou
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 
---
 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 @@
   https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventCallback"/>
   
-  
+  
 
 
   
 
-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