From 49ab1315a360edf54852e3749c66f90c7003eccc Mon Sep 17 00:00:00 2001 From: Patrick Nawracay Date: Tue, 11 Sep 2018 08:53:56 +0200 Subject: [PATCH] mgr/dashboard: Fix flaky QA tests Signed-off-by: Patrick Nawracay --- qa/tasks/mgr/dashboard/test_osd.py | 8 ++++++-- src/pybind/mgr/dashboard/controllers/osd.py | 15 ++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/qa/tasks/mgr/dashboard/test_osd.py b/qa/tasks/mgr/dashboard/test_osd.py index 6e22399a982..73b7da2463e 100644 --- a/qa/tasks/mgr/dashboard/test_osd.py +++ b/qa/tasks/mgr/dashboard/test_osd.py @@ -99,13 +99,17 @@ class OsdTest(DashboardTestCase): self.assertStatus(200) def test_safe_to_destroy(self): - self._get('/api/osd/5/safe_to_destroy') + osd_dump = json.loads(self._ceph_cmd(['osd', 'dump', '-f', 'json'])) + unused_osd_id = max(map(lambda e: e['osd'], osd_dump['osds'])) + 10 + self._get('/api/osd/{}/safe_to_destroy'.format(unused_osd_id)) self.assertStatus(200) self.assertJsonBody({'safe-to-destroy': True}) def get_destroy_status(): self._get('/api/osd/0/safe_to_destroy') - return self.jsonBody()['safe-to-destroy'] + if 'safe-to-destroy' in self.jsonBody(): + return self.jsonBody()['safe-to-destroy'] + return None self.wait_until_equal(get_destroy_status, False, 10) self.assertStatus(200) diff --git a/src/pybind/mgr/dashboard/controllers/osd.py b/src/pybind/mgr/dashboard/controllers/osd.py index 33f1b222ce0..068d8da7805 100644 --- a/src/pybind/mgr/dashboard/controllers/osd.py +++ b/src/pybind/mgr/dashboard/controllers/osd.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -import re from . import ApiController, RESTController, UpdatePermission from .. import mgr, logger from ..security import Scope @@ -154,16 +153,10 @@ class Osd(RESTController): 'mon', 'osd safe-to-destroy', ids=svc_id, target=('mgr', '')) return {'safe-to-destroy': True} except SendCommandError as e: - match = re.match( - r'OSD\(s\) (\d+) have (\d+) pgs currently mapped to them', - e.message) - if match: - return { - 'message': e.message, - 'safe-to-destroy': False - } - else: - raise e + return { + 'message': e.message, + 'safe-to-destroy': False, + } @ApiController('/osd/flags', Scope.OSD) -- 2.39.5