]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Refactor pool API tests
authorStephan Müller <smueller@suse.com>
Wed, 13 Nov 2019 16:11:54 +0000 (17:11 +0100)
committerErnesto Puerta <epuertat@redhat.com>
Fri, 2 Oct 2020 08:55:13 +0000 (10:55 +0200)
Renamed "__create_pool" to "__yield_pool" to make it's purpose clearer
and added a description.

Split up create pool test into three different tests.
Used "__yield_pool" for creation tests, too.

Fixes: https://tracker.ceph.com/issues/42776
Signed-off-by: Stephan Müller <smueller@suse.com>
(cherry picked from commit 96fd06b7db1d57b8384edc1af6cc39e4e532fb77)

Conflicts:
      qa/tasks/mgr/dashboard/test_pool.py:
      - Ignore incoming pool quota tests
Signed-off-by: Ernesto Puerta <epuertat@redhat.com>
qa/tasks/mgr/dashboard/test_pool.py

index 59d86d3b0e604378a8f460cdafeebbac435e88e6..fdf664c72b863d8d9ef4d1bd2d217e9a0a32fe03 100644 (file)
@@ -46,8 +46,22 @@ class PoolTest(DashboardTestCase):
     }))
 
     @contextmanager
-    def __create_pool(self, name, data=None):
-        pool_data = data or {
+    def __yield_pool(self, name=None, data=None, deletion_name=None):
+        """
+        Use either just a name or whole description of a pool to create one.
+        This also validates the correct creation and deletion after the pool was used.
+
+        :param name: Name of the pool
+        :param data: Describes the pool in full length
+        :param deletion_name: Only needed if the pool was renamed
+        :return:
+        """
+        data = self._create_pool(name, data)
+        yield data
+        self._delete_pool(deletion_name or data['pool'])
+
+    def _create_pool(self, name, data):
+        data = data or {
             'pool': name,
             'pg_num': '4',
             'pool_type': 'replicated',
@@ -61,11 +75,12 @@ class PoolTest(DashboardTestCase):
                 'rbd_qos_iops_limit': 5000,
             }
         }
-        self._task_post('/api/pool/', pool_data)
+        self._task_post('/api/pool/', data)
         self.assertStatus(201)
-        time.sleep(5)
-        self._validate_pool_properties(pool_data, self._get_pool(name))
-        yield pool_data
+        self._validate_pool_properties(data, self._get_pool(data['pool']))
+        return data
+
+    def _delete_pool(self, name):
         self._task_delete('/api/pool/' + name)
         self.assertStatus(204)
 
@@ -130,13 +145,6 @@ class PoolTest(DashboardTestCase):
         for p in ['pg_num', pgp_prop]:  # Should have the same values
             self.assertEqual(pool[p], int(value), '{}: {} != {}'.format(p, pool[p], value))
 
-    @classmethod
-    def tearDownClass(cls):
-        super(PoolTest, cls).tearDownClass()
-        for name in ['dashboard_pool1', 'dashboard_pool2', 'dashboard_pool3']:
-            cls._ceph_cmd(['osd', 'pool', 'delete', name, name, '--yes-i-really-really-mean-it'])
-        cls._ceph_cmd(['osd', 'erasure-code-profile', 'rm', 'ecprofile'])
-
     @DashboardTestCase.RunAs('test', 'test', [{'pool': ['create', 'update', 'delete']}])
     def test_read_access_permissions(self):
         self._get('/api/pool')
@@ -210,37 +218,29 @@ class PoolTest(DashboardTestCase):
         self.assertNotIn('flags_names', pool)
         self.assertSchema(pool['configuration'], self.pool_rbd_conf_schema)
 
-    def test_pool_create(self):
-        self._ceph_cmd(['osd', 'crush', 'rule', 'create-erasure', 'ecrule'])
-        self._ceph_cmd(
-            ['osd', 'erasure-code-profile', 'set', 'ecprofile', 'crush-failure-domain=osd'])
-
-        pool = {
+    def test_pool_create_with_two_applications(self):
+        self.__yield_pool(None, {
             'pool': 'dashboard_pool1',
             'pg_num': '32',
             'pool_type': 'replicated',
             'application_metadata': ['rbd', 'sth'],
-        }
-        self._task_post('/api/pool/', pool)
-        self.assertStatus(201)
-        self._validate_pool_properties(pool, self._get_pool(pool['pool']))
-        self._task_delete("/api/pool/" + pool['pool'])
-        self.assertStatus(204)
+        })
 
-        pool = {
+    def test_pool_create_with_ecp_and_rule(self):
+        self._ceph_cmd(['osd', 'crush', 'rule', 'create-erasure', 'ecrule'])
+        self._ceph_cmd(
+            ['osd', 'erasure-code-profile', 'set', 'ecprofile', 'crush-failure-domain=osd'])
+        self.__yield_pool(None, {
             'pool': 'dashboard_pool2',
             'pg_num': '32',
             'pool_type': 'erasure',
             'application_metadata': ['rbd'],
             'erasure_code_profile': 'ecprofile',
             'crush_rule': 'ecrule',
-        }
-        self._task_post('/api/pool/', pool)
-        self.assertStatus(201)
-        self._validate_pool_properties(pool, self._get_pool(pool['pool']))
-        self._task_delete("/api/pool/" + pool['pool'])
-        self.assertStatus(204)
+        })
+        self._ceph_cmd(['osd', 'erasure-code-profile', 'rm', 'ecprofile'])
 
+    def test_pool_create_with_compression(self):
         pool = {
             'pool': 'dashboard_pool3',
             'pg_num': '32',
@@ -254,28 +254,23 @@ class PoolTest(DashboardTestCase):
                 'rbd_qos_iops_limit': None,
             },
         }
-        expected_configuration = [{
-            'name': 'rbd_qos_bps_limit',
-            'source': 1,
-            'value': '2048',
-        }, {
-            'name': 'rbd_qos_iops_limit',
-            'source': 0,
-            'value': '0',
-        }]
-        self._task_post('/api/pool/', pool)
-        self.assertStatus(201)
-        new_pool = self._get_pool(pool['pool'])
-        self._validate_pool_properties(pool, new_pool)
-        for conf in expected_configuration:
-            self.assertIn(conf, new_pool['configuration'])
-
-        self._task_delete("/api/pool/" + pool['pool'])
-        self.assertStatus(204)
+        with self.__yield_pool(None, pool):
+            expected_configuration = [{
+                'name': 'rbd_qos_bps_limit',
+                'source': 1,
+                'value': '2048',
+            }, {
+                'name': 'rbd_qos_iops_limit',
+                'source': 0,
+                'value': '0',
+            }]
+            new_pool = self._get_pool(pool['pool'])
+            for conf in expected_configuration:
+                self.assertIn(conf, new_pool['configuration'])
 
     def test_pool_update_metadata(self):
         pool_name = 'pool_update_metadata'
-        with self.__create_pool(pool_name):
+        with self.__yield_pool(pool_name):
             props = {'application_metadata': ['rbd', 'sth']}
             self._task_put('/api/pool/{}'.format(pool_name), props)
             self._validate_pool_properties(props, self._get_pool(pool_name),
@@ -298,7 +293,7 @@ class PoolTest(DashboardTestCase):
 
     def test_pool_update_configuration(self):
         pool_name = 'pool_update_configuration'
-        with self.__create_pool(pool_name):
+        with self.__yield_pool(pool_name):
             configuration = {
                 'rbd_qos_bps_limit': 1024,
                 'rbd_qos_iops_limit': None,
@@ -320,7 +315,7 @@ class PoolTest(DashboardTestCase):
 
     def test_pool_update_compression(self):
         pool_name = 'pool_update_compression'
-        with self.__create_pool(pool_name):
+        with self.__yield_pool(pool_name):
             properties = {
                 'compression_algorithm': 'zstd',
                 'compression_mode': 'aggressive',
@@ -333,7 +328,7 @@ class PoolTest(DashboardTestCase):
 
     def test_pool_update_unset_compression(self):
         pool_name = 'pool_update_unset_compression'
-        with self.__create_pool(pool_name):
+        with self.__yield_pool(pool_name):
             self._task_put('/api/pool/' + pool_name, {'compression_mode': 'unset'})
             time.sleep(5)
             self._validate_pool_properties({