diff options
Diffstat (limited to 'testcases/config_functest.py')
-rwxr-xr-x[-rw-r--r--] | testcases/config_functest.py | 108 |
1 files changed, 58 insertions, 50 deletions
diff --git a/testcases/config_functest.py b/testcases/config_functest.py index 7fbd06042..507e24696 100644..100755 --- a/testcases/config_functest.py +++ b/testcases/config_functest.py @@ -13,6 +13,7 @@ import functest_utils from git import Repo from os import stat from pwd import getpwuid +from neutronclient.v2_0 import client as neutronclient actions = ['start', 'check', 'clean'] parser = argparse.ArgumentParser() @@ -50,33 +51,31 @@ f.close() """ global variables """ # Directories -HOME = os.environ['HOME']+"/" REPO_PATH = args.repo_path RALLY_DIR = REPO_PATH + functest_yaml.get("general").get("directories").get("dir_rally") -RALLY_REPO_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_rally_repo") -RALLY_INSTALLATION_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_rally_inst") -RALLY_RESULT_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_rally_res") +RALLY_REPO_DIR = functest_yaml.get("general").get("directories").get("dir_repo_rally") +RALLY_INSTALLATION_DIR = functest_yaml.get("general").get("directories").get("dir_rally_inst") +RALLY_RESULT_DIR = functest_yaml.get("general").get("directories").get("dir_rally_res") VPING_DIR = REPO_PATH + functest_yaml.get("general").get("directories").get("dir_vping") ODL_DIR = REPO_PATH + functest_yaml.get("general").get("directories").get("dir_odl") +IMAGE_DIR = functest_yaml.get("general").get("directories").get("dir_functest_data") +# Tempest/Rally configuration details +DEPLOYMENT_MAME = "opnfv-rally" +RALLY_COMMIT = functest_yaml.get("general").get("openstack").get("rally_stable_commit") #GLANCE image parameters 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_DIR = HOME + functest_yaml.get("general").get("openstack").get("image_download_path") -IMAGE_PATH = IMAGE_DIR + IMAGE_FILE_NAME +IMAGE_PATH = IMAGE_DIR + "/" + IMAGE_FILE_NAME def action_start(): """ Start the functest environment installation """ - if not check_permissions(): - logger.error("Bad Python cache directory ownership.") - exit(-1) - if not functest_utils.check_internet_connectivity(): logger.error("There is no Internet connectivity. Please check the network configuration.") exit(-1) @@ -90,11 +89,6 @@ def action_start(): logger.debug("Cleaning possible functest environment leftovers.") action_clean() - logger.info("Installing needed libraries on the host") - cmd = "sudo yum -y install gcc libffi-devel python-devel openssl-devel gmp-devel libxml2-devel libxslt-devel postgresql-devel git wget" - if not functest_utils.execute_command(cmd, logger): - logger.error("There has been a problem while installing software packages.") - exit(-1) logger.info("Installing ODL environment...") if not install_odl(): @@ -109,6 +103,12 @@ def action_start(): action_clean() exit(-1) + logger.info("Configuring Tempest...") + if not configure_tempest(): + logger.error("There has been a problem while configuring Tempest.") + action_clean() + exit(-1) + # Create result folder under functest if necessary if not os.path.exists(RALLY_RESULT_DIR): os.makedirs(RALLY_RESULT_DIR) @@ -133,11 +133,11 @@ def action_check(): Check if the functest environment is properly installed """ errors_all = False - + errors = False logger.info("Checking current functest configuration...") logger.debug("Checking script directories...") - errors = False + dirs = [RALLY_DIR, RALLY_INSTALLATION_DIR, VPING_DIR, ODL_DIR] for dir in dirs: if not os.path.exists(dir): @@ -188,11 +188,7 @@ def action_check(): logger.debug("...FAIL") #TODO: check OLD environment setup - if errors_all: - return False - else: - return True - + return not errors_all @@ -205,11 +201,6 @@ def action_clean(): logger.debug("Removing Rally installation directory %s" % RALLY_INSTALLATION_DIR) shutil.rmtree(RALLY_INSTALLATION_DIR,ignore_errors=True) - if os.path.exists(RALLY_REPO_DIR): - logger.debug("Removing Rally repository %s" % RALLY_REPO_DIR) - cmd = "sudo rm -rf " + RALLY_REPO_DIR #need to be sudo, not possible with rmtree - functest_utils.execute_command(cmd,logger) - if os.path.exists(IMAGE_PATH): logger.debug("Deleting image") os.remove(IMAGE_PATH) @@ -231,35 +222,17 @@ def action_clean(): -def check_permissions(): - current_user = getpass.getuser() - cache_dir = HOME+".cache/pip" - logger.info("Checking permissions of '%s'..." %cache_dir) - logger.debug("Current user is '%s'" %current_user) - cache_user = getpwuid(stat(cache_dir).st_uid).pw_name - logger.debug("Cache directory owner is '%s'" %cache_user) - if cache_user != current_user: - logger.info("The owner of '%s' is '%s'. Please run 'sudo chown -R %s %s'." %(cache_dir, cache_user, current_user, cache_dir)) - return False - - return True - - def install_rally(): if check_rally(): logger.info("Rally is already installed.") else: - logger.debug("Cloning repository...") - url = "https://git.openstack.org/openstack/rally" - 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 --yes" + logger.debug("Executing %s/install_rally.sh..." %RALLY_REPO_DIR) + install_script = RALLY_REPO_DIR + "/install_rally.sh --yes" cmd = 'sudo ' + install_script functest_utils.execute_command(cmd,logger) logger.debug("Creating Rally environment...") - cmd = "rally deployment create --fromenv --name=opnfv-arno-rally" + cmd = "rally deployment create --fromenv --name="+DEPLOYMENT_MAME functest_utils.execute_command(cmd,logger) logger.debug("Installing tempest...") @@ -279,6 +252,40 @@ def install_rally(): return True +def configure_tempest(): + """ + Add/update needed parameters into tempest.conf file generated by Rally + """ + + creds_neutron = functest_utils.get_credentials("neutron") + neutron_client = neutronclient.Client(**creds_neutron) + + logger.debug("Generating tempest.conf file...") + cmd = "rally verify genconfig" + functest_utils.execute_command(cmd,logger) + + logger.debug("Resolving deployment UUID...") + cmd = "rally deployment list | awk '/"+DEPLOYMENT_MAME+"/ {print $2}'" + p = subprocess.Popen(cmd, shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT); + deployment_uuid = p.stdout.readline().rstrip() + if deployment_uuid == "": + logger.debug(" Rally deployment NOT found") + return False + + logger.debug("Finding tempest.conf file...") + tempest_conf_file = RALLY_INSTALLATION_DIR+"/tempest/for-deployment-" \ + +deployment_uuid+"/tempest.conf" + + logger.debug(" Updating fixed_network_name...") + fixed_network = functest_utils.get_network_list(neutron_client)[0]['name'] + if fixed_network != None: + cmd = "crudini --set "+tempest_conf_file+" compute fixed_network_name "+fixed_network + functest_utils.execute_command(cmd,logger) + + return True + def check_rally(): """ @@ -287,7 +294,7 @@ def check_rally(): 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"; + cmd="rally deployment list | grep "+DEPLOYMENT_MAME logger.debug(' Executing command : {}'.format(cmd)) p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=FNULL); #if the command does not exist or there is no deployment @@ -316,7 +323,8 @@ def create_glance_image(path,name,disk_format): """ Create a glance image given the absolute path of the image, its name and the disk format """ - cmd = "glance image-create --name "+name+" --is-public true --disk-format "+disk_format+" --container-format bare --file "+path + cmd = ("glance image-create --name "+name+" --visibility public " + "--disk-format "+disk_format+" --container-format bare --file "+path) functest_utils.execute_command(cmd,logger) return True |