Blame SOURCES/0031-v2v-o-rhv-upload-check-whether-the-cluster-exists.patch

da373f
From fed5b4195b1b220e43964aa61d01634b307f09a4 Mon Sep 17 00:00:00 2001
3efd08
From: Pino Toscano <ptoscano@redhat.com>
3efd08
Date: Mon, 15 Apr 2019 17:24:42 +0200
3efd08
Subject: [PATCH] v2v: -o rhv-upload: check whether the cluster exists
3efd08
3efd08
In the precheck script, check that the target cluster actually exists.
3efd08
This will avoid errors when creating the VM after the data copying.
3efd08
3efd08
(cherry picked from commit 05e559549dab75f17e147f4a4eafbac868a7aa5d)
3efd08
---
3efd08
 v2v/rhv-upload-precheck.py                             | 10 ++++++++++
3efd08
 v2v/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py |  7 +++++++
3efd08
 2 files changed, 17 insertions(+)
3efd08
3efd08
diff --git a/v2v/rhv-upload-precheck.py b/v2v/rhv-upload-precheck.py
3efd08
index 2798a29dd..b79f91b4a 100644
3efd08
--- a/v2v/rhv-upload-precheck.py
3efd08
+++ b/v2v/rhv-upload-precheck.py
3efd08
@@ -70,4 +70,14 @@ if len(vms) > 0:
3efd08
     raise RuntimeError("VM already exists with name ‘%s’, id ‘%s’" %
3efd08
                        (params['output_name'], vm.id))
3efd08
 
3efd08
+# Check whether the specified cluster exists.
3efd08
+clusters_service = system_service.clusters_service()
3efd08
+clusters = clusters_service.list(
3efd08
+    search='name=%s' % params['rhv_cluster'],
3efd08
+    case_sensitive=True,
3efd08
+)
3efd08
+if len(clusters) == 0:
3efd08
+    raise RuntimeError("The cluster ‘%s’ does not exist" %
3efd08
+                       (params['rhv_cluster']))
3efd08
+
3efd08
 # Otherwise everything is OK, exit with no error.
3efd08
diff --git a/v2v/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py b/v2v/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py
3efd08
index 8d1058d67..cc4224ccd 100644
3efd08
--- a/v2v/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py
3efd08
+++ b/v2v/test-v2v-o-rhv-upload-module/ovirtsdk4/__init__.py
3efd08
@@ -39,6 +39,9 @@ class Connection(object):
3efd08
         return SystemService()
3efd08
 
3efd08
 class SystemService(object):
3efd08
+    def clusters_service(self):
3efd08
+        return ClustersService()
3efd08
+
3efd08
     def data_centers_service(self):
3efd08
         return DataCentersService()
3efd08
 
3efd08
@@ -54,6 +57,10 @@ class SystemService(object):
3efd08
     def vms_service(self):
3efd08
         return VmsService()
3efd08
 
3efd08
+class ClustersService(object):
3efd08
+    def list(self, search=None, case_sensitive=False):
3efd08
+        return ["Default"]
3efd08
+
3efd08
 class DataCentersService(object):
3efd08
     def list(self, search=None, case_sensitive=False):
3efd08
         return []
3efd08
-- 
da373f
2.18.4
3efd08