From: Paul Cuzner Date: Thu, 3 Dec 2020 03:00:27 +0000 (+1300) Subject: orchestrator: validate osd yaml X-Git-Tag: v16.1.0~290^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0f236c7911bdcc4b0266833e1b7da01a3c7e4eac;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 --- diff --git a/src/pybind/mgr/orchestrator/module.py b/src/pybind/mgr/orchestrator/module.py index c3f31ba663c63..1345931415a7c 100644 --- a/src/pybind/mgr/orchestrator/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -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)