Fix tests for setting (shared) file storage directory
authorPetr Pudlak <pudlak@google.com>
Wed, 10 Jun 2015 09:10:01 +0000 (11:10 +0200)
committerPetr Pudlak <pudlak@google.com>
Wed, 10 Jun 2015 10:59:49 +0000 (12:59 +0200)
- Fix the test for setting file_storage_dir, which didn't check if the
  value was really set.
- Add tests for shared_file_storage_dir, which were missing completely.

Signed-off-by: Petr Pudlak <pudlak@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>

test/py/cmdlib/cluster_unittest.py

index 7097ac8..5d4de36 100644 (file)
@@ -487,6 +487,7 @@ class TestLUClusterSetParams(CmdlibTestCase):
   def testFileStorageDir(self):
     op = opcodes.OpClusterSetParams(file_storage_dir="/random/path")
     self.ExecOpCode(op)
+    self.assertEqual("/random/path", self.cluster.file_storage_dir)
 
   def testSetFileStorageDirToCurrentValue(self):
     op = opcodes.OpClusterSetParams(
@@ -511,6 +512,36 @@ class TestLUClusterSetParams(CmdlibTestCase):
     self.ExecOpCode(op)
     self.mcpu.assertLogContainsRegex("although file storage is not enabled")
 
+  def testSharedFileStorageDir(self):
+    op = opcodes.OpClusterSetParams(shared_file_storage_dir="/random/path")
+    self.ExecOpCode(op)
+    self.assertEqual("/random/path", self.cluster.shared_file_storage_dir)
+
+  def testSetSharedFileStorageDirToCurrentValue(self):
+    op = opcodes.OpClusterSetParams(shared_file_storage_dir="/random/path")
+    self.ExecOpCode(op)
+    op = opcodes.OpClusterSetParams(shared_file_storage_dir="/random/path")
+    self.ExecOpCode(op)
+    self.mcpu.assertLogContainsRegex("shared file storage dir already set to"
+                                     " value")
+
+  def testUnsetSharedFileStorageDirSharedFileStorageEnabled(self):
+    self.cfg.SetEnabledDiskTemplates([constants.DT_SHARED_FILE])
+    op = opcodes.OpClusterSetParams(shared_file_storage_dir='')
+    self.ExecOpCodeExpectOpPrereqError(op, "Unsetting the 'sharedfile' storage")
+
+  def testUnsetSharedFileStorageDirSharedFileStorageDisabled(self):
+    self.cfg.SetEnabledDiskTemplates([constants.DT_PLAIN])
+    op = opcodes.OpClusterSetParams(shared_file_storage_dir='')
+    self.ExecOpCode(op)
+
+  def testSetSharedFileStorageDirSharedFileStorageDisabled(self):
+    self.cfg.SetEnabledDiskTemplates([constants.DT_PLAIN])
+    op = opcodes.OpClusterSetParams(shared_file_storage_dir='/some/path/')
+    self.ExecOpCode(op)
+    self.mcpu.assertLogContainsRegex("although sharedfile storage is not"
+                                     " enabled")
+
   def testValidDrbdHelper(self):
     node1 = self.cfg.AddNewNode()
     node1.offline = True