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,
'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
# -*- 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
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: