[dbus PATCH 1/3] Implement LookupByID method for Connect Interface.

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

 



tests: Moved `domain` method from test_domain.py to
libvirttest.py so that it can be reused from test_connect.py.

Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx>
---
 data/org.libvirt.Connect.xml |  6 ++++++
 src/connect.c                | 29 +++++++++++++++++++++++++++++
 src/domain.c                 |  1 +
 test/libvirttest.py          |  5 +++++
 test/test_connect.py         | 13 ++++++++++++-
 test/test_domain.py          |  5 -----
 6 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index 8260a63..53f996b 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -26,6 +26,12 @@
       <arg name="xml" type="s" direction="in"/>
       <arg name="domain" type="o" direction="out"/>
     </method>
+    <method name="LookupByID">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLookupByID"/>
+      <arg name="id" type="u" direction="in"/>
+      <arg name="domain" type="o" direction="out"/>
+    </method>
     <signal name="DomainCrashed">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-domain.html#VIR_DOMAIN_EVENT_CRASHED"/>
diff --git a/src/connect.c b/src/connect.c
index 8898e6d..f1177d2 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -195,6 +195,34 @@ virtDBusConnectDefineXML(GVariant *inArgs,
     *outArgs = g_variant_new("(o)", path);
 }
 
+static void
+virtDBusDomainLookupByID(GVariant *inArgs,
+                         GUnixFDList *inFDs G_GNUC_UNUSED,
+                         const gchar *objectPath G_GNUC_UNUSED,
+                         gpointer userData,
+                         GVariant **outArgs,
+                         GUnixFDList **outFDs G_GNUC_UNUSED,
+                         GError **error)
+{
+    virtDBusConnect *connect = userData;
+    g_autoptr(virDomain) domain = NULL;
+    g_autofree gchar *path = NULL;
+    guint id;
+
+    g_variant_get(inArgs, "(u)", &id);
+
+    if (!virtDBusConnectOpen(connect, NULL))
+        return;
+
+    domain = virDomainLookupByID(connect->connection, id);
+    if (!domain)
+        return virtDBusUtilSetLastVirtError(error);
+
+    path = virtDBusUtilBusPathForVirDomain(domain, connect->domainPath);
+
+    *outArgs = g_variant_new("(o)", path);
+}
+
 static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = {
     { "Version", virtDBusConnectGetVersion, NULL },
     { NULL, NULL, NULL }
@@ -204,6 +232,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
     { "ListDomains", virtDBusConnectListDomains },
     { "CreateXML", virtDBusConnectCreateXML },
     { "DefineXML", virtDBusConnectDefineXML },
+    { "LookupByID", virtDBusDomainLookupByID },
     { NULL, NULL }
 };
 
diff --git a/src/domain.c b/src/domain.c
index 3c09351..c9f9e2b 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -450,6 +450,7 @@ virtDBusDomainUndefine(GVariant *inArgs G_GNUC_UNUSED,
         virtDBusUtilSetLastVirtError(error);
 }
 
+
 static virtDBusGDBusPropertyTable virtDBusDomainPropertyTable[] = {
     { "Name", virtDBusDomainGetName, NULL },
     { "UUID", virtDBusDomainGetUUID, NULL },
diff --git a/test/libvirttest.py b/test/libvirttest.py
index 23fe536..c4dc96f 100644
--- a/test/libvirttest.py
+++ b/test/libvirttest.py
@@ -65,3 +65,8 @@ class BaseTestClass():
         self.loop = GLib.MainLoop()
         GLib.timeout_add(1000, timeout)
         self.loop.run()
+
+    def domain(self):
+        path = self.connect.ListDomains(0)[0]
+        obj = self.bus.get_object('org.libvirt', path)
+        return obj, dbus.Interface(obj, 'org.libvirt.Domain')
diff --git a/test/test_connect.py b/test/test_connect.py
index 01d4d41..ea6fdde 100755
--- a/test/test_connect.py
+++ b/test/test_connect.py
@@ -15,7 +15,6 @@ class TestConnect(libvirttest.BaseTestClass):
       </os>
     </domain>
     '''
-
     def test_list_domains(self):
         domains = self.connect.ListDomains(0)
         assert isinstance(domains, dbus.Array)
@@ -54,6 +53,18 @@ class TestConnect(libvirttest.BaseTestClass):
 
         self.main_loop()
 
+    @pytest.mark.parametrize("lookup_method_name,lookup_item", [
+        ("LookupByID", 'Id'),
+    ])
+    def test_connect_lookup_by_id(self, lookup_method_name, lookup_item):
+        """Parameterized test for all LookupBy* API calls of Connect interface
+        """
+        original_path = self.connect.ListDomains(0)[0]
+        obj, _ = self.domain()
+        props = obj.GetAll('org.libvirt.Domain', dbus_interface=dbus.PROPERTIES_IFACE)
+        path = getattr(self.connect, lookup_method_name)(props[lookup_item])
+        assert original_path == path
+
     @pytest.mark.parametrize("property_name,expected_type", [
         ("Version", dbus.UInt64),
     ])
diff --git a/test/test_domain.py b/test/test_domain.py
index 73737d7..e617b1b 100755
--- a/test/test_domain.py
+++ b/test/test_domain.py
@@ -6,11 +6,6 @@ import libvirttest
 DBUS_EXCEPTION_MISSING_FUNCTION = 'this function is not supported by the connection driver'
 
 class TestDomain(libvirttest.BaseTestClass):
-    def domain(self):
-        path = self.connect.ListDomains(0)[0]
-        obj = self.bus.get_object('org.libvirt', path)
-        return obj, dbus.Interface(obj, 'org.libvirt.Domain')
-
     def test_api(self):
         obj, domain = self.domain()
 
-- 
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