From e5a45a16db128a867ad00daad0cc145a8e006dc5 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 20 Jul 2009 12:29:55 +0200
Subject: [PATCH] Fix backend import errors from GetHypervisorClass

The merge of commit 360b0dc into branch-2.1 broke import of backend,
since it uses hypervisor.GetHypervisor() which returns an instance of
the hypervisor. Some of the hypervisors create directories at init time,
thus the import of backend failed due this chain if it's not done on a
(proper) ganeti node, such as during unittest time.

This patch adds in hypervisor a GetHypervisorClass() function, which
returns the class not the instance of the hypervisor, and uses that in
_BuildUploadFiles(). The existing GetHypervisor is then changed to use
this function.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 lib/backend.py             |  2 +-
 lib/hypervisor/__init__.py | 23 +++++++++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/lib/backend.py b/lib/backend.py
index fc6fca7c9..5392efdcc 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -166,7 +166,7 @@ def _BuildUploadFileList():
     ])
 
   for hv_name in constants.HYPER_TYPES:
-    hv_class = hypervisor.GetHypervisor(hv_name)
+    hv_class = hypervisor.GetHypervisorClass(hv_name)
     allowed_files.update(hv_class.GetAncillaryFiles())
 
   return frozenset(allowed_files)
diff --git a/lib/hypervisor/__init__.py b/lib/hypervisor/__init__.py
index 83604022d..453286c07 100644
--- a/lib/hypervisor/__init__.py
+++ b/lib/hypervisor/__init__.py
@@ -39,11 +39,11 @@ _HYPERVISOR_MAP = {
     }
 
 
-def GetHypervisor(ht_kind):
-  """Return a Hypervisor instance.
+def GetHypervisorClass(ht_kind):
+  """Return a Hypervisor class.
 
-  This function parses the cluster hypervisor configuration file and
-  instantiates a class based on the value of this file.
+  This function returns the hypervisor class corresponding to the
+  given hypervisor name.
 
   @type ht_kind: string
   @param ht_kind: The requested hypervisor type
@@ -53,4 +53,19 @@ def GetHypervisor(ht_kind):
     raise errors.HypervisorError("Unknown hypervisor type '%s'" % ht_kind)
 
   cls = _HYPERVISOR_MAP[ht_kind]
+  return cls
+
+
+def GetHypervisor(ht_kind):
+  """Return a Hypervisor instance.
+
+  This is a wrapper over L{GetHypervisorClass} which returns an
+  instance of the class.
+
+  @type ht_kind: string
+  @param ht_kind: The requested hypervisor type
+
+  """
+  cls = GetHypervisorClass(ht_kind)
+
   return cls()
-- 
GitLab