[VVP] Added new three new reports
[vvp/validation-scripts.git] / ice_validator / tests / test_port_resource_ids.py
index a6f7093..511af35 100644 (file)
@@ -2,11 +2,11 @@
 # ============LICENSE_START=======================================================
 # org.onap.vvp/validation-scripts
 # ===================================================================
-# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+# Copyright © 2018 AT&T Intellectual Property. All rights reserved.
 # ===================================================================
 #
 # Unless otherwise specified, all software contained herein is licensed
-# under the Apache License, Version 2.0 (the “License”);
+# under the Apache License, Version 2.0 (the "License");
 # you may not use this software except in compliance with the License.
 # You may obtain a copy of the License at
 #
@@ -21,7 +21,7 @@
 #
 #
 # Unless otherwise specified, all documentation contained herein is licensed
-# under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
+# under the Creative Commons License, Attribution 4.0 Intl. (the "License");
 # you may not use this documentation except in compliance with the License.
 # You may obtain a copy of the License at
 #
@@ -43,29 +43,33 @@ import pytest
 import yaml
 from .helpers import validates
 from .utils.vm_types import get_vm_type_for_nova_server
-from .utils.network_roles import get_network_role_from_port,\
-                                 get_network_type_from_port,\
-                                 property_uses_get_resource
-
-
-@validates('R-29865',
-           'R-69014',
-           'R-05201',
-           'R-68936',
-           'R-32025',
-           'R-11168',
-           'R-84322',
-           'R-96983',
-           'R-26506',
-           'R-20453',
-           'R-26351')
+from .utils.network_roles import (
+    get_network_role_from_port,
+    get_network_type_from_port,
+    property_uses_get_resource,
+)
+
+
+@validates(
+    "R-29865",
+    "R-69014",
+    "R-05201",
+    "R-68936",
+    "R-32025",
+    "R-11168",
+    "R-84322",
+    "R-96983",
+    "R-26506",
+    "R-20453",
+    "R-26351",
+)
 def test_port_resource_ids(heat_template):
-    '''
+    """
     Check that all resource ids for ports follow the right
     naming convention to include the {vm_type} of the
     nova server it is associated to and also contains the
     {network_role} of the network it is associated with
-    '''
+    """
     with open(heat_template) as fh:
         yml = yaml.load(fh)
 
@@ -74,22 +78,22 @@ def test_port_resource_ids(heat_template):
         pytest.skip("No resources specified in the heat template")
 
     port_patterns = {
-                    'internal': re.compile(r'(.+?)_\d+_int_(.+?)_port_\d+'),
-                    'external': re.compile(r'(.+?)_\d+_(.+?)_port_\d+'),
-                    }
-    resources = yml['resources']
+        "internal": re.compile(r"(.+?)_\d+_int_(.+?)_port_\d+"),
+        "external": re.compile(r"(.+?)_\d+_(.+?)_port_\d+"),
+    }
+    resources = yml["resources"]
 
     invalid_ports = []
     for k, v in resources.items():
         if not isinstance(v, dict):
             continue
-        if 'type' not in v:
+        if "type" not in v:
             continue
-        if v['type'] not in 'OS::Nova::Server':
+        if v["type"] not in "OS::Nova::Server":
             continue
-        if 'properties' not in v:
+        if "properties" not in v:
             continue
-        if 'networks' not in v['properties']:
+        if "networks" not in v["properties"]:
             continue
 
         has_vm_type = False
@@ -102,18 +106,18 @@ def test_port_resource_ids(heat_template):
         vm_type = vm_type.lower()
 
         # get all ports associated with the nova server
-        properties = v['properties']
-        for v2 in properties['networks']:
+        properties = v["properties"]
+        for v2 in properties["networks"]:
             for k3, v3 in v2.items():
-                if k3 != 'port':
+                if k3 != "port":
                     continue
                 if not isinstance(v3, dict):
                     continue
 
-                if 'get_param' in v3:
+                if "get_param" in v3:
                     continue
-                elif 'get_resource' in v3:
-                    port_id = v3['get_resource']
+                elif "get_resource" in v3:
+                    port_id = v3["get_resource"]
                     if not resources[port_id]:
                         continue
                     port_resource = resources[port_id]
@@ -121,7 +125,7 @@ def test_port_resource_ids(heat_template):
                 else:
                     continue
 
-                has_vm_type = vm_type+"_" in port_id
+                has_vm_type = vm_type + "_" in port_id
                 has_network_role = False
 
                 if port_resource:
@@ -141,9 +145,9 @@ def test_port_resource_ids(heat_template):
                 else:
                     # match the assumed naming convention for ports
                     # if the specified port is provided via get_param
-                    network_type = 'external'
+                    network_type = "external"
                     if "int_" in port_id:
-                        network_type = 'internal'
+                        network_type = "internal"
                     if port_patterns[network_type].match(port_id):
                         has_network_role = True