From 8553c686e32c0fa54affb4745e04cce6e36a98ff Mon Sep 17 00:00:00 2001 From: "jose.lausuch" Date: Sat, 9 May 2015 22:44:17 +0200 Subject: Added functest.yaml to centralize the common parameters for all scripts of functest adapted scripts to get the parameters from the yaml JIRA: FUNCTEST-1 JIRA: FUNCTEST-3 Change-Id: Id761394c3cd0efec611c9c511adfee041c3f4c58 Signed-off-by: jose.lausuch --- testcases/VIM/OpenStack/CI/libraries/run_rally.py | 47 +++++----- testcases/config_functest.py | 107 ++++++++++++---------- testcases/functest.yaml | 26 ++++++ testcases/vPing/CI/libraries/vPing.py | 40 +++++--- 4 files changed, 140 insertions(+), 80 deletions(-) create mode 100644 testcases/functest.yaml (limited to 'testcases') diff --git a/testcases/VIM/OpenStack/CI/libraries/run_rally.py b/testcases/VIM/OpenStack/CI/libraries/run_rally.py index 0bcb6316c..2bfb8127f 100644 --- a/testcases/VIM/OpenStack/CI/libraries/run_rally.py +++ b/testcases/VIM/OpenStack/CI/libraries/run_rally.py @@ -8,7 +8,15 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 # -import re, json, os, urllib2, argparse, logging +import re, json, os, urllib2, argparse, logging, yaml + +with open('../functest.yaml') as f: + functest_yaml = yaml.safe_load(f) +f.close() + +HOME = os.environ['HOME']+"/" +SCENARIOS_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_rally_scn") +RESULTS_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_rally_res") """ tests configuration """ tests = ['authenticate', 'glance', 'cinder', 'heat', 'keystone', 'neutron', 'nova', 'quotas', 'requests', 'tempest', 'vm', 'all', 'smoke'] @@ -55,7 +63,7 @@ def get_tempest_id(cmd_raw): match = taskid_re.match(line) if match: - return match.group(1) + return match.group(1) return None def get_task_id(cmd_raw): @@ -111,17 +119,16 @@ def run_tempest(): logger.debug('task_id : {}'.format(task_id)) if task_id is None: - logger.error("failed to retrieve task_id") - exit(-1) + logger.error("failed to retrieve task_id") + exit(-1) """ check for result directory and create it otherwise """ - report_path = "./results" - if not os.path.exists(report_path): - logger.debug('does not exists, we create it'.format(report_path)) - os.makedirs(report_path) + if not os.path.exists(RESULTS_DIR): + logger.debug('does not exists, we create it'.format(RESULTS_DIR)) + os.makedirs(RESULTS_DIR) """ write log report file """ - report_file_name = '{}/opnfv-tempest-{}.log'.format(report_path, test_date) + report_file_name = '{}opnfv-tempest-{}.log'.format(RESULTS_DIR, test_date) cmd_line = "rally verify detailed {} > {} ".format(task_id, report_file_name) logger.debug('running command line : {}'.format(cmd_line)) os.popen(cmd_line) @@ -141,15 +148,14 @@ def run_task(test_name): """ check directory for scenarios test files or retrieve from git otherwise""" proceed_test = True - tests_path = "./scenarios" - test_file_name = '{}/opnfv-{}.json'.format(tests_path, test_name) + test_file_name = '{}opnfv-{}.json'.format(SCENARIOS_DIR, test_name) if not os.path.exists(test_file_name): logger.debug('{} does not exists'.format(test_file_name)) - proceed_test = retrieve_test_cases_file(test_name, tests_path) + proceed_test = retrieve_test_cases_file(test_name, SCENARIOS_DIR) """ we do the test only if we have a scenario test file """ if proceed_test: - logger.debug('successfully downloaded to : {}'.format(test_file_name)) + logger.debug('Scenario fetched from : {}'.format(test_file_name)) cmd_line = "rally task start --abort-on-sla-failure %s" % test_file_name logger.debug('running command line : {}'.format(cmd_line)) cmd = os.popen(cmd_line) @@ -161,13 +167,12 @@ def run_task(test_name): exit(-1) """ check for result directory and create it otherwise """ - report_path = "./results" - if not os.path.exists(report_path): - logger.debug('does not exists, we create it'.format(report_path)) - os.makedirs(report_path) + if not os.path.exists(RESULTS_DIR): + logger.debug('does not exists, we create it'.format(RESULTS_DIR)) + os.makedirs(RESULTS_DIR) """ write html report file """ - report_file_name = '{}/opnfv-{}-{}.html'.format(report_path, test_name, test_date) + report_file_name = '{}opnfv-{}-{}.html'.format(RESULTS_DIR, test_name, test_date) cmd_line = "rally task report %s --out %s" % (task_id, report_file_name) logger.debug('running command line : {}'.format(cmd_line)) os.popen(cmd_line) @@ -177,7 +182,7 @@ def run_task(test_name): logger.debug('running command line : {}'.format(cmd_line)) cmd = os.popen(cmd_line) json_results = cmd.read() - with open('{}/opnfv-{}-{}.json'.format(report_path, test_name, test_date), 'w') as f: + with open('{}opnfv-{}-{}.json'.format(RESULTS_DIR, test_name, test_date), 'w') as f: logger.debug('saving json file') f.write(json_results) logger.debug('saving json file2') @@ -188,7 +193,7 @@ def run_task(test_name): else: print 'Test KO' else: - logger.error('{} test failed, unable to download a scenario test file'.format(test_name)) + logger.error('{} test failed, unable to fetch a scenario test file'.format(test_name)) def retrieve_test_cases_file(test_name, tests_path): @@ -232,7 +237,7 @@ def main(): else: print(args.test_name) if args.test_name == 'tempest': - run_tempest() + run_tempest() else: run_task(args.test_name) diff --git a/testcases/config_functest.py b/testcases/config_functest.py index ad804d146..7a74fbd56 100644 --- a/testcases/config_functest.py +++ b/testcases/config_functest.py @@ -8,26 +8,35 @@ # http://www.apache.org/licenses/LICENSE-2.0 # -import re, json, os, urllib2, argparse, logging, shutil, subprocess +import re, json, os, urllib2, argparse, logging, shutil, subprocess, yaml from git import Repo actions = ['start', 'check', 'clean'] -""" global variables """ -functest_dir = os.environ['HOME'] + '/.functest/' -#image_url = 'https://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img' -image_url = 'http://download.cirros-cloud.net/0.3.0/cirros-0.3.0-i386-disk.img' +with open('functest.yaml') as f: + functest_yaml = yaml.safe_load(f) +f.close() -image_disk_format = 'raw' -image_name = image_url.rsplit('/')[-1] -image_path = functest_dir + image_name -rally_repo_dir = functest_dir + "Rally_repo/" -rally_test_dir = functest_dir + "Rally_test/" -bench_tests_dir = rally_test_dir + "scenarios/" -rally_installation_dir = os.environ['HOME'] + "/.rally" -vPing_dir = functest_dir + "vPing/" -odl_dir = functest_dir + "ODL/" +logger.info("Downloading functest.yaml...") +yaml_url = 'https://git.opnfv.org/cgit/functest/plain/testcases/functest.yaml' +if not download_url(yaml_url,"./"): + logger.error("Unable to download the configuration file functest.yaml") + exit(-1) +""" global variables """ +HOME = os.environ['HOME']+"/" +FUNCTEST_BASE_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_functest") +RALLY_REPO_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_rally_repo") +RALLY_TEST_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_rally") +RALLY_INSTALLATION_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_rally_inst") +BENCH_TESTS_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_rally_scn") +VPING_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_vping") +ODL_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_odl") +IMAGE_URL = functest_yaml.get("general").get("openstack").get("image_url") +IMAGE_DISK_FORMAT = functest_yaml.get("general").get("openstack").get("image_disk_format") +IMAGE_NAME = functest_yaml.get("general").get("openstack").get("image_name") +IMAGE_FILE_NAME = IMAGE_URL.rsplit('/')[-1] +IMAGE_DOWNLOAD_PATH = FUNCTEST_BASE_DIR + IMAGE_FILE_NAME parser = argparse.ArgumentParser() parser.add_argument("action", help="Possible actions are: '{d[0]}|{d[1]}|{d[2]}' ".format(d=actions)) @@ -56,7 +65,7 @@ def config_functest_start(): Start the functest environment installation """ if config_functest_check(): - logger.info("Functest environment already installed in %s. Nothing to do." %functest_dir) + logger.info("Functest environment already installed in %s. Nothing to do." %FUNCTEST_BASE_DIR) exit(0) elif not check_internet_connectivity(): logger.error("There is no Internet connectivity. Please check the network configuration.") @@ -68,9 +77,9 @@ def config_functest_start(): else: config_functest_clean() - logger.info("Starting installationg of functest environment in %s" %functest_dir) - os.makedirs(functest_dir) - if not os.path.exists(functest_dir): + logger.info("Starting installationg of functest environment in %s" %FUNCTEST_BASE_DIR) + os.makedirs(FUNCTEST_BASE_DIR) + if not os.path.exists(FUNCTEST_BASE_DIR): logger.error("There has been a problem while creating the environment directory.") exit(-1) @@ -93,13 +102,13 @@ def config_functest_start(): exit(-1) logger.info("Donwloading image...") - if not download_url_with_progress(image_url, functest_dir): + if not download_url_with_progress(IMAGE_URL, FUNCTEST_BASE_DIR): logger.error("There has been a problem while downloading the image.") config_functest_clean() exit(-1) - logger.info("Creating Glance image: %s ..." %image_name) - if not create_glance_image(image_path,image_name,image_disk_format): + logger.info("Creating Glance image: %s ..." %IMAGE_NAME) + if not create_glance_image(IMAGE_DOWNLOAD_PATH,IMAGE_NAME,IMAGE_DISK_FORMAT): logger.error("There has been a problem while creating the Glance image.") config_functest_clean() exit(-1) @@ -115,7 +124,7 @@ def config_functest_check(): logger.info("Checking current functest configuration...") logger.debug("Checking directories...") - dirs = [functest_dir, rally_installation_dir, rally_repo_dir, rally_test_dir, bench_tests_dir, vPing_dir, odl_dir] + dirs = [FUNCTEST_BASE_DIR, RALLY_INSTALLATION_DIR, RALLY_REPO_DIR, RALLY_TEST_DIR, BENCH_TESTS_DIR, VPING_DIR, ODL_DIR] for dir in dirs: if not os.path.exists(dir): logger.debug("The directory %s does not exist." %dir) @@ -130,11 +139,11 @@ def config_functest_check(): logger.debug("...OK") logger.debug("Checking Image...") - if not os.path.isfile(image_path): + if not os.path.isfile(IMAGE_DOWNLOAD_PATH): return False - logger.debug(" Image file found in %s" %image_path) + logger.debug(" Image file found in %s" %IMAGE_DOWNLOAD_PATH) - cmd="glance image-list | grep " + image_name + cmd="glance image-list | grep " + IMAGE_NAME FNULL = open(os.devnull, 'w'); logger.debug(' Executing command : {}'.format(cmd)) p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=FNULL); @@ -158,17 +167,17 @@ def config_functest_clean(): Clean the existing functest environment """ logger.info("Removing current functest environment...") - if os.path.exists(rally_installation_dir): - logger.debug("Removing rally installation directory %s" % rally_installation_dir) - shutil.rmtree(rally_installation_dir,ignore_errors=True) + if os.path.exists(RALLY_INSTALLATION_DIR): + logger.debug("Removing rally installation directory %s" % RALLY_INSTALLATION_DIR) + shutil.rmtree(RALLY_INSTALLATION_DIR,ignore_errors=True) - if os.path.exists(functest_dir): - logger.debug("Removing functest directory %s" % functest_dir) - cmd = "sudo rm -rf " + functest_dir #need to be sudo, not possible with rmtree + if os.path.exists(FUNCTEST_BASE_DIR): + logger.debug("Removing functest directory %s" % FUNCTEST_BASE_DIR) + cmd = "sudo rm -rf " + FUNCTEST_BASE_DIR #need to be sudo, not possible with rmtree execute_command(cmd) logger.debug("Deleting glance images") - cmd = "glance image-list | grep "+image_name+" | cut -c3-38" + cmd = "glance image-list | grep "+IMAGE_NAME+" | cut -c3-38" p = os.popen(cmd,"r") #while image_id = p.readline() @@ -185,10 +194,10 @@ def install_rally(): else: logger.debug("Cloning repository...") url = "https://git.openstack.org/openstack/rally" - Repo.clone_from(url, rally_repo_dir) + Repo.clone_from(url, RALLY_REPO_DIR) - logger.debug("Executing %s./install_rally.sh..." %rally_repo_dir) - install_script = rally_repo_dir + "install_rally.sh" + logger.debug("Executing %s./install_rally.sh..." %RALLY_REPO_DIR) + install_script = RALLY_REPO_DIR + "install_rally.sh" cmd = 'sudo ' + install_script execute_command(cmd) #subprocess.call(['sudo', install_script]) @@ -219,8 +228,8 @@ def check_rally(): """ Check if Rally is installed and properly configured """ - if os.path.exists(rally_installation_dir): - logger.debug(" Rally installation directory found in %s" % rally_installation_dir) + if os.path.exists(RALLY_INSTALLATION_DIR): + logger.debug(" Rally installation directory found in %s" % RALLY_INSTALLATION_DIR) FNULL = open(os.devnull, 'w'); cmd="rally deployment list | grep opnfv"; logger.debug(' Executing command : {}'.format(cmd)) @@ -238,9 +247,9 @@ def check_rally(): def install_odl(): - cmd = "chmod +x " + odl_dir + "create_venv.sh" + cmd = "chmod +x " + ODL_DIR + "create_venv.sh" execute_command(cmd) - cmd = odl_dir + "create_venv.sh" + cmd = ODL_DIR + "create_venv.sh" execute_command(cmd) return True @@ -274,19 +283,25 @@ def check_credentials(): def download_tests(): - os.makedirs(vPing_dir) - os.makedirs(odl_dir) - os.makedirs(bench_tests_dir) + os.makedirs(VPING_DIR) + os.makedirs(ODL_DIR) + os.makedirs(BENCH_TESTS_DIR) + + logger.info("Downloading functest.yaml...") + yaml_url = 'https://git.opnfv.org/cgit/functest/plain/testcases/functest.yaml' + if not download_url(yaml_url,FUNCTEST_BASE_DIR): + logger.error("Unable to download the configuration file functest.yaml") + return False logger.info("Downloading vPing test...") vPing_url = 'https://git.opnfv.org/cgit/functest/plain/testcases/vPing/CI/libraries/vPing.py' - if not download_url(vPing_url,vPing_dir): + if not download_url(vPing_url,VPING_DIR): return False logger.info("Downloading Rally bench tests...") run_rally_url = 'https://git.opnfv.org/cgit/functest/plain/testcases/VIM/OpenStack/CI/libraries/run_rally.py' - if not download_url(run_rally_url,rally_test_dir): + if not download_url(run_rally_url,RALLY_TEST_DIR): return False rally_bench_base_url = 'https://git.opnfv.org/cgit/functest/plain/testcases/VIM/OpenStack/CI/suites/' @@ -294,7 +309,7 @@ def download_tests(): for i in bench_tests: rally_bench_url = rally_bench_base_url + "opnfv-" + i + ".json" logger.debug("Downloading %s" %rally_bench_url) - if not download_url(rally_bench_url,bench_tests_dir): + if not download_url(rally_bench_url,BENCH_TESTS_DIR): return False logger.info("Downloading OLD tests...") @@ -303,7 +318,7 @@ def download_tests(): for i in odl_tests: odl_url = odl_base_url + i logger.debug("Downloading %s" %odl_url) - if not download_url(odl_url,odl_dir): + if not download_url(odl_url,ODL_DIR): return False return True diff --git a/testcases/functest.yaml b/testcases/functest.yaml new file mode 100644 index 000000000..c103834d1 --- /dev/null +++ b/testcases/functest.yaml @@ -0,0 +1,26 @@ +--- +general: + directories: + dir_functest: .functest/ + dir_rally_repo: .functest/Rally_repo/ + dir_rally: .functest/Rally_test/ + dir_rally_scn: .functest/Rally_test/scenarios/ + dir_rally_res: .functest/Rally_test/results/ + dir_vping: .functest/vPing/ + dir_odl: .functest/ODL/ + dir_rally_inst: .rally/ + openstack: + image_name: Ubuntu14.04 + image_url: https://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img + image_disk_format: raw + neutron_net_name: functest-net + neutron_subnet_name: functest-subnet + neutro_subnet_range: 192.168.120.0/24 + neutron_subnet_start: 192.168.120.2 + neutron_subnet_end: 192.168.120.254 + neutron_subnet_gateway: 192.168.120.254 +vping: + ping_timeout: 200 + vm_flavor: m1.small #adapt to your environment + vm_name_1: opnfv-vping-1 + vm_name_2: opnfv-vping-2 diff --git a/testcases/vPing/CI/libraries/vPing.py b/testcases/vPing/CI/libraries/vPing.py index ed94df2fa..d140eee18 100644 --- a/testcases/vPing/CI/libraries/vPing.py +++ b/testcases/vPing/CI/libraries/vPing.py @@ -13,26 +13,27 @@ # Note: this is script works only with Ubuntu image, not with Cirros image # -import os +import os, time, subprocess, logging, argparse, yaml import pprint -import subprocess -import time -import argparse -import logging import novaclient.v2.client as novaclient +import neutronclient.client as neutronclient #import novaclient.v1_1.client as novaclient import cinderclient.v1.client as cinderclient pp = pprint.PrettyPrinter(indent=4) EXIT_CODE = -1 -#tODO: this parameters should be taken from a conf file -PING_TIMEOUT = 200 -NAME_VM_1 = "opnfv-vping-1" -NAME_VM_2 = "opnfv-vping-2" -GLANCE_IMAGE_NAME = "trusty-server-cloudimg-amd64-disk1.img" -NEUTRON_NET_NAME = "test" -FLAVOR = "m1.small" +with open('../functest.yaml') as f: + functest_yaml = yaml.safe_load(f) +f.close() + +PING_TIMEOUT = functest_yaml.get("vping").get("ping_timeout") +NAME_VM_1 = functest_yaml.get("vping").get("vm_name_1") +NAME_VM_2 = functest_yaml.get("vping").get("vm_name_2") +GLANCE_IMAGE_NAME = functest_yaml.get("general").get("openstack").get("image_name") +NEUTRON_NET_NAME = functest_yaml.get("general").get("openstack").get("neutron_net_name") +FLAVOR = functest_yaml.get("vping").get("vm_flavor") + parser = argparse.ArgumentParser() parser.add_argument("-d", "--debug", help="Debug mode", action="store_true") @@ -123,7 +124,7 @@ def main(): print_title("servers list") pMsg(nova.servers.list()) """ - + # Check if the given image is created images=nova.images.list() image_found = False for image in images: @@ -136,6 +137,19 @@ def main(): pMsg(nova.images.list()) exit(-1) + # Check if the given neutron network is created + networks=nova.networks.list() + network_found = False + for net in networks: + if net.human_id == NEUTRON_NET_NAME: + logger.info("Network found '%s'" %net.human_id) + network_found = True + if not network_found: + logger.error("ERROR: Neutron network %s not found." % NEUTRON_NET_NAME) + logger.info("Available networks are: ") + pMsg(nova.networks.list()) + exit(-1) + servers=nova.servers.list() for server in servers: if server.name == NAME_VM_1 or server.name == NAME_VM_2: -- cgit 1.2.3-korg