]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Fix OSD's safe_to_destroy method 30499/head
authorTiago Melo <tmelo@suse.com>
Fri, 20 Sep 2019 16:08:03 +0000 (16:08 +0000)
committerTiago Melo <tmelo@suse.com>
Fri, 18 Oct 2019 10:23:54 +0000 (10:23 +0000)
We were passing the wrong value in "send_command".

Changed the ids path param to a query param.

Signed-off-by: Tiago Melo <tmelo@suse.com>
qa/tasks/mgr/dashboard/test_osd.py
src/pybind/mgr/dashboard/controllers/osd.py
src/pybind/mgr/dashboard/frontend/src/app/shared/api/osd.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/osd.service.ts

index fdd84ac7ea728604827257eb17e2a1e7d369aed9..610d612150d8e1a892d8c28ea025e8d3d3c96913 100644 (file)
@@ -99,8 +99,11 @@ class OsdTest(DashboardTestCase):
 
     def test_safe_to_destroy(self):
         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))
+        max_id = max(map(lambda e: e['osd'], osd_dump['osds']))
+
+        # 1 OSD safe to destroy
+        unused_osd_id = max_id + 10
+        self._get('/api/osd/safe_to_destroy?ids={}'.format(unused_osd_id))
         self.assertStatus(200)
         self.assertJsonBody({
             'is_safe_to_destroy': True,
@@ -110,8 +113,21 @@ class OsdTest(DashboardTestCase):
             'stored_pgs': [],
         })
 
+        # multiple OSDs safe to destroy
+        unused_osd_ids = [max_id + 11, max_id + 12]
+        self._get('/api/osd/safe_to_destroy?ids={}'.format(str(unused_osd_ids)))
+        self.assertStatus(200)
+        self.assertJsonBody({
+            'is_safe_to_destroy': True,
+            'active': [],
+            'missing_stats': [],
+            'safe_to_destroy': unused_osd_ids,
+            'stored_pgs': [],
+        })
+
+        # 1 OSD unsafe to destroy
         def get_destroy_status():
-            self._get('/api/osd/0/safe_to_destroy')
+            self._get('/api/osd/safe_to_destroy?ids=0')
             if 'is_safe_to_destroy' in self.jsonBody():
                 return self.jsonBody()['is_safe_to_destroy']
             return None
index e9eb229aff235202ce8040e6215345b03837055b..5e742863a9cf1500a6f7f6edaf404214201b5b3e 100644 (file)
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 from __future__ import absolute_import
-from . import ApiController, RESTController, UpdatePermission
+import json
+from . import ApiController, RESTController, Endpoint, ReadPermission, UpdatePermission
 from .. import mgr, logger
 from ..security import Scope
 from ..services.ceph_service import CephService, SendCommandError
@@ -196,18 +197,23 @@ class Osd(RESTController):
         CephService.send_command(
             'mon', 'osd destroy-actual', id=int(svc_id), yes_i_really_mean_it=True)
 
-    @RESTController.Resource('GET')
-    def safe_to_destroy(self, svc_id):
+    @Endpoint('GET', query_params=['ids'])
+    @ReadPermission
+    def safe_to_destroy(self, ids):
         """
-        :type svc_id: int|[int]
+        :type ids: int|[int]
         """
-        if not isinstance(svc_id, list):
-            svc_id = [svc_id]
-        svc_id = list(map(str, svc_id))
+
+        ids = json.loads(ids)
+        if isinstance(ids, list):
+            ids = list(map(str, ids))
+        else:
+            ids = [str(ids)]
+
         try:
             result = CephService.send_command(
-                'mon', 'osd safe-to-destroy', ids=svc_id, target=('mgr', ''))
-            result['is_safe_to_destroy'] = set(result['safe_to_destroy']) == set(map(int, svc_id))
+                'mon', 'osd safe-to-destroy', ids=ids, target=('mgr', ''))
+            result['is_safe_to_destroy'] = set(result['safe_to_destroy']) == set(map(int, ids))
             return result
 
         except SendCommandError as e:
index fc1e52fff372420cf19a1779644000489abcf211..f30e099c52b3388ee95642957db71fd66fb9c178 100644 (file)
@@ -108,7 +108,7 @@ describe('OsdService', () => {
 
   it('should return if it is safe to destroy an OSD', () => {
     service.safeToDestroy('[0,1]').subscribe();
-    const req = httpTesting.expectOne('api/osd/[0,1]/safe_to_destroy');
+    const req = httpTesting.expectOne('api/osd/safe_to_destroy?ids=[0,1]');
     expect(req.request.method).toBe('GET');
   });
 });
index 008b877b149260a37900aa34e4b2e9c5a70c59d7..f99132a7672e5a9c889db5810af0a2cb37b3ac70 100644 (file)
@@ -248,6 +248,6 @@ export class OsdService {
       'safe-to-destroy': boolean;
       message?: string;
     }
-    return this.http.get<SafeToDestroyResponse>(`${this.path}/${ids}/safe_to_destroy`);
+    return this.http.get<SafeToDestroyResponse>(`${this.path}/safe_to_destroy?ids=${ids}`);
   }
 }