aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--functest/ci/config_aarch64_patch.yaml16
-rw-r--r--functest/ci/config_functest.yaml8
-rw-r--r--functest/ci/config_patch.yaml44
-rw-r--r--functest/core/singlevm.py35
-rw-r--r--functest/core/tenantnetwork.py24
-rw-r--r--functest/opnfv_tests/openstack/rally/rally.py140
-rw-r--r--functest/opnfv_tests/openstack/tempest/tempest.py5
-rw-r--r--functest/tests/unit/openstack/rally/test_rally.py169
-rw-r--r--functest/tests/unit/utils/test_functest_utils.py66
-rw-r--r--functest/utils/functest_utils.py19
10 files changed, 150 insertions, 376 deletions
diff --git a/functest/ci/config_aarch64_patch.yaml b/functest/ci/config_aarch64_patch.yaml
index 990c7d6be..b288641e1 100644
--- a/functest/ci/config_aarch64_patch.yaml
+++ b/functest/ci/config_aarch64_patch.yaml
@@ -126,6 +126,22 @@ os:
hw_disk_bus: 'scsi'
hw_scsi_model: 'virtio-scsi'
+ rally_sanity:
+ image: /home/opnfv/functest/images/cirros-0.4.0-aarch64-disk.img
+ extra_properties:
+ hw_firmware_type: 'uefi'
+ hw_video_model: 'vga'
+ hw_disk_bus: 'scsi'
+ hw_scsi_model: 'virtio-scsi'
+
+ rally_full:
+ image: /home/opnfv/functest/images/cirros-0.4.0-aarch64-disk.img
+ extra_properties:
+ hw_firmware_type: 'uefi'
+ hw_video_model: 'vga'
+ hw_disk_bus: 'scsi'
+ hw_scsi_model: 'virtio-scsi'
+
snaps:
images:
glance_tests:
diff --git a/functest/ci/config_functest.yaml b/functest/ci/config_functest.yaml
index 67ecc3424..5aa02be68 100644
--- a/functest/ci/config_functest.yaml
+++ b/functest/ci/config_functest.yaml
@@ -151,14 +151,6 @@ tempest:
rally:
deployment_name: opnfv-rally
network_name: rally-net
- # network_type: vlan
- # physical_network: physnet2
- # segmentation_id: 2366
- subnet_name: rally-subnet
- subnet_cidr: 192.168.140.0/24
- router_name: rally-router
- flavor_name: rally-tiny
- flavor_alt_name: rally-mini
vnf:
juju_epc:
diff --git a/functest/ci/config_patch.yaml b/functest/ci/config_patch.yaml
index 563dbe35d..c2c6cb417 100644
--- a/functest/ci/config_patch.yaml
+++ b/functest/ci/config_patch.yaml
@@ -17,45 +17,67 @@ fdio:
vmready1:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
vmready2:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
singlevm1:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
singlevm2:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
vping_ssh:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
vping_userdata:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
cinder_test:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
tempest_smoke_serial:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
refstack_defcore:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
patrole:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
shaker:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
neutron_trunk:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
barbican:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
tempest_full_parallel:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
+ rally_sanity:
+ flavor_extra_specs: {'hw:mem_page_size':'large'}
+ extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
+ rally_full:
+ flavor_extra_specs: {'hw:mem_page_size':'large'}
+ extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
ovs:
general:
@@ -68,42 +90,64 @@ ovs:
vmready1:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
vmready2:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
singlevm1:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
singlevm2:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
vping_ssh:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
vping_userdata:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
cinder_test:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
tempest_smoke_serial:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
refstack_defcore:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
patrole:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
shaker:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
neutron_trunk:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
barbican:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
tempest_full_parallel:
flavor_extra_specs: {'hw:mem_page_size':'large'}
extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
+ rally_sanity:
+ flavor_extra_specs: {'hw:mem_page_size':'large'}
+ extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
+ rally_full:
+ flavor_extra_specs: {'hw:mem_page_size':'large'}
+ extra_properties: {'hw_mem_page_size':'large'}
+ flavor_ram: 1024
diff --git a/functest/core/singlevm.py b/functest/core/singlevm.py
index e6cf01835..88e5155cb 100644
--- a/functest/core/singlevm.py
+++ b/functest/core/singlevm.py
@@ -39,9 +39,14 @@ class VmReady1(tenantnetwork.TenantNetwork1):
filename = '/home/opnfv/functest/images/cirros-0.4.0-x86_64-disk.img'
visibility = 'private'
extra_properties = None
- flavor_ram = 1024
+ flavor_ram = 512
flavor_vcpus = 1
flavor_disk = 1
+ flavor_alt_ram = 1024
+ flavor_alt_vcpus = 1
+ flavor_alt_disk = 1
+
+ image_format = 'qcow2'
def __init__(self, **kwargs):
if "case_name" not in kwargs:
@@ -70,6 +75,9 @@ class VmReady1(tenantnetwork.TenantNetwork1):
meta=getattr(
config.CONF, '{}_extra_properties'.format(self.case_name),
self.extra_properties),
+ disk_format=getattr(
+ config.CONF, '{}_image_format'.format(self.case_name),
+ self.image_format),
visibility=getattr(
config.CONF, '{}_visibility'.format(self.case_name),
self.visibility))
@@ -100,6 +108,31 @@ class VmReady1(tenantnetwork.TenantNetwork1):
flavor.id, getattr(config.CONF, 'flavor_extra_specs', {}))
return flavor
+ def create_flavor_alt(self, name=None):
+ """Create flavor
+
+ It allows creating multiple alt flavors for the child testcases. It
+ forces the same configuration for all subtestcases.
+
+ Returns: flavor
+
+ Raises: expection on error
+ """
+ assert self.orig_cloud
+ flavor = self.orig_cloud.create_flavor(
+ name if name else '{}-flavor_alt_{}'.format(
+ self.case_name, self.guid),
+ getattr(config.CONF, '{}_flavor_alt_ram'.format(self.case_name),
+ self.flavor_alt_ram),
+ getattr(config.CONF, '{}_flavor_alt_vcpus'.format(self.case_name),
+ self.flavor_alt_vcpus),
+ getattr(config.CONF, '{}_flavor_alt_disk'.format(self.case_name),
+ self.flavor_alt_disk))
+ self.__logger.debug("flavor: %s", flavor)
+ self.orig_cloud.set_flavor_specs(
+ flavor.id, getattr(config.CONF, 'flavor_extra_specs', {}))
+ return flavor
+
def boot_vm(self, name=None, **kwargs):
"""Boot the virtual machine
diff --git a/functest/core/tenantnetwork.py b/functest/core/tenantnetwork.py
index bf14f4126..3a212d871 100644
--- a/functest/core/tenantnetwork.py
+++ b/functest/core/tenantnetwork.py
@@ -28,7 +28,6 @@ from xtesting.core import testcase
from functest.utils import config
from functest.utils import env
-from functest.utils import functest_utils
class NewProject(object):
@@ -105,6 +104,7 @@ class TenantNetwork1(testcase.TestCase):
__logger = logging.getLogger(__name__)
cidr = '192.168.0.0/24'
+ shared_network = False
def __init__(self, **kwargs):
if "case_name" not in kwargs:
@@ -120,7 +120,7 @@ class TenantNetwork1(testcase.TestCase):
self.ext_net = None
self.__logger.exception("Cannot connect to Cloud")
try:
- self.ext_net = functest_utils.get_external_network(self.cloud)
+ self.ext_net = self.get_external_network(self.cloud)
except Exception: # pylint: disable=broad-except
self.__logger.exception("Cannot get the external network")
self.guid = str(uuid.uuid4())
@@ -128,6 +128,23 @@ class TenantNetwork1(testcase.TestCase):
self.subnet = None
self.router = None
+ @staticmethod
+ def get_external_network(cloud):
+ """
+ Returns the configured external network name or
+ the first retrieved external network name
+ """
+ assert cloud
+ if env.get("EXTERNAL_NETWORK"):
+ network = cloud.get_network(
+ env.get("EXTERNAL_NETWORK"), {"router:external": True})
+ if network:
+ return network
+ networks = cloud.list_networks({"router:external": True})
+ if networks:
+ return networks[0]
+ return None
+
def _create_network_ressources(self):
assert self.cloud
assert self.ext_net
@@ -143,7 +160,8 @@ class TenantNetwork1(testcase.TestCase):
config.CONF, '{}_segmentation_id'.format(self.case_name))
self.network = self.cloud.create_network(
'{}-net_{}'.format(self.case_name, self.guid),
- provider=provider)
+ provider=provider,
+ shared=self.shared_network)
self.__logger.debug("network: %s", self.network)
self.subnet = self.cloud.create_subnet(
diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py
index c3c53fbca..872e75b8e 100644
--- a/functest/opnfv_tests/openstack/rally/rally.py
+++ b/functest/opnfv_tests/openstack/rally/rally.py
@@ -18,44 +18,27 @@ import os
import re
import subprocess
import time
-import uuid
-import os_client_config
import pkg_resources
import prettytable
from xtesting.core import testcase
from xtesting.energy import energy
import yaml
+from functest.core import singlevm
from functest.opnfv_tests.openstack.tempest import conf_utils
from functest.utils import config
-from functest.utils import functest_utils
from functest.utils import env
LOGGER = logging.getLogger(__name__)
-class RallyBase(testcase.TestCase):
+class RallyBase(singlevm.VmReady1):
"""Base class form Rally testcases implementation."""
# pylint: disable=too-many-instance-attributes
TESTS = ['authenticate', 'glance', 'cinder', 'gnocchi', 'heat',
'keystone', 'neutron', 'nova', 'quotas', 'vm', 'all']
- GLANCE_IMAGE_NAME = getattr(config.CONF, 'openstack_image_name')
- GLANCE_IMAGE_FILENAME = getattr(config.CONF, 'openstack_image_file_name')
- GLANCE_IMAGE_PATH = os.path.join(getattr(
- config.CONF, 'dir_functest_images'), GLANCE_IMAGE_FILENAME)
- GLANCE_IMAGE_FORMAT = getattr(config.CONF, 'openstack_image_disk_format')
- GLANCE_IMAGE_EXTRA_PROPERTIES = getattr(
- config.CONF, 'openstack_extra_properties', {})
- FLAVOR_NAME = getattr(config.CONF, 'rally_flavor_name')
- FLAVOR_ALT_NAME = getattr(config.CONF, 'rally_flavor_alt_name')
- FLAVOR_RAM = 512
- FLAVOR_RAM_ALT = 1024
- FLAVOR_EXTRA_SPECS = getattr(config.CONF, 'flavor_extra_specs', {})
- if FLAVOR_EXTRA_SPECS:
- FLAVOR_RAM = 1024
- FLAVOR_RAM_ALT = 2048
RALLY_DIR = pkg_resources.resource_filename(
'functest', 'opnfv_tests/openstack/rally')
@@ -73,45 +56,32 @@ class RallyBase(testcase.TestCase):
BLACKLIST_FILE = os.path.join(RALLY_DIR, "blacklist.txt")
TEMP_DIR = os.path.join(RALLY_DIR, "var")
- RALLY_PRIVATE_NET_NAME = getattr(config.CONF, 'rally_network_name')
- RALLY_PRIVATE_SUBNET_NAME = str(getattr(config.CONF, 'rally_subnet_name'))
- RALLY_PRIVATE_SUBNET_CIDR = getattr(config.CONF, 'rally_subnet_cidr')
- RALLY_ROUTER_NAME = getattr(config.CONF, 'rally_router_name')
+ visibility = 'public'
+ shared_network = True
def __init__(self, **kwargs):
"""Initialize RallyBase object."""
super(RallyBase, self).__init__(**kwargs)
- self.cloud = os_client_config.make_shade()
- self.guid = '-' + str(uuid.uuid4())
self.creators = []
self.mode = ''
self.summary = []
self.scenario_dir = ''
- self.image_name = None
- self.ext_net = None
- self.flavor_name = None
- self.flavor_alt_name = None
self.smoke = None
self.test_name = None
self.start_time = None
self.result = None
self.details = None
self.compute_cnt = 0
- self.image = None
- self.flavor = None
self.flavor_alt = None
- self.network = None
- self.subnet = None
- self.router = None
def _build_task_args(self, test_file_name):
"""Build arguments for the Rally task."""
task_args = {'service_list': [test_file_name]}
- task_args['image_name'] = str(self.image_name)
- task_args['flavor_name'] = str(self.flavor_name)
- task_args['flavor_alt_name'] = str(self.flavor_alt_name)
- task_args['glance_image_location'] = str(self.GLANCE_IMAGE_PATH)
- task_args['glance_image_format'] = str(self.GLANCE_IMAGE_FORMAT)
+ task_args['image_name'] = str(self.image.name)
+ task_args['flavor_name'] = str(self.flavor.name)
+ task_args['flavor_alt_name'] = str(self.flavor_alt.name)
+ task_args['glance_image_location'] = str(self.filename)
+ task_args['glance_image_format'] = str(self.image_format)
task_args['tmpl_dir'] = str(self.TEMPLATE_DIR)
task_args['sup_dir'] = str(self.SUPPORT_DIR)
task_args['users_amount'] = self.USERS_AMOUNT
@@ -435,75 +405,9 @@ class RallyBase(testcase.TestCase):
if self.test_name not in self.TESTS:
raise Exception("Test name '%s' is invalid" % self.test_name)
- network_name = self.RALLY_PRIVATE_NET_NAME + self.guid
- subnet_name = self.RALLY_PRIVATE_SUBNET_NAME + self.guid
- router_name = self.RALLY_ROUTER_NAME + self.guid
- self.image_name = self.GLANCE_IMAGE_NAME + self.guid
- self.flavor_name = self.FLAVOR_NAME + self.guid
- self.flavor_alt_name = self.FLAVOR_ALT_NAME + self.guid
self.compute_cnt = len(self.cloud.list_hypervisors())
- self.ext_net = functest_utils.get_external_network(self.cloud)
- if self.ext_net is None:
- raise Exception("No external network found")
-
- LOGGER.debug("Creating image '%s'...", self.image_name)
- self.image = self.cloud.create_image(
- self.image_name,
- filename=self.GLANCE_IMAGE_PATH,
- disk_format=self.GLANCE_IMAGE_FORMAT,
- meta=self.GLANCE_IMAGE_EXTRA_PROPERTIES,
- is_public=True)
- if self.image is None:
- raise Exception("Failed to create image")
-
- LOGGER.debug("Creating network '%s'...", network_name)
- provider = {}
- if hasattr(config.CONF, 'rally_network_type'):
- provider["network_type"] = getattr(
- config.CONF, 'rally_network_type')
- if hasattr(config.CONF, 'rally_physical_network'):
- provider["physical_network"] = getattr(
- config.CONF, 'rally_physical_network')
- if hasattr(config.CONF, 'rally_segmentation_id'):
- provider["segmentation_id"] = getattr(
- config.CONF, 'rally_segmentation_id')
-
- self.network = self.cloud.create_network(
- network_name, shared=True, provider=provider)
- if self.network is None:
- raise Exception("Failed to create private network")
-
- self.subnet = self.cloud.create_subnet(
- self.network.id,
- subnet_name=subnet_name,
- cidr=self.RALLY_PRIVATE_SUBNET_CIDR,
- enable_dhcp=True,
- dns_nameservers=[env.get('NAMESERVER')])
- if self.subnet is None:
- raise Exception("Failed to create private subnet")
-
- LOGGER.debug("Creating router '%s'...", router_name)
- self.router = self.cloud.create_router(
- router_name, ext_gateway_net_id=self.ext_net.id)
- if self.router is None:
- raise Exception("Failed to create router")
- self.cloud.add_router_interface(self.router, subnet_id=self.subnet.id)
-
- LOGGER.debug("Creating flavor '%s'...", self.flavor_name)
- self.flavor = self.cloud.create_flavor(
- self.flavor_name, self.FLAVOR_RAM, 1, 1)
- if self.flavor is None:
- raise Exception("Failed to create flavor")
- self.cloud.set_flavor_specs(
- self.flavor.id, self.FLAVOR_EXTRA_SPECS)
-
- LOGGER.debug("Creating flavor '%s'...", self.flavor_alt_name)
- self.flavor_alt = self.cloud.create_flavor(
- self.flavor_alt_name, self.FLAVOR_RAM_ALT, 1, 1)
- if self.flavor_alt is None:
- raise Exception("Failed to create flavor")
- self.cloud.set_flavor_specs(
- self.flavor_alt.id, self.FLAVOR_EXTRA_SPECS)
+ self.flavor_alt = self.create_flavor_alt()
+ LOGGER.debug("flavor: %s", self.flavor_alt)
def _run_tests(self):
"""Execute tests."""
@@ -572,22 +476,10 @@ class RallyBase(testcase.TestCase):
'nb success': success_rate}})
self.details = payload
- def _clean_up(self):
+ def clean(self):
"""Cleanup of OpenStack resources. Should be called on completion."""
- if self.flavor_alt:
- self.cloud.delete_flavor(self.flavor_alt.id)
- if self.flavor:
- self.cloud.delete_flavor(self.flavor.id)
- if self.router and self.subnet:
- self.cloud.remove_router_interface(self.router, self.subnet.id)
- if self.router:
- self.cloud.delete_router(self.router.id)
- if self.subnet:
- self.cloud.delete_subnet(self.subnet.id)
- if self.network:
- self.cloud.delete_network(self.network.id)
- if self.image:
- self.cloud.delete_image(self.image.id)
+ super(RallyBase, self).clean()
+ self.orig_cloud.delete_flavor(self.flavor_alt.id)
def is_successful(self):
"""The overall result of the test."""
@@ -602,6 +494,7 @@ class RallyBase(testcase.TestCase):
"""Run testcase."""
self.start_time = time.time()
try:
+ super(RallyBase, self).run(**kwargs)
conf_utils.create_rally_deployment()
self._prepare_env()
self._run_tests()
@@ -610,9 +503,6 @@ class RallyBase(testcase.TestCase):
except Exception as exc: # pylint: disable=broad-except
LOGGER.error('Error with run: %s', exc)
res = testcase.TestCase.EX_RUN_ERROR
- finally:
- self._clean_up()
-
self.stop_time = time.time()
return res
diff --git a/functest/opnfv_tests/openstack/tempest/tempest.py b/functest/opnfv_tests/openstack/tempest/tempest.py
index baa7e14fc..05e1021b2 100644
--- a/functest/opnfv_tests/openstack/tempest/tempest.py
+++ b/functest/opnfv_tests/openstack/tempest/tempest.py
@@ -265,12 +265,9 @@ class TempestCommon(singlevm.VmReady1):
os.makedirs(self.res_dir)
compute_cnt = len(self.cloud.list_hypervisors())
- LOGGER.info("Creating two images for Tempest suite")
self.image_alt = self.publish_image(
'{}-img_alt_{}'.format(self.case_name, self.guid))
- LOGGER.debug("image_alt: %s", self.image_alt)
- self.flavor_alt = self.create_flavor(
- '{}-flavor_alt_{}'.format(self.case_name, self.guid))
+ self.flavor_alt = self.create_flavor_alt()
LOGGER.debug("flavor: %s", self.flavor_alt)
self.conf_file = conf_utils.configure_verifier(self.deployment_dir)
diff --git a/functest/tests/unit/openstack/rally/test_rally.py b/functest/tests/unit/openstack/rally/test_rally.py
index f7523b4a0..28f6055bd 100644
--- a/functest/tests/unit/openstack/rally/test_rally.py
+++ b/functest/tests/unit/openstack/rally/test_rally.py
@@ -13,6 +13,7 @@ import os
import unittest
import mock
+import munch
from xtesting.core import testcase
from functest.opnfv_tests.openstack.rally import rally
@@ -21,19 +22,24 @@ from functest.opnfv_tests.openstack.rally import rally
class OSRallyTesting(unittest.TestCase):
# pylint: disable=too-many-public-methods
def setUp(self):
- with mock.patch('os_client_config.make_shade') as mock_make_shade:
+ with mock.patch('os_client_config.get_config') as mock_get_config, \
+ mock.patch('shade.OpenStackCloud') as mock_shade:
self.rally_base = rally.RallyBase()
- self.assertTrue(mock_make_shade.called)
+ self.rally_base.image = munch.Munch(name='foo')
+ self.rally_base.flavor = munch.Munch(name='foo')
+ self.rally_base.flavor_alt = munch.Munch(name='bar')
+ self.assertTrue(mock_get_config.called)
+ self.assertTrue(mock_shade.called)
def test_build_task_args_missing_floating_network(self):
os.environ['OS_AUTH_URL'] = ''
- self.rally_base.ext_net_name = ''
+ self.rally_base.ext_net = None
task_args = self.rally_base._build_task_args('test_file_name')
self.assertEqual(task_args['floating_network'], '')
def test_build_task_args_missing_net_id(self):
os.environ['OS_AUTH_URL'] = ''
- self.rally_base.priv_net_id = ''
+ self.rally_base.network = None
task_args = self.rally_base._build_task_args('test_file_name')
self.assertEqual(task_args['netid'], '')
@@ -279,107 +285,8 @@ class OSRallyTesting(unittest.TestCase):
with self.assertRaises(Exception):
self.rally_base._prepare_env()
- @mock.patch('functest.utils.functest_utils.get_external_network')
- def test_prepare_env_image_missing(self, *args):
- # pylint: disable=unused-argument
- self.rally_base.TESTS = ['test1', 'test2']
- self.rally_base.test_name = 'test1'
- with mock.patch.object(self.rally_base.cloud, 'list_hypervisors'), \
- mock.patch.object(self.rally_base.cloud, 'create_image',
- return_value=None):
- with self.assertRaises(Exception):
- self.rally_base._prepare_env()
-
- @mock.patch('functest.utils.functest_utils.get_external_network')
- def test_prepare_env_network_creation_failed(self, *args):
- # pylint: disable=unused-argument
- self.rally_base.TESTS = ['test1', 'test2']
- self.rally_base.test_name = 'test1'
- with mock.patch.object(self.rally_base.cloud,
- 'list_hypervisors') as mock_list_hyperv, \
- mock.patch.object(self.rally_base.cloud,
- 'create_image') as mock_create_img, \
- mock.patch.object(self.rally_base.cloud, 'create_network',
- return_value=None) as mock_create_net:
- with self.assertRaises(Exception):
- self.rally_base._prepare_env()
- mock_create_net.assert_called()
- mock_create_img.assert_called()
- mock_list_hyperv.assert_called()
-
- @mock.patch('functest.utils.functest_utils.get_external_network')
- def test_prepare_env_subnet_creation_failed(self, *args):
- # pylint: disable=unused-argument
- self.rally_base.TESTS = ['test1', 'test2']
- self.rally_base.test_name = 'test1'
- with mock.patch.object(self.rally_base.cloud,
- 'list_hypervisors') as mock_list_hyperv, \
- mock.patch.object(self.rally_base.cloud,
- 'create_image') as mock_create_img, \
- mock.patch.object(self.rally_base.cloud,
- 'create_network') as mock_create_net, \
- mock.patch.object(self.rally_base.cloud, 'create_subnet',
- return_value=None) as mock_create_subnet:
- with self.assertRaises(Exception):
- self.rally_base._prepare_env()
- mock_create_subnet.assert_called()
- mock_create_net.assert_called()
- mock_create_img.assert_called()
- mock_list_hyperv.assert_called()
-
- @mock.patch('functest.utils.functest_utils.get_external_network')
- def test_prepare_env_router_creation_failed(self, *args):
- # pylint: disable=unused-argument
- self.rally_base.TESTS = ['test1', 'test2']
- self.rally_base.test_name = 'test1'
- with mock.patch.object(self.rally_base.cloud,
- 'list_hypervisors') as mock_list_hyperv, \
- mock.patch.object(self.rally_base.cloud,
- 'create_image') as mock_create_img, \
- mock.patch.object(self.rally_base.cloud,
- 'create_network') as mock_create_net, \
- mock.patch.object(self.rally_base.cloud,
- 'create_subnet') as mock_create_subnet, \
- mock.patch.object(self.rally_base.cloud, 'create_router',
- return_value=None) as mock_create_router:
- with self.assertRaises(Exception):
- self.rally_base._prepare_env()
- mock_create_router.assert_called()
- mock_create_subnet.assert_called()
- mock_create_net.assert_called()
- mock_create_img.assert_called()
- mock_list_hyperv.assert_called()
-
- @mock.patch('functest.utils.functest_utils.get_external_network')
- def test_prepare_env_flavor_creation_failed(self, *args):
- # pylint: disable=unused-argument
- self.rally_base.TESTS = ['test1', 'test2']
- self.rally_base.test_name = 'test1'
- with mock.patch.object(self.rally_base.cloud,
- 'list_hypervisors') as mock_list_hyperv, \
- mock.patch.object(self.rally_base.cloud,
- 'create_image') as mock_create_img, \
- mock.patch.object(self.rally_base.cloud,
- 'create_network') as mock_create_net, \
- mock.patch.object(self.rally_base.cloud,
- 'create_subnet') as mock_create_subnet, \
- mock.patch.object(self.rally_base.cloud,
- 'add_router_interface') as mock_add_router_if, \
- mock.patch.object(self.rally_base.cloud,
- 'create_router') as mock_create_router, \
- mock.patch.object(self.rally_base.cloud, 'create_flavor',
- return_value=None) as mock_create_flavor:
- with self.assertRaises(Exception):
- self.rally_base._prepare_env()
- mock_create_flavor.assert_called_once()
- mock_add_router_if.assert_called()
- mock_create_router.assert_called()
- mock_create_subnet.assert_called()
- mock_create_net.assert_called()
- mock_create_img.assert_called()
- mock_list_hyperv.assert_called()
-
- @mock.patch('functest.utils.functest_utils.get_external_network')
+ @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
+ 'get_external_network')
def test_prepare_env_flavor_alt_creation_failed(self, *args):
# pylint: disable=unused-argument
self.rally_base.TESTS = ['test1', 'test2']
@@ -387,30 +294,15 @@ class OSRallyTesting(unittest.TestCase):
with mock.patch.object(self.rally_base.cloud,
'list_hypervisors') as mock_list_hyperv, \
mock.patch.object(self.rally_base.cloud,
- 'create_image') as mock_create_img, \
- mock.patch.object(self.rally_base.cloud,
- 'create_network') as mock_create_net, \
- mock.patch.object(self.rally_base.cloud,
- 'create_subnet') as mock_create_subnet, \
- mock.patch.object(self.rally_base.cloud,
- 'add_router_interface') as mock_add_router_if, \
- mock.patch.object(self.rally_base.cloud,
- 'create_router') as mock_create_router, \
- mock.patch.object(self.rally_base.cloud,
'set_flavor_specs') as mock_set_flavor_specs, \
mock.patch.object(self.rally_base.cloud, 'create_flavor',
- side_effect=[mock.Mock(), None]) \
+ side_effect=Exception) \
as mock_create_flavor:
with self.assertRaises(Exception):
self.rally_base._prepare_env()
- self.assertEqual(mock_create_flavor.call_count, 2)
- mock_set_flavor_specs.assert_called_once()
- mock_add_router_if.assert_called()
- mock_create_router.assert_called()
- mock_create_subnet.assert_called()
- mock_create_net.assert_called()
- mock_create_img.assert_called()
- mock_list_hyperv.assert_called()
+ mock_list_hyperv.assert_called_once()
+ mock_create_flavor.assert_called_once()
+ mock_set_flavor_specs.assert_not_called()
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
'_run_task')
@@ -431,31 +323,10 @@ class OSRallyTesting(unittest.TestCase):
def test_clean_up_default(self):
with mock.patch.object(self.rally_base.cloud,
- 'delete_flavor') as mock_delete_flavor, \
- mock.patch.object(self.rally_base.cloud,
- 'remove_router_interface') \
- as mock_remove_router_if, \
- mock.patch.object(self.rally_base.cloud,
- 'delete_router') as mock_delete_router, \
- mock.patch.object(self.rally_base.cloud,
- 'delete_subnet') as mock_delete_subnet, \
- mock.patch.object(self.rally_base.cloud,
- 'delete_network') as mock_delete_net, \
- mock.patch.object(self.rally_base.cloud,
- 'delete_image') as mock_delete_img:
+ 'delete_flavor') as mock_delete_flavor:
self.rally_base.flavor_alt = mock.Mock()
- self.rally_base.flavor = mock.Mock()
- self.rally_base.router = mock.Mock()
- self.rally_base.subnet = mock.Mock()
- self.rally_base.network = mock.Mock()
- self.rally_base.image = mock.Mock()
- self.rally_base._clean_up()
- self.assertEqual(mock_delete_flavor.call_count, 2)
- mock_remove_router_if.assert_called()
- mock_delete_router.assert_called()
- mock_delete_subnet.assert_called()
- mock_delete_net.assert_called()
- mock_delete_img.assert_called()
+ self.rally_base.clean()
+ self.assertEqual(mock_delete_flavor.call_count, 1)
@mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
'create_rally_deployment')
@@ -465,8 +336,6 @@ class OSRallyTesting(unittest.TestCase):
'_run_tests')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
'_generate_report')
- @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
- '_clean_up')
def test_run_default(self, *args):
self.assertEqual(self.rally_base.run(), testcase.TestCase.EX_OK)
for func in args:
diff --git a/functest/tests/unit/utils/test_functest_utils.py b/functest/tests/unit/utils/test_functest_utils.py
index 7debcc1df..d35ed8ced 100644
--- a/functest/tests/unit/utils/test_functest_utils.py
+++ b/functest/tests/unit/utils/test_functest_utils.py
@@ -11,11 +11,9 @@
import logging
import time
-import os
import unittest
import mock
-import munch
import pkg_resources
from functest.utils import functest_utils
@@ -220,70 +218,6 @@ class FunctestUtilsTesting(unittest.TestCase):
self.test_file),
'test_image_name')
- def test_get_extnetwork_nocloud(self):
- with self.assertRaises(AssertionError):
- functest_utils.get_external_network(None)
-
- def test_get_extnetwork_env_ok1(self):
- cloud = mock.Mock()
- cloud.get_network.return_value = munch.Munch(name="dummy")
- os.environ["EXTERNAL_NETWORK"] = 'dummy'
- self.assertEqual(
- functest_utils.get_external_network(cloud),
- cloud.get_network.return_value)
- cloud.get_network.assert_called_once_with(
- 'dummy', {'router:external': True})
- cloud.list_networks.assert_not_called()
-
- def test_get_extnetwork_env_ok2(self):
- cloud = mock.Mock()
- cloud.get_network.return_value = None
- cloud.list_networks.return_value = None
- os.environ["EXTERNAL_NETWORK"] = 'dummy'
- self.assertEqual(functest_utils.get_external_network(cloud), None)
- cloud.get_network.assert_called_once_with(
- 'dummy', {'router:external': True})
- cloud.list_networks.assert_called_once_with(
- {'router:external': True})
-
- def test_get_extnetwork_env_ko(self):
- cloud = mock.Mock()
- cloud.get_network.return_value = None
- cloud.list_networks.return_value = [munch.Munch(name="dummy")]
- os.environ["EXTERNAL_NETWORK"] = 'dummy'
- self.assertEqual(
- functest_utils.get_external_network(cloud),
- cloud.list_networks.return_value[0])
- cloud.get_network.assert_called_once_with(
- 'dummy', {'router:external': True})
- cloud.list_networks.assert_called_once_with(
- {'router:external': True})
-
- def test_get_extnetwork_noenv_ko(self):
- try:
- del os.environ["EXTERNAL_NETWORK"]
- except Exception: # pylint: disable=broad-except
- pass
- cloud = mock.Mock()
- cloud.list_networks.return_value = None
- self.assertEqual(functest_utils.get_external_network(cloud), None)
- cloud.get_network.assert_not_called()
- cloud.list_networks.assert_called_once_with(
- {'router:external': True})
-
- def test_get_extnetwork_noenv_ok(self):
- try:
- del os.environ["EXTERNAL_NETWORK"]
- except Exception: # pylint: disable=broad-except
- pass
- cloud = mock.Mock()
- cloud.list_networks.return_value = [munch.Munch(name="dummy")]
- self.assertEqual(
- functest_utils.get_external_network(cloud),
- cloud.list_networks.return_value[0])
- cloud.get_network.assert_not_called()
- cloud.list_networks.assert_called_once_with(
- {'router:external': True})
if __name__ == "__main__":
logging.disable(logging.CRITICAL)
diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py
index b860828f1..b614af321 100644
--- a/functest/utils/functest_utils.py
+++ b/functest/utils/functest_utils.py
@@ -15,8 +15,6 @@ import subprocess
import sys
import yaml
-from functest.utils import env
-
LOGGER = logging.getLogger(__name__)
@@ -74,20 +72,3 @@ def get_parameter_from_yaml(parameter, yfile):
raise ValueError("The parameter %s is not defined in"
" %s" % (parameter, yfile))
return value
-
-
-def get_external_network(cloud):
- """
- Returns the configured external network name or
- the first retrieved external network name
- """
- assert cloud
- if env.get("EXTERNAL_NETWORK"):
- network = cloud.get_network(
- env.get("EXTERNAL_NETWORK"), {"router:external": True})
- if network:
- return network
- networks = cloud.list_networks({"router:external": True})
- if networks:
- return networks[0]
- return None