# 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']
match = taskid_re.match(line)
if match:
- return match.group(1)
+ return match.group(1)
return None
def get_task_id(cmd_raw):
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)
""" 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)
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)
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')
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):
else:
print(args.test_name)
if args.test_name == 'tempest':
- run_tempest()
+ run_tempest()
else:
run_task(args.test_name)
# 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))
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.")
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)
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)
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)
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);
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()
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])
"""
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))
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
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/'
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...")
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
# 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")
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:
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: