From 2c31312320ae35beac0b7693fc6b254156a36a1c Mon Sep 17 00:00:00 2001
From: Manuel Franceschini <manuel.franceschini@gmail.com>
Date: Wed, 9 Apr 2008 17:45:40 +0000
Subject: [PATCH] Bugfix instance create when file-storage-dir None

os.path.join does not like None as argument and fails with
AttributeError: 'NoneType' object has no attribute 'startswith'.

This patch makes sure the passed argument is a string in any case.

Reviewed-by: iustinp
---
 lib/cmdlib.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 9e62a79eb..67ae4c3ae 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -3196,10 +3196,16 @@ class LUCreateInstance(LogicalUnit):
     else:
       network_port = None
 
+    # this is needed because os.path.join does not accept None arguments
+    if self.op.file_storage_dir is None:
+      string_file_storage_dir = ""
+    else:
+      string_file_storage_dir = self.op.file_storage_dir
+
     # build the full file storage dir path
     file_storage_dir = os.path.normpath(os.path.join(
                                         self.sstore.GetFileStorageDir(),
-                                        self.op.file_storage_dir, instance))
+                                        string_file_storage_dir, instance))
 
 
     disks = _GenerateDiskTemplate(self.cfg,
-- 
GitLab