diff options
-rw-r--r-- | docker/requirements.pip | 1 | ||||
-rw-r--r-- | testcases/config_functest.yaml | 37 | ||||
-rw-r--r-- | testcases/functest_utils.py | 3 | ||||
-rw-r--r-- | testcases/vIMS/CI/clearwater.py | 63 | ||||
-rw-r--r-- | testcases/vIMS/CI/orchestrator.py | 179 | ||||
-rw-r--r-- | testcases/vIMS/CI/requirements.pip | 2 | ||||
-rw-r--r-- | testcases/vIMS/CI/vIMS.py | 389 |
7 files changed, 450 insertions, 224 deletions
diff --git a/docker/requirements.pip b/docker/requirements.pip index 43777e87f..03036a828 100644 --- a/docker/requirements.pip +++ b/docker/requirements.pip @@ -5,7 +5,6 @@ python-novaclient==2.28.1 python-glanceclient==1.1.0 python-cinderclient==1.4.0 python-keystoneclient==1.6.0 -cloudify==3.2.1 virtualenv==1.11.4 pexpect==4.0 requests==2.8.0 diff --git a/testcases/config_functest.yaml b/testcases/config_functest.yaml index ce56517ed..ab75ee384 100644 --- a/testcases/config_functest.yaml +++ b/testcases/config_functest.yaml @@ -72,36 +72,32 @@ vIMS: general: tenant_name: vIMS tenant_description: vIMS Functionality Testing - base_image_url: http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img - base_image_name: ubuntu_14.04 + images: + ubuntu: + image_url: 'http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img' + image_name: ubuntu_14.04 + centos: + image_url: 'http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1510.qcow2' + image_name: centos_7 cloudify: blueprint: url: https://github.com/boucherv-orange/cloudify-manager-blueprints.git - branch: "3.2-build" - file_name: "openstack-manager-blueprint.yaml" + branch: "3.3-build" + requierments: + ram_min: 3000 + os_image: centos_7 inputs: keystone_username: "" keystone_password: "" keystone_tenant_name: "" keystone_url: "" - manager_public_key_name: 'cloudify-manager' - agent_public_key_name: 'cloudify-agent' + manager_public_key_name: 'manager-kp' + agent_public_key_name: 'agent-kp' image_id: "" - flavor_id: "2" + flavor_id: "3" external_network_name: "" - use_existing_manager_keypair: false - use_existing_agent_keypair: false - manager_server_name: cloudify-management-server - manager_server_user: ubuntu - manager_security_group_name: cloudify-sg-manager - agents_security_group_name: cloudify-sg-agents - manager_private_key_path: ~/.ssh/cloudify-manager-kp.pem - agent_private_key_path: ~/.ssh/cloudify-agent-kp.pem + ssh_user: centos agents_user: ubuntu - nova_url: "" - neutron_url: "" - resources_prefix: "" - inputs_path: openstack/inputs.yaml clearwater: blueprint: file_name: 'openstack-blueprint.yaml' @@ -110,6 +106,9 @@ vIMS: url: 'https://github.com/Orange-OpenSource/opnfv-cloudify-clearwater.git' branch: "stable" deployment-name: 'clearwater-opnfv' + requierments: + ram_min: 1700 + os_image: ubuntu_14.04 inputs: image_id: '' flavor_id: '' diff --git a/testcases/functest_utils.py b/testcases/functest_utils.py index 875060835..327608691 100644 --- a/testcases/functest_utils.py +++ b/testcases/functest_utils.py @@ -16,6 +16,7 @@ import subprocess import sys import requests import json +import shutil from git import Repo @@ -513,7 +514,7 @@ def download_url(url, dest_path): return False with open(dest, 'wb') as f: - f.write(response.read()) + shutil.copyfileobj(response, f) return True diff --git a/testcases/vIMS/CI/clearwater.py b/testcases/vIMS/CI/clearwater.py new file mode 100644 index 000000000..0456cd231 --- /dev/null +++ b/testcases/vIMS/CI/clearwater.py @@ -0,0 +1,63 @@ +#!/usr/bin/python +# coding: utf8 +####################################################################### +# +# Copyright (c) 2015 Orange +# valentin.boucher@orange.com +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +######################################################################## +import sys, subprocess + +class clearwater: + + def __init__(self, inputs={}, orchestrator=None, logger=None): + self.config = inputs + self.orchestrator = orchestrator + self.logger = logger + self.deploy = False + + def set_orchestrator(self, orchestrator): + self.orchestrator = orchestrator + + def set_flavor_id(self, flavor_id): + self.config['flavor_id'] = flavor_id + + def set_image_id(self, image_id): + self.config['image_id'] = image_id + + def set_agent_user(self, agent_user): + self.config['agent_user'] = agent_user + + def set_external_network_name(self, external_network_name): + self.config['external_network_name'] = external_network_name + + def set_public_domain(self, public_domain): + self.config['public_domain'] = public_domain + + def deploy_vnf(self, blueprint, bp_name='clearwater', dep_name='clearwater-opnfv'): + if self.orchestrator: + self.dep_name = dep_name + self.orchestrator.download_upload_and_deploy_blueprint(blueprint, self.config, bp_name, dep_name) + self.deploy = True + else: + if self.logger: + logger.error("Cloudify manager is down or not provide...") + + def undeploy_vnf(self): + if self.orchestrator: + if self.deploy: + self.deploy = False + self.orchestrator.undeploy_deployment(self.dep_name) + else: + if self.logger: + logger.error("Clearwater isn't already deploy...") + else: + if self.logger: + logger.error("Cloudify manager is down or not provide...") + + + diff --git a/testcases/vIMS/CI/orchestrator.py b/testcases/vIMS/CI/orchestrator.py new file mode 100644 index 000000000..409b3e0cb --- /dev/null +++ b/testcases/vIMS/CI/orchestrator.py @@ -0,0 +1,179 @@ +#!/usr/bin/python +# coding: utf8 +####################################################################### +# +# Copyright (c) 2015 Orange +# valentin.boucher@orange.com +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +######################################################################## +import sys, subprocess, os, shutil, yaml +from git import Repo + +class orchestrator: + + def __init__(self, testcase_dir, inputs={}, logger=None): + self.testcase_dir = testcase_dir + self.blueprint_dir = testcase_dir + 'cloudify-manager-blueprint/' + self.input_file = 'inputs.yaml' + self.manager_blueprint = False + self.config = inputs + self.logger = logger + self.manager_up = False + + def set_credentials(self, username, password, tenant_name, auth_url): + self.config['keystone_username'] = username + self.config['keystone_password'] = password + self.config['keystone_url'] = auth_url + self.config['keystone_tenant_name'] = tenant_name + + def set_flavor_id(self, flavor_id): + self.config['flavor_id'] = flavor_id + + def set_image_id(self, image_id): + self.config['image_id'] = image_id + + def set_external_network_name(self, external_network_name): + self.config['external_network_name'] = external_network_name + + def set_ssh_user(self, ssh_user): + self.config['ssh_user'] = ssh_user + + def set_logger(self, logger): + self.logger = logger + + def download_manager_blueprint(self, manager_blueprint_url, manager_blueprint_branch): + if self.manager_blueprint: + if self.logger: + self.logger.info("cloudify manager server blueprint is already downloaded !") + else: + if self.logger: + self.logger.info("Downloading the cloudify manager server blueprint") + download_result = download_blueprints(manager_blueprint_url, manager_blueprint_branch, self.blueprint_dir) + + if not download_result: + if self.logger: + self.logger.error("Failed to download manager blueprint") + exit(-1) + else: + self.manager_blueprint = True + + def manager_up(self): + return manager_up + + def deploy_manager(self): + if self.manager_blueprint: + if self.logger: + self.logger.info("Writing the inputs file") + with open( self.blueprint_dir + "inputs.yaml", "w") as f: + f.write(yaml.dump(self.config, default_style='"') ) + f.close() + + if self.logger: + self.logger.info("Launching the cloudify-manager deployment") + script = "source " + self.testcase_dir + "venv_cloudify/bin/activate; " + script += "cd " + self.testcase_dir + "; " + script += "cfy init -r; " + script += "cd cloudify-manager-blueprint; " + script += "cfy local create-requirements -o requirements.txt -p openstack-manager-blueprint.yaml; " + script += "pip install -r requirements.txt; " + script += "cfy bootstrap --install-plugins -p openstack-manager-blueprint.yaml -i inputs.yaml; " + cmd = "/bin/bash -c '" + script + "'" + execute_command(cmd, self.logger) + + if self.logger: + self.logger.info("Cloudify-manager server is UP !") + + self.manager_up = True + + def undeploy_manager(self): + if self.logger: + self.logger.info("Launching the cloudify-manager undeployment") + + self.manager_up = False + + script = "source " + self.testcase_dir + "venv_cloudify/bin/activate; " + script += "cd " + self.testcase_dir + "; " + script += "cfy teardown -f; " + cmd = "/bin/bash -c '" + script + "'" + execute_command(cmd, self.logger) + + if self.logger: + self.logger.info("Cloudify-manager server has been successfully removed!") + + def download_upload_and_deploy_blueprint(self, blueprint, config, bp_name, dep_name): + if self.logger: + self.logger.info("Downloading the {0} blueprint".format(blueprint['file_name'])) + download_result = download_blueprints(blueprint['url'], blueprint['branch'], + self.testcase_dir + blueprint['destination_folder']) + + if not download_result: + if self.logger: + self.logger.error("Failed to download blueprint {0}".format(blueprint['file_name'])) + exit(-1) + + if self.logger: + self.logger.info("Writing the inputs file") + with open(self.testcase_dir + blueprint['destination_folder'] + "/inputs.yaml", "w") as f: + f.write(yaml.dump(config, default_style='"') ) + f.close() + + if self.logger: + self.logger.info("Launching the {0} deployment".format(bp_name)) + script = "source " + self.testcase_dir + "venv_cloudify/bin/activate; " + script += "cd " + self.testcase_dir + blueprint['destination_folder'] + "; " + script += "cfy blueprints upload -b " + bp_name + " -p openstack-blueprint.yaml; " + script += "cfy deployments create -b " + bp_name + " -d " + dep_name + " --inputs inputs.yaml; " + script += "cfy executions start -w install -d " + dep_name + " --timeout 1800; " + + cmd = "/bin/bash -c '" + script + "'" + execute_command(cmd, self.logger) + + if self.logger: + self.logger.info("The deployment of {0} is ended".format(dep_name)) + + def undeploy_deployment(self, dep_name): + if self.logger: + self.logger.info("Launching the {0} undeployment".format(dep_name)) + script = "source " + self.testcase_dir + "venv_cloudify/bin/activate; " + script += "cd " + self.testcase_dir + "; " + script += "cfy executions start -w uninstall -d " + dep_name + " --timeout 1800 ; " + script += "cfy deployments delete -d " + dep_name + "; " + + cmd = "/bin/bash -c '" + script + "'" + execute_command(cmd, self.logger) + + +def execute_command(cmd, logger): + """ + Execute Linux command + """ + if logger: + logger.debug('Executing command : {}'.format(cmd)) + output_file = "output.txt" + f = open(output_file, 'w+') + p = subprocess.call(cmd, shell=True, stdout=f, stderr=subprocess.STDOUT) + f.close() + f = open(output_file, 'r') + result = f.read() + if result != "" and logger: + logger.debug(result) + if p == 0: + return True + else: + if logger: + logger.error("Error when executing command %s" % cmd) + exit(-1) + + +def download_blueprints(blueprint_url, branch, dest_path): + if os.path.exists(dest_path): + shutil.rmtree(dest_path) + try: + Repo.clone_from(blueprint_url, dest_path, branch=branch) + return True + except: + return False
\ No newline at end of file diff --git a/testcases/vIMS/CI/requirements.pip b/testcases/vIMS/CI/requirements.pip index 287c68c5d..9b9d0ba53 100644 --- a/testcases/vIMS/CI/requirements.pip +++ b/testcases/vIMS/CI/requirements.pip @@ -1 +1 @@ -cloudify==3.2.1
\ No newline at end of file +cloudify==3.3
\ No newline at end of file diff --git a/testcases/vIMS/CI/vIMS.py b/testcases/vIMS/CI/vIMS.py index 772e070b9..12fb775a6 100644 --- a/testcases/vIMS/CI/vIMS.py +++ b/testcases/vIMS/CI/vIMS.py @@ -18,6 +18,9 @@ import glanceclient.client as glclient import novaclient.client as nvclient from neutronclient.v2_0 import client as ntclient +from orchestrator import * +from clearwater import * + import urllib pp = pprint.PrettyPrinter(indent=4) @@ -29,7 +32,6 @@ parser.add_argument("-r", "--report", action="store_true") args = parser.parse_args() - """ logging configuration """ logger = logging.getLogger('vIMS') logger.setLevel(logging.DEBUG) @@ -50,7 +52,7 @@ if not os.path.exists(REPO_PATH): sys.path.append(REPO_PATH + "testcases/") import functest_utils -with open(REPO_PATH + "testcases/config_functest.yaml") as f: +with open( REPO_PATH + "testcases/config_functest.yaml") as f: functest_yaml = yaml.safe_load(f) f.close() @@ -62,27 +64,21 @@ TEST_DB = functest_yaml.get("results").get("test_db_url") TENANT_NAME = functest_yaml.get("vIMS").get("general").get("tenant_name") TENANT_DESCRIPTION = functest_yaml.get("vIMS").get("general").get("tenant_description") -BASE_IMAGE_URL = functest_yaml.get("vIMS").get("general").get("base_image_url") -BASE_IMAGE_NAME = functest_yaml.get("vIMS").get("general").get("base_image_name") -GLANCE_IMAGE_NAME = functest_yaml.get("vIMS").get("cloudify").get("inputs").get("image_id") +IMAGES = functest_yaml.get("vIMS").get("general").get("images") CFY_MANAGER_BLUEPRINT = functest_yaml.get("vIMS").get("cloudify").get("blueprint") +CFY_MANAGER_REQUIERMENTS = functest_yaml.get("vIMS").get("cloudify").get("requierments") CFY_INPUTS = functest_yaml.get("vIMS").get("cloudify").get("inputs") -CFY_INPUTS_PATH = functest_yaml.get("vIMS").get("cloudify").get("inputs_path") CW_BLUEPRINT = functest_yaml.get("vIMS").get("clearwater").get("blueprint") CW_DEPLOYMENT_NAME = functest_yaml.get("vIMS").get("clearwater").get("deployment-name") CW_INPUTS = functest_yaml.get("vIMS").get("clearwater").get("inputs") -CW_DOMAIN_NAME = functest_yaml.get("vIMS").get("clearwater").get("inputs").get("public_domain") +CW_REQUIERMENTS = functest_yaml.get("vIMS").get("clearwater").get("requierments") CFY_DEPLOYMENT_DURATION = 0 CW_DEPLOYMENT_DURATION = 0 -def pMsg(value): - """pretty printing""" - pp.pprint(value) - def download_and_add_image_on_glance(glance, image_name, image_url): dest_path = VIMS_DATA_DIR + "tmp/" if not os.path.exists(dest_path): @@ -99,16 +95,78 @@ def download_and_add_image_on_glance(glance, image_name, image_url): return image -def download_blueprints(blueprint_url, branch, dest_path): - if os.path.exists(dest_path): - shutil.rmtree(dest_path) +def test_clearwater(): + + time.sleep(180) + + script = "source " + VIMS_DATA_DIR + "venv_cloudify/bin/activate; " + script += "cd " + VIMS_DATA_DIR + "; " + script += "cfy deployments outputs -d " + CW_DEPLOYMENT_NAME + " | grep Value: | sed \"s/ *Value: //g\";" + cmd = "/bin/bash -c '" + script + "'" + try: - Repo.clone_from(blueprint_url, dest_path, branch=branch) - return True + logger.debug("Trying to get clearwater nameserver IP ... ") + dns_ip = os.popen(cmd).read() + dns_ip = dns_ip.splitlines()[0] except: - return False + logger.error("Unable to retrieve the IP of the DNS server !") + + start_time_ts = time.time() + end_time_ts = start_time_ts + logger.info("vIMS functional test Start Time:'%s'" % ( + datetime.datetime.fromtimestamp(start_time_ts).strftime( + '%Y-%m-%d %H:%M:%S'))) + + if dns_ip != "": + script = 'echo -e "nameserver ' + dns_ip + '\nnameserver 8.8.8.8\nnameserver 8.8.4.4" > /etc/resolv.conf; ' + script += 'source /etc/profile.d/rvm.sh; ' + script += 'cd ' + VIMS_TEST_DIR + '; ' + script += 'rake test[' + CW_INPUTS["public_domain"] + '] SIGNUP_CODE="secret"' + + cmd = "/bin/bash -c '" + script + "'" + output_file = "output.txt" + f = open(output_file, 'w+') + p = subprocess.call(cmd, shell=True, stdout=f, stderr=subprocess.STDOUT) + f.close() + end_time_ts = time.time() + duration = round(end_time_ts - start_time_ts, 1) + logger.info("vIMS functional test duration:'%s'" %duration) + f = open(output_file, 'r') + result = f.read() + if result != "" and logger: + logger.debug(result) + + vims_test_result="" + try: + logger.debug("Trying to load test results") + with open(VIMS_TEST_DIR + "temp.json") as f: + vims_test_result = json.load(f) + f.close() + except: + logger.error("Unable to retrieve test results") + + if vims_test_result != "": + if args.report: + logger.debug("Push result into DB") + logger.debug("Pushing results to DB....") + git_version = functest_utils.get_git_branch(args.repo_path) + functest_utils.push_results_to_db(db_url=TEST_DB, case_name="vIMS", + logger=logger, pod_name="opnfv-jump-2", git_version=git_version, + payload={'orchestrator':{'duration': CFY_DEPLOYMENT_DURATION, + 'result': ""}, + 'vIMS': {'duration': CW_DEPLOYMENT_DURATION, + 'result': ""}, + 'sig_test': {'duration': duration, + 'result': vims_test_result}}) + try: + os.remove(VIMS_TEST_DIR + "temp.json") + except: + logger.error("Deleting file failed") + +def main(): + + ################ GENERAL INITIALISATION ################ -def initialize_deployments(): if not os.path.exists(VIMS_DATA_DIR): os.makedirs(VIMS_DATA_DIR) @@ -156,58 +214,78 @@ def initialize_deployments(): "project_id": TENANT_NAME, }) - logger.info("Upload ubuntu image if it doesn't exist") + logger.info("Upload some OS images if it doesn't exist") glance_endpoint = keystone.service_catalog.url_for(service_type='image', endpoint_type='publicURL') glance = glclient.Client(1, glance_endpoint, token=keystone.auth_token) - image_id = functest_utils.get_image_id(glance, BASE_IMAGE_NAME) - if image_id == '': - logger.info("""%s image doesn't exist on glance repository. - Try downloading this image and upload on glance !""" %BASE_IMAGE_NAME) - image_id = download_and_add_image_on_glance(glance, BASE_IMAGE_NAME, BASE_IMAGE_URL) + for img in IMAGES.keys(): + image_name = IMAGES[img]['image_name'] + image_url = IMAGES[img]['image_url'] - if image_id == '': - logger.error("Error : Failed to find or upload required OS image for this deployment" %flavor_name) + image_id = functest_utils.get_image_id(glance, image_name) + + if image_id == '': + 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(glance, image_name, image_url) + + if image_id == '': + logger.error("Error : Failed to find or upload required OS image for this deployment") + exit(-1) + + nova = nvclient.Client("2", **nv_creds) + + logger.info("Update security group quota for this tenant") + neutron = ntclient.Client(**nt_creds) + if not functest_utils.update_sg_quota(neutron, tenant_id, 50, 100): + logger.error("Failed to update security group quota for tenant %s" %TENANT_NAME) exit(-1) - logger.info("Collect flavor id for cloudify and clearwater VMs") + + ################ CLOUDIFY INITIALISATION ################ + + cfy = orchestrator(VIMS_DATA_DIR, CFY_INPUTS, logger) + + cfy.set_credentials(username=ks_creds['username'], password=ks_creds['password'], tenant_name=ks_creds['tenant_name'], auth_url=ks_creds['auth_url']) + + logger.info("Collect flavor id for cloudify manager server") nova = nvclient.Client("2", **nv_creds) - flavor_name = "m1.small" + flavor_name = "m1.medium" flavor_id = functest_utils.get_flavor_id(nova, flavor_name) + for requirement in CFY_MANAGER_REQUIERMENTS: + if requirement == 'ram_min': + flavor_id = functest_utils.get_flavor_id_by_ram_range(nova, CFY_MANAGER_REQUIERMENTS['ram_min'], 8196) + if flavor_id == '': - logger.error("Failed to find %s flavor. Try with ram range requirement !" %flavor_name) - flavor_id = get_flavor_id_by_ram_range(nova, 1792, 2048) + logger.error("Failed to find %s flavor. Try with ram range default requirement !" %flavor_name) + flavor_id = functest_utils.get_flavor_id_by_ram_range(nova, 4000, 8196) if flavor_id == '': logger.error("Failed to find required flavor for this deployment" %flavor_name) exit(-1) - logger.info("Update security group quota for this tenant") - neutron = ntclient.Client(**nt_creds) - if not functest_utils.update_sg_quota(neutron, tenant_id, 50, 100): - logger.error("Failed to update security group quota for tenant %s" %TENANT_NAME) + cfy.set_flavor_id(flavor_id) + + image_name = "centos_7" + image_id = functest_utils.get_image_id(glance, image_name) + for requirement in CFY_MANAGER_REQUIERMENTS: + if requirement == 'os_image': + image_id = functest_utils.get_image_id(glance, CFY_MANAGER_REQUIERMENTS['os_image']) + + if image_id == '': + logger.error("Error : Failed to find required OS image for cloudify manager") exit(-1) + cfy.set_image_id(image_id) + ext_net = functest_utils.get_external_net(neutron) if not ext_net: logger.error("Failed to get external network") exit(-1) - logger.info("Update inputs informations") - CFY_INPUTS['image_id'] = image_id - CFY_INPUTS['flavor_id'] = flavor_id - CFY_INPUTS['external_network_name'] = ext_net - - CW_INPUTS['image_id'] = image_id - CW_INPUTS['flavor_id'] = flavor_id - CW_INPUTS['external_network_name'] = ext_net - - CFY_INPUTS['keystone_username'] = ks_creds['username'] - CFY_INPUTS['keystone_password'] = ks_creds['password'] - CFY_INPUTS['keystone_url'] = ks_creds['auth_url'] - CFY_INPUTS['keystone_tenant_name'] = ks_creds['tenant_name'] + cfy.set_external_network_name(ext_net) logger.info("Prepare virtualenv for cloudify-cli") cmd = "chmod +x " + VIMS_DIR + "create_venv.sh" @@ -215,94 +293,65 @@ def initialize_deployments(): cmd = VIMS_DIR + "create_venv.sh " + VIMS_DATA_DIR functest_utils.execute_command(cmd,logger) -def cleanup_deployments(): - ks_creds = functest_utils.get_credentials("keystone") - - keystone = ksclient.Client(**ks_creds) - - logger.info("Removing %s tenant .." %CFY_INPUTS['keystone_tenant_name']) - tenant_id = functest_utils.get_tenant_id(keystone, CFY_INPUTS['keystone_tenant_name']) - if tenant_id == '': - logger.error("Error : Failed to get id of %s tenant" %CFY_INPUTS['keystone_tenant_name']) - else: - if not functest_utils.delete_tenant(keystone, tenant_id): - logger.error("Error : Failed to remove %s tenant" %CFY_INPUTS['keystone_tenant_name']) - - logger.info("Removing %s user .." %CFY_INPUTS['keystone_username']) - user_id = functest_utils.get_user_id(keystone, CFY_INPUTS['keystone_username']) - if user_id == '': - logger.error("Error : Failed to get id of %s user" %CFY_INPUTS['keystone_username']) - else: - if not functest_utils.delete_user(keystone, user_id): - logger.error("Error : Failed to remove %s user" %CFY_INPUTS['keystone_username']) - -def deploy_cloudify_manager(): - - logger.info("Downloading the cloudify manager server blueprint") - download_result = download_blueprints(CFY_MANAGER_BLUEPRINT['url'], - CFY_MANAGER_BLUEPRINT['branch'], - VIMS_DATA_DIR + 'cloudify-manager-blueprint/') - - if not download_result: - logger.error("Failed to download manager blueprint") - exit(-1) - - logger.info("Writing the inputs file") - with open( VIMS_DATA_DIR + 'cloudify-manager-blueprint/' + CFY_INPUTS_PATH, "w") as f: - f.write(yaml.dump(CFY_INPUTS, default_style='"') ) - f.close() + cfy.download_manager_blueprint(CFY_MANAGER_BLUEPRINT['url'], CFY_MANAGER_BLUEPRINT['branch']) + ################ CLOUDIFY DEPLOYMENT ################ start_time_ts = time.time() end_time_ts = start_time_ts logger.info("Cloudify deployment Start Time:'%s'" % ( datetime.datetime.fromtimestamp(start_time_ts).strftime( '%Y-%m-%d %H:%M:%S'))) - logger.info("Launching the cloudify-manager deployment") - script = "source " + VIMS_DATA_DIR + "venv_cloudify/bin/activate; " - script += "cd " + VIMS_DATA_DIR + "; " - script += "cfy init -r; " - script += "cd cloudify-manager-blueprint/openstack; " - script += "cfy local create-requirements -o requirements.txt -p openstack-manager-blueprint.yaml; " - script += "pip install -r requirements.txt; " - script += "cfy bootstrap --install-plugins -p openstack-manager-blueprint.yaml -i inputs.yaml; " - cmd = "/bin/bash -c '" + script + "'" - functest_utils.execute_command(cmd, logger) - - logger.info("Cloudify-manager server is UP !") + cfy.deploy_manager() global CFY_DEPLOYMENT_DURATION end_time_ts = time.time() CFY_DEPLOYMENT_DURATION = round(end_time_ts - start_time_ts, 1) logger.info("Cloudify deployment duration:'%s'" %CFY_DEPLOYMENT_DURATION) -def undeploy_cloudify_manager(): + ################ CLEARWATER INITIALISATION ################ - logger.info("Launching the cloudify-manager undeployment") - script = "source " + VIMS_DATA_DIR + "venv_cloudify/bin/activate; " - script += "cd " + VIMS_DATA_DIR + "; " - script += "cfy teardown -f; " - cmd = "/bin/bash -c '" + script + "'" - functest_utils.execute_command(cmd, logger) + cw = clearwater(CW_INPUTS, cfy, logger) + + logger.info("Collect flavor id for all clearwater vm") + nova = nvclient.Client("2", **nv_creds) - logger.info("Cloudify-manager server has been successfully removed!") + flavor_name = "m1.small" + flavor_id = functest_utils.get_flavor_id(nova, flavor_name) + for requirement in CW_REQUIERMENTS: + if requirement == 'ram_min': + flavor_id = functest_utils.get_flavor_id_by_ram_range(nova, CW_REQUIERMENTS['ram_min'], 8196) -def deploy_clearwater(): + if flavor_id == '': + logger.error("Failed to find %s flavor. Try with ram range default requirement !" %flavor_name) + flavor_id = functest_utils.get_flavor_id_by_ram_range(nova, 4000, 8196) + + if flavor_id == '': + logger.error("Failed to find required flavor for this deployment" %flavor_name) + exit(-1) + + cw.set_flavor_id(flavor_id) + + image_name = "ubuntu_14.04" + image_id = functest_utils.get_image_id(glance, image_name) + for requirement in CW_REQUIERMENTS: + if requirement == 'os_image': + image_id = functest_utils.get_image_id(glance, CW_REQUIERMENTS['os_image']) + + if image_id == '': + logger.error("Error : Failed to find required OS image for cloudify manager") + exit(-1) - logger.info("Downloading the {0} blueprint".format(CW_BLUEPRINT['file_name'])) - download_result = download_blueprints(CW_BLUEPRINT['url'], CW_BLUEPRINT['branch'], - VIMS_DATA_DIR + CW_BLUEPRINT['destination_folder']) + cw.set_image_id(image_id) - if not download_result: - logger.error("Failed to download blueprint {0}".format(CW_BLUEPRINT['file_name'])) + ext_net = functest_utils.get_external_net(neutron) + if not ext_net: + logger.error("Failed to get external network") exit(-1) - logger.info("Writing the inputs file") - with open(VIMS_DATA_DIR + CW_BLUEPRINT['destination_folder'] + "/inputs.yaml", "w") as f: - f.write(yaml.dump(CW_INPUTS, default_style='"') ) - f.close() + cw.set_external_network_name(ext_net) - time.sleep(30) + ################ CLEARWATER DEPLOYMENT ################ start_time_ts = time.time() end_time_ts = start_time_ts @@ -310,111 +359,47 @@ def deploy_clearwater(): datetime.datetime.fromtimestamp(start_time_ts).strftime( '%Y-%m-%d %H:%M:%S'))) - logger.info("Launching the {0} deployment".format(CW_BLUEPRINT['name'])) - script = "source " + VIMS_DATA_DIR + "venv_cloudify/bin/activate; " - script += "cd " + VIMS_DATA_DIR + CW_BLUEPRINT['destination_folder'] + "; " - script += "cfy blueprints upload -b " + CW_BLUEPRINT['name'] + " -p openstack-blueprint.yaml; " - script += "cfy deployments create -b " + CW_BLUEPRINT['name'] + " -d " + CW_DEPLOYMENT_NAME + " --inputs inputs.yaml; " - script += "cfy executions start -w install -d " + CW_DEPLOYMENT_NAME + " --timeout 1800; " - - cmd = "/bin/bash -c '" + script + "'" - functest_utils.execute_command(cmd, logger) - - logger.info("Clearwater vIMS is UP !") + cw.deploy_vnf(CW_BLUEPRINT) global CW_DEPLOYMENT_DURATION end_time_ts = time.time() CW_DEPLOYMENT_DURATION = round(end_time_ts - start_time_ts, 1) logger.info("vIMS VNF deployment duration:'%s'" %CW_DEPLOYMENT_DURATION) -def undeploy_clearwater(): - - logger.info("Launching the {0} undeployment".format(CW_BLUEPRINT['name'])) - script = "source " + VIMS_DATA_DIR + "venv_cloudify/bin/activate; " - script += "cd " + VIMS_DATA_DIR + "; " - script += "cfy executions start -w uninstall -d " + CW_DEPLOYMENT_NAME + " --timeout 1800 ; " - script += "cfy deployments delete -d " + CW_DEPLOYMENT_NAME + "; " - - cmd = "/bin/bash -c '" + script + "'" - functest_utils.execute_command(cmd, logger) - -def test_clearwater(): + ################ CLEARWATER TEST ################ - time.sleep(180) + test_clearwater() - script = "source " + VIMS_DATA_DIR + "venv_cloudify/bin/activate; " - script += "cd " + VIMS_DATA_DIR + "; " - script += "cfy deployments outputs -d " + CW_DEPLOYMENT_NAME + " | grep Value: | sed \"s/ *Value: //g\";" - cmd = "/bin/bash -c '" + script + "'" + ########### CLEARWATER UNDEPLOYMENT ############ - try: - logger.debug("Trying to get clearwater nameserver IP ... ") - dns_ip = os.popen(cmd).read() - dns_ip = dns_ip.splitlines()[0] - except: - logger.error("Unable to retrieve the IP of the DNS server !") + cw.undeploy_vnf() - start_time_ts = time.time() - end_time_ts = start_time_ts - logger.info("vIMS functional test Start Time:'%s'" % ( - datetime.datetime.fromtimestamp(start_time_ts).strftime( - '%Y-%m-%d %H:%M:%S'))) + ############ CLOUDIFY UNDEPLOYMENT ############# - if dns_ip != "": - script = 'echo -e "nameserver ' + dns_ip + '\nnameserver 8.8.8.8\nnameserver 8.8.4.4" > /etc/resolv.conf; ' - script += 'source /etc/profile.d/rvm.sh; ' - script += 'cd ' + VIMS_TEST_DIR + '; ' - script += 'rake test[' + CW_INPUTS["public_domain"] + '] SIGNUP_CODE="secret"' + cfy.undeploy_manager() - cmd = "/bin/bash -c '" + script + "'" - output_file = "output.txt" - f = open(output_file, 'w+') - p = subprocess.call(cmd, shell=True, stdout=f, stderr=subprocess.STDOUT) - f.close() - end_time_ts = time.time() - duration = round(end_time_ts - start_time_ts, 1) - logger.info("vIMS functional test duration:'%s'" %duration) - f = open(output_file, 'r') - result = f.read() - if result != "" and logger: - logger.debug(result) + ############### GENERAL CLEANUP ################ - vims_test_result="" - try: - logger.debug("Trying to load test results") - with open(VIMS_TEST_DIR + "temp.json") as f: - vims_test_result = json.load(f) - f.close() - except: - logger.error("Unable to retrieve test results") + ks_creds = functest_utils.get_credentials("keystone") - if vims_test_result != "" & args.report: - logger.debug("Push result into DB") - logger.debug("Pushing results to DB....") - git_version = functest_utils.get_git_branch(REPO_PATH) - functest_utils.push_results_to_db(db_url=TEST_DB, case_name="vIMS", - logger=logger, pod_name="opnfv-jump-2", git_version=git_version, - payload={'orchestrator':{'duration': CFY_DEPLOYMENT_DURATION, - 'result': ""}, - 'vIMS': {'duration': CW_DEPLOYMENT_DURATION, - 'result': ""}, - 'sig_test': {'duration': duration, - 'result': vims_test_result}}) - try: - os.remove(VIMS_TEST_DIR + "temp.json") - except: - logger.error("Deleting file failed") + keystone = ksclient.Client(**ks_creds) -def main(): - initialize_deployments() - deploy_cloudify_manager() - deploy_clearwater() + logger.info("Removing %s tenant .." %CFY_INPUTS['keystone_tenant_name']) + tenant_id = functest_utils.get_tenant_id(keystone, CFY_INPUTS['keystone_tenant_name']) + if tenant_id == '': + logger.error("Error : Failed to get id of %s tenant" %CFY_INPUTS['keystone_tenant_name']) + else: + if not functest_utils.delete_tenant(keystone, tenant_id): + logger.error("Error : Failed to remove %s tenant" %CFY_INPUTS['keystone_tenant_name']) - test_clearwater() + logger.info("Removing %s user .." %CFY_INPUTS['keystone_username']) + user_id = functest_utils.get_user_id(keystone, CFY_INPUTS['keystone_username']) + if user_id == '': + logger.error("Error : Failed to get id of %s user" %CFY_INPUTS['keystone_username']) + else: + if not functest_utils.delete_user(keystone, user_id): + logger.error("Error : Failed to remove %s user" %CFY_INPUTS['keystone_username']) - undeploy_clearwater() - undeploy_cloudify_manager() - cleanup_deployments() if __name__ == '__main__': main() |