From 663e7b27b55e2851c251cc8d3245db8628320df7 Mon Sep 17 00:00:00 2001 From: Paul Cuzner Date: Thu, 3 Dec 2020 16:00:27 +1300 Subject: [PATCH] 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) --- src/pybind/mgr/orchestrator/module.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/orchestrator/module.py b/src/pybind/mgr/orchestrator/module.py index 8a34195a636bb..2268d83564301 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) -- 2.39.5