-def test_network_format(heat_template):
- '''
- Make sure all network properties use the allowed naming
- conventions
- '''
- with open(heat_template) as fh:
+from tests.helpers import validates
+
+RE_INTERNAL_NETWORK_RID = re.compile(r"int_(?P<network_role>.+)_network$")
+NETWORK_RESOURCE_TYPES = ["OS::Neutron::Net", "OS::ContrailV2::VirtualNetwork"]
+
+
+@validates("R-16968")
+def test_network_resource_id_format(yaml_file):
+ heat = Heat(yaml_file)
+ network_ids = chain.from_iterable(
+ heat.get_resource_by_type(t) for t in NETWORK_RESOURCE_TYPES
+ )
+ invalid_networks = {
+ r_id for r_id in network_ids if not RE_INTERNAL_NETWORK_RID.match(r_id)
+ }
+ assert not invalid_networks, (
+ "Heat templates must only create internal networks "
+ "and their resource IDs must follow the format "
+ "int_{{network-role}}_network. The following network's resource IDs "
+ "have invalid resource ID formats: "
+ "{}".format(", ".join(invalid_networks))
+ )
+
+
+@validates("R-16241")
+def test_network_has_subnet(yaml_file):
+ """
+ if creating internal network, make sure there is a
+ corresponding subnet that references it
+ """
+
+ with open(yaml_file) as fh: