aboutsummaryrefslogtreecommitdiffstats
path: root/functest
diff options
context:
space:
mode:
Diffstat (limited to 'functest')
-rwxr-xr-xfunctest/ci/config_functest.yaml43
-rwxr-xr-xfunctest/ci/prepare_env.py6
-rwxr-xr-xfunctest/ci/run_tests.py4
-rw-r--r--functest/core/vnf_base.py26
-rw-r--r--functest/opnfv_tests/vnf/ims/cloudify_ims.py212
-rw-r--r--functest/opnfv_tests/vnf/ims/cloudify_ims.yaml39
-rw-r--r--functest/tests/unit/utils/test_openstack_utils.py36
-rwxr-xr-xfunctest/utils/openstack_utils.py14
8 files changed, 241 insertions, 139 deletions
diff --git a/functest/ci/config_functest.yaml b/functest/ci/config_functest.yaml
index 6a10e382..d0442cf9 100755
--- a/functest/ci/config_functest.yaml
+++ b/functest/ci/config_functest.yaml
@@ -5,7 +5,6 @@ general:
dir_odl: functest/opnfv_tests/sdn/odl
rally: functest/opnfv_tests/openstack/rally
tempest_cases: functest/opnfv_tests/openstack/tempest/custom_tests
- dir_vIMS: functest/opnfv_tests/vnf/ims
dir_onos: functest/opnfv_tests/sdn/onos/teston
dir_onos_sfc: functest/opnfv_tests/sdn/onos/sfc
@@ -34,7 +33,7 @@ general:
functest_logging_cfg: /home/opnfv/repos/functest/functest/ci/logging.json
functest_conf: /home/opnfv/functest/conf
functest_data: /home/opnfv/functest/data
- dir_vIMS_data: /home/opnfv/functest/data/vIMS/
+ ims_data: /home/opnfv/functest/data/ims/
rally_inst: /home/opnfv/.rally
openstack:
@@ -126,45 +125,7 @@ vnf:
cloudify_ims:
tenant_name: cloudify_ims
tenant_description: vIMS
- tenant_images:
- ubuntu_14.04: http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img
- centos_7: http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1510.qcow2
- cloudify:
- blueprint:
- url: https://github.com/boucherv-orange/cloudify-manager-blueprints.git
- branch: "3.3.1-build"
- requierments:
- ram_min: 3000
- os_image: centos_7
- inputs:
- keystone_username: ""
- keystone_password: ""
- keystone_tenant_name: ""
- keystone_url: ""
- manager_public_key_name: 'manager-kp'
- agent_public_key_name: 'agent-kp'
- image_id: ""
- flavor_id: "3"
- external_network_name: ""
- ssh_user: centos
- agents_user: ubuntu
- clearwater:
- blueprint:
- file_name: 'openstack-blueprint.yaml'
- name: "clearwater-opnfv"
- destination_folder: "opnfv-cloudify-clearwater"
- url: https://github.com/Orange-OpenSource/opnfv-cloudify-clearwater.git
- branch: "stable"
- deployment_name: 'clearwater-opnfv'
- requirements:
- ram_min: 1700
- os_image: ubuntu_14.04
- inputs:
- image_id: ''
- flavor_id: ''
- agent_user: 'ubuntu'
- external_network_name: ''
- public_domain: clearwater.opnfv
+ config: cloudify_ims.yaml
orchestra_ims:
tenant_name: orchestra_ims
tenant_description: ims deployed with openbaton
diff --git a/functest/ci/prepare_env.py b/functest/ci/prepare_env.py
index b3e59020..cca9ac73 100755
--- a/functest/ci/prepare_env.py
+++ b/functest/ci/prepare_env.py
@@ -170,12 +170,10 @@ def source_rc_file():
sys.exit(1)
logger.info("Sourcing the OpenStack RC file...")
- creds = os_utils.source_credentials(
+ os_utils.source_credentials(
CONST.openstack_creds)
- str = ""
- for key, value in creds.iteritems():
+ for key, value in os.environ.iteritems():
if re.search("OS_", key):
- str += "\n\t\t\t\t\t\t " + key + "=" + value
if key == 'OS_AUTH_URL':
CONST.OS_AUTH_URL = value
elif key == 'OS_USERNAME':
diff --git a/functest/ci/run_tests.py b/functest/ci/run_tests.py
index 320102dd..6a6516ab 100755
--- a/functest/ci/run_tests.py
+++ b/functest/ci/run_tests.py
@@ -78,8 +78,8 @@ def source_rc_file():
logger.error("RC file %s does not exist..." % rc_file)
sys.exit(1)
logger.debug("Sourcing the OpenStack RC file...")
- creds = os_utils.source_credentials(rc_file)
- for key, value in creds.iteritems():
+ os_utils.source_credentials(rc_file)
+ for key, value in os.environ.iteritems():
if re.search("OS_", key):
if key == 'OS_AUTH_URL':
ft_constants.OS_AUTH_URL = value
diff --git a/functest/core/vnf_base.py b/functest/core/vnf_base.py
index 4d019858..44b4ae04 100644
--- a/functest/core/vnf_base.py
+++ b/functest/core/vnf_base.py
@@ -7,12 +7,10 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
-import os
import time
import inspect
-
import functest.utils.functest_logger as ft_logger
import functest.utils.openstack_utils as os_utils
import functest.utils.functest_utils as ft_utils
@@ -161,30 +159,6 @@ class VnfOnBoardingBase(base.TestcaseBase):
"username": self.tenant_name,
"password": self.tenant_name,
})
- self.glance_client = os_utils.get_glance_client(self.creds)
- self.logger.info("Upload some OS images if it doesn't exist")
-
- temp_dir = os.path.join(self.data_dir, "tmp/")
- for image_name, image_url in self.images.iteritems():
- image_id = os_utils.get_image_id(self.glance_client, image_name)
-
- if image_id == '':
- self.logger.info("""%s image doesn't exist on glance repository. Try
- downloading this image and upload on glance !""" % image_name)
- image_id = os_utils.download_and_add_image_on_glance(
- self.glance_client, image_name, image_url, temp_dir)
-
- if image_id == '':
- self.step_failure(
- "Failed to find or upload required OS "
- "image for this deployment")
-
- self.logger.info("Update security group quota for this tenant")
-
- if not os_utils.update_sg_quota(self.neutron_client,
- tenant_id, 50, 100):
- self.step_failure("Failed to update security group quota" +
- " for tenant " + self.tenant_name)
# orchestrator is not mandatory to dpeloy and test VNF
def deploy_orchestrator(self, **kwargs):
diff --git a/functest/opnfv_tests/vnf/ims/cloudify_ims.py b/functest/opnfv_tests/vnf/ims/cloudify_ims.py
index 13a5af4f..e2508c22 100644
--- a/functest/opnfv_tests/vnf/ims/cloudify_ims.py
+++ b/functest/opnfv_tests/vnf/ims/cloudify_ims.py
@@ -11,7 +11,9 @@ import json
import os
import requests
import subprocess
+import sys
import time
+import yaml
import functest.core.vnf_base as vnf_base
import functest.utils.functest_logger as ft_logger
@@ -29,57 +31,127 @@ class ImsVnf(vnf_base.VnfOnBoardingBase):
repo='', cmd=''):
super(ImsVnf, self).__init__(project, case, repo, cmd)
self.logger = ft_logger.Logger("vIMS").getLogger()
- self.case_dir = os.path.join(CONST.functest_test, 'vnf/ims/')
- self.data_dir = CONST.dir_vIMS_data
+ self.case_dir = os.path.join(CONST.dir_functest_test, 'vnf/ims/')
+ self.data_dir = CONST.dir_ims_data
self.test_dir = CONST.dir_repo_vims_test
+ # Retrieve the configuration
+ try:
+ self.config = CONST.__getattribute__(
+ 'vnf_{}_config'.format(self.case_name))
+ except:
+ raise Exception("VNF config file not found")
+
+ config_file = self.case_dir + self.config
self.orchestrator = dict(
- requirements=CONST.cloudify_requirements,
- blueprint=CONST.cloudify_blueprint,
- inputs=CONST.cloudify_inputs
+ requirements=get_config("cloudify.requirements", config_file),
+ blueprint=get_config("cloudify.blueprint", config_file),
+ inputs=get_config("cloudify.inputs", config_file)
)
-
+ self.logger.debug("Orchestrator configuration: %s" % self.orchestrator)
self.vnf = dict(
- blueprint=CONST.clearwater_blueprint,
- deployment_name=CONST.clearwater_deployment_name,
- inputs=CONST.clearwater_inputs,
- requirements=CONST.clearwater_requirements
+ blueprint=get_config("clearwater.blueprint", config_file),
+ deployment_name=get_config("clearwater.deployment_name",
+ config_file),
+ inputs=get_config("clearwater.inputs", config_file),
+ requirements=get_config("clearwater.requirements", config_file)
)
+ self.logger.debug("VNF configuration: %s" % self.vnf)
+
+ self.images = get_config("tenant_images", config_file)
+ self.logger.info("Images needed for vIMS: %s" % self.images)
# vIMS Data directory creation
if not os.path.exists(self.data_dir):
os.makedirs(self.data_dir)
def deploy_orchestrator(self, **kwargs):
+
+ self.logger.info("Additional pre-configuration steps")
+ self.neutron_client = os_utils.get_neutron_client(self.creds)
+ self.glance_client = os_utils.get_glance_client(self.creds)
+ self.keystone_client = os_utils.get_keystone_client(self.creds)
+ self.nova_client = os_utils.get_nova_client(self.creds)
+
+ # needs some images
+ self.logger.info("Upload some OS images if it doesn't exist")
+ temp_dir = os.path.join(self.data_dir, "tmp/")
+ for image_name, image_url in self.images.iteritems():
+ self.logger.info("image: %s, url: %s" % (image_name, image_url))
+ try:
+ image_id = os_utils.get_image_id(self.glance_client,
+ image_name)
+ self.logger.debug("image_id: %s" % image_id)
+ except:
+ self.logger.error("Unexpected error: %s" % sys.exc_info()[0])
+
+ if image_id == '':
+ self.logger.info("""%s image doesn't exist on glance repository. Try
+ downloading this image and upload on glance !""" % image_name)
+ image_id = download_and_add_image_on_glance(self.glance_client,
+ image_name,
+ image_url,
+ temp_dir)
+ if image_id == '':
+ self.step_failure(
+ "Failed to find or upload required OS "
+ "image for this deployment")
+ # Need to extend quota
+ self.logger.info("Update security group quota for this tenant")
+ tenant_id = os_utils.get_tenant_id(self.keystone_client,
+ self.tenant_name)
+ self.logger.debug("Tenant id found %s" % tenant_id)
+ if not os_utils.update_sg_quota(self.neutron_client,
+ tenant_id, 50, 100):
+ self.step_failure("Failed to update security group quota" +
+ " for tenant " + self.tenant_name)
+ self.logger.debug("group quota extended")
+
+ # start the deployment of cloudify
public_auth_url = os_utils.get_endpoint('identity')
- cfy = Orchestrator(self.data_dir, self.orchestrator.inputs)
- self.orchestrator.object = cfy
+ self.logger.debug("CFY inputs: %s" % self.orchestrator['inputs'])
+ cfy = Orchestrator(self.data_dir, self.orchestrator['inputs'])
+ self.orchestrator['object'] = cfy
+ self.logger.debug("Orchestrator object created")
- if 'tenant_name' in self.creds.keys():
- tenant_name = self.creds['tenant_name']
- elif 'project_name' in self.creds.keys():
- tenant_name = self.creds['project_name']
+ self.logger.debug("Tenant name: %s" % self.tenant_name)
- cfy.set_credentials(username=self.creds['username'],
- password=self.creds['password'],
- tenant_name=tenant_name,
+ cfy.set_credentials(username=self.tenant_name,
+ password=self.tenant_name,
+ tenant_name=self.tenant_name,
auth_url=public_auth_url)
+ self.logger.info("Credentials set in CFY")
# orchestrator VM flavor
- flavor_id = self.get_flavor("m1.large", self.orchestrator.requirements)
+ self.logger.info("Check Flavor is available, if not create one")
+ self.logger.debug("Flavor details %s " %
+ self.orchestrator['requirements']['ram_min'])
+ flavor_exist, flavor_id = os_utils.get_or_create_flavor(
+ "m1.large",
+ self.orchestrator['requirements']['ram_min'],
+ '1',
+ '1',
+ public=True)
+ self.logger.debug("Flavor id: %s" % flavor_id)
+
if not flavor_id:
self.logger.info("Available flavors are: ")
- self.pMsg(self.nova_client.flavor.list())
+ self.logger.info(self.nova_client.flavor.list())
self.step_failure("Failed to find required flavor"
"for this deployment")
cfy.set_flavor_id(flavor_id)
+ self.logger.debug("Flavor OK")
# orchestrator VM image
- if 'os_image' in self.orchestrator.requirements.keys():
+ self.logger.debug("Orchestrator image")
+ if 'os_image' in self.orchestrator['requirements'].keys():
image_id = os_utils.get_image_id(
- self.glance_client, self.orchestrator.requirements['os_image'])
+ self.glance_client,
+ self.orchestrator['requirements']['os_image'])
+ self.logger.debug("Orchestrator image id: %s" % image_id)
if image_id == '':
+ self.logger.error("CFY image not found")
self.step_failure("Failed to find required OS image"
" for cloudify manager")
else:
@@ -87,16 +159,22 @@ class ImsVnf(vnf_base.VnfOnBoardingBase):
" for cloudify manager")
cfy.set_image_id(image_id)
+ self.logger.debug("Orchestrator image set")
+ self.logger.debug("Get External network")
ext_net = os_utils.get_external_net(self.neutron_client)
+ self.logger.debug("External network: %s" % ext_net)
if not ext_net:
self.step_failure("Failed to get external network")
cfy.set_external_network_name(ext_net)
+ self.logger.debug("CFY External network set")
+ self.logger.debug("get resolvconf")
ns = ft_utils.get_resolvconf_ns()
if ns:
cfy.set_nameservers(ns)
+ self.logger.debug("Resolvconf set")
if 'compute' in self.nova_client.client.services_url:
cfy.set_nova_url(self.nova_client.client.services_url['compute'])
@@ -110,8 +188,9 @@ class ImsVnf(vnf_base.VnfOnBoardingBase):
cmd = self.case_dir + "create_venv.sh " + self.data_dir
ft_utils.execute_command(cmd)
- cfy.download_manager_blueprint(self.orchestrator.blueprint['url'],
- self.orchestrator.blueprint['branch'])
+ cfy.download_manager_blueprint(
+ self.orchestrator['blueprint']['url'],
+ self.orchestrator['blueprint']['branch'])
cfy.deploy_manager()
return {'status': 'PASS', 'result': ''}
@@ -121,10 +200,16 @@ class ImsVnf(vnf_base.VnfOnBoardingBase):
self.vnf.object = cw
self.logger.info("Collect flavor id for all clearwater vm")
- flavor_id = self.get_flavor("m1.small", self.vnf.requirements)
+ flavor_exist, flavor_id = os_utils.get_or_create_flavor(
+ "m1.small",
+ self.vnf['requirements']['ram_min'],
+ '1',
+ '1',
+ public=True)
+ self.logger.debug("Flavor id: %s" % flavor_id)
if not flavor_id:
self.logger.info("Available flavors are: ")
- self.pMsg(self.nova_client.flavor.list())
+ self.logger.info(self.nova_client.flavor.list())
self.step_failure("Failed to find required flavor"
" for this deployment")
@@ -133,7 +218,7 @@ class ImsVnf(vnf_base.VnfOnBoardingBase):
# VMs image
if 'os_image' in self.vnf.requirements.keys():
image_id = os_utils.get_image_id(
- self.glance_client, self.vnf.requirements['os_image'])
+ self.glance_client, self.vnf['requirements']['os_image'])
if image_id == '':
self.step_failure("Failed to find required OS image"
" for clearwater VMs")
@@ -256,23 +341,54 @@ class ImsVnf(vnf_base.VnfOnBoardingBase):
self.orchestrator.object.undeploy_manager()
super(ImsVnf, self).clean()
- def get_flavor(self, flavor_name, requirements):
- try:
- flavor_id = os_utils.get_flavor_id(self.nova_client, flavor_name)
- if 'ram_min' in requirements.keys():
- flavor_id = os_utils.get_flavor_id_by_ram_range(
- self.nova_client, requirements['ram_min'], 7500)
-
- if flavor_id == '':
- self.logger.error(
- "Failed to find %s flavor. "
- "Try with ram range default requirement !" % flavor_name)
- flavor_id = os_utils.get_flavor_id_by_ram_range(
- self.nova_client,
- 4000, 10000)
- return flavor_id
- except:
- self.logger.error("Flavor '%s' not found." % self.flavor_name)
- self.logger.info("Available flavors are: ")
- self.pMsg(self.nova_client.flavor.list())
- return None
+ def main(self, **kwargs):
+ self.logger.info("Cloudify IMS VNF onboarding test starting")
+ self.execute()
+ self.logger.info("Cloudify IMS VNF onboarding test executed")
+ if self.criteria is "PASS":
+ return self.EX_OK
+ else:
+ return self.EX_RUN_ERROR
+
+ def run(self):
+ kwargs = {}
+ return self.main(**kwargs)
+
+
+# ----------------------------------------------------------
+#
+# YAML UTILS
+#
+# -----------------------------------------------------------
+def get_config(parameter, file):
+ """
+ Returns the value of a given parameter in file.yaml
+ parameter must be given in string format with dots
+ Example: general.openstack.image_name
+ """
+ with open(file) as f:
+ file_yaml = yaml.safe_load(f)
+ f.close()
+ value = file_yaml
+ for element in parameter.split("."):
+ value = value.get(element)
+ if value is None:
+ raise ValueError("The parameter %s is not defined in"
+ " reporting.yaml" % parameter)
+ return value
+
+
+def download_and_add_image_on_glance(glance, image_name, image_url, data_dir):
+ dest_path = data_dir
+ if not os.path.exists(dest_path):
+ os.makedirs(dest_path)
+ file_name = image_url.rsplit('/')[-1]
+ if not ft_utils.download_url(image_url, dest_path):
+ return False
+
+ image = os_utils.create_glance_image(
+ glance, image_name, dest_path + file_name)
+ if not image:
+ return False
+
+ return image
diff --git a/functest/opnfv_tests/vnf/ims/cloudify_ims.yaml b/functest/opnfv_tests/vnf/ims/cloudify_ims.yaml
new file mode 100644
index 00000000..c5918087
--- /dev/null
+++ b/functest/opnfv_tests/vnf/ims/cloudify_ims.yaml
@@ -0,0 +1,39 @@
+tenant_images:
+ ubuntu_14.04: http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img
+ centos_7: http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1510.qcow2
+cloudify:
+ blueprint:
+ url: https://github.com/boucherv-orange/cloudify-manager-blueprints.git
+ branch: '3.3.1-build'
+ requirements:
+ ram_min: 3000
+ os_image: centos_7
+ inputs:
+ keystone_username: ""
+ keystone_password: ""
+ keystone_tenant_name: ""
+ keystone_url: ""
+ manager_public_key_name: 'manager-kp'
+ agent_public_key_name: 'agent-kp'
+ image_id: ""
+ flavor_id: "3"
+ external_network_name: ""
+ ssh_user: centos
+ agents_user: ubuntu
+clearwater:
+ blueprint:
+ file_name: openstack-blueprint.yaml
+ name: clearwater-opnfv
+ destination_folder: opnfv-cloudify-clearwater
+ url: https://github.com/Orange-OpenSource/opnfv-cloudify-clearwater.git
+ branch: stable
+ deployment_name: clearwater-opnfv
+ requirements:
+ ram_min: 1700
+ os_image: ubuntu_14.04
+ inputs:
+ image_id: ''
+ flavor_id: ''
+ agent_user: ubuntu
+ external_network_name: ''
+ public_domain: clearwaterfv
diff --git a/functest/tests/unit/utils/test_openstack_utils.py b/functest/tests/unit/utils/test_openstack_utils.py
index 0f510414..0971b4e8 100644
--- a/functest/tests/unit/utils/test_openstack_utils.py
+++ b/functest/tests/unit/utils/test_openstack_utils.py
@@ -7,6 +7,7 @@
import copy
import logging
+import os
import unittest
import mock
@@ -353,18 +354,31 @@ class OSUtilsTesting(unittest.TestCase):
def test_get_credentials_missing_endpoint_type(self):
self._get_credentials_missing_env('OS_ENDPOINT_TYPE')
+ def _test_source_credentials(self, msg, key='OS_TENANT_NAME',
+ value='admin'):
+ try:
+ del os.environ[key]
+ except:
+ pass
+ f = 'rc_file'
+ with mock.patch('__builtin__.open', mock.mock_open(read_data=msg),
+ create=True) as m:
+ m.return_value.__iter__ = lambda self: iter(self.readline, '')
+ openstack_utils.source_credentials(f)
+ m.assert_called_once_with(f, 'r')
+ self.assertEqual(os.environ[key], value)
+
def test_source_credentials(self):
- with mock.patch('functest.utils.openstack_utils.subprocess.Popen') \
- as mock_subproc_popen, \
- mock.patch('functest.utils.openstack_utils.os.environ'):
- process_mock = mock.Mock()
- attrs = {'communicate.return_value': ('OS_USER_NAME=test_name',
- 'success')}
- process_mock.configure_mock(**attrs)
- mock_subproc_popen.return_value = process_mock
-
- self.assertDictEqual(openstack_utils.source_credentials('rc_file'),
- {'OS_USER_NAME': 'test_name'})
+ self._test_source_credentials('OS_TENANT_NAME=admin')
+ self._test_source_credentials('OS_TENANT_NAME= admin')
+ self._test_source_credentials('OS_TENANT_NAME = admin')
+ self._test_source_credentials('OS_TENANT_NAME = "admin"')
+ self._test_source_credentials('export OS_TENANT_NAME=admin')
+ self._test_source_credentials('export OS_TENANT_NAME =admin')
+ self._test_source_credentials('export OS_TENANT_NAME = admin')
+ self._test_source_credentials('export OS_TENANT_NAME = "admin"')
+ self._test_source_credentials('OS_TENANT_NAME', value='')
+ self._test_source_credentials('export OS_TENANT_NAME', value='')
@mock.patch('functest.utils.openstack_utils.os.getenv',
return_value=None)
diff --git a/functest/utils/openstack_utils.py b/functest/utils/openstack_utils.py
index 64f18504..a0d78ae9 100755
--- a/functest/utils/openstack_utils.py
+++ b/functest/utils/openstack_utils.py
@@ -10,7 +10,7 @@
import os
import os.path
-import subprocess
+import re
import sys
import time
@@ -112,12 +112,12 @@ def get_credentials(other_creds={}):
def source_credentials(rc_file):
- pipe = subprocess.Popen(". %s; env" % rc_file, stdout=subprocess.PIPE,
- shell=True)
- output = pipe.communicate()[0]
- env = dict((line.split("=", 1) for line in output.splitlines()))
- os.environ.update(env)
- return env
+ with open(rc_file, "r") as f:
+ for line in f:
+ var = line.rstrip('"\n').replace('export ', '').split("=")
+ key = re.sub(r'^ *| *$', '', var[0])
+ value = re.sub(r'^[" ]*|[ "]*$', '', "".join(var[1:]))
+ os.environ[key] = value
def get_credentials_for_rally():