Blame SOURCES/0001-DOWNSTREAM-Workaround-inconsistency-with-REST-API.patch

2a0fe3
From 182fb30ff7cd85873d479b214bebf291aed2eaf1 Mon Sep 17 00:00:00 2001
394f7b
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
394f7b
Date: Fri, 23 Aug 2019 11:30:32 -0300
2a0fe3
Subject: [PATCH virt-viewer] [DOWNSTREAM] Workaround inconsistency with REST
2a0fe3
 API
394f7b
394f7b
The storage domain object returned in this stage does not provide a link
394f7b
to the files subcollection. To workaround this problem, we use the id of
394f7b
the given storage domain to create a new object but referencing the
394f7b
toplevel api, which in turn provides the file collection.
394f7b
394f7b
This is meant to be a donwnstream patch only, while this issue is not
394f7b
addressed by RHV.
394f7b
394f7b
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1717900
394f7b
394f7b
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
394f7b
---
394f7b
 src/ovirt-foreign-menu.c | 38 ++++++++++++++++++++++++++++++++++++--
394f7b
 1 file changed, 36 insertions(+), 2 deletions(-)
394f7b
394f7b
diff --git a/src/ovirt-foreign-menu.c b/src/ovirt-foreign-menu.c
2a0fe3
index 98ab7b9..a849991 100644
394f7b
--- a/src/ovirt-foreign-menu.c
394f7b
+++ b/src/ovirt-foreign-menu.c
2a0fe3
@@ -686,6 +686,37 @@ static gboolean ovirt_foreign_menu_set_file_collection(OvirtForeignMenu *menu, O
394f7b
     return TRUE;
394f7b
 }
394f7b
 
394f7b
+static gboolean set_file_collection_from_toplevel_storage_domain(OvirtForeignMenu *menu, OvirtStorageDomain *domain)
394f7b
+{
394f7b
+    gboolean ret = FALSE;
394f7b
+    GError *error = NULL;
394f7b
+    OvirtResource *resource = NULL;
394f7b
+    gchar *href = NULL, *id = NULL;
394f7b
+
394f7b
+    g_object_get(domain, "guid", &id, NULL);
394f7b
+    href = g_strdup_printf("/ovirt-engine/api/storagedomains/%s", id);
394f7b
+    resource = g_initable_new(OVIRT_TYPE_STORAGE_DOMAIN, NULL, &error, "guid", id, "href", href, NULL);
394f7b
+    if (error != NULL) {
394f7b
+        g_warning("Failed to create storage domain with href %s: %s", href, error->message);
394f7b
+        goto end;
394f7b
+    }
394f7b
+
394f7b
+    ovirt_resource_refresh(resource, menu->priv->proxy, &error);
394f7b
+    if (error != NULL) {
394f7b
+        g_warning("Failed to refresh storage domain: %s", error->message);
394f7b
+        goto end;
394f7b
+    }
394f7b
+
394f7b
+    ret = ovirt_foreign_menu_set_file_collection(menu, ovirt_storage_domain_get_files(OVIRT_STORAGE_DOMAIN(resource)));
394f7b
+
394f7b
+end:
394f7b
+    g_clear_error(&error);
394f7b
+    g_clear_object(&resource);
394f7b
+    g_free(id);
394f7b
+    g_free(href);
394f7b
+    return ret;
394f7b
+}
394f7b
+
394f7b
 static void storage_domains_fetched_cb(GObject *source_object,
394f7b
                                        GAsyncResult *result,
394f7b
                                        gpointer user_data)
2a0fe3
@@ -717,8 +748,11 @@ static void storage_domains_fetched_cb(GObject *source_object,
394f7b
             domain_valid = TRUE;
394f7b
 
394f7b
         file_collection = ovirt_storage_domain_get_files(domain);
394f7b
-        if (!ovirt_foreign_menu_set_file_collection(menu, file_collection))
394f7b
-            continue;
394f7b
+        if (!ovirt_foreign_menu_set_file_collection(menu, file_collection)) {
394f7b
+            /* Retry with toplevel storage domain */
394f7b
+            if (!set_file_collection_from_toplevel_storage_domain(menu, domain))
394f7b
+                continue;
394f7b
+        }
394f7b
 
394f7b
         break; /* There can only be one valid storage domain at a time,
394f7b
                   no need to iterate more on the list */
394f7b
-- 
2a0fe3
2.26.2
394f7b