Revert "bug fix: get installer using functest_utils"
[functest.git] / testcases / config_functest.py
index 12ae647..21c569c 100755 (executable)
@@ -37,11 +37,12 @@ formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(messag
 ch.setFormatter(formatter)
 logger.addHandler(ch)
 
-REPO_PATH=os.environ['repos_dir']+'/functest/'
-if not os.path.exists(REPO_PATH):
-    logger.error("Functest repository directory not found '%s'" % 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(REPO_PATH + "testcases/")
+sys.path.append(FUNCTEST_REPO + "testcases/")
 
 with open("/home/opnfv/functest/conf/config_functest.yaml") as f:
     functest_yaml = yaml.safe_load(f)
@@ -50,13 +51,13 @@ f.close()
 
 """ global variables """
 # Directories
-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")
+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 = REPO_PATH + functest_yaml.get("general").get("directories").get("dir_odl")
+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
@@ -132,13 +133,7 @@ def action_start():
         cmd = "/bin/bash -c '" + script + "'"
         functest_utils.execute_command(cmd, logger = logger_debug, exit_on_error=False)
 
-
-        logger.info("Installing dependencies for Promise testcase...")
-        cmd = 'npm install -g yangforge'
-        functest_utils.execute_command(cmd,logger = logger_debug, exit_on_error=False)
-
-        cmd = 'npm install'
-        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):
@@ -167,24 +162,16 @@ def action_check():
     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
@@ -196,11 +183,6 @@ def action_check():
         logger.debug("   Image file found in %s" % IMAGE_PATH)
 
 
-    if not errors:
-        logger.debug("...OK")
-    else:
-        logger.debug("...FAIL")
-
     #TODO: check OLD environment setup
     return not errors_all
 
@@ -219,10 +201,6 @@ def action_clean():
         logger.debug("Removing Result directory")
         shutil.rmtree(RALLY_RESULT_DIR,ignore_errors=True)
 
-    logger.debug("Cleaning up the OpenStack deployment...")
-    cmd='python ' + REPO_PATH + \
-        '/testcases/VIM/OpenStack/CI/libraries/clean_openstack.py --debug'
-    functest_utils.execute_command(cmd,logger)
     logger.info("Functest environment clean!")
 
 
@@ -259,6 +237,24 @@ def install_rally():
 
     return True
 
+def install_promise(logger_debug):
+    logger.info("Installing dependencies for Promise testcase...")
+    current_dir = os.getcwd()
+    os.chdir(REPOS_DIR+'/promise/')
+
+    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)
+
+    cmd = 'sudo apt-get install -y nodejs'
+    functest_utils.execute_command(cmd,logger = logger_debug, exit_on_error=False)
+
+    cmd = 'sudo npm -g install npm@latest'
+    functest_utils.execute_command(cmd,logger = logger_debug, exit_on_error=False)
+
+    cmd = 'npm install'
+    functest_utils.execute_command(cmd,logger = logger_debug, exit_on_error=False)
+    os.chdir(current_dir)
+
 
 def check_rally():
     """
@@ -283,21 +279,21 @@ def check_rally():
 
 def create_private_neutron_net(neutron):
     neutron.format = 'json'
-    logger.info('Creating neutron network %s...' % NEUTRON_PRIVATE_NET_NAME)
+    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.debug("Network '%s' created successfully." % network_id)
 
-    logger.info('Updating neutron network %s...' % NEUTRON_PRIVATE_NET_NAME)
+    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)
+        logger.debug("Network '%s' updated successfully." % network_id)
     else:
-        logger.info('Updating neutron network %s failed' % network_id)
+        logger.info("Updating neutron network '%s' failed" % network_id)
 
-    logger.debug('Creating Subnet....')
+    logger.info("Creating Subnet....")
     subnet_id = functest_utils. \
         create_neutron_subnet(neutron,
                               NEUTRON_PRIVATE_SUBNET_NAME,
@@ -305,16 +301,16 @@ def create_private_neutron_net(neutron):
                               network_id)
     if not subnet_id:
         return False
-    logger.debug("Subnet '%s' created successfully" % subnet_id)
-    logger.debug('Creating Router...')
+    logger.debug("Subnet '%s' created successfully." % subnet_id)
+    logger.info("Creating Router...")
     router_id = functest_utils. \
         create_neutron_router(neutron, NEUTRON_ROUTER_NAME)
 
     if not router_id:
         return False
 
-    logger.debug("Router '%s' created successfully" % router_id)
-    logger.debug('Adding router to subnet...')
+    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)