]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/tasks: tests for 'fs volume create' and 'fs volume ls'
authorJos Collin <jcollin@redhat.com>
Tue, 26 Nov 2019 10:00:58 +0000 (15:30 +0530)
committerRamana Raja <rraja@redhat.com>
Wed, 12 Feb 2020 10:11:59 +0000 (05:11 -0500)
Fixes: https://tracker.ceph.com/issues/42872
Signed-off-by: Jos Collin <jcollin@redhat.com>
(cherry picked from commit 5e998bd9b5d0a6d819d87f74b9769a4086b886fe)

qa/tasks/cephfs/test_volumes.py

index 6b0462bae4a1e15938d0aceec168d9ed2d7017fb..51365c56120f4abe6bf319c2306e1b170d817fba 100644 (file)
@@ -11,7 +11,7 @@ from teuthology.exceptions import CommandFailedError
 log = logging.getLogger(__name__)
 
 class TestVolumes(CephFSTestCase):
-    TEST_VOLUME_NAME = "fs_test_vol"
+    TEST_VOLUME_PREFIX = "volume"
     TEST_SUBVOLUME_PREFIX="subvolume"
     TEST_GROUP_PREFIX="group"
     TEST_SNAPSHOT_PREFIX="snapshot"
@@ -27,6 +27,11 @@ class TestVolumes(CephFSTestCase):
     def _fs_cmd(self, *args):
         return self.mgr_cluster.mon_manager.raw_cluster_cmd("fs", *args)
 
+    def _generate_random_volume_name(self, count=1):
+        r = random.sample(range(10000), count)
+        volumes = ["{0}_{1}".format(TestVolumes.TEST_VOLUME_PREFIX, c) for c in r]
+        return volumes[0] if count == 1 else volumes
+
     def _generate_random_subvolume_name(self, count=1):
         r = random.sample(range(10000), count)
         subvolumes = ["{0}_{1}".format(TestVolumes.TEST_SUBVOLUME_PREFIX, c) for c in r]
@@ -49,7 +54,7 @@ class TestVolumes(CephFSTestCase):
         result = json.loads(self._fs_cmd("volume", "ls"))
         if len(result) == 0:
             self.vol_created = True
-            self.volname = TestVolumes.TEST_VOLUME_NAME
+            self.volname = self._generate_random_volume_name()
             self._fs_cmd("volume", "create", self.volname)
         else:
             self.volname = result[0]['name']
@@ -117,6 +122,48 @@ class TestVolumes(CephFSTestCase):
         # Now wait for the mgr to expire the connection:
         self.wait_until_evicted(sessions[0]['id'], timeout=90)
 
+    def test_volume_create(self):
+        """
+        That the volume can be created and then cleans up
+        """
+        volname = self._generate_random_volume_name()
+        self._fs_cmd("volume", "create", volname)
+        volumels = json.loads(self._fs_cmd("volume", "ls"))
+        try:
+            if (not (volname in ([volume['name'] for volume in volumels]))):
+                raise RuntimeError("Error creating volume '{0}'".format(volname))
+        finally:
+            # clean up
+            self._fs_cmd("volume", "rm", volname, "--yes-i-really-mean-it")
+
+    def test_volume_ls(self):
+        """
+        That the existing and the newly created volumes can be listed and
+        finally cleans up.
+        """
+        vls = json.loads(self._fs_cmd("volume", "ls"))
+        volumes = [volume['name'] for volume in vls]
+
+        #create new volumes and add it to the existing list of volumes
+        volumenames = self._generate_random_volume_name(3)
+        for volumename in volumenames:
+            self._fs_cmd("volume", "create", volumename)
+        volumes.extend(volumenames)
+
+        # list volumes
+        try:
+            volumels = json.loads(self._fs_cmd('volume', 'ls'))
+            if len(volumels) == 0:
+                raise RuntimeError("Expected the 'fs volume ls' command to list the created volumes.")
+            else:
+                volnames = [volume['name'] for volume in volumels]
+                if collections.Counter(volnames) != collections.Counter(volumes):
+                    raise RuntimeError("Error creating or listing volumes")
+        finally:
+            # clean up
+            for volume in volumenames:
+                self._fs_cmd("volume", "rm", volume, "--yes-i-really-mean-it")
+
     def test_volume_rm(self):
         try:
             self._fs_cmd("volume", "rm", self.volname)