Blame SOURCES/0002-DOWNSTREAM-ovirt-foreign-menu-Bypass-errors-from-Hos.patch

616d49
From d8dc636c63a3616a938c600487e473a71c67cf96 Mon Sep 17 00:00:00 2001
3e75f9
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
3e75f9
Date: Fri, 6 Jul 2018 09:12:18 -0300
616d49
Subject: [PATCH virt-viewer] [DOWNSTREAM] ovirt-foreign-menu: Bypass errors
616d49
 from Host/Cluster/Data Center
3e75f9
3e75f9
When accessing ovirt as a regular user, it may happen that queries to
3e75f9
Hosts, Clusters and Data Centers return errors due to insufficient
3e75f9
permissions, while they will work fine if access is done by admin user.
3e75f9
In this case, we skip the errors and fallback to the old method.
3e75f9
3e75f9
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
3e75f9
---
3e75f9
 src/ovirt-foreign-menu.c | 60 ++++++++++++++++++++++++++++++----------
3e75f9
 1 file changed, 46 insertions(+), 14 deletions(-)
3e75f9
3e75f9
diff --git a/src/ovirt-foreign-menu.c b/src/ovirt-foreign-menu.c
616d49
index a849991..dc6ecf4 100644
3e75f9
--- a/src/ovirt-foreign-menu.c
3e75f9
+++ b/src/ovirt-foreign-menu.c
616d49
@@ -627,12 +627,21 @@ G_GNUC_END_IGNORE_DEPRECATIONS
616d49
 }
3e75f9
 
3e75f9
 static gboolean storage_domain_attached_to_data_center(OvirtStorageDomain *domain,
3e75f9
-                                                      OvirtDataCenter *data_center)
3e75f9
+                                                       OvirtDataCenter *data_center)
3e75f9
 {
3e75f9
     GStrv data_center_ids;
3e75f9
     char *data_center_guid;
3e75f9
     gboolean match;
3e75f9
 
3e75f9
+    /* For some reason we did not get data center information, so just return
3e75f9
+     * TRUE as it will work like a fallback to old method, where we did not
3e75f9
+     * check relationship between data center and storage domain.
3e75f9
+     */
3e75f9
+    if (data_center == NULL) {
3e75f9
+        g_debug("Could not get data center info, considering storage domain is attached to it");
3e75f9
+        return TRUE;
3e75f9
+    }
3e75f9
+
3e75f9
     g_object_get(domain, "data-center-ids", &data_center_ids, NULL);
3e75f9
     g_object_get(data_center, "guid", &data_center_guid, NULL);
616d49
     match = strv_contains((const gchar * const *) data_center_ids, data_center_guid);
616d49
@@ -779,9 +788,11 @@ static void ovirt_foreign_menu_fetch_storage_domain_async(OvirtForeignMenu *menu
3e75f9
 #ifdef HAVE_OVIRT_DATA_CENTER
3e75f9
     g_return_if_fail(OVIRT_IS_FOREIGN_MENU(menu));
3e75f9
     g_return_if_fail(OVIRT_IS_PROXY(menu->priv->proxy));
3e75f9
-    g_return_if_fail(OVIRT_IS_DATA_CENTER(menu->priv->data_center));
3e75f9
 
3e75f9
-    collection = ovirt_data_center_get_storage_domains(menu->priv->data_center);
3e75f9
+    if (menu->priv->data_center != NULL)
3e75f9
+        collection = ovirt_data_center_get_storage_domains(menu->priv->data_center);
3e75f9
+    else
3e75f9
+        collection = ovirt_api_get_storage_domains(menu->priv->api);
3e75f9
 #else
3e75f9
     collection = ovirt_api_get_storage_domains(menu->priv->api);
3e75f9
 #endif
616d49
@@ -806,9 +817,7 @@ static void data_center_fetched_cb(GObject *source_object,
3e75f9
     ovirt_resource_refresh_finish(resource, result, &error);
3e75f9
     if (error != NULL) {
3e75f9
         g_debug("failed to fetch Data Center: %s", error->message);
3e75f9
-        g_task_return_error(task, error);
3e75f9
-        g_object_unref(task);
3e75f9
-        return;
3e75f9
+        g_clear_error(&error);
3e75f9
     }
3e75f9
 
3e75f9
     ovirt_foreign_menu_next_async_step(menu, task, STATE_DATA_CENTER);
616d49
@@ -823,6 +832,12 @@ static void ovirt_foreign_menu_fetch_data_center_async(OvirtForeignMenu *menu,
3e75f9
     g_return_if_fail(OVIRT_IS_CLUSTER(menu->priv->cluster));
3e75f9
 
3e75f9
     menu->priv->data_center = ovirt_cluster_get_data_center(menu->priv->cluster);
3e75f9
+
3e75f9
+    if (menu->priv->data_center == NULL) {
3e75f9
+        ovirt_foreign_menu_next_async_step(menu, task, STATE_DATA_CENTER);
3e75f9
+        return;
3e75f9
+    }
3e75f9
+
3e75f9
     ovirt_resource_refresh_async(OVIRT_RESOURCE(menu->priv->data_center),
3e75f9
                                  menu->priv->proxy,
3e75f9
                                  g_task_get_cancellable(task),
616d49
@@ -843,9 +858,7 @@ static void cluster_fetched_cb(GObject *source_object,
3e75f9
     ovirt_resource_refresh_finish(resource, result, &error);
3e75f9
     if (error != NULL) {
3e75f9
         g_debug("failed to fetch Cluster: %s", error->message);
3e75f9
-        g_task_return_error(task, error);
3e75f9
-        g_object_unref(task);
3e75f9
-        return;
3e75f9
+        g_clear_error(&error);
3e75f9
     }
3e75f9
 
3e75f9
     ovirt_foreign_menu_next_async_step(menu, task, STATE_CLUSTER);
616d49
@@ -857,9 +870,21 @@ static void ovirt_foreign_menu_fetch_cluster_async(OvirtForeignMenu *menu,
3e75f9
 {
3e75f9
     g_return_if_fail(OVIRT_IS_FOREIGN_MENU(menu));
3e75f9
     g_return_if_fail(OVIRT_IS_PROXY(menu->priv->proxy));
3e75f9
-    g_return_if_fail(OVIRT_IS_HOST(menu->priv->host));
3e75f9
 
3e75f9
-    menu->priv->cluster = ovirt_host_get_cluster(menu->priv->host);
3e75f9
+    /* If there is no host information, we get cluster from the VM */
3e75f9
+    if (menu->priv->host == NULL) {
3e75f9
+        g_return_if_fail(OVIRT_IS_VM(menu->priv->vm));
3e75f9
+        menu->priv->cluster = ovirt_vm_get_cluster(menu->priv->vm);
3e75f9
+    } else {
3e75f9
+        g_return_if_fail(OVIRT_IS_HOST(menu->priv->host));
3e75f9
+        menu->priv->cluster = ovirt_host_get_cluster(menu->priv->host);
3e75f9
+    }
3e75f9
+
3e75f9
+    if (menu->priv->cluster == NULL) {
3e75f9
+        ovirt_foreign_menu_next_async_step(menu, task, STATE_CLUSTER);
3e75f9
+        return;
3e75f9
+    }
3e75f9
+
3e75f9
     ovirt_resource_refresh_async(OVIRT_RESOURCE(menu->priv->cluster),
3e75f9
                                  menu->priv->proxy,
3e75f9
                                  g_task_get_cancellable(task),
616d49
@@ -880,9 +905,7 @@ static void host_fetched_cb(GObject *source_object,
3e75f9
     ovirt_resource_refresh_finish(resource, result, &error);
3e75f9
     if (error != NULL) {
3e75f9
         g_debug("failed to fetch Host: %s", error->message);
3e75f9
-        g_task_return_error(task, error);
3e75f9
-        g_object_unref(task);
3e75f9
-        return;
3e75f9
+        g_clear_error(&error);
3e75f9
     }
3e75f9
 
3e75f9
     ovirt_foreign_menu_next_async_step(menu, task, STATE_HOST);
616d49
@@ -897,6 +920,15 @@ static void ovirt_foreign_menu_fetch_host_async(OvirtForeignMenu *menu,
3e75f9
     g_return_if_fail(OVIRT_IS_VM(menu->priv->vm));
3e75f9
 
3e75f9
     menu->priv->host = ovirt_vm_get_host(menu->priv->vm);
3e75f9
+
3e75f9
+    /* In some cases the VM XML does not include host information, so we just
3e75f9
+     * skip to the next step
3e75f9
+     */
3e75f9
+    if (menu->priv->host == NULL) {
3e75f9
+        ovirt_foreign_menu_next_async_step(menu, task, STATE_HOST);
3e75f9
+        return;
3e75f9
+    }
3e75f9
+
3e75f9
     ovirt_resource_refresh_async(OVIRT_RESOURCE(menu->priv->host),
3e75f9
                                  menu->priv->proxy,
3e75f9
                                  g_task_get_cancellable(task),
3e75f9
-- 
616d49
2.26.2
3e75f9