]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: fix PUT - /api/host/{hostname} while adding labels
authorAvan Thakkar <athakkar@localhost.localdomain>
Mon, 15 Feb 2021 14:18:08 +0000 (19:48 +0530)
committerAvan Thakkar <athakkar@localhost.localdomain>
Mon, 1 Mar 2021 16:26:13 +0000 (21:56 +0530)
Fixes: https://tracker.ceph.com/issues/49292
Signed-off-by: Avan Thakkar <athakkar@redhat.com>
Fixes PUT - /api/host/{hostname} for adding labels.

src/pybind/mgr/dashboard/controllers/host.py
src/pybind/mgr/dashboard/openapi.yaml
src/pybind/mgr/dashboard/tests/test_host.py

index cdce5c895a4c951c601b5c42efadc41e8d27143b..d0129777d157505441b446ec267cba6537d9e479 100644 (file)
@@ -375,6 +375,12 @@ class Host(RESTController):
 
     @raise_if_no_orchestrator([OrchFeature.HOST_LABEL_ADD, OrchFeature.HOST_LABEL_REMOVE])
     @handle_orchestrator_error('host')
+    @EndpointDoc('',
+                 parameters={
+                     'hostname': (str, 'Hostname'),
+                     'labels': ([str], 'Host Labels'),
+                 },
+                 responses={200: None, 204: None})
     def set(self, hostname: str, labels: List[str]):
         """
         Update the specified host.
@@ -384,6 +390,12 @@ class Host(RESTController):
         """
         orch = OrchClient.instance()
         host = get_host(hostname)
+        # only allow List[str] type for labels
+        if not isinstance(labels, list):
+            raise DashboardException(
+                msg='Expected list of labels. Please check API documentation.',
+                http_status_code=400,
+                component='orchestrator')
         current_labels = set(host['labels'])
         # Remove labels.
         remove_labels = list(current_labels.difference(set(labels)))
index cd2a570a8be2eec55375450fc42fc77cc66c6784..3b583399001c7b8243f0fe03e2502ae4f18d5393 100644 (file)
@@ -3334,7 +3334,8 @@ paths:
         \ name of the host to be processed.\n        :param labels: List of labels.\n\
         \        "
       parameters:
-      - in: path
+      - description: Hostname
+        in: path
         name: hostname
         required: true
         schema:
@@ -3345,7 +3346,10 @@ paths:
             schema:
               properties:
                 labels:
-                  type: string
+                  description: Host Labels
+                  items:
+                    type: string
+                  type: array
               required:
               - labels
               type: object
@@ -3353,7 +3357,9 @@ paths:
         '200':
           content:
             application/vnd.ceph.api.v1.0+json:
-              type: object
+              schema:
+                properties: {}
+                type: object
           description: Resource updated.
         '202':
           content:
index 050e28e881076df21b4e8a986e0c6c3b0f76b8f6..bd0deb5f8219189b8e89b0830728f2879e6998ae 100644 (file)
@@ -136,6 +136,10 @@ class HostControllerTest(ControllerTestCase):
             fake_client.hosts.remove_label.assert_called_once_with('node0', 'aaa')
             fake_client.hosts.add_label.assert_called_once_with('node0', 'ccc')
 
+            # return 400 if type other than List[str]
+            self._put('{}/node0'.format(self.URL_HOST), {'labels': 'ddd'})
+            self.assertStatus(400)
+
     @mock.patch('dashboard.controllers.host.time')
     def test_identify_device(self, mock_time):
         url = '{}/host-0/identify_device'.format(self.URL_HOST)