self.assertEqual(len(self.json_body()), 2, 'It should display two OSDs without failure')
self.assertStatus(200)
+ @mock.patch('dashboard.controllers.osd.CephService')
+ def test_osd_scrub(self, ceph_service):
+ self._task_post('/api/osd/1/scrub', {'deep': True})
+ ceph_service.send_command.assert_called_once_with('mon', 'osd deep-scrub', who='1')
+ self.assertStatus(200)
+ self.assertJsonBody(None)
+
@mock.patch('dashboard.controllers.osd.CephService')
def test_osd_create_bare(self, ceph_service):
ceph_service.send_command.return_value = '5'
self.assertStatus(201)
ceph_service.send_command.assert_called()
+ # unknown method
+ data['method'] = 'other'
+ self._task_post('/api/osd', data)
+ self.assertStatus(400)
+ res = self.json_body()
+ self.assertIn('Unknown method', res['detail'])
+
+ # svc_id is not int
+ data['data']['svc_id'] = "five"
+ data['method'] = 'bare'
+ self._task_post('/api/osd', data)
+ self.assertStatus(400)
+ res = self.json_body()
+ self.assertIn(data['data']['svc_id'], res['detail'])
+
@mock.patch('dashboard.controllers.orchestrator.OrchClient.instance')
def test_osd_create_with_drive_groups(self, instance):
# without orchestrator service
fake_client = mock.Mock()
instance.return_value = fake_client
action_list = ['OUT', 'IN', 'DOWN']
+
for action in action_list:
data = {'action': action}
self._task_put('/api/osd/1/mark', data)
self.assertStatus(200)
+
+ # invalid mark
+ instance.reset_mock()
+ with self.assertLogs(level='ERROR') as cm:
+ self._task_put('/api/osd/1/mark', {'action': 'OTHER'})
+ instance.send_command.assert_not_called()
+ self.assertIn('Invalid OSD mark action', cm.output[0])
+ self.assertStatus(200)
+ self.assertJsonBody(None)
+
+ self._task_post('/api/osd/1/purge', {'svc_id': 1})
+ instance.send_command.assert_called_once_with('mon', 'osd purge-actual', id=1,
+ yes_i_really_mean_it=True)
+ self.assertStatus(200)
+ self.assertJsonBody(None)
+
+ @mock.patch('dashboard.controllers.osd.CephService')
+ def test_reweight_osd(self, instance):
+ instance.send_command.return_value = '5'
+ uuid1 = str(uuid.uuid1())
+ sample_data = {
+ 'uuid': uuid1,
+ 'svc_id': 1
+ }
+ data = {
+ 'method': 'bare',
+ 'data': sample_data,
+ 'tracking_id': 'bare-1'
+ }
+ self._task_post('/api/osd', data)
+ self._task_put('/api/osd/1/mark', {'action': 'DOWN'})
+ self.assertStatus(200)
+ self._task_post('/api/osd/1/reweight', {'weight': '1'})
+ instance.send_command.assert_called_with('mon', 'osd reweight', id=1, weight=1.0)
+ self.assertStatus(200)