From bfdf561e941f8fc4f925b026aace13989b5c3176 Mon Sep 17 00:00:00 2001 From: boucherv Date: Wed, 6 Jan 2016 17:09:51 +0100 Subject: Bugfix: cfy teardown -f Change-Id: I8ced2251ad4cd1cb07c856ea79faf8458d051b33 Signed-off-by: boucherv --- testcases/vIMS/CI/clearwater.py | 10 +- testcases/vIMS/CI/orchestrator.py | 2 +- testcases/vIMS/CI/vIMS.py | 209 ++++++++++++++++++++++++-------------- 3 files changed, 137 insertions(+), 84 deletions(-) (limited to 'testcases/vIMS/CI') diff --git a/testcases/vIMS/CI/clearwater.py b/testcases/vIMS/CI/clearwater.py index 0456cd231..d2d189f60 100644 --- a/testcases/vIMS/CI/clearwater.py +++ b/testcases/vIMS/CI/clearwater.py @@ -10,7 +10,9 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ######################################################################## -import sys, subprocess +import sys +import subprocess + class clearwater: @@ -41,7 +43,8 @@ class clearwater: 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.orchestrator.download_upload_and_deploy_blueprint( + blueprint, self.config, bp_name, dep_name) self.deploy = True else: if self.logger: @@ -58,6 +61,3 @@ class clearwater: 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 index be1c6e335..c62cba4f7 100644 --- a/testcases/vIMS/CI/orchestrator.py +++ b/testcases/vIMS/CI/orchestrator.py @@ -115,7 +115,7 @@ class orchestrator: script = "source " + self.testcase_dir + "venv_cloudify/bin/activate; " script += "cd " + self.testcase_dir + "; " - script += "cfy teardown -f --ignore-deployments=True; " + script += "cfy teardown -f --ignore-deployments; " cmd = "/bin/bash -c '" + script + "'" execute_command(cmd, self.logger) diff --git a/testcases/vIMS/CI/vIMS.py b/testcases/vIMS/CI/vIMS.py index 9ff1762d4..a729e233e 100644 --- a/testcases/vIMS/CI/vIMS.py +++ b/testcases/vIMS/CI/vIMS.py @@ -11,7 +11,17 @@ # http://www.apache.org/licenses/LICENSE-2.0 ######################################################################## -import os, time, subprocess, logging, argparse, yaml, pprint, sys, shutil, json, datetime +import os +import time +import subprocess +import logging +import argparse +import yaml +import pprint +import sys +import shutil +import json +import datetime from git import Repo import keystoneclient.v2_0.client as ksclient import glanceclient.client as glclient @@ -41,39 +51,48 @@ if args.debug: ch.setLevel(logging.DEBUG) else: ch.setLevel(logging.INFO) -formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +formatter = logging.Formatter( + '%(asctime)s - %(name)s - %(levelname)s - %(message)s') ch.setFormatter(formatter) logger.addHandler(ch) -REPO_PATH=os.environ['repos_dir']+'/functest/' +REPO_PATH = os.environ['repos_dir'] + '/functest/' if not os.path.exists(REPO_PATH): logger.error("Functest repository directory not found '%s'" % REPO_PATH) exit(-1) 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() # Cloudify parameters -VIMS_DIR = REPO_PATH + functest_yaml.get("general").get("directories").get("dir_vIMS") -VIMS_DATA_DIR = functest_yaml.get("general").get("directories").get("dir_vIMS_data")+"/" -VIMS_TEST_DIR = functest_yaml.get("general").get("directories").get("dir_repo_vims_test")+"/" +VIMS_DIR = REPO_PATH + \ + functest_yaml.get("general").get("directories").get("dir_vIMS") +VIMS_DATA_DIR = functest_yaml.get("general").get( + "directories").get("dir_vIMS_data") + "/" +VIMS_TEST_DIR = functest_yaml.get("general").get( + "directories").get("dir_repo_vims_test") + "/" 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") +TENANT_DESCRIPTION = functest_yaml.get("vIMS").get( + "general").get("tenant_description") 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_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") 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_REQUIERMENTS = functest_yaml.get("vIMS").get("clearwater").get("requierments") +CW_DEPLOYMENT_NAME = functest_yaml.get("vIMS").get( + "clearwater").get("deployment-name") +CW_INPUTS = functest_yaml.get("vIMS").get("clearwater").get("inputs") +CW_REQUIERMENTS = functest_yaml.get("vIMS").get( + "clearwater").get("requierments") CFY_DEPLOYMENT_DURATION = 0 CW_DEPLOYMENT_DURATION = 0 @@ -85,23 +104,26 @@ def download_and_add_image_on_glance(glance, image_name, image_url): os.makedirs(dest_path) file_name = image_url.rsplit('/')[-1] if not functest_utils.download_url(image_url, dest_path): - logger.error("Failed to download image %s" %file_name) + logger.error("Failed to download image %s" % file_name) return False - image = functest_utils.create_glance_image(glance, image_name, dest_path + file_name) + image = functest_utils.create_glance_image( + glance, image_name, dest_path + file_name) if not image: logger.error("Failed to upload image on glance") return False return image + 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\";" + script += "cfy deployments outputs -d " + CW_DEPLOYMENT_NAME + \ + " | grep Value: | sed \"s/ *Value: //g\";" cmd = "/bin/bash -c '" + script + "'" try: @@ -118,25 +140,29 @@ def test_clearwater(): '%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 = '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"' + script += 'rake test[' + \ + CW_INPUTS["public_domain"] + '] SIGNUP_CODE="secret"' cmd = "/bin/bash -c '" + script + "'" + print cmd output_file = "output.txt" f = open(output_file, 'w+') - p = subprocess.call(cmd, shell=True, stdout=f, stderr=subprocess.STDOUT) + 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) + 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="" + vims_test_result = "" try: logger.debug("Trying to load test results") with open(VIMS_TEST_DIR + "temp.json") as f: @@ -151,18 +177,19 @@ def test_clearwater(): 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}}) + 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 ################ @@ -179,44 +206,48 @@ def main(): user_id = functest_utils.get_user_id(keystone, ks_creds['username']) if user_id == '': - logger.error("Error : Failed to get id of %s user" %ks_creds['username']) + logger.error("Error : Failed to get id of %s user" % + ks_creds['username']) exit(-1) - tenant_id = functest_utils.create_tenant(keystone, TENANT_NAME, TENANT_DESCRIPTION) + tenant_id = functest_utils.create_tenant( + keystone, TENANT_NAME, TENANT_DESCRIPTION) if tenant_id == '': - logger.error("Error : Failed to create %s tenant" %TENANT_NAME) + logger.error("Error : Failed to create %s tenant" % TENANT_NAME) exit(-1) role_name = "admin" role_id = functest_utils.get_role_id(keystone, role_name) if role_id == '': - logger.error("Error : Failed to get id for %s role" %role_name) + logger.error("Error : Failed to get id for %s role" % role_name) if not functest_utils.add_role_user(keystone, user_id, role_id, tenant_id): - logger.error("Error : Failed to add %s on tenant" %ks_creds['username']) + logger.error("Error : Failed to add %s on tenant" % + ks_creds['username']) - user_id = functest_utils.create_user(keystone, TENANT_NAME, TENANT_NAME, None, tenant_id) + user_id = functest_utils.create_user( + keystone, TENANT_NAME, TENANT_NAME, None, tenant_id) if user_id == '': - logger.error("Error : Failed to create %s user" %TENANT_NAME) + logger.error("Error : Failed to create %s user" % TENANT_NAME) logger.info("Update OpenStack creds informations") ks_creds.update({ "username": TENANT_NAME, "password": TENANT_NAME, "tenant_name": TENANT_NAME, - }) + }) nt_creds.update({ "tenant_name": TENANT_NAME, - }) + }) nv_creds.update({ "project_id": TENANT_NAME, - }) + }) logger.info("Upload some OS images if it doesn't exist") glance_endpoint = keystone.service_catalog.url_for(service_type='image', - endpoint_type='publicURL') + endpoint_type='publicURL') glance = glclient.Client(1, glance_endpoint, token=keystone.auth_token) for img in IMAGES.keys(): @@ -227,11 +258,13 @@ def main(): 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) + 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") + logger.error( + "Error : Failed to find or upload required OS image for this deployment") exit(-1) nova = nvclient.Client("2", **nv_creds) @@ -239,27 +272,30 @@ def main(): 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) + logger.error( + "Failed to update security group quota for tenant %s" % TENANT_NAME) exit(-1) logger.info("Update cinder quota for this tenant") from cinderclient import client as cinderclient creds_cinder = functest_utils.get_credentials("cinder") - cinder_client = cinderclient.Client('1',creds_cinder['username'], + cinder_client = cinderclient.Client('1', creds_cinder['username'], creds_cinder['api_key'], creds_cinder['project_id'], creds_cinder['auth_url'], service_type="volume") - if not functest_utils.update_cinder_quota(cinder_client,tenant_id,20,50,1500): - logger.error("Failed to update cinder quota for tenant %s" % TENANT_NAME) + if not functest_utils.update_cinder_quota(cinder_client, tenant_id, 20, 50, 1500): + logger.error("Failed to update cinder quota for tenant %s" % + TENANT_NAME) exit(-1) ################ 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']) + 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) @@ -268,14 +304,17 @@ def main(): 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) + 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 default requirement !" %flavor_name) + 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) + logger.error( + "Failed to find required flavor for this deployment" % flavor_name) exit(-1) cfy.set_flavor_id(flavor_id) @@ -284,10 +323,12 @@ def main(): 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']) + 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") + logger.error( + "Error : Failed to find required OS image for cloudify manager") exit(-1) cfy.set_image_id(image_id) @@ -301,13 +342,14 @@ def main(): logger.info("Prepare virtualenv for cloudify-cli") cmd = "chmod +x " + VIMS_DIR + "create_venv.sh" - functest_utils.execute_command(cmd,logger) + functest_utils.execute_command(cmd, logger) cmd = VIMS_DIR + "create_venv.sh " + VIMS_DATA_DIR - functest_utils.execute_command(cmd,logger) + functest_utils.execute_command(cmd, logger) - cfy.download_manager_blueprint(CFY_MANAGER_BLUEPRINT['url'], CFY_MANAGER_BLUEPRINT['branch']) + cfy.download_manager_blueprint( + CFY_MANAGER_BLUEPRINT['url'], CFY_MANAGER_BLUEPRINT['branch']) - ################ CLOUDIFY DEPLOYMENT ################ + ################ CLOUDIFY DEPLOYMENT ################ start_time_ts = time.time() end_time_ts = start_time_ts logger.info("Cloudify deployment Start Time:'%s'" % ( @@ -319,9 +361,9 @@ def main(): 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) + logger.info("Cloudify deployment duration:'%s'" % CFY_DEPLOYMENT_DURATION) - ################ CLEARWATER INITIALISATION ################ + ################ CLEARWATER INITIALISATION ################ cw = clearwater(CW_INPUTS, cfy, logger) @@ -332,14 +374,17 @@ def main(): 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) + flavor_id = functest_utils.get_flavor_id_by_ram_range( + nova, CW_REQUIERMENTS['ram_min'], 8196) if flavor_id == '': - logger.error("Failed to find %s flavor. Try with ram range default requirement !" %flavor_name) + 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) + logger.error( + "Failed to find required flavor for this deployment" % flavor_name) exit(-1) cw.set_flavor_id(flavor_id) @@ -348,10 +393,12 @@ def main(): 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']) + 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") + logger.error( + "Error : Failed to find required OS image for cloudify manager") exit(-1) cw.set_image_id(image_id) @@ -363,7 +410,7 @@ def main(): cw.set_external_network_name(ext_net) - ################ CLEARWATER DEPLOYMENT ################ + ################ CLEARWATER DEPLOYMENT ################ start_time_ts = time.time() end_time_ts = start_time_ts @@ -376,41 +423,47 @@ def main(): 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) + logger.info("vIMS VNF deployment duration:'%s'" % CW_DEPLOYMENT_DURATION) - ################ CLEARWATER TEST ################ + ################ CLEARWATER TEST ################ test_clearwater() - ########### CLEARWATER UNDEPLOYMENT ############ + ########### CLEARWATER UNDEPLOYMENT ############ cw.undeploy_vnf() - ############ CLOUDIFY UNDEPLOYMENT ############# + ############ CLOUDIFY UNDEPLOYMENT ############# cfy.undeploy_manager() - ############### GENERAL CLEANUP ################ + ############### GENERAL CLEANUP ################ 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']) + 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']) + 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.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']) + 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']) + 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']) + logger.error("Error : Failed to remove %s user" % + CFY_INPUTS['keystone_username']) if __name__ == '__main__': -- cgit 1.2.3-korg