[dbus PATCH v2 8/9] Remove state to string translation in virtDBusDomainGetState

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

 



Adjust tests to comply with the new type.

Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx>
---
 data/org.libvirt.Domain.xml |  2 +-
 src/domain.c                | 31 +------------------------------
 tests/libvirttest.py        | 12 ++++++++++++
 tests/test_domain.py        | 10 +++++-----
 4 files changed, 19 insertions(+), 36 deletions(-)

diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml
index 98c018c..3627b1b 100644
--- a/data/org.libvirt.Domain.xml
+++ b/data/org.libvirt.Domain.xml
@@ -32,7 +32,7 @@
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetSchedulerType"/>
     </property>
-    <property name="State" type="s" access="read">
+    <property name="State" type="u" access="read">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetState"/>
     </property>
diff --git a/src/domain.c b/src/domain.c
index 40cf2f7..059cd3e 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -251,7 +251,6 @@ virtDBusDomainGetState(const gchar *objectPath,
     virtDBusConnect *connect = userData;
     g_autoptr(virDomain) domain = NULL;
     gint state = 0;
-    const gchar *string;
 
     domain = virtDBusDomainGetVirDomain(connect, objectPath, error);
     if (!domain)
@@ -260,35 +259,7 @@ virtDBusDomainGetState(const gchar *objectPath,
     if (virDomainGetState(domain, &state, NULL, 0) < 0)
         return virtDBusUtilSetLastVirtError(error);
 
-    switch (state) {
-    case VIR_DOMAIN_NOSTATE:
-    default:
-        string = "nostate";
-        break;
-    case VIR_DOMAIN_RUNNING:
-        string = "running";
-        break;
-    case VIR_DOMAIN_BLOCKED:
-        string = "blocked";
-        break;
-    case VIR_DOMAIN_PAUSED:
-        string = "paused";
-        break;
-    case VIR_DOMAIN_SHUTDOWN:
-        string = "shutdown";
-        break;
-    case VIR_DOMAIN_SHUTOFF:
-        string = "shutoff";
-        break;
-    case VIR_DOMAIN_CRASHED:
-        string = "crashed";
-        break;
-    case VIR_DOMAIN_PMSUSPENDED:
-        string = "pmsuspended";
-        break;
-    }
-
-    *value = g_variant_new("s", string);
+    *value = g_variant_new("u", state);
 }
 
 static void
diff --git a/tests/libvirttest.py b/tests/libvirttest.py
index 0e84a94..06ac0e4 100644
--- a/tests/libvirttest.py
+++ b/tests/libvirttest.py
@@ -100,6 +100,18 @@ class DomainEvent(IntEnum):
     CRASHED = 8
 
 
+class DomainState(IntEnum):
+    NOSTATE = 0
+    RUNNING = 1
+    BLOCKED = 2
+    PAUSED = 3
+    SHUTDOWN = 4
+    SHUTOFF = 5
+    CRASHED = 6
+    PMSUSPENDED = 7
+    LAST = 8
+
+
 class NetworkEvent(IntEnum):
     DEFINED = 0
     UNDEFINED = 1
diff --git a/tests/test_domain.py b/tests/test_domain.py
index 2def6c1..c7e09cd 100755
--- a/tests/test_domain.py
+++ b/tests/test_domain.py
@@ -19,7 +19,7 @@ class TestDomain(libvirttest.BaseTestClass):
         assert any([isinstance(props['SchedulerType'], dbus.Struct),
                     isinstance(props['SchedulerType'][0], dbus.String),
                     isinstance(props['SchedulerType'][1], dbus.Int32)])
-        assert isinstance(props['State'], dbus.String)
+        assert isinstance(props['State'], dbus.UInt32)
         assert isinstance(props['Updated'], dbus.Boolean)
         assert isinstance(props['UUID'], dbus.String)
 
@@ -59,7 +59,7 @@ class TestDomain(libvirttest.BaseTestClass):
         domain.ManagedSave(0)
         assert domain.HasManagedSaveImage(0) == dbus.Boolean(True)
         state = obj.Get('org.libvirt.Domain', 'State', dbus_interface=dbus.PROPERTIES_IFACE)
-        assert state == 'shutoff'
+        assert state == libvirttest.DomainState.SHUTOFF
         domain.ManagedSaveRemove(0)
         assert domain.HasManagedSaveImage(0) == dbus.Boolean(False)
 
@@ -87,7 +87,7 @@ class TestDomain(libvirttest.BaseTestClass):
         domain.Resume()
 
         state = obj.Get('org.libvirt.Domain', 'State', dbus_interface=dbus.PROPERTIES_IFACE)
-        assert state == 'running'
+        assert state == libvirttest.DomainState.RUNNING
 
         self.main_loop()
 
@@ -104,7 +104,7 @@ class TestDomain(libvirttest.BaseTestClass):
         domain.Shutdown(0)
 
         state = obj.Get('org.libvirt.Domain', 'State', dbus_interface=dbus.PROPERTIES_IFACE)
-        assert state == 'shutoff'
+        assert state == libvirttest.DomainState.SHUTOFF
 
         self.main_loop()
 
@@ -121,7 +121,7 @@ class TestDomain(libvirttest.BaseTestClass):
         domain.Suspend()
 
         state = obj.Get('org.libvirt.Domain', 'State', dbus_interface=dbus.PROPERTIES_IFACE)
-        assert state == 'paused'
+        assert state == libvirttest.DomainState.PAUSED
 
         self.main_loop()
 
-- 
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