Sonarfix: Reduce cognitive complexity 80/96280/3
authorEzhilarasi <ezhrajam@in.ibm.com>
Thu, 26 Sep 2019 11:47:50 +0000 (17:17 +0530)
committerEzhilarasi R <ezhrajam@in.ibm.com>
Tue, 1 Oct 2019 13:52:49 +0000 (13:52 +0000)
Reduced cognitive complexity in validate_metadata method
Change-Id: I195971985214f54a44c56a2e425825251a91c83b
Issue-ID: VVP-294
Signed-off-by: Ezhilarasi <ezhrajam@in.ibm.com>
ice_validator/tests/test_nova_servers_workload_context.py

index 4c2ec10..dc4c437 100644 (file)
@@ -43,7 +43,7 @@
 import pytest
 from tests import cached_yaml as yaml
 
-from .helpers import validates
+from .helpers import validates, get_param
 
 VERSION = "1.0.0"
 
@@ -89,16 +89,7 @@ def validate_metadata(metadata, parameters):
     Return error message string or None if no errors.
     """
     for value in metadata.values():
-        if isinstance(value, dict):
-            if "get_param" in value:
-                if value["get_param"] == "workload_context":
-                    wc = parameters.get("workload_context", {})
-                    if wc.get("type") == "string":
-                        break
-                    else:
-                        return (
-                            'must have parameter "workload_context"' ' of type "string"'
-                        )
-                    break
-    else:
-        return None
+        if get_param(value) == "workload_context" and parameters.get("workload_context", {}).get("type", "") != "string":
+            return 'must have parameter "workload_context" of type "string"'
+        else:
+            return None