]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
orchestrator: validate osd yaml
authorPaul Cuzner <pcuzner@redhat.com>
Thu, 3 Dec 2020 03:00:27 +0000 (16:00 +1300)
committerSebastian Wagner <sebastian.wagner@suse.com>
Thu, 7 Jan 2021 12:02:43 +0000 (13:02 +0100)
Validate the yaml document ahead of usage, to catch
any basic errors in the yaml doc. If errors are found the
exception is shown in the mgr log, and the user gets a
more friendly error message, without the traceback.

Signed-off-by: Paul Cuzner <pcuzner@redhat.com>
(cherry picked from commit 0f236c7911bdcc4b0266833e1b7da01a3c7e4eac)

src/pybind/mgr/orchestrator/module.py

index 8a34195a636bbf97a422eb19c99864720d1bc95e..2268d8356430107ae8d0fdc2ddec2d0036b3dbea 100644 (file)
@@ -681,9 +681,15 @@ Examples:
         if inbuf:
             if unmanaged is not None:
                 return HandleCommandResult(-errno.EINVAL, stderr=usage)
+
             try:
-                drivegroups = yaml.safe_load_all(inbuf)
+                drivegroups = [_dg for _dg in yaml.safe_load_all(inbuf)]
+            except yaml.scanner.ScannerError as e:
+                msg = f"Invalid YAML received : {str(e)}"
+                self.log.exception(e)
+                return HandleCommandResult(-errno.EINVAL, stderr=msg)
 
+            try:
                 dg_specs = []
                 for dg in drivegroups:
                     spec = DriveGroupSpec.from_json(dg)