]> git-server-git.apps.pok.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)
committerPaul Cuzner <pcuzner@redhat.com>
Thu, 3 Dec 2020 03:00:27 +0000 (16:00 +1300)
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>
src/pybind/mgr/orchestrator/module.py

index c3f31ba663c63dc422ec9d8da2f1a47fc4f92b27..1345931415a7c126abf6d1d5a4d980de6f36bad7 100644 (file)
@@ -667,9 +667,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)