diff --git a/qa/tasks/mgr/dashboard/helper.py b/qa/tasks/mgr/dashboard/helper.py index 55355048a36..95beabda19c 100644 --- a/qa/tasks/mgr/dashboard/helper.py +++ b/qa/tasks/mgr/dashboard/helper.py @@ -336,9 +336,20 @@ class DashboardTestCase(MgrTestCase): raise ex @classmethod - def _get(cls, url, params=None, version=DEFAULT_API_VERSION, set_cookies=False, headers=None): - return cls._request(url, 'GET', params=params, version=version, - set_cookies=set_cookies, headers=headers) + def _get(cls, url, params=None, version=DEFAULT_API_VERSION, set_cookies=False, headers=None, + retries=0, wait_func=None): + while retries >= 0: + try: + return cls._request(url, 'GET', params=params, version=version, + set_cookies=set_cookies, headers=headers) + except requests.RequestException as e: + if retries == 0: + raise e from None + + log.info("Retrying the GET req. Total retries left is... %s", retries) + if wait_func: + wait_func() + retries -= 1 @classmethod def _view_cache_get(cls, url, retries=5): @@ -510,9 +521,11 @@ class DashboardTestCase(MgrTestCase): self.assertEqual(body['detail'], detail) @classmethod - def _ceph_cmd(cls, cmd): + def _ceph_cmd(cls, cmd, wait=0): res = cls.mgr_cluster.mon_manager.raw_cluster_cmd(*cmd) log.debug("command result: %s", res) + if wait: + time.sleep(wait) return res @classmethod diff --git a/qa/tasks/mgr/dashboard/test_mgr_module.py b/qa/tasks/mgr/dashboard/test_mgr_module.py index 1dbdef23d34..f5094bd95b4 100644 --- a/qa/tasks/mgr/dashboard/test_mgr_module.py +++ b/qa/tasks/mgr/dashboard/test_mgr_module.py @@ -39,9 +39,13 @@ class MgrModuleTestCase(DashboardTestCase): class MgrModuleTest(MgrModuleTestCase): def test_list_disabled_module(self): - self._ceph_cmd(['mgr', 'module', 'disable', 'iostat']) - self.wait_until_rest_api_accessible() - data = self._get('/api/mgr/module') + self._ceph_cmd(['mgr', 'module', 'disable', 'iostat'], wait=3) + data = self._get( + '/api/mgr/module', + retries=1, + wait_func=lambda: # pylint: disable=unnecessary-lambda + self.wait_until_rest_api_accessible() + ) self.assertStatus(200) self.assertSchema( data, @@ -57,9 +61,13 @@ class MgrModuleTest(MgrModuleTestCase): self.assertFalse(module_info['enabled']) def test_list_enabled_module(self): - self._ceph_cmd(['mgr', 'module', 'enable', 'iostat']) - self.wait_until_rest_api_accessible() - data = self._get('/api/mgr/module') + self._ceph_cmd(['mgr', 'module', 'enable', 'iostat'], wait=3) + data = self._get( + '/api/mgr/module', + retries=1, + wait_func=lambda: # pylint: disable=unnecessary-lambda + self.wait_until_rest_api_accessible() + ) self.assertStatus(200) self.assertSchema( data,