Merge "Config physical network when creating tempest net"
[functest.git] / functest / opnfv_tests / openstack / tempest / tempest.py
index 1920014..5481b13 100644 (file)
@@ -16,6 +16,7 @@ import re
 import shutil
 import subprocess
 import time
+import uuid
 
 import yaml
 
@@ -25,11 +26,13 @@ from functest.opnfv_tests.openstack.tempest import conf_utils
 from functest.utils.constants import CONST
 import functest.utils.functest_utils as ft_utils
 
+from snaps.config.flavor import FlavorConfig
+from snaps.config.network import NetworkConfig, SubnetConfig
+from snaps.config.project import ProjectConfig
+from snaps.config.user import UserConfig
+
 from snaps.openstack import create_flavor
-from snaps.openstack.create_flavor import FlavorSettings, OpenStackFlavor
-from snaps.openstack.create_project import ProjectSettings
-from snaps.openstack.create_network import NetworkSettings, SubnetSettings
-from snaps.openstack.create_user import UserSettings
+from snaps.openstack.create_flavor import OpenStackFlavor
 from snaps.openstack.tests import openstack_tests
 from snaps.openstack.utils import deploy_utils
 
@@ -315,6 +318,8 @@ class TempestResourcesManager(object):
             self.os_creds = openstack_tests.get_credentials(
                 os_env_file=CONST.__getattribute__('openstack_creds'))
 
+        self.guid = '-' + str(uuid.uuid4())
+
         self.creators = list()
 
         if hasattr(CONST, 'snaps_images_cirros'):
@@ -328,9 +333,9 @@ class TempestResourcesManager(object):
         if create_project:
             logger.debug("Creating project (tenant) for Tempest suite")
             project_name = CONST.__getattribute__(
-                'tempest_identity_tenant_name')
+                'tempest_identity_tenant_name') + self.guid
             project_creator = deploy_utils.create_project(
-                self.os_creds, ProjectSettings(
+                self.os_creds, ProjectConfig(
                     name=project_name,
                     description=CONST.__getattribute__(
                         'tempest_identity_tenant_description')))
@@ -342,8 +347,9 @@ class TempestResourcesManager(object):
 
             logger.debug("Creating user for Tempest suite")
             user_creator = deploy_utils.create_user(
-                self.os_creds, UserSettings(
-                    name=CONST.__getattribute__('tempest_identity_user_name'),
+                self.os_creds, UserConfig(
+                    name=CONST.__getattribute__(
+                        'tempest_identity_user_name') + self.guid,
                     password=CONST.__getattribute__(
                         'tempest_identity_user_password'),
                     project_name=project_name))
@@ -357,12 +363,32 @@ class TempestResourcesManager(object):
             user_id = None
 
         logger.debug("Creating private network for Tempest suite")
+
+        tempest_network_type = None
+        tempest_physical_network = None
+        tempest_segmentation_id = None
+
+        if hasattr(CONST, 'tempest_network_type'):
+            tempest_network_type = CONST.__getattribute__(
+                'tempest_network_type')
+        if hasattr(CONST, 'tempest_physical_network'):
+            tempest_physical_network = CONST.__getattribute__(
+                'tempest_physical_network')
+        if hasattr(CONST, 'tempest_segmentation_id'):
+            tempest_segmentation_id = CONST.__getattribute__(
+                'tempest_segmentation_id')
+
         network_creator = deploy_utils.create_network(
-            self.os_creds, NetworkSettings(
-                name=CONST.__getattribute__('tempest_private_net_name'),
+            self.os_creds, NetworkConfig(
+                name=CONST.__getattribute__(
+                    'tempest_private_net_name') + self.guid,
                 project_name=project_name,
-                subnet_settings=[SubnetSettings(
-                    name=CONST.__getattribute__('tempest_private_subnet_name'),
+                network_type=tempest_network_type,
+                physical_network=tempest_physical_network,
+                segmentation_id=tempest_segmentation_id,
+                subnet_settings=[SubnetConfig(
+                    name=CONST.__getattribute__(
+                        'tempest_private_subnet_name') + self.guid,
                     cidr=CONST.__getattribute__('tempest_private_subnet_cidr'))
                 ]))
         if network_creator is None or network_creator.get_network() is None:
@@ -374,25 +400,24 @@ class TempestResourcesManager(object):
         flavor_id = None
         flavor_id_alt = None
 
-        if (CONST.__getattribute__('tempest_use_custom_images') or
-           use_custom_images):
-            logger.debug("Creating image for Tempest suite")
-            image_base_name = CONST.__getattribute__('openstack_image_name')
-            os_image_settings = openstack_tests.cirros_image_settings(
-                image_base_name, public=True,
-                image_metadata=self.cirros_image_config)
-            logger.debug("Creating image for Tempest suite")
-            image_creator = deploy_utils.create_image(
-                self.os_creds, os_image_settings)
-            if image_creator is None:
-                raise Exception('Failed to create image')
-            self.creators.append(image_creator)
-            image_id = image_creator.get_image().id
+        logger.debug("Creating image for Tempest suite")
+        image_base_name = CONST.__getattribute__(
+            'openstack_image_name') + self.guid
+        os_image_settings = openstack_tests.cirros_image_settings(
+            image_base_name, public=True,
+            image_metadata=self.cirros_image_config)
+        logger.debug("Creating image for Tempest suite")
+        image_creator = deploy_utils.create_image(
+            self.os_creds, os_image_settings)
+        if image_creator is None:
+            raise Exception('Failed to create image')
+        self.creators.append(image_creator)
+        image_id = image_creator.get_image().id
 
         if use_custom_images:
             logger.debug("Creating 2nd image for Tempest suite")
             image_base_name_alt = CONST.__getattribute__(
-                'openstack_image_name_alt')
+                'openstack_image_name_alt') + self.guid
             os_image_settings_alt = openstack_tests.cirros_image_settings(
                 image_base_name_alt, public=True,
                 image_metadata=self.cirros_image_config)
@@ -404,7 +429,7 @@ class TempestResourcesManager(object):
             self.creators.append(image_creator_alt)
             image_id_alt = image_creator_alt.get_image().id
 
-        if (CONST.__getattribute__('tempest_use_custom_flavors') or
+        if (CONST.__getattribute__('tempest_use_custom_flavors') == 'True' or
            use_custom_flavors):
             logger.info("Creating flavor for Tempest suite")
             scenario = CONST.__getattribute__('DEPLOY_SCENARIO')
@@ -412,8 +437,9 @@ class TempestResourcesManager(object):
             if 'ovs' in scenario or 'fdio' in scenario:
                 flavor_metadata = create_flavor.MEM_PAGE_SIZE_LARGE
             flavor_creator = OpenStackFlavor(
-                self.os_creds, FlavorSettings(
-                    name=CONST.__getattribute__('openstack_flavor_name'),
+                self.os_creds, FlavorConfig(
+                    name=CONST.__getattribute__(
+                        'openstack_flavor_name') + self.guid,
                     ram=CONST.__getattribute__('openstack_flavor_ram'),
                     disk=CONST.__getattribute__('openstack_flavor_disk'),
                     vcpus=CONST.__getattribute__('openstack_flavor_vcpus'),
@@ -430,9 +456,11 @@ class TempestResourcesManager(object):
             flavor_metadata_alt = None
             if 'ovs' in scenario or 'fdio' in scenario:
                 flavor_metadata_alt = create_flavor.MEM_PAGE_SIZE_LARGE
+                CONST.__setattr__('openstack_flavor_ram', 1024)
             flavor_creator_alt = OpenStackFlavor(
-                self.os_creds, FlavorSettings(
-                    name=CONST.__getattribute__('openstack_flavor_name_alt'),
+                self.os_creds, FlavorConfig(
+                    name=CONST.__getattribute__(
+                        'openstack_flavor_name_alt') + self.guid,
                     ram=CONST.__getattribute__('openstack_flavor_ram'),
                     disk=CONST.__getattribute__('openstack_flavor_disk'),
                     vcpus=CONST.__getattribute__('openstack_flavor_vcpus'),