From 4a55a9531396e69fa54ae8c74c30f9a070a2b909 Mon Sep 17 00:00:00 2001 From: Fiete Ostkamp Date: Fri, 13 Feb 2026 14:44:36 +0100 Subject: [PATCH] Log diff when cds-resource-resolution fails Issue-ID: INT-2351 Change-Id: Idc77f403cf2d80eb3972ccf2c0f38b66ab93ebbf Signed-off-by: Fiete Ostkamp --- README.md | 3 ++- src/onaptests/steps/onboard/cds.py | 41 +++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 35f4836..faceca0 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,8 @@ and create zip file for heat template `templates/heat_files`. - Create a virtual environment and clone the python-onapsdk ```shell - virtualenv my_test + virtualenv my_test # use `python3.11 -m virtualenv .venv` if 3.11 is + # not your systems default source my_test/bin/activate git clone git@gitlab.com:Orange-OpenSource/lfn/onap/python-onapsdk. git -b develop diff --git a/src/onaptests/steps/onboard/cds.py b/src/onaptests/steps/onboard/cds.py index e91eb4a..794b0a1 100644 --- a/src/onaptests/steps/onboard/cds.py +++ b/src/onaptests/steps/onboard/cds.py @@ -27,6 +27,7 @@ class CDSBaseStep(BaseStep, ABC): class ExposeCDSBlueprintprocessorNodePortStep(CDSBaseStep, ExposeServiceNodePortStep): """Expose CDS blueprintsprocessor port.""" + def __init__(self) -> None: """Initialize step.""" super().__init__(component="CDS", @@ -185,4 +186,42 @@ class CbaProcessStep(CDSBaseStep): workflow: Workflow = blueprint.get_workflow_by_name(settings.CDS_WORKFLOW_NAME) output: Dict[str, Any] = workflow.execute(settings.CDS_WORKFLOW_INPUT) if not output == settings.CDS_WORKFLOW_EXPECTED_OUTPUT: - raise OnapTestException("Response is not equal to the expected one") + error_msg = format_error_message(output) + self._logger.error(error_msg) + raise OnapTestException(error_msg) + + +def format_error_message(output): + """Format error message with diff between expected and actual output. + + Args: + output: The actual output from the workflow execution. + + Returns: + str: Formatted error message with expected vs actual comparison and diff. + + """ + import json + import difflib + + # Pretty print both outputs for comparison + expected_str = json.dumps(settings.CDS_WORKFLOW_EXPECTED_OUTPUT, indent=2, sort_keys=True) + actual_str = json.dumps(output, indent=2, sort_keys=True) + + # Generate a unified diff + diff = difflib.unified_diff( + expected_str.splitlines(keepends=True), + actual_str.splitlines(keepends=True), + fromfile='expected_output', + tofile='actual_output', + lineterm='' + ) + diff_text = ''.join(diff) + + error_msg = ( + f"CDS workflow response does not match expected output.\n\n" + f"Expected output:\n{expected_str}\n\n" + f"Actual output:\n{actual_str}\n\n" + f"Diff:\n{diff_text}" + ) + return error_msg -- 2.16.6