Create network for integration scenarios

Current behavior creates a stack for the autoscaling scenario,
where it uses the first available network for creating servers.
We've seen failures in our downstream CI, which seem to be caused
by the scenario chosing ironic provisioning network.

With this patch a new network and a subnet are created at the
start of the integration scenarios. The network and subnet
is then deleted at the end of course.

Change-Id: Ib049bf96a345f64181cdca6616b44ba97e26d07a
diff --git a/telemetry_tempest_plugin/scenario/test_telemetry_integration.py b/telemetry_tempest_plugin/scenario/test_telemetry_integration.py
index 6af6811..44a6dff 100644
--- a/telemetry_tempest_plugin/scenario/test_telemetry_integration.py
+++ b/telemetry_tempest_plugin/scenario/test_telemetry_integration.py
@@ -32,6 +32,14 @@
     @classmethod
     def resource_setup(cls):
         cls.stack_name = data_utils.rand_name("telemetry")
+        networks = cls.os_primary.networks_client
+        subnets = cls.os_primary.subnets_client
+        cls.stack_network_id = networks.create_network()['network']['id']
+        cls.stack_subnet_id = subnets.create_subnet(
+            ip_version=4,
+            network_id=cls.stack_network_id,
+            cidr=config.CONF.network.project_network_cidr
+        )['subnet']['id']
 
     @classmethod
     def skip_checks(cls):
@@ -100,14 +108,14 @@
                 time.sleep(2)
                 r = requests.get(stack_url, headers=headers)
                 repeats += 1
+        cls.os_primary.subnets_client.delete_subnet(cls.stack_subnet_id)
+        cls.os_primary.networks_client.delete_network(cls.stack_network_id)
 
         super(TestTelemetryIntegration, cls).resource_cleanup()
 
     def _prep_test(self, filename):
         admin_auth = self.os_admin.auth_provider.get_auth()
         auth = self.os_primary.auth_provider.get_auth()
-        networks = self.os_primary.networks_client.list_networks(
-            **{'router:external': False, 'fields': 'id'})['networks']
 
         os.environ.update({
             "ADMIN_TOKEN": admin_auth[0],
@@ -124,7 +132,7 @@
             "NOVA_SERVICE_URL": self._get_endpoint(auth, "compute"),
             "GLANCE_IMAGE_NAME": self.image_create(),
             "NOVA_FLAVOR_REF": config.CONF.compute.flavor_ref,
-            "NEUTRON_NETWORK": networks[0].get('id'),
+            "NEUTRON_NETWORK": self.stack_network_id,
             "STACK_NAME": self.stack_name,
         })
 
diff --git a/telemetry_tempest_plugin/scenario/test_telemetry_integration_prometheus.py b/telemetry_tempest_plugin/scenario/test_telemetry_integration_prometheus.py
index 122a3f9..49ce5e8 100644
--- a/telemetry_tempest_plugin/scenario/test_telemetry_integration_prometheus.py
+++ b/telemetry_tempest_plugin/scenario/test_telemetry_integration_prometheus.py
@@ -33,6 +33,14 @@
     @classmethod
     def resource_setup(cls):
         cls.stack_name = data_utils.rand_name("telemetry")
+        networks = cls.os_primary.networks_client
+        subnets = cls.os_primary.subnets_client
+        cls.stack_network_id = networks.create_network()['network']['id']
+        cls.stack_subnet_id = subnets.create_subnet(
+            ip_version=4,
+            network_id=cls.stack_network_id,
+            cidr=config.CONF.network.project_network_cidr
+        )['subnet']['id']
 
     @classmethod
     def skip_checks(cls):
@@ -102,6 +110,9 @@
                 r = requests.get(stack_url, headers=headers)
                 repeats += 1
 
+        cls.os_primary.subnets_client.delete_subnet(cls.stack_subnet_id)
+        cls.os_primary.networks_client.delete_network(cls.stack_network_id)
+
         super(PrometheusGabbiTest, cls).resource_cleanup()
 
     def _prep_query(self, prometheus_rate_duration, resource_prefix):
@@ -128,8 +139,6 @@
 
     def _prep_test(self, filename):
         auth = self.os_primary.auth_provider.get_auth()
-        networks = self.os_primary.networks_client.list_networks(
-            **{'router:external': False, 'fields': 'id'})['networks']
         # NOTE(marihan): This is being used in prometheus query as heat is
         # using the last 7 digits from stack_name to create the autoscaling
         # resources.
@@ -154,7 +163,7 @@
             config.CONF.telemetry.prometheus_service_url,
             "GLANCE_IMAGE_NAME": self.image_create(),
             "NOVA_FLAVOR_REF": config.CONF.compute.flavor_ref,
-            "NEUTRON_NETWORK": networks[0].get('id'),
+            "NEUTRON_NETWORK": self.stack_network_id,
             "STACK_NAME": self.stack_name,
             "RESOURCE_PREFIX": resource_prefix,
             "PROMETHEUS_RATE_DURATION": str(prometheus_rate_duration),