- 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
class ExposeCDSBlueprintprocessorNodePortStep(CDSBaseStep, ExposeServiceNodePortStep):
"""Expose CDS blueprintsprocessor port."""
+
def __init__(self) -> None:
"""Initialize step."""
super().__init__(component="CDS",
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