actions = ['start', 'check', 'clean']
parser = argparse.ArgumentParser()
-parser.add_argument("repo_path", help="Path to the repository")
parser.add_argument("action", help="Possible actions are: '{d[0]}|{d[1]}|{d[2]}' ".format(d=actions))
parser.add_argument("-d", "--debug", help="Debug mode", action="store_true")
parser.add_argument("-f", "--force", help="Force", action="store_true")
ch.setFormatter(formatter)
logger.addHandler(ch)
-if not os.path.exists(args.repo_path):
- logger.error("Repo directory not found '%s'" % args.repo_path)
+REPOS_DIR=os.environ['repos_dir']
+FUNCTEST_REPO=REPOS_DIR+'/functest/'
+if not os.path.exists(FUNCTEST_REPO):
+ logger.error("Functest repository directory not found '%s'" % FUNCTEST_REPO)
exit(-1)
+sys.path.append(FUNCTEST_REPO + "testcases/")
-with open(args.repo_path+"testcases/config_functest.yaml") as f:
+with open("/home/opnfv/functest/conf/config_functest.yaml") as f:
functest_yaml = yaml.safe_load(f)
f.close()
-
-
""" global variables """
# Directories
-REPO_PATH = args.repo_path
-RALLY_DIR = REPO_PATH + functest_yaml.get("general").get("directories").get("dir_rally")
+RALLY_DIR = FUNCTEST_REPO + functest_yaml.get("general").get("directories").get("dir_rally")
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")
+VPING_DIR = FUNCTEST_REPO + functest_yaml.get("general").get("directories").get("dir_vping")
+VIMS_TEST_DIR = functest_yaml.get("general").get("directories").get("dir_repo_vims_test")
+ODL_DIR = FUNCTEST_REPO + functest_yaml.get("general").get("directories").get("dir_odl")
+DATA_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_PATH = IMAGE_DIR + "/" + IMAGE_FILE_NAME
-
+DEPLOYMENT_MAME = functest_yaml.get("rally").get("deployment_name")
+RALLY_COMMIT = functest_yaml.get("general").get("repositories").get("rally_commit")
+
+#Image (cirros)
+IMAGE_FILE_NAME = functest_yaml.get("general").get("openstack").get("image_file_name")
+IMAGE_PATH = DATA_DIR + "/" + IMAGE_FILE_NAME
+
+# NEUTRON Private Network parameters
+NEUTRON_PRIVATE_NET_NAME = functest_yaml.get("general"). \
+ get("openstack").get("neutron_private_net_name")
+NEUTRON_PRIVATE_SUBNET_NAME = functest_yaml.get("general"). \
+ get("openstack").get("neutron_private_subnet_name")
+NEUTRON_PRIVATE_SUBNET_CIDR = functest_yaml.get("general"). \
+ get("openstack").get("neutron_private_subnet_cidr")
+NEUTRON_ROUTER_NAME = functest_yaml.get("general"). \
+ get("openstack").get("neutron_router_name")
+
+creds_neutron = functest_utils.get_credentials("neutron")
+neutron_client = neutronclient.Client(**creds_neutron)
def action_start():
"""
# Clean in case there are left overs
logger.debug("Cleaning possible functest environment leftovers.")
action_clean()
+ logger.info("Starting installation of functest environment")
+ private_net = functest_utils.get_private_net(neutron_client)
+ if private_net is None:
+ # If there is no private network in the deployment we create one
+ if not create_private_neutron_net(neutron_client):
+ logger.error("There has been a problem while creating the functest network.")
+ action_clean()
+ exit(-1)
+ else:
+ logger.info("Private network '%s' already existing in the deployment."
+ % private_net['name'])
- logger.info("Installing ODL environment...")
- if not install_odl():
- logger.error("There has been a problem while installing Robot.")
- action_clean()
- exit(-1)
-
- logger.info("Starting installation of functest environment")
logger.info("Installing Rally...")
if not install_rally():
logger.error("There has been a problem while installing Rally.")
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)
+ logger.info("Installing Ruby libraries for vIMS testcase...")
+ # Install ruby libraries for vims test-case
+ script = 'source /etc/profile.d/rvm.sh; '
+ script += 'cd ' + VIMS_TEST_DIR + '; '
+ script += 'rvm autolibs enable ;'
+ script += 'rvm install 1.9.3; '
+ script += 'rvm use 1.9.3;'
+ script += 'bundle install'
+
+ logger_debug = None
+ CI_DEBUG = os.environ.get("CI_DEBUG")
+ if CI_DEBUG == "true" or CI_DEBUG == "True":
+ logger_debug = logger
+
+ cmd = "/bin/bash -c '" + script + "'"
+ functest_utils.execute_command(cmd, logger = logger_debug, exit_on_error=False)
+
+ install_promise(logger_debug)
# Create result folder under functest if necessary
if not os.path.exists(RALLY_RESULT_DIR):
os.makedirs(RALLY_RESULT_DIR)
- logger.info("Downloading image...")
- if not functest_utils.download_url(IMAGE_URL, IMAGE_DIR):
- logger.error("There has been a problem downloading the image '%s'." %IMAGE_URL)
- action_clean()
- exit(-1)
-
- logger.info("Creating Glance image: %s ..." %IMAGE_NAME)
- if not create_glance_image(IMAGE_PATH,IMAGE_NAME,IMAGE_DISK_FORMAT):
- logger.error("There has been a problem while creating the Glance image.")
- action_clean()
- exit(-1)
+ try:
+ logger.info("CI: Generate the list of executable tests.")
+ runnable_test = functest_utils.generateTestcaseList(functest_yaml)
+ logger.info("List of runnable tests generated: %s" % runnable_test)
+ except:
+ logger.error("Impossible to generate the list of runnable tests")
exit(0)
dirs = [RALLY_DIR, RALLY_INSTALLATION_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(" %s NOT found" % dir)
errors = True
errors_all = True
else:
logger.debug(" %s found" % dir)
- if not errors:
- logger.debug("...OK")
- else:
- logger.debug("...FAIL")
-
logger.debug("Checking Rally deployment...")
if not check_rally():
logger.debug(" Rally deployment NOT installed.")
errors_all = True
- logger.debug("...FAIL")
- else:
- logger.debug("...OK")
logger.debug("Checking Image...")
errors = False
else:
logger.debug(" Image file found in %s" % IMAGE_PATH)
- 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);
- #if the command does not exist or there is no glance image
- line = p.stdout.readline()
- if line == "":
- logger.debug(" Glance image NOT found.")
- errors = True
- errors_all = True
- else:
- logger.debug(" Glance image found.")
-
- if not errors:
- logger.debug("...OK")
- else:
- logger.debug("...FAIL")
#TODO: check OLD environment setup
return not errors_all
logger.debug("Removing Rally installation directory %s" % RALLY_INSTALLATION_DIR)
shutil.rmtree(RALLY_INSTALLATION_DIR,ignore_errors=True)
- if os.path.exists(IMAGE_PATH):
- logger.debug("Deleting image")
- os.remove(IMAGE_PATH)
-
- cmd = "glance image-list | grep "+IMAGE_NAME+" | cut -c3-38"
- p = os.popen(cmd,"r")
-
- #while image_id = p.readline()
- for image_id in p.readlines():
- cmd = "glance image-delete " + image_id
- functest_utils.execute_command(cmd,logger)
-
if os.path.exists(RALLY_RESULT_DIR):
logger.debug("Removing Result directory")
shutil.rmtree(RALLY_RESULT_DIR,ignore_errors=True)
-
logger.info("Functest environment clean!")
if check_rally():
logger.info("Rally is already installed.")
else:
- logger.debug("Executing %s./install_rally.sh..." %RALLY_REPO_DIR)
+ 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)
+ if os.environ.get("CI_DEBUG") == "false":
+ functest_utils.execute_command(cmd)
+ else:
+ functest_utils.execute_command(cmd,logger)
logger.debug("Creating Rally environment...")
cmd = "rally deployment create --fromenv --name="+DEPLOYMENT_MAME
return True
+def install_promise(logger_debug):
+ logger.info("Installing dependencies for Promise testcase...")
+ current_dir = os.getcwd()
+ os.chdir(REPOS_DIR+'/promise/')
-def configure_tempest():
- """
- Add/update needed parameters into tempest.conf file generated by Rally
- """
+ cmd = 'curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -'
+ functest_utils.execute_command(cmd,logger = logger_debug, exit_on_error=False)
- 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
+ cmd = 'sudo apt-get install -y nodejs'
+ functest_utils.execute_command(cmd,logger = logger_debug, exit_on_error=False)
- logger.debug("Finding tempest.conf file...")
- tempest_conf_file = RALLY_INSTALLATION_DIR+"/tempest/for-deployment-" \
- +deployment_uuid+"/tempest.conf"
+ cmd = 'sudo npm -g install npm@latest'
+ functest_utils.execute_command(cmd,logger = logger_debug, exit_on_error=False)
- 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
+ cmd = 'npm install'
+ functest_utils.execute_command(cmd,logger = logger_debug, exit_on_error=False)
+ os.chdir(current_dir)
def check_rally():
return False
-def install_odl():
- cmd = "chmod +x " + ODL_DIR + "start_tests.sh"
- functest_utils.execute_command(cmd,logger)
- cmd = "chmod +x " + ODL_DIR + "create_venv.sh"
- functest_utils.execute_command(cmd,logger)
- cmd = ODL_DIR + "create_venv.sh"
- functest_utils.execute_command(cmd,logger)
- return True
+def create_private_neutron_net(neutron):
+ neutron.format = 'json'
+ logger.info("Creating network '%s'..." % NEUTRON_PRIVATE_NET_NAME)
+ network_id = functest_utils. \
+ create_neutron_net(neutron, NEUTRON_PRIVATE_NET_NAME)
+ if not network_id:
+ return False
+ logger.debug("Network '%s' created successfully." % network_id)
+ logger.info("Updating network '%s' with shared=True..." % NEUTRON_PRIVATE_NET_NAME)
+ if functest_utils.update_neutron_net(neutron, network_id, shared=True):
+ logger.debug("Network '%s' updated successfully." % network_id)
+ else:
+ logger.info("Updating neutron network '%s' failed" % network_id)
+
+ logger.info("Creating Subnet....")
+ subnet_id = functest_utils. \
+ create_neutron_subnet(neutron,
+ NEUTRON_PRIVATE_SUBNET_NAME,
+ NEUTRON_PRIVATE_SUBNET_CIDR,
+ network_id)
+ if not subnet_id:
+ return False
+ logger.debug("Subnet '%s' created successfully." % subnet_id)
+ logger.info("Creating Router...")
+ router_id = functest_utils. \
+ create_neutron_router(neutron, NEUTRON_ROUTER_NAME)
-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+" --visibility public "
- "--disk-format "+disk_format+" --container-format bare --file "+path)
- functest_utils.execute_command(cmd,logger)
- return True
+ if not router_id:
+ return False
+
+ logger.debug("Router '%s' created successfully." % router_id)
+ logger.info("Adding router to subnet...")
+
+ result = functest_utils.add_interface_router(neutron, router_id, subnet_id)
+ if not result:
+ return False
+ logger.debug("Interface added successfully.")
+ network_dic = {'net_id': network_id,
+ 'subnet_id': subnet_id,
+ 'router_id': router_id}
+ return True
def main():
#TODO: source the credentials in this script
exit(-1)
+
if args.action == "start":
action_start()