43fe83
From 12fa7634a0d5026efef950a7b5583260bd9d316c Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <12fa7634a0d5026efef950a7b5583260bd9d316c.1381871412.git.jdenemar@redhat.com>
43fe83
From: "Daniel P. Berrange" <berrange@redhat.com>
43fe83
Date: Mon, 14 Oct 2013 16:45:15 +0100
43fe83
Subject: [PATCH] Fix virsystemdtest for previous commit
43fe83
43fe83
For
43fe83
43fe83
  https://bugzilla.redhat.com/show_bug.cgi?id=1018730
43fe83
43fe83
The change to query org.freedesktop.DBus.ListActivatableNames
43fe83
to detect systemd broke the test suite, since we did not have
43fe83
stubs to respond to this dbus call.
43fe83
43fe83
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
43fe83
(cherry picked from commit 468f684e84a6f2dedc60f2a8ed13ba9fbd3df459)
43fe83
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
43fe83
---
43fe83
 tests/virsystemdmock.c | 54 +++++++++++++++++++++++++++++++++-----------------
43fe83
 tests/virsystemdtest.c |  4 ++++
43fe83
 2 files changed, 40 insertions(+), 18 deletions(-)
43fe83
43fe83
diff --git a/tests/virsystemdmock.c b/tests/virsystemdmock.c
43fe83
index 5dbd33f..59b312d 100644
43fe83
--- a/tests/virsystemdmock.c
43fe83
+++ b/tests/virsystemdmock.c
43fe83
@@ -65,29 +65,47 @@ dbus_bool_t dbus_message_set_reply_serial(DBusMessage *message ATTRIBUTE_UNUSED,
43fe83
 }
43fe83
 
43fe83
 DBusMessage *dbus_connection_send_with_reply_and_block(DBusConnection *connection ATTRIBUTE_UNUSED,
43fe83
-                                                       DBusMessage *message ATTRIBUTE_UNUSED,
43fe83
+                                                       DBusMessage *message,
43fe83
                                                        int timeout_milliseconds ATTRIBUTE_UNUSED,
43fe83
-                                                       DBusError *error)
43fe83
+                                                       DBusError *error ATTRIBUTE_UNUSED)
43fe83
 {
43fe83
     DBusMessage *reply = NULL;
43fe83
+    const char *service = dbus_message_get_destination(message);
43fe83
 
43fe83
-    if (getenv("FAIL_BAD_SERVICE")) {
43fe83
-        DBusMessageIter iter;
43fe83
-        const char *error_message = "Something went wrong creating the machine";
43fe83
-        if (!(reply = dbus_message_new(DBUS_MESSAGE_TYPE_ERROR)))
43fe83
-            return NULL;
43fe83
-        dbus_message_set_error_name(reply, "org.freedesktop.systemd.badthing");
43fe83
-        dbus_message_iter_init_append(reply, &iter);
43fe83
-        if (!dbus_message_iter_append_basic(&iter,
43fe83
-                                            DBUS_TYPE_STRING,
43fe83
-                                            &error_message)) {
43fe83
-            dbus_message_unref(reply);
43fe83
-            return NULL;
43fe83
+    if (STREQ(service, "org.freedesktop.machine1")) {
43fe83
+        if (getenv("FAIL_BAD_SERVICE")) {
43fe83
+            DBusMessageIter iter;
43fe83
+            const char *error_message = "Something went wrong creating the machine";
43fe83
+            if (!(reply = dbus_message_new(DBUS_MESSAGE_TYPE_ERROR)))
43fe83
+                return NULL;
43fe83
+            dbus_message_set_error_name(reply, "org.freedesktop.systemd.badthing");
43fe83
+            dbus_message_iter_init_append(reply, &iter);
43fe83
+            if (!dbus_message_iter_append_basic(&iter,
43fe83
+                                                DBUS_TYPE_STRING,
43fe83
+                                                &error_message)) {
43fe83
+                dbus_message_unref(reply);
43fe83
+                return NULL;
43fe83
+            }
43fe83
+        } else {
43fe83
+            reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
43fe83
         }
43fe83
-    } else if (getenv("FAIL_NO_SERVICE")) {
43fe83
-        dbus_set_error(error,
43fe83
-                       "org.freedesktop.DBus.Error.ServiceUnknown",
43fe83
-                       "%s", "The name org.freedesktop.machine1 was not provided by any .service files");
43fe83
+    } else if (STREQ(service, "org.freedesktop.DBus")) {
43fe83
+        const char *svc1 = "org.foo.bar.wizz";
43fe83
+        const char *svc2 = "org.freedesktop.machine1";
43fe83
+        DBusMessageIter iter, sub;
43fe83
+        reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
43fe83
+        dbus_message_iter_init_append(reply, &iter);
43fe83
+        dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
43fe83
+                                         "s", &sub);
43fe83
+
43fe83
+        dbus_message_iter_append_basic(&sub,
43fe83
+                                       DBUS_TYPE_STRING,
43fe83
+                                       &svc1);
43fe83
+        if (!getenv("FAIL_NO_SERVICE"))
43fe83
+            dbus_message_iter_append_basic(&sub,
43fe83
+                                           DBUS_TYPE_STRING,
43fe83
+                                           &svc2);
43fe83
+        dbus_message_iter_close_container(&iter, &sub);
43fe83
     } else {
43fe83
         reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
43fe83
     }
43fe83
diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c
43fe83
index a9c6d32..7dc7520 100644
43fe83
--- a/tests/virsystemdtest.c
43fe83
+++ b/tests/virsystemdtest.c
43fe83
@@ -94,9 +94,11 @@ static int testCreateNoSystemd(const void *opaque ATTRIBUTE_UNUSED)
43fe83
                                       123,
43fe83
                                       false,
43fe83
                                       NULL)) == 0) {
43fe83
+        unsetenv("FAIL_NO_SERVICE");
43fe83
         fprintf(stderr, "%s", "Unexpected create machine success\n");
43fe83
         return -1;
43fe83
     }
43fe83
+    unsetenv("FAIL_NO_SERVICE");
43fe83
 
43fe83
     if (rv != -2) {
43fe83
         fprintf(stderr, "%s", "Unexpected create machine error\n");
43fe83
@@ -126,9 +128,11 @@ static int testCreateBadSystemd(const void *opaque ATTRIBUTE_UNUSED)
43fe83
                                       123,
43fe83
                                       false,
43fe83
                                       NULL)) == 0) {
43fe83
+        unsetenv("FAIL_BAD_SERVICE");
43fe83
         fprintf(stderr, "%s", "Unexpected create machine success\n");
43fe83
         return -1;
43fe83
     }
43fe83
+    unsetenv("FAIL_BAD_SERVICE");
43fe83
 
43fe83
     if (rv != -1) {
43fe83
         fprintf(stderr, "%s", "Unexpected create machine error\n");
43fe83
-- 
43fe83
1.8.3.2
43fe83