Merge "Protect vs OS_ENDPOINT_TYPE in shaker"
[functest.git] / functest / core / tenantnetwork.py
index 5c3af22..9f5913c 100644 (file)
@@ -9,10 +9,11 @@
 
 """Ease deploying tenant networks
 
 
 """Ease deploying tenant networks
 
-It offers a simple way to create all tenant network ressources required by a
+It offers a simple way to create all tenant network resources required by a
 testcase (including all Functest ones):
 testcase (including all Functest ones):
+
   - TenantNetwork1 selects the user and the project set as env vars
   - TenantNetwork1 selects the user and the project set as env vars
-  - TenantNetwork2 creates a user and project to isolate the same ressources
+  - TenantNetwork2 creates a user and project to isolate the same resources
 
 This classes could be reused by more complexed scenarios (Single VM)
 """
 
 This classes could be reused by more complexed scenarios (Single VM)
 """
@@ -58,7 +59,7 @@ class NewProject(object):
             name_or_id=self.orig_cloud.auth.get(
                 "project_domain_name", "Default"))
         self.project = self.orig_cloud.create_project(
             name_or_id=self.orig_cloud.auth.get(
                 "project_domain_name", "Default"))
         self.project = self.orig_cloud.create_project(
-            name='{}-project_{}'.format(self.case_name, self.guid),
+            name='{}-project_{}'.format(self.case_name[:18], self.guid),
             description="Created by OPNFV Functest: {}".format(
                 self.case_name),
             domain_id=self.domain.id)
             description="Created by OPNFV Functest: {}".format(
                 self.case_name),
             domain_id=self.domain.id)
@@ -106,14 +107,14 @@ class NewProject(object):
             if self.role:
                 self.orig_cloud.delete_role(self.role.id)
         except Exception:  # pylint: disable=broad-except
             if self.role:
                 self.orig_cloud.delete_role(self.role.id)
         except Exception:  # pylint: disable=broad-except
-            self.__logger.exception("Cannot clean all ressources")
+            self.__logger.exception("Cannot clean all resources")
 
 
 class TenantNetwork1(testcase.TestCase):
     # pylint: disable=too-many-instance-attributes
     """Create a tenant network (scenario1)
 
 
 
 class TenantNetwork1(testcase.TestCase):
     # pylint: disable=too-many-instance-attributes
     """Create a tenant network (scenario1)
 
-    It creates and configures all tenant network ressources required by
+    It creates and configures all tenant network resources required by
     advanced testcases (subnet, network and router).
 
     It ensures that all testcases inheriting from TenantNetwork1 could work
     advanced testcases (subnet, network and router).
 
     It ensures that all testcases inheriting from TenantNetwork1 could work
@@ -133,9 +134,10 @@ class TenantNetwork1(testcase.TestCase):
             getattr(config.CONF, 'dir_results'), self.case_name)
         try:
             cloud_config = os_client_config.get_config()
             getattr(config.CONF, 'dir_results'), self.case_name)
         try:
             cloud_config = os_client_config.get_config()
-            self.cloud = shade.OpenStackCloud(cloud_config=cloud_config)
+            self.cloud = self.orig_cloud = shade.OpenStackCloud(
+                cloud_config=cloud_config)
         except Exception:  # pylint: disable=broad-except
         except Exception:  # pylint: disable=broad-except
-            self.cloud = None
+            self.cloud = self.orig_cloud = None
             self.ext_net = None
             self.__logger.exception("Cannot connect to Cloud")
         try:
             self.ext_net = None
             self.__logger.exception("Cannot connect to Cloud")
         try:
@@ -184,7 +186,14 @@ class TenantNetwork1(testcase.TestCase):
                      'service_id': keystone_id})[0].url
         return endpoint
 
                      'service_id': keystone_id})[0].url
         return endpoint
 
-    def _create_network_resources(self):
+    def create_network_resources(self):
+        """Create all tenant network resources
+
+        It creates a router which gateway is the external network detected.
+        The new subnet is attached to that router.
+
+        Raises: expection on error
+        """
         assert self.cloud
         assert self.ext_net
         provider = {}
         assert self.cloud
         assert self.ext_net
         provider = {}
@@ -197,9 +206,15 @@ class TenantNetwork1(testcase.TestCase):
         if hasattr(config.CONF, '{}_segmentation_id'.format(self.case_name)):
             provider["segmentation_id"] = getattr(
                 config.CONF, '{}_segmentation_id'.format(self.case_name))
         if hasattr(config.CONF, '{}_segmentation_id'.format(self.case_name)):
             provider["segmentation_id"] = getattr(
                 config.CONF, '{}_segmentation_id'.format(self.case_name))
-        self.network = self.cloud.create_network(
+        domain = self.orig_cloud.get_domain(
+            name_or_id=self.orig_cloud.auth.get(
+                "project_domain_name", "Default"))
+        project = self.orig_cloud.get_project(
+            self.cloud.auth['project_name'],
+            domain_id=domain.id)
+        self.network = self.orig_cloud.create_network(
             '{}-net_{}'.format(self.case_name, self.guid),
             '{}-net_{}'.format(self.case_name, self.guid),
-            provider=provider,
+            provider=provider, project_id=project.id,
             shared=self.shared_network)
         self.__logger.debug("network: %s", self.network)
 
             shared=self.shared_network)
         self.__logger.debug("network: %s", self.network)
 
@@ -224,7 +239,7 @@ class TenantNetwork1(testcase.TestCase):
         try:
             assert self.cloud
             self.start_time = time.time()
         try:
             assert self.cloud
             self.start_time = time.time()
-            self._create_network_resources()
+            self.create_network_resources()
             self.result = 100
             status = testcase.TestCase.EX_OK
         except Exception:  # pylint: disable=broad-except
             self.result = 100
             status = testcase.TestCase.EX_OK
         except Exception:  # pylint: disable=broad-except
@@ -246,14 +261,14 @@ class TenantNetwork1(testcase.TestCase):
             if self.network:
                 self.cloud.delete_network(self.network.id)
         except Exception:  # pylint: disable=broad-except
             if self.network:
                 self.cloud.delete_network(self.network.id)
         except Exception:  # pylint: disable=broad-except
-            self.__logger.exception("cannot clean all ressources")
+            self.__logger.exception("cannot clean all resources")
 
 
 class TenantNetwork2(TenantNetwork1):
     """Create a tenant network (scenario2)
 
     It creates new user/project before creating and configuring all tenant
 
 
 class TenantNetwork2(TenantNetwork1):
     """Create a tenant network (scenario2)
 
     It creates new user/project before creating and configuring all tenant
-    network ressources required by a testcase (subnet, network and router).
+    network resources required by a testcase (subnet, network and router).
 
     It ensures that all testcases inheriting from TenantNetwork2 could work
     without network specific configurations (or at least read the same config
 
     It ensures that all testcases inheriting from TenantNetwork2 could work
     without network specific configurations (or at least read the same config
@@ -283,4 +298,4 @@ class TenantNetwork2(TenantNetwork1):
             assert self.project
             self.project.clean()
         except Exception:  # pylint: disable=broad-except
             assert self.project
             self.project.clean()
         except Exception:  # pylint: disable=broad-except
-            self.__logger.exception("Cannot clean all ressources")
+            self.__logger.exception("Cannot clean all resources")