From bc3d1997bd9f12ecbbc52251e1f1a1bad77c2bff Mon Sep 17 00:00:00 2001 From: Tatjana Dehler Date: Tue, 6 Oct 2020 09:03:31 +0200 Subject: [PATCH] mgr/dashboard/qa: add flake8 linting Add flake8 linting to the QA test files and fix issues. Fixes: https://tracker.ceph.com/issues/47757 Signed-off-by: Tatjana Dehler --- qa/tasks/mgr/dashboard/helper.py | 5 +- qa/tasks/mgr/dashboard/test_cephfs.py | 4 +- .../dashboard/test_cluster_configuration.py | 100 +++++++++--------- qa/tasks/mgr/dashboard/test_crush_rule.py | 1 - .../dashboard/test_erasure_code_profile.py | 2 - qa/tasks/mgr/dashboard/test_ganesha.py | 15 ++- qa/tasks/mgr/dashboard/test_host.py | 1 + qa/tasks/mgr/dashboard/test_monitor.py | 1 - qa/tasks/mgr/dashboard/test_orchestrator.py | 5 +- qa/tasks/mgr/dashboard/test_osd.py | 2 +- qa/tasks/mgr/dashboard/test_pool.py | 2 +- qa/tasks/mgr/dashboard/test_rbd.py | 24 +++-- qa/tasks/mgr/dashboard/test_requests.py | 2 +- src/pybind/mgr/dashboard/tox.ini | 1 + 14 files changed, 87 insertions(+), 78 deletions(-) diff --git a/qa/tasks/mgr/dashboard/helper.py b/qa/tasks/mgr/dashboard/helper.py index d65f23b04110c..9176b18cf36d5 100644 --- a/qa/tasks/mgr/dashboard/helper.py +++ b/qa/tasks/mgr/dashboard/helper.py @@ -314,7 +314,7 @@ class DashboardTestCase(MgrTestCase): executing_tasks = [task for task in _res['executing_tasks'] if task['metadata'] == task_metadata] finished_tasks = [task for task in _res['finished_tasks'] if - task['metadata'] == task_metadata] + task['metadata'] == task_metadata] if not executing_tasks and finished_tasks: res_task = finished_tasks[0] @@ -466,17 +466,20 @@ class DashboardTestCase(MgrTestCase): return obj return None + # TODP: pass defaults=(False,) to namedtuple() if python3.7 class JLeaf(namedtuple('JLeaf', ['typ', 'none'])): def __new__(cls, typ, none=False): return super().__new__(cls, typ, none) + JList = namedtuple('JList', ['elem_typ']) JTuple = namedtuple('JList', ['elem_typs']) JUnion = namedtuple('JUnion', ['elem_typs']) + class JObj(namedtuple('JObj', ['sub_elems', 'allow_unknown', 'none', 'unknown_schema'])): def __new__(cls, sub_elems, allow_unknown=False, none=False, unknown_schema=None): """ diff --git a/qa/tasks/mgr/dashboard/test_cephfs.py b/qa/tasks/mgr/dashboard/test_cephfs.py index 2dbd9add72fef..a4c5284d7fdc5 100644 --- a/qa/tasks/mgr/dashboard/test_cephfs.py +++ b/qa/tasks/mgr/dashboard/test_cephfs.py @@ -25,7 +25,7 @@ class CephfsTest(DashboardTestCase): def rm_dir(self, path, expectedStatus=200): self._delete("/api/cephfs/{}/tree".format(self.get_fs_id()), - params={'path': path}) + params={'path': path}) self.assertStatus(expectedStatus) def get_root_directory(self, expectedStatus=200): @@ -239,7 +239,7 @@ class CephfsTest(DashboardTestCase): self.assertEqual(len(snapshots), 0) self._delete("/api/cephfs/{}/snapshot".format(fs_id), - params={'path': '/movies/dune', 'name': 'test'}) + params={'path': '/movies/dune', 'name': 'test'}) self.assertStatus(200) data = self.ls_dir('/movies', 1) diff --git a/qa/tasks/mgr/dashboard/test_cluster_configuration.py b/qa/tasks/mgr/dashboard/test_cluster_configuration.py index dac91ca281386..dc96bced02aea 100644 --- a/qa/tasks/mgr/dashboard/test_cluster_configuration.py +++ b/qa/tasks/mgr/dashboard/test_cluster_configuration.py @@ -29,17 +29,17 @@ class ClusterConfigurationTest(DashboardTestCase): self._ceph_cmd(['config', 'set', 'mon', config_name, 'true']) self.wait_until_equal( - lambda: self._get_config_by_name(config_name), - [{'section': 'mon', 'value': 'true'}], - timeout=30, - period=1) + lambda: self._get_config_by_name(config_name), + [{'section': 'mon', 'value': 'true'}], + timeout=30, + period=1) self._ceph_cmd(['config', 'set', 'mon', config_name, 'false']) self.wait_until_equal( - lambda: self._get_config_by_name(config_name), - [{'section': 'mon', 'value': 'false'}], - timeout=30, - period=1) + lambda: self._get_config_by_name(config_name), + [{'section': 'mon', 'value': 'false'}], + timeout=30, + period=1) # restore value if orig_value: @@ -90,10 +90,10 @@ class ClusterConfigurationTest(DashboardTestCase): }) self.assertStatus(201) self.wait_until_equal( - lambda: self._get_config_by_name(config_name), - expected_result, - timeout=30, - period=1) + lambda: self._get_config_by_name(config_name), + expected_result, + timeout=30, + period=1) # reset original value self._clear_all_values_for_config_option(config_name) @@ -111,19 +111,19 @@ class ClusterConfigurationTest(DashboardTestCase): }) self.assertStatus(201) self.wait_until_equal( - lambda: self._get_config_by_name(config_name), - expected_result, - timeout=30, - period=1) + lambda: self._get_config_by_name(config_name), + expected_result, + timeout=30, + period=1) # delete it and check if it's deleted self._delete('/api/cluster_conf/{}?section={}'.format(config_name, 'mon')) self.assertStatus(204) self.wait_until_equal( - lambda: self._get_config_by_name(config_name), - None, - timeout=30, - period=1) + lambda: self._get_config_by_name(config_name), + None, + timeout=30, + period=1) # reset original value self._clear_all_values_for_config_option(config_name) @@ -147,10 +147,10 @@ class ClusterConfigurationTest(DashboardTestCase): # check if config option value is still the original one self.wait_until_equal( - lambda: self._get_config_by_name(config_name), - orig_value, - timeout=30, - period=1) + lambda: self._get_config_by_name(config_name), + orig_value, + timeout=30, + period=1) def test_create_two_values(self): config_name = 'debug_ms' @@ -168,10 +168,10 @@ class ClusterConfigurationTest(DashboardTestCase): }) self.assertStatus(201) self.wait_until_equal( - lambda: self._get_config_by_name(config_name), - expected_result, - timeout=30, - period=1) + lambda: self._get_config_by_name(config_name), + expected_result, + timeout=30, + period=1) # reset original value self._clear_all_values_for_config_option(config_name) @@ -193,10 +193,10 @@ class ClusterConfigurationTest(DashboardTestCase): expected_result = [{'section': 'mon', 'value': '0/3'}] self.wait_until_equal( - lambda: self._get_config_by_name(config_name), - expected_result, - timeout=30, - period=1) + lambda: self._get_config_by_name(config_name), + expected_result, + timeout=30, + period=1) # reset original value self._clear_all_values_for_config_option(config_name) @@ -217,10 +217,10 @@ class ClusterConfigurationTest(DashboardTestCase): self.assertStatus(201) self.wait_until_equal( - lambda: self._get_config_by_name(config_name), - expected_result, - timeout=30, - period=1) + lambda: self._get_config_by_name(config_name), + expected_result, + timeout=30, + period=1) # reset original value self._clear_all_values_for_config_option(config_name) @@ -246,10 +246,10 @@ class ClusterConfigurationTest(DashboardTestCase): for config_name, value in expected_result.items(): self.wait_until_equal( - lambda: self._get_config_by_name(config_name), - [value], - timeout=30, - period=1) + lambda: self._get_config_by_name(config_name), + [value], + timeout=30, + period=1) # reset original value self._clear_all_values_for_config_option(config_name) @@ -276,10 +276,10 @@ class ClusterConfigurationTest(DashboardTestCase): # check if config option values are still the original ones for config_name, value in orig_values.items(): self.wait_until_equal( - lambda: self._get_config_by_name(config_name), - value, - timeout=30, - period=1) + lambda: self._get_config_by_name(config_name), + value, + timeout=30, + period=1) def test_bulk_set_cant_update_at_runtime_partial(self): config_options = { @@ -302,10 +302,10 @@ class ClusterConfigurationTest(DashboardTestCase): # check if config option values are still the original ones for config_name, value in orig_values.items(): self.wait_until_equal( - lambda: self._get_config_by_name(config_name), - value, - timeout=30, - period=1) + lambda: self._get_config_by_name(config_name), + value, + timeout=30, + period=1) def test_check_existence(self): """ @@ -368,8 +368,8 @@ class ClusterConfigurationTest(DashboardTestCase): self.assertIn('services', data) self.assertIn('type', data) self.assertIn('desc', data) - self.assertIn(data['type'], ['str', 'bool', 'float', 'int', 'size', 'uint', 'addr', 'addrvec', 'uuid', - 'secs']) + self.assertIn(data['type'], ['str', 'bool', 'float', 'int', 'size', 'uint', 'addr', + 'addrvec', 'uuid', 'secs']) if 'value' in data: self.assertIn('source', data) diff --git a/qa/tasks/mgr/dashboard/test_crush_rule.py b/qa/tasks/mgr/dashboard/test_crush_rule.py index 514f16a401315..c39983239875d 100644 --- a/qa/tasks/mgr/dashboard/test_crush_rule.py +++ b/qa/tasks/mgr/dashboard/test_crush_rule.py @@ -84,4 +84,3 @@ class CrushRuleTest(DashboardTestCase): 'names': JList(str), 'nodes': JList(JObj({}, allow_unknown=True)) })) - diff --git a/qa/tasks/mgr/dashboard/test_erasure_code_profile.py b/qa/tasks/mgr/dashboard/test_erasure_code_profile.py index 27fe884c8b0cc..ecc4958da0a6f 100644 --- a/qa/tasks/mgr/dashboard/test_erasure_code_profile.py +++ b/qa/tasks/mgr/dashboard/test_erasure_code_profile.py @@ -49,7 +49,6 @@ class ECPTest(DashboardTestCase): get_data = self._get('/api/erasure_code_profile/default') self.assertEqual(get_data, default[0]) - def test_create(self): data = {'name': 'ecp32', 'k': 3, 'm': 2} self._post('/api/erasure_code_profile', data) @@ -104,4 +103,3 @@ class ECPTest(DashboardTestCase): 'directory': str, 'nodes': JList(JObj({}, allow_unknown=True)) })) - diff --git a/qa/tasks/mgr/dashboard/test_ganesha.py b/qa/tasks/mgr/dashboard/test_ganesha.py index 229d8af819539..6ed803406f865 100644 --- a/qa/tasks/mgr/dashboard/test_ganesha.py +++ b/qa/tasks/mgr/dashboard/test_ganesha.py @@ -33,7 +33,8 @@ class GaneshaTest(DashboardTestCase): cls._rados_cmd(['-p', 'ganesha', '-N', 'ganesha2', 'create', 'conf-node1']) cls._rados_cmd(['-p', 'ganesha', '-N', 'ganesha2', 'create', 'conf-node2']) cls._rados_cmd(['-p', 'ganesha', '-N', 'ganesha2', 'create', 'conf-node3']) - cls._ceph_cmd(['dashboard', 'set-ganesha-clusters-rados-pool-namespace', 'cluster1:ganesha/ganesha1,cluster2:ganesha/ganesha2']) + cls._ceph_cmd(['dashboard', 'set-ganesha-clusters-rados-pool-namespace', + 'cluster1:ganesha/ganesha1,cluster2:ganesha/ganesha2']) # RGW setup cls._radosgw_admin_cmd([ @@ -47,7 +48,8 @@ class GaneshaTest(DashboardTestCase): def tearDownClass(cls): super(GaneshaTest, cls).tearDownClass() cls._radosgw_admin_cmd(['user', 'rm', '--uid', 'admin', '--purge-data']) - cls._ceph_cmd(['osd', 'pool', 'delete', 'ganesha', 'ganesha', '--yes-i-really-really-mean-it']) + cls._ceph_cmd(['osd', 'pool', 'delete', 'ganesha', 'ganesha', + '--yes-i-really-really-mean-it']) @DashboardTestCase.RunAs('test', 'test', [{'rbd-image': ['create', 'update', 'delete']}]) def test_read_access_permissions(self): @@ -68,7 +70,8 @@ class GaneshaTest(DashboardTestCase): @classmethod def create_export(cls, path, cluster_id, daemons, fsal, sec_label_xattr=None): if fsal == 'CEPH': - fsal = {"name": "CEPH", "user_id": "admin", "fs_name": None, "sec_label_xattr": sec_label_xattr} + fsal = {"name": "CEPH", "user_id": "admin", "fs_name": None, + "sec_label_xattr": sec_label_xattr} pseudo = "/cephfs{}".format(path) else: fsal = {"name": "RGW", "rgw_user_id": "admin"} @@ -107,7 +110,8 @@ class GaneshaTest(DashboardTestCase): exports = self._get("/api/nfs-ganesha/export") self.assertEqual(len(exports), 0) - data = self.create_export(cephfs_path, 'cluster1', ['node1', 'node2'], 'CEPH', "security.selinux") + data = self.create_export(cephfs_path, 'cluster1', ['node1', 'node2'], 'CEPH', + "security.selinux") exports = self._get("/api/nfs-ganesha/export") self.assertEqual(len(exports), 1) @@ -166,7 +170,8 @@ class GaneshaTest(DashboardTestCase): "setting or deploy an NFS-Ganesha cluster with the Orchestrator."), data['message']) - self._ceph_cmd(['dashboard', 'set-ganesha-clusters-rados-pool-namespace', 'cluster1:ganesha/ganesha1,cluster2:ganesha/ganesha2']) + self._ceph_cmd(['dashboard', 'set-ganesha-clusters-rados-pool-namespace', + 'cluster1:ganesha/ganesha1,cluster2:ganesha/ganesha2']) def test_valid_status(self): data = self._get('/api/nfs-ganesha/status') diff --git a/qa/tasks/mgr/dashboard/test_host.py b/qa/tasks/mgr/dashboard/test_host.py index da8f8849b1084..1904e6964e6ce 100644 --- a/qa/tasks/mgr/dashboard/test_host.py +++ b/qa/tasks/mgr/dashboard/test_host.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import + import json from .helper import DashboardTestCase, JList, JObj diff --git a/qa/tasks/mgr/dashboard/test_monitor.py b/qa/tasks/mgr/dashboard/test_monitor.py index 0cf7e25a282a6..e32c2c10ce141 100644 --- a/qa/tasks/mgr/dashboard/test_monitor.py +++ b/qa/tasks/mgr/dashboard/test_monitor.py @@ -12,7 +12,6 @@ class MonitorTest(DashboardTestCase): self._get('/api/monitor') self.assertStatus(403) - def test_monitor_default(self): data = self._get("/api/monitor") self.assertStatus(200) diff --git a/qa/tasks/mgr/dashboard/test_orchestrator.py b/qa/tasks/mgr/dashboard/test_orchestrator.py index 9f4204379ac9a..596b2556afadd 100644 --- a/qa/tasks/mgr/dashboard/test_orchestrator.py +++ b/qa/tasks/mgr/dashboard/test_orchestrator.py @@ -59,7 +59,6 @@ class OrchestratorControllerTest(DashboardTestCase): URL_INVENTORY = '/api/orchestrator/inventory' URL_OSD = '/api/orchestrator/osd' - @property def test_data_inventory(self): return test_data['inventory'] @@ -119,7 +118,9 @@ class OrchestratorControllerTest(DashboardTestCase): data = self._get(self.URL_INVENTORY) self.assertStatus(200) - sorting_key = lambda node: node['name'] + def sorting_key(node): + return node['name'] + test_inventory = sorted(self.test_data_inventory, key=sorting_key) resp_inventory = sorted(data, key=sorting_key) self.assertEqual(len(test_inventory), len(resp_inventory)) diff --git a/qa/tasks/mgr/dashboard/test_osd.py b/qa/tasks/mgr/dashboard/test_osd.py index 3747fcb164a4d..5ea8b043508d5 100644 --- a/qa/tasks/mgr/dashboard/test_osd.py +++ b/qa/tasks/mgr/dashboard/test_osd.py @@ -55,7 +55,7 @@ class OsdTest(DashboardTestCase): data = self._get('/api/osd/0/histogram') self.assertStatus(200) self.assert_in_and_not_none(data['osd'], ['op_w_latency_in_bytes_histogram', - 'op_r_latency_out_bytes_histogram']) + 'op_r_latency_out_bytes_histogram']) def test_scrub(self): self._post('/api/osd/0/scrub?deep=False') diff --git a/qa/tasks/mgr/dashboard/test_pool.py b/qa/tasks/mgr/dashboard/test_pool.py index 123d8a3cb864b..0a4d2407ca9b3 100644 --- a/qa/tasks/mgr/dashboard/test_pool.py +++ b/qa/tasks/mgr/dashboard/test_pool.py @@ -22,7 +22,7 @@ class PoolTest(DashboardTestCase): }, allow_unknown=True) pool_list_stat_schema = JObj(sub_elems={ - 'latest': JUnion([int,float]), + 'latest': JUnion([int, float]), 'rate': float, 'rates': JList(JAny(none=False)), }) diff --git a/qa/tasks/mgr/dashboard/test_rbd.py b/qa/tasks/mgr/dashboard/test_rbd.py index c6150dd06df27..62db5440a1f2e 100644 --- a/qa/tasks/mgr/dashboard/test_rbd.py +++ b/qa/tasks/mgr/dashboard/test_rbd.py @@ -178,7 +178,7 @@ class RbdTest(DashboardTestCase): img = self._get('/api/block/image/{}%2F{}'.format(pool, name)) self._task_post("/api/block/image/{}%2F{}/move_trash".format(pool, name), - {'delay': delay}) + {'delay': delay}) self.assertStatus([200, 201]) return img['id'] @@ -403,7 +403,8 @@ class RbdTest(DashboardTestCase): res = self.create_image('rbd', None, 'test_rbd_twice', 10240) self.assertStatus(400) self.assertEqual(res, {"code": '17', 'status': 400, "component": "rbd", - "detail": "[errno 17] RBD image already exists (error creating image)", + "detail": "[errno 17] RBD image already exists (error creating " + "image)", 'task': {'name': 'rbd/create', 'metadata': {'pool_name': 'rbd', 'namespace': None, 'image_name': 'test_rbd_twice'}}}) @@ -756,6 +757,7 @@ class RbdTest(DashboardTestCase): def test_clone_format_version(self): config_name = 'rbd_default_clone_format' + def _get_config_by_name(conf_name): data = self._get('/api/cluster_conf/{}'.format(conf_name)) if 'value' in data: @@ -774,9 +776,9 @@ class RbdTest(DashboardTestCase): 'value': value }) self.wait_until_equal( - lambda: _get_config_by_name(config_name), - value, - timeout=60) + lambda: _get_config_by_name(config_name), + value, + timeout=60) clone_format_version = self._get('/api/block/image/clone_format_version') self.assertEqual(clone_format_version, 1) self.assertStatus(200) @@ -788,9 +790,9 @@ class RbdTest(DashboardTestCase): 'value': value }) self.wait_until_equal( - lambda: _get_config_by_name(config_name), - value, - timeout=60) + lambda: _get_config_by_name(config_name), + value, + timeout=60) clone_format_version = self._get('/api/block/image/clone_format_version') self.assertEqual(clone_format_version, 2) self.assertStatus(200) @@ -801,9 +803,9 @@ class RbdTest(DashboardTestCase): 'value': value }) self.wait_until_equal( - lambda: _get_config_by_name(config_name), - None, - timeout=60) + lambda: _get_config_by_name(config_name), + None, + timeout=60) def test_image_with_namespace(self): self.create_namespace('rbd', 'ns') diff --git a/qa/tasks/mgr/dashboard/test_requests.py b/qa/tasks/mgr/dashboard/test_requests.py index 25460914866ad..aa431a252c7a9 100644 --- a/qa/tasks/mgr/dashboard/test_requests.py +++ b/qa/tasks/mgr/dashboard/test_requests.py @@ -26,4 +26,4 @@ class RequestsTest(DashboardTestCase): self._get('/api/summary') self.assertHeaders({ 'server': 'Ceph-Dashboard' - }) \ No newline at end of file + }) diff --git a/src/pybind/mgr/dashboard/tox.ini b/src/pybind/mgr/dashboard/tox.ini index 8ac4ce6c83880..4707d567aa9c1 100644 --- a/src/pybind/mgr/dashboard/tox.ini +++ b/src/pybind/mgr/dashboard/tox.ini @@ -105,6 +105,7 @@ deps = {[base-lint]deps} commands = flake8 + flake8 --config=tox.ini ../../../../qa/tasks/mgr/dashboard isort . --check {[base-pylint]commands} {[base-rst]commands} -- 2.39.5