From: Paul Cuzner Date: Thu, 3 Dec 2020 03:00:27 +0000 (+1300) Subject: orchestrator: validate osd yaml X-Git-Tag: v15.2.9~88^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=663e7b27b55e2851c251cc8d3245db8628320df7;p=ceph.git orchestrator: validate osd yaml 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 (cherry picked from commit 0f236c7911bdcc4b0266833e1b7da01a3c7e4eac) --- diff --git a/src/pybind/mgr/orchestrator/module.py b/src/pybind/mgr/orchestrator/module.py index 8a34195a636b..2268d8356430 100644 --- a/src/pybind/mgr/orchestrator/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -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)