render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 12fa7634a0d5026efef950a7b5583260bd9d316c Mon Sep 17 00:00:00 2001
Message-Id: <12fa7634a0d5026efef950a7b5583260bd9d316c.1381871412.git.jdenemar@redhat.com>
From: "Daniel P. Berrange" <berrange@redhat.com>
Date: Mon, 14 Oct 2013 16:45:15 +0100
Subject: [PATCH] Fix virsystemdtest for previous commit

For

  https://bugzilla.redhat.com/show_bug.cgi?id=1018730

The change to query org.freedesktop.DBus.ListActivatableNames
to detect systemd broke the test suite, since we did not have
stubs to respond to this dbus call.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 468f684e84a6f2dedc60f2a8ed13ba9fbd3df459)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 tests/virsystemdmock.c | 54 +++++++++++++++++++++++++++++++++-----------------
 tests/virsystemdtest.c |  4 ++++
 2 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/tests/virsystemdmock.c b/tests/virsystemdmock.c
index 5dbd33f..59b312d 100644
--- a/tests/virsystemdmock.c
+++ b/tests/virsystemdmock.c
@@ -65,29 +65,47 @@ dbus_bool_t dbus_message_set_reply_serial(DBusMessage *message ATTRIBUTE_UNUSED,
 }
 
 DBusMessage *dbus_connection_send_with_reply_and_block(DBusConnection *connection ATTRIBUTE_UNUSED,
-                                                       DBusMessage *message ATTRIBUTE_UNUSED,
+                                                       DBusMessage *message,
                                                        int timeout_milliseconds ATTRIBUTE_UNUSED,
-                                                       DBusError *error)
+                                                       DBusError *error ATTRIBUTE_UNUSED)
 {
     DBusMessage *reply = NULL;
+    const char *service = dbus_message_get_destination(message);
 
-    if (getenv("FAIL_BAD_SERVICE")) {
-        DBusMessageIter iter;
-        const char *error_message = "Something went wrong creating the machine";
-        if (!(reply = dbus_message_new(DBUS_MESSAGE_TYPE_ERROR)))
-            return NULL;
-        dbus_message_set_error_name(reply, "org.freedesktop.systemd.badthing");
-        dbus_message_iter_init_append(reply, &iter);
-        if (!dbus_message_iter_append_basic(&iter,
-                                            DBUS_TYPE_STRING,
-                                            &error_message)) {
-            dbus_message_unref(reply);
-            return NULL;
+    if (STREQ(service, "org.freedesktop.machine1")) {
+        if (getenv("FAIL_BAD_SERVICE")) {
+            DBusMessageIter iter;
+            const char *error_message = "Something went wrong creating the machine";
+            if (!(reply = dbus_message_new(DBUS_MESSAGE_TYPE_ERROR)))
+                return NULL;
+            dbus_message_set_error_name(reply, "org.freedesktop.systemd.badthing");
+            dbus_message_iter_init_append(reply, &iter);
+            if (!dbus_message_iter_append_basic(&iter,
+                                                DBUS_TYPE_STRING,
+                                                &error_message)) {
+                dbus_message_unref(reply);
+                return NULL;
+            }
+        } else {
+            reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
         }
-    } else if (getenv("FAIL_NO_SERVICE")) {
-        dbus_set_error(error,
-                       "org.freedesktop.DBus.Error.ServiceUnknown",
-                       "%s", "The name org.freedesktop.machine1 was not provided by any .service files");
+    } else if (STREQ(service, "org.freedesktop.DBus")) {
+        const char *svc1 = "org.foo.bar.wizz";
+        const char *svc2 = "org.freedesktop.machine1";
+        DBusMessageIter iter, sub;
+        reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
+        dbus_message_iter_init_append(reply, &iter);
+        dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+                                         "s", &sub);
+
+        dbus_message_iter_append_basic(&sub,
+                                       DBUS_TYPE_STRING,
+                                       &svc1);
+        if (!getenv("FAIL_NO_SERVICE"))
+            dbus_message_iter_append_basic(&sub,
+                                           DBUS_TYPE_STRING,
+                                           &svc2);
+        dbus_message_iter_close_container(&iter, &sub);
     } else {
         reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
     }
diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c
index a9c6d32..7dc7520 100644
--- a/tests/virsystemdtest.c
+++ b/tests/virsystemdtest.c
@@ -94,9 +94,11 @@ static int testCreateNoSystemd(const void *opaque ATTRIBUTE_UNUSED)
                                       123,
                                       false,
                                       NULL)) == 0) {
+        unsetenv("FAIL_NO_SERVICE");
         fprintf(stderr, "%s", "Unexpected create machine success\n");
         return -1;
     }
+    unsetenv("FAIL_NO_SERVICE");
 
     if (rv != -2) {
         fprintf(stderr, "%s", "Unexpected create machine error\n");
@@ -126,9 +128,11 @@ static int testCreateBadSystemd(const void *opaque ATTRIBUTE_UNUSED)
                                       123,
                                       false,
                                       NULL)) == 0) {
+        unsetenv("FAIL_BAD_SERVICE");
         fprintf(stderr, "%s", "Unexpected create machine success\n");
         return -1;
     }
+    unsetenv("FAIL_BAD_SERVICE");
 
     if (rv != -1) {
         fprintf(stderr, "%s", "Unexpected create machine error\n");
-- 
1.8.3.2