Create a router in both vping scenarii
[functest.git] / functest / opnfv_tests / openstack / vping / vping_base.py
index 40fcb07..a8525a3 100644 (file)
@@ -13,12 +13,13 @@ import time
 import uuid
 
 from functest.core import testcase
-from functest.utils import functest_utils
+from functest.opnfv_tests.openstack.snaps import snaps_utils
 from functest.utils.constants import CONST
 
 from snaps.openstack import create_flavor
 from snaps.openstack.create_flavor import FlavorSettings, OpenStackFlavor
 from snaps.openstack.create_network import NetworkSettings, SubnetSettings
+from snaps.openstack.create_router import RouterSettings
 from snaps.openstack.tests import openstack_tests
 from snaps.openstack.utils import deploy_utils
 
@@ -63,6 +64,8 @@ class VPingBase(testcase.TestCase):
         if CONST.__getattribute__('vping_unique_names'):
             self.guid = '-' + str(uuid.uuid4())
 
+        self.router_name = CONST.__getattribute__(
+            'vping_router_name') + self.guid
         self.vm1_name = CONST.__getattribute__('vping_vm_name_1') + self.guid
         self.vm2_name = CONST.__getattribute__('vping_vm_name_2') + self.guid
 
@@ -113,13 +116,13 @@ class VPingBase(testcase.TestCase):
         vping_physical_network = None
         vping_segmentation_id = None
 
-        if (hasattr(CONST, 'network_type')):
+        if (hasattr(CONST, 'vping_network_type')):
             vping_network_type = CONST.__getattribute__(
                 'vping_network_type')
-        if (hasattr(CONST, 'physical_network')):
+        if (hasattr(CONST, 'vping_physical_network')):
             vping_physical_network = CONST.__getattribute__(
                 'vping_physical_network')
-        if (hasattr(CONST, 'segmentation_id')):
+        if (hasattr(CONST, 'vping_segmentation_id')):
             vping_segmentation_id = CONST.__getattribute__(
                 'vping_segmentation_id')
 
@@ -137,9 +140,21 @@ class VPingBase(testcase.TestCase):
                     cidr=private_subnet_cidr)]))
         self.creators.append(self.network_creator)
 
+        # Creating router to external network
+        log = "Creating router with name: '%s'" % self.router_name
+        self.logger.info(log)
+        ext_net_name = snaps_utils.get_ext_net_name(self.os_creds)
+        self.router_creator = deploy_utils.create_router(
+            self.os_creds,
+            RouterSettings(
+                name=self.router_name,
+                external_gateway=ext_net_name,
+                internal_subnets=[private_subnet_name]))
+        self.creators.append(self.router_creator)
+
         self.logger.info(
             "Creating flavor with name: '%s'" % self.flavor_name)
-        scenario = functest_utils.get_scenario()
+        scenario = CONST.__getattribute__('DEPLOY_SCENARIO')
         flavor_metadata = None
         if 'ovs' in scenario or 'fdio' in scenario:
             flavor_metadata = create_flavor.MEM_PAGE_SIZE_LARGE
@@ -166,7 +181,7 @@ class VPingBase(testcase.TestCase):
         else:
             raise Exception('VMs never became active')
 
-        if result == testcase.TestCase.EX_RUN_ERROR:
+        if result != testcase.TestCase.EX_OK:
             return testcase.TestCase.EX_RUN_ERROR
 
         self.stop_time = time.time()