remove bootstrap._InitSharedFileStorage
authorGuido Trotter <ultrotter@google.com>
Fri, 17 Jun 2011 14:27:36 +0000 (17:27 +0300)
committerGuido Trotter <ultrotter@google.com>
Thu, 23 Jun 2011 13:53:24 +0000 (14:53 +0100)
This function is a copy of bootstrap._InitFileStorage with the following
differences:
  - check constants.ENABLE_SHARED_FILE_STORAGE and not
    constants.ENABLE_FILE_STORAGE
  - use different local variable names
  - one different error string

Thus:
  - move the constant check outside of the function call
  - change error string so it's clear where the error is
  - call the same function twice

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/bootstrap.py

index c72754e..4bc9ebf 100644 (file)
@@ -221,14 +221,11 @@ def _InitFileStorage(file_storage_dir):
       time) or the normalized path to the storage directory
 
   """
-  if not constants.ENABLE_FILE_STORAGE:
-    return ""
-
   file_storage_dir = os.path.normpath(file_storage_dir)
 
   if not os.path.isabs(file_storage_dir):
-    raise errors.OpPrereqError("The file storage directory you passed is"
-                               " not an absolute path.", errors.ECODE_INVAL)
+    raise errors.OpPrereqError("File storage directory '%s' is not an absolute"
+                               " path" % file_storage_dir, errors.ECODE_INVAL)
 
   if not os.path.exists(file_storage_dir):
     try:
@@ -245,39 +242,6 @@ def _InitFileStorage(file_storage_dir):
   return file_storage_dir
 
 
-def _InitSharedFileStorage(shared_file_storage_dir):
-  """Initialize if needed the shared file storage.
-
-  @param shared_file_storage_dir: the user-supplied value
-  @return: either empty string (if file storage was disabled at build
-      time) or the normalized path to the storage directory
-
-  """
-  if not constants.ENABLE_SHARED_FILE_STORAGE:
-    return ""
-
-  shared_file_storage_dir = os.path.normpath(shared_file_storage_dir)
-
-  if not os.path.isabs(shared_file_storage_dir):
-    raise errors.OpPrereqError("The shared file storage directory you"
-                               " passed is not an absolute path.",
-                               errors.ECODE_INVAL)
-
-  if not os.path.exists(shared_file_storage_dir):
-    try:
-      os.makedirs(shared_file_storage_dir, 0750)
-    except OSError, err:
-      raise errors.OpPrereqError("Cannot create file storage directory"
-                                 " '%s': %s" % (shared_file_storage_dir, err),
-                                 errors.ECODE_ENVIRON)
-
-  if not os.path.isdir(shared_file_storage_dir):
-    raise errors.OpPrereqError("The file storage directory '%s' is not"
-                               " a directory." % shared_file_storage_dir,
-                               errors.ECODE_ENVIRON)
-  return shared_file_storage_dir
-
-
 def InitCluster(cluster_name, mac_prefix, # pylint: disable-msg=R0913
                 master_netdev, file_storage_dir, shared_file_storage_dir,
                 candidate_pool_size, secondary_ip=None, vg_name=None,
@@ -379,8 +343,15 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable-msg=R0913
                                                              curr_helper),
                                  errors.ECODE_INVAL)
 
-  file_storage_dir = _InitFileStorage(file_storage_dir)
-  shared_file_storage_dir = _InitSharedFileStorage(shared_file_storage_dir)
+  if constants.ENABLE_FILE_STORAGE:
+    file_storage_dir = _InitFileStorage(file_storage_dir)
+  else:
+    file_storage_dir = ""
+
+  if constants.ENABLE_SHARED_FILE_STORAGE:
+    shared_file_storage_dir = _InitFileStorage(shared_file_storage_dir)
+  else:
+    shared_file_storage_dir = ""
 
   if not re.match("^[0-9a-z]{2}:[0-9a-z]{2}:[0-9a-z]{2}$", mac_prefix):
     raise errors.OpPrereqError("Invalid mac prefix given '%s'" % mac_prefix,