]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard:add unittest in test_osd.py 43855/head
authorzhangmengqian_yw <zhangmengqian_yewu@cmss.chinamobile.com>
Tue, 9 Nov 2021 02:52:03 +0000 (10:52 +0800)
committerzhangmengqian_yw <zhangmengqian_yewu@cmss.chinamobile.com>
Tue, 9 Nov 2021 05:38:10 +0000 (13:38 +0800)
Add some unittests in src/pybind/mgr/dashboard/tests/test_osd.py
Signed-off-by: Zhang Meng Qian <zhangmengqian_yewu@cmss.chinamobile.com>
src/pybind/mgr/dashboard/tests/test_osd.py

index 790c9b359262cab34c0bea42fd5707e2aef68a6b..775c6ca739708eff9f9d72da2900ebccc81fee18 100644 (file)
@@ -253,6 +253,13 @@ class OsdTest(ControllerTestCase):
             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'
@@ -270,6 +277,21 @@ class OsdTest(ControllerTestCase):
         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
@@ -312,7 +334,43 @@ class OsdTest(ControllerTestCase):
         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)