def run_defcore(self, conf, testlist): logger.debug("Generating test case list...") cmd = ("cd {0};" "./refstack-client test -c {1} -v --test-list {2};" "cd -;".format(CONST.dir_refstack_client, conf, testlist)) ft_utils.execute_command(cmd)
def install_rally(): print_separator() logger.info("Creating Rally environment...") cmd = "rally deployment destroy opnfv-rally" ft_utils.execute_command(cmd, error_msg=( "Deployment %s does not exist." % CONST.rally_deployment_name), verbose=False) rally_conf = os_utils.get_credentials_for_rally() with open('rally_conf.json', 'w') as fp: json.dump(rally_conf, fp) cmd = ("rally deployment create " "--file=rally_conf.json --name={}" .format(CONST.rally_deployment_name)) ft_utils.execute_command(cmd, error_msg=("Problem while creating " "Rally deployment")) cmd = "rally deployment check" ft_utils.execute_command(cmd, error_msg=("OpenStack not responding or " "faulty Rally deployment.")) cmd = "rally deployment list" ft_utils.execute_command(cmd, error_msg=("Problem while listing " "Rally deployment.")) cmd = "rally plugin list | head -5" ft_utils.execute_command(cmd, error_msg=("Problem while showing " "Rally plugins."))
def install_tempest(): logger.info("Installing tempest from existing repo...") cmd = ("rally verify create-verifier --source {0} " "--name {1} --type tempest" .format(CONST.dir_repo_tempest, CONST.tempest_deployment_name)) ft_utils.execute_command(cmd, error_msg="Problem while installing Tempest.")
def configure_tempest(deployment_dir): """ Add/update needed parameters into tempest.conf file generated by Rally """ logger.debug("Generating tempest.conf file...") cmd = "rally verify genconfig" ft_utils.execute_command(cmd, logger) logger.debug("Finding tempest.conf file...") tempest_conf_file = deployment_dir + "/tempest.conf" if not os.path.isfile(tempest_conf_file): logger.error("Tempest configuration file %s NOT found." % tempest_conf_file) exit(-1) logger.debug("Updating selected tempest.conf parameters...") config = ConfigParser.RawConfigParser() config.read(tempest_conf_file) config.set('compute', 'fixed_network_name', PRIVATE_NET_NAME) config.set('identity', 'tenant_name', TENANT_NAME) config.set('identity', 'username', USER_NAME) config.set('identity', 'password', USER_PASSWORD) with open(tempest_conf_file, 'wb') as config_file: config.write(config_file) # Copy tempest.conf to /home/opnfv/functest/results/tempest/ shutil.copyfile(tempest_conf_file, TEMPEST_RESULTS_DIR + '/tempest.conf') return True
def generate_test_list(self, verifier_repo_dir): logger.debug("Generating test case list...") if self.MODE == 'defcore': shutil.copyfile(conf_utils.TEMPEST_DEFCORE, conf_utils.TEMPEST_RAW_LIST) elif self.MODE == 'custom': if os.path.isfile(conf_utils.TEMPEST_CUSTOM): shutil.copyfile(conf_utils.TEMPEST_CUSTOM, conf_utils.TEMPEST_RAW_LIST) else: raise Exception("Tempest test list file %s NOT found." % conf_utils.TEMPEST_CUSTOM) else: if self.MODE == 'smoke': testr_mode = "smoke" elif self.MODE == 'feature_multisite': testr_mode = "'[Kk]ingbird'" elif self.MODE == 'full': testr_mode = "" else: testr_mode = 'tempest.api.' + self.MODE cmd = ("cd {0};" "testr list-tests {1} > {2};" "cd -;".format(verifier_repo_dir, testr_mode, conf_utils.TEMPEST_RAW_LIST)) ft_utils.execute_command(cmd)
def create_rally_deployment(): # set the architecture to default pod_arch = os.getenv("POD_ARCH", None) arch_filter = ['aarch64'] if pod_arch and pod_arch in arch_filter: logger.info("Apply aarch64 specific to rally config...") with open(RALLY_AARCH64_PATCH_PATH, "r") as f: rally_patch_conf = f.read() for line in fileinput.input(RALLY_CONF_PATH, inplace=1): print line, if "cirros|testvm" in line: print rally_patch_conf logger.info("Creating Rally environment...") cmd = "rally deployment destroy opnfv-rally" ft_utils.execute_command(cmd, error_msg=( "Deployment %s does not exist." % CONST.__getattribute__('rally_deployment_name')), verbose=False) cmd = ("rally deployment create --fromenv --name={0}" .format(CONST.__getattribute__('rally_deployment_name'))) error_msg = "Problem while creating Rally deployment" ft_utils.execute_command_raise(cmd, error_msg=error_msg) cmd = "rally deployment check" error_msg = "OpenStack not responding or faulty Rally deployment." ft_utils.execute_command_raise(cmd, error_msg=error_msg)
def fetch_credentials(self): if os.path.isfile(RC_FILE): answer = raw_input("It seems the RC file is already present. " "Do you want to overwrite it? [y|n]\n") while True: if answer.lower() in ["y", "yes"]: break elif answer.lower() in ["n", "no"]: return else: answer = raw_input("Invalid answer. Please type [y|n]\n") CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE') if CI_INSTALLER_TYPE is None: click.echo("The environment variable 'INSTALLER_TYPE' is not" "defined. Please export it") CI_INSTALLER_IP = os.getenv('INSTALLER_IP') if CI_INSTALLER_IP is None: click.echo("The environment variable 'INSTALLER_IP' is not" "defined. Please export it") cmd = ("/home/opnfv/repos/releng/utils/fetch_os_creds.sh " "-d %s -i %s -a %s" % (RC_FILE, CI_INSTALLER_TYPE, CI_INSTALLER_IP)) click.echo("Fetching credentials from installer node '%s' with IP=%s.." % (CI_INSTALLER_TYPE, CI_INSTALLER_IP)) ft_utils.execute_command(cmd, verbose=False)
def fetch_credentials(self): if os.path.isfile(RC_FILE): answer = raw_input("It seems the RC file is already present. " "Do you want to overwrite it? [y|n]\n") while True: if answer.lower() in ["y", "yes"]: break elif answer.lower() in ["n", "no"]: return else: answer = raw_input("Invalid answer. Please type [y|n]\n") CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE') if CI_INSTALLER_TYPE is None: click.echo("The environment variable 'INSTALLER_TYPE' is not" "defined. Please export it") CI_INSTALLER_IP = os.getenv('INSTALLER_IP') if CI_INSTALLER_IP is None: click.echo("The environment variable 'INSTALLER_IP' is not" "defined. Please export it") cmd = ("/home/opnfv/repos/releng/utils/fetch_os_creds.sh " "-d %s -i %s -a %s" % (RC_FILE, CI_INSTALLER_TYPE, CI_INSTALLER_IP)) click.echo( "Fetching credentials from installer node '%s' with IP=%s.." % (CI_INSTALLER_TYPE, CI_INSTALLER_IP)) ft_utils.execute_command(cmd, verbose=False)
def fetch_credentials(self): if os.path.isfile(self.openstack_creds): answer = raw_input("It seems the RC file is already present. " "Do you want to overwrite it? [y|n]\n") while True: if answer.lower() in ["y", "yes"]: break elif answer.lower() in ["n", "no"]: return else: answer = raw_input("Invalid answer. Please type [y|n]\n") installer_type = CONST.INSTALLER_TYPE if installer_type is None: click.echo("The environment variable 'INSTALLER_TYPE' is not" "defined. Please export it") installer_ip = CONST.INSTALLER_IP if installer_ip is None: click.echo("The environment variable 'INSTALLER_IP' is not" "defined. Please export it") cmd = ("%s/releng/utils/fetch_os_creds.sh -d %s -i %s -a %s" % (CONST.dir_repos, self.openstack_creds, installer_type, installer_ip)) click.echo( "Fetching credentials from installer node '%s' with IP=%s.." % (installer_type, installer_ip)) ft_utils.execute_command(cmd, verbose=False)
def run_clearwater_live_test(self, dns_ip, public_domain, bono_ip=None, ellis_ip=None, signup_code='secret'): self.logger.info('Run Clearwater live test') nameservers = ft_utils.get_resolvconf_ns() resolvconf = [ '{0}{1}{2}'.format(os.linesep, 'nameserver ', ns) for ns in nameservers ] self.logger.debug('resolvconf: %s', resolvconf) dns_file = '/etc/resolv.conf' dns_file_bak = '/etc/resolv.conf.bak' shutil.copy(dns_file, dns_file_bak) script = ('echo -e "nameserver {0}{1}" > {2};' 'source /etc/profile.d/rvm.sh;' 'cd {3};' 'rake test[{4}] SIGNUP_CODE={5}'.format( dns_ip, ''.join(resolvconf), dns_file, self.test_dir, public_domain, signup_code)) if bono_ip and ellis_ip: subscript = ' PROXY={0} ELLIS={1}'.format(bono_ip, ellis_ip) script = '{0}{1}'.format(script, subscript) script = ('{0}{1}'.format(script, ' --trace')) cmd = "/bin/bash -c '{0}'".format(script) self.logger.info('Live test cmd: %s', cmd) output_file = os.path.join(self.result_dir, "ims_test_output.txt") ft_utils.execute_command(cmd, error_msg='Clearwater live test failed', output_file=output_file) with open(dns_file_bak, 'r') as bak_file: result = bak_file.read() with open(dns_file, 'w') as f: f.write(result) f = open(output_file, 'r') result = f.read() if result != "": self.logger.debug(result) vims_test_result = "" tempFile = os.path.join(self.test_dir, "temp.json") try: self.logger.debug("Trying to load test results") with open(tempFile) as f: vims_test_result = json.load(f) f.close() except Exception: self.logger.error("Unable to retrieve test results") try: os.remove(tempFile) except Exception: self.logger.error("Deleting file failed") return vims_test_result
def run(self, tiername): if not os.path.isfile(ENV_FILE): click.echo("Functest environment is not ready. " "Run first 'functest env prepare'") else: cmd = ("python /home/opnfv/repos/functest/ci/run_tests.py -t %s" % tiername) ft_utils.execute_command(cmd)
def prepare(self, args): # pylint: disable=no-self-use, unused-argument """ Prepare environment """ try: ft_utils.execute_command("prepare_env start") except Exception as err: # pylint: disable=broad-except return api_utils.result_handler(status=1, data=str(err)) return api_utils.result_handler(status=0, data="Prepare env successfully")
def run(tiername, noclean=False, report=False): flags = "" if noclean: flags += "-n " if report: flags += "-r " cmd = "run_tests {}-t {}".format(flags, tiername) ft_utils.execute_command(cmd)
def run_clearwater_live_test(self, dns_ip, public_domain, bono_ip=None, ellis_ip=None, signup_code='secret'): self.logger.info('Run Clearwater live test') dns_file = '/etc/resolv.conf' dns_file_bak = '/etc/resolv.conf.bak' self.logger.debug('Backup %s -> %s', dns_file, dns_file_bak) shutil.copy(dns_file, dns_file_bak) cmd = ("dnsmasq -d -u root --server=/clearwater.opnfv/{0} " "-r /etc/resolv.conf.bak".format(dns_ip)) dnsmasq_process = subprocess.Popen(shlex.split(cmd)) script = ('echo -e "nameserver {0}" > {1};' 'cd {2};' 'rake test[{3}] SIGNUP_CODE={4}' .format('127.0.0.1', dns_file, self.test_dir, public_domain, signup_code)) if bono_ip and ellis_ip: subscript = ' PROXY={0} ELLIS={1}'.format(bono_ip, ellis_ip) script = '{0}{1}'.format(script, subscript) script = ('{0}{1}'.format(script, ' --trace')) cmd = "/bin/bash -c '{0}'".format(script) self.logger.debug('Live test cmd: %s', cmd) output_file = os.path.join(self.result_dir, "ims_test_output.txt") ft_utils.execute_command(cmd, error_msg='Clearwater live test failed', output_file=output_file) dnsmasq_process.kill() with open(dns_file_bak, 'r') as bak_file: result = bak_file.read() with open(dns_file, 'w') as f: f.write(result) f = open(output_file, 'r') result = f.read() if result != "": self.logger.debug(result) vims_test_result = "" tempFile = os.path.join(self.test_dir, "temp.json") try: self.logger.debug("Trying to load test results") with open(tempFile) as f: vims_test_result = json.load(f) f.close() except Exception: # pylint: disable=broad-except self.logger.error("Unable to retrieve test results") try: os.remove(tempFile) except Exception: # pylint: disable=broad-except self.logger.error("Deleting file failed") return vims_test_result
def configure_tempest(deployment_dir): """ Add/update needed parameters into tempest.conf file generated by Rally """ tempest_conf_file = deployment_dir + "/tempest.conf" if os.path.isfile(tempest_conf_file): logger.debug("Deleting old tempest.conf file...") os.remove(tempest_conf_file) logger.debug("Generating new tempest.conf file...") cmd = "rally verify genconfig" ft_utils.execute_command(cmd) logger.debug("Finding tempest.conf file...") if not os.path.isfile(tempest_conf_file): logger.error("Tempest configuration file %s NOT found." % tempest_conf_file) exit(-1) logger.debug("Updating selected tempest.conf parameters...") config = ConfigParser.RawConfigParser() config.read(tempest_conf_file) config.set('compute', 'fixed_network_name', TEMPEST_PRIVATE_NET_NAME) if TEMPEST_USE_CUSTOM_IMAGES: if GlobalVariables.IMAGE_ID is not None: config.set('compute', 'image_ref', GlobalVariables.IMAGE_ID) if IMAGE_ID_ALT is not None: config.set('compute', 'image_ref_alt', IMAGE_ID_ALT) if TEMPEST_USE_CUSTOM_FLAVORS: if GlobalVariables.FLAVOR_ID is not None: config.set('compute', 'flavor_ref', GlobalVariables.FLAVOR_ID) if FLAVOR_ID_ALT is not None: config.set('compute', 'flavor_ref_alt', FLAVOR_ID_ALT) config.set('identity', 'tenant_name', TEMPEST_TENANT_NAME) config.set('identity', 'username', TEMPEST_USER_NAME) config.set('identity', 'password', TEMPEST_USER_PASSWORD) config.set('validation', 'ssh_timeout', TEMPEST_SSH_TIMEOUT) if ft_constants.OS_ENDPOINT_TYPE is not None: services_list = [ 'compute', 'volume', 'image', 'network', 'data-processing', 'object-storage', 'orchestration' ] sections = config.sections() for service in services_list: if service not in sections: config.add_section(service) config.set(service, 'endpoint_type', ft_constants.OS_ENDPOINT_TYPE) with open(tempest_conf_file, 'wb') as config_file: config.write(config_file) # Copy tempest.conf to /home/opnfv/functest/results/tempest/ shutil.copyfile(tempest_conf_file, TEMPEST_RESULTS_DIR + '/tempest.conf') return True
def run_clearwater_live_test(self, public_domain, signup_code='secret'): """Run the Clearwater live tests It first runs dnsmasq to reach clearwater services by FQDN and then the Clearwater live tests. All results are saved in ims_test_output.txt. Returns: - a dict containing the overall results - None on error """ # pylint: disable=too-many-locals,too-many-arguments self.logger.info('Run Clearwater live test') script = ('cd {0};' 'rake test[{1}] SIGNUP_CODE={2}'.format( self.test_dir, public_domain, signup_code)) if self.bono_ip and self.ellis_ip: subscript = ' PROXY={0} ELLIS={1}'.format(self.bono_ip, self.ellis_ip) script = '{0}{1}'.format(script, subscript) script = ('{0}{1}'.format(script, ' --trace')) cmd = "/bin/bash -c '{0}'".format(script) self.logger.debug('Live test cmd: %s', cmd) output_file = os.path.join(self.result_dir, "ims_test_output.txt") ft_utils.execute_command(cmd, error_msg='Clearwater live test failed', output_file=output_file) with open(output_file, 'r') as ofile: result = ofile.read() if result != "": self.logger.debug(result) vims_test_result = {} try: grp = re.search( r'^(\d+) failures out of (\d+) tests run.*\n' r'(\d+) tests skipped$', result, re.MULTILINE | re.DOTALL) assert grp vims_test_result["failures"] = int(grp.group(1)) vims_test_result["total"] = int(grp.group(2)) vims_test_result["skipped"] = int(grp.group(3)) vims_test_result['passed'] = (int(grp.group(2)) - int(grp.group(3)) - int(grp.group(1))) if vims_test_result['total'] - vims_test_result['skipped'] > 0: vnf_test_rate = vims_test_result['passed'] / ( vims_test_result['total'] - vims_test_result['skipped']) else: vnf_test_rate = 0 except Exception: # pylint: disable=broad-except self.logger.exception("Cannot parse live tests results") return None, 0 return vims_test_result, vnf_test_rate
def run(self, tiername, noclean=False): if not os.path.isfile(ft_constants.ENV_FILE): click.echo("Functest environment is not ready. " "Run first 'functest env prepare'") else: if noclean: cmd = ("python %s/functest/ci/run_tests.py " "-n -t %s" % (ft_constants.FUNCTEST_REPO_DIR, tiername)) else: cmd = ("python %s/functest/ci/run_tests.py " "-t %s" % (ft_constants.FUNCTEST_REPO_DIR, tiername)) ft_utils.execute_command(cmd)
def run(tiername, noclean=False, report=False): flags = "" if noclean: flags += "-n " if report: flags += "-r " if not os.path.isfile(CONST.__getattribute__('env_active')): click.echo("Functest environment is not ready. " "Run first 'functest env prepare'") else: cmd = "run_tests {}-t {}".format(flags, tiername) ft_utils.execute_command(cmd)
def run(self, testname, noclean=False): if testname == 'vacation': vacation.main() elif not os.path.isfile(ENV_FILE): click.echo("Functest environment is not ready. " "Run first 'functest env prepare'") else: if noclean: cmd = ("python /home/opnfv/repos/functest/ci/run_tests.py " "-t --no-clean %s" % testname) else: cmd = ("python /home/opnfv/repos/functest/ci/run_tests.py " "-t %s" % testname) ft_utils.execute_command(cmd)
def create_verifier(): logger.info("Create verifier from existing repo...") cmd = ("rally verify delete-verifier --id '{0}' --force").format( CONST.__getattribute__('tempest_verifier_name')) ft_utils.execute_command(cmd, error_msg=( "Verifier %s does not exist." % CONST.__getattribute__('tempest_verifier_name')), verbose=False) cmd = ("rally verify create-verifier --source {0} " "--name {1} --type tempest --system-wide" .format(CONST.__getattribute__('dir_repo_tempest'), CONST.__getattribute__('tempest_verifier_name'))) ft_utils.execute_command_raise(cmd, error_msg='Problem while creating verifier')
def run(tiername, noclean=False, report=False): flags = "" if noclean: flags += "-n " if report: flags += "-r " if not os.path.isfile(CONST.env_active): click.echo("Functest environment is not ready. " "Run first 'functest env prepare'") else: cmd = ("python %s/functest/ci/run_tests.py " "%s -t %s" % (CONST.dir_repo_functest, flags, tiername)) ft_utils.execute_command(cmd)
def prepare(self): if self.status(verbose=False) == 0: answer = raw_input("It seems that the environment has been " "already prepared. Do you want to do " "it again? [y|n]\n") while True: if answer.lower() in ["y", "yes"]: os.remove(CONST.__getattribute__('env_active')) break elif answer.lower() in ["n", "no"]: return else: answer = raw_input("Invalid answer. Please type [y|n]\n") ft_utils.execute_command("prepare_env start")
def run(testname, noclean=False, report=False): flags = "" if noclean: flags += "-n " if report: flags += "-r " if testname == 'vacation': vacation.main() else: tests = testname.split(",") for test in tests: cmd = "run_tests {}-t {}".format(flags, test) ft_utils.execute_command(cmd)
def test_execute_command_args_missing_with_success( self, mock_logger_info, ): with mock.patch('functest.utils.functest_utils.subprocess.Popen') \ as mock_subproc_open: FunctestUtilsTesting.readline = 2 mock_obj = mock.Mock() attrs = {'readline.side_effect': self.cmd_readline()} mock_obj.configure_mock(**attrs) mock_obj2 = mock.Mock() attrs = {'stdout': mock_obj, 'wait.return_value': 0} mock_obj2.configure_mock(**attrs) mock_subproc_open.return_value = mock_obj2 resp = functest_utils.execute_command(self.cmd, info=False, error_msg="", verbose=False, output_file=None) self.assertEqual(resp, 0)
def _run(self, args): # pylint: disable=no-self-use """ The built_in function to run a test case """ case_name = args.get('testcase') self._update_logging_ini(args.get('task_id')) if not os.path.isfile(CONST.__getattribute__('env_active')): raise Exception("Functest environment is not ready.") else: try: cmd = "run_tests -t {}".format(case_name) runner = ft_utils.execute_command(cmd) except Exception: # pylint: disable=broad-except result = 'FAIL' LOGGER.exception("Running test case %s failed!", case_name) if runner == os.EX_OK: result = 'PASS' else: result = 'FAIL' env_info = { 'installer': CONST.__getattribute__('INSTALLER_TYPE'), 'scenario': CONST.__getattribute__('DEPLOY_SCENARIO'), 'build_tag': CONST.__getattribute__('BUILD_TAG'), 'ci_loop': CONST.__getattribute__('CI_LOOP') } result = { 'task_id': args.get('task_id'), 'case_name': case_name, 'env_info': env_info, 'result': result } return {'result': result}
def prepare(self): if self.status(verbose=False) == 0: answer = raw_input("It seems that the environment has been " "already prepared. Do you want to do " "it again? [y|n]\n") while True: if answer.lower() in ["y", "yes"]: os.remove(ENV_FILE) break elif answer.lower() in ["n", "no"]: return else: answer = raw_input("Invalid answer. Please type [y|n]\n") cmd = ("python /home/opnfv/repos/functest/ci/prepare_env.py start") ft_utils.execute_command(cmd)
def test_execute_command_args_present_with_success( self, mock_logger_info, ): with mock.patch('functest.utils.functest_utils.subprocess.Popen') \ as mock_subproc_open, \ mock.patch('six.moves.builtins.open', mock.mock_open()) as mopen: FunctestUtilsTesting.readline = 0 mock_obj = mock.Mock() attrs = {'readline.side_effect': self.cmd_readline()} mock_obj.configure_mock(**attrs) mock_obj2 = mock.Mock() attrs = {'stdout': mock_obj, 'wait.return_value': 0} mock_obj2.configure_mock(**attrs) mock_subproc_open.return_value = mock_obj2 resp = functest_utils.execute_command(self.cmd, info=True, error_msg=self.error_msg, verbose=True, output_file=self.output_file) self.assertEqual(resp, 0) msg_exec = ("Executing command: '%s'" % self.cmd) mock_logger_info.assert_called_once_with(msg_exec) mopen.assert_called_once_with(self.output_file, "w")
def run_test(test): test_name = test.get_name() print_separator("=") logger.info("Running test case '%s'..." % test_name) print_separator("=") logger.debug("\n%s" % test) generate_os_snapshot() flags = (" -t %s" % (test_name)) if REPORT_FLAG: flags += " -r" cmd = ("%s%s" % (EXEC_SCRIPT, flags)) logger.debug("Executing command '%s'" % cmd) result = ft_utils.execute_command(cmd, logger, exit_on_error=False) if result != 0: logger.error("The test case '%s' failed. Cleaning and exiting." % test_name) if CLEAN_FLAG: cleanup() sys.exit(1) if CLEAN_FLAG: cleanup()
def run(testname, noclean=False, report=False): flags = "" if noclean: flags += "-n " if report: flags += "-r " if testname == 'vacation': vacation.main() elif not os.path.isfile(CONST.__getattribute__('env_active')): click.echo("Functest environment is not ready. " "Run first 'functest env prepare'") else: tests = testname.split(",") for test in tests: cmd = "run_tests {}-t {}".format(flags, test) ft_utils.execute_command(cmd)
def ping_ip_test(self, address): ping = "ping %s -c 3" % address testcase_name = "Ping IP %s" % address exit_code = ft_utils.execute_command(ping) if exit_code != 0: self.add_failure(testcase_name) else: self.add_success(testcase_name)
def run(testname, noclean=False, report=False): flags = "" if noclean: flags += "-n " if report: flags += "-r " if testname == 'vacation': vacation.main() elif not os.path.isfile(CONST.env_active): click.echo("Functest environment is not ready. " "Run first 'functest env prepare'") else: tests = testname.split(",") for test in tests: cmd = ("python %s/functest/ci/run_tests.py " "%s -t %s" % (CONST.dir_repo_functest, flags, test)) ft_utils.execute_command(cmd)
def test_moon_openstack(): log_filename = RESULTS_DIR + "/moonclient_selftest.log" cmd = "moon test --password console --self --logfile {}".format(log_filename) ret_val = functest_utils.execute_command(cmd, info=True, exit_on_error=False, output_file=log_filename) return ret_val, open(log_filename, "rt").read()
def generate_test_list(deployment_dir, mode): logger.debug("Generating test case list...") if mode == 'defcore': shutil.copyfile(TEMPEST_DEFCORE, TEMPEST_RAW_LIST) elif mode == 'custom': if os.path.isfile(TEMPEST_CUSTOM): shutil.copyfile(TEMPEST_CUSTOM, TEMPEST_RAW_LIST) else: logger.error("Tempest test list file %s NOT found." % TEMPEST_CUSTOM) exit(-1) else: if mode == 'smoke': testr_mode = "smoke" elif mode == 'full': testr_mode = "" else: testr_mode = 'tempest.api.' + mode cmd = ("cd " + deployment_dir + ";" + "testr list-tests " + testr_mode + ">" + TEMPEST_RAW_LIST + ";cd") ft_utils.execute_command(cmd, logger)
def main(): cmd = 'cd %s/tests && ./run.sh' % DOCTOR_REPO start_time = time.time() ret = functest_utils.execute_command(cmd, logger, exit_on_error=False) stop_time = time.time() duration = round(stop_time - start_time, 1) if ret == 0: logger.info("doctor OK") test_status = 'OK' else: logger.info("doctor FAILED") test_status = 'NOK' details = { 'timestart': start_time, 'duration': duration, 'status': test_status, } pod_name = functest_utils.get_pod_name(logger) scenario = functest_utils.get_scenario(logger) version = functest_utils.get_version(logger) build_tag = functest_utils.get_build_tag(logger) status = "FAIL" if details['status'] == "OK": status = "PASS" logger.info("Pushing Doctor results: TEST_DB_URL=%(db)s pod_name=%(pod)s " "version=%(v)s scenario=%(s)s criteria=%(c)s details=%(d)s" % { 'db': TEST_DB_URL, 'pod': pod_name, 'v': version, 's': scenario, 'c': status, 'b': build_tag, 'd': details, }) functest_utils.push_results_to_db("doctor", "doctor-notification", logger, start_time, stop_time, status, details)
def main(): cmd = ('%s/tests/run.sh' % COPPER_REPO) start_time = time.time() ret = functest_utils.execute_command(cmd, logger, exit_on_error=False) stop_time = time.time() duration = round(stop_time - start_time, 1) if ret == 0: logger.info("COPPER PASSED") test_status = 'PASS' else: logger.info("COPPER FAILED") test_status = 'FAIL' details = { 'timestart': start_time, 'duration': duration, 'status': test_status, } pod_name = functest_utils.get_pod_name(logger) scenario = functest_utils.get_scenario(logger) version = functest_utils.get_version(logger) build_tag = functest_utils.get_build_tag(logger) logger.info("Pushing COPPER results: TEST_DB_URL=%(db)s pod_name=%(pod)s " "version=%(v)s scenario=%(s)s criteria=%(c)s details=%(d)s" % { 'db': TEST_DB_URL, 'pod': pod_name, 'v': version, 's': scenario, 'c': details['status'], 'b': build_tag, 'd': details, }) functest_utils.push_results_to_db("COPPER", "COPPER-notification", logger, start_time, stop_time, details['status'], details)
def install_rally(): print_separator() logger.info("Creating Rally environment...") cmd = "rally deployment destroy opnfv-rally" ft_utils.execute_command(cmd, logger=logger, exit_on_error=False, error_msg=("Deployment %s does not exist." % DEPLOYMENT_MAME), verbose=False) cmd = "rally deployment create --fromenv --name=" + DEPLOYMENT_MAME ft_utils.execute_command(cmd, logger, error_msg="Problem creating Rally deployment") logger.info("Installing tempest from existing repo...") cmd = ("rally verify install --source " + TEMPEST_REPO_DIR + " --system-wide") ft_utils.execute_command(cmd, logger, error_msg="Problem installing Tempest.") cmd = "rally deployment check" ft_utils.execute_command(cmd, logger, error_msg=("OpenStack not responding or " "faulty Rally deployment.")) cmd = "rally show images" ft_utils.execute_command(cmd, logger, error_msg=("Problem while listing " "OpenStack images.")) cmd = "rally show flavors" ft_utils.execute_command(cmd, logger, error_msg=("Problem while showing " "OpenStack flavors."))
def check(self): self.ping_endpoint() cmd = FUNCTEST_REPO + "ci/check_os.sh" ft_utils.execute_command(cmd, verbose=False)
def show_credentials(self): cmd = "env|grep OS_" ft_utils.execute_command(cmd, exit_on_error=False, verbose=False) click.echo("")
def main(): # ############### GENERAL INITIALISATION ################ if not os.path.exists(vHello_DATA_DIR): os.makedirs(vHello_DATA_DIR) ks_creds = os_utils.get_credentials("keystone") nv_creds = os_utils.get_credentials("nova") nt_creds = os_utils.get_credentials("neutron") logger.info("Prepare OpenStack plateform (create tenant and user)") keystone = ksclient.Client(**ks_creds) user_id = os_utils.get_user_id(keystone, ks_creds['username']) if user_id == '': step_failure("init", "Error : Failed to get id of " + ks_creds['username']) tenant_id = os_utils.create_tenant( keystone, TENANT_NAME, TENANT_DESCRIPTION) if tenant_id == '': step_failure("init", "Error : Failed to create " + TENANT_NAME + " tenant") roles_name = ["admin", "Admin"] role_id = '' for role_name in roles_name: if role_id == '': role_id = os_utils.get_role_id(keystone, role_name) if role_id == '': logger.error("Error : Failed to get id for %s role" % role_name) if not os_utils.add_role_user(keystone, user_id, role_id, tenant_id): logger.error("Error : Failed to add %s on tenant" % ks_creds['username']) user_id = os_utils.create_user( keystone, TENANT_NAME, TENANT_NAME, None, tenant_id) if user_id == '': logger.error("Error : Failed to create %s user" % TENANT_NAME) logger.info("Update OpenStack creds informations") ks_creds.update({ "username": TENANT_NAME, "password": TENANT_NAME, "tenant_name": TENANT_NAME, }) nt_creds.update({ "tenant_name": TENANT_NAME, }) nv_creds.update({ "project_id": TENANT_NAME, }) logger.info("Upload some OS images if it doesn't exist") glance_endpoint = keystone.service_catalog.url_for( service_type='image', endpoint_type='publicURL') glance = glclient.Client(1, glance_endpoint, token=keystone.auth_token) for img in IMAGES.keys(): image_name = IMAGES[img]['image_name'] image_url = IMAGES[img]['image_url'] image_id = os_utils.get_image_id(glance, image_name) if image_id == '': logger.info("""%s image doesn't exist on glance repository. Try downloading this image and upload on glance !""" % image_name) image_id = download_and_add_image_on_glance( glance, image_name, image_url) if image_id == '': step_failure( "init", "Error : Failed to find or upload required OS " "image for this deployment") nova = nvclient.Client("2", **nv_creds) logger.info("Update security group quota for this tenant") neutron = ntclient.Client(**nt_creds) if not os_utils.update_sg_quota(neutron, tenant_id, 50, 100): step_failure( "init", "Failed to update security group quota for tenant " + TENANT_NAME) logger.info("Update cinder quota for this tenant") from cinderclient import client as cinderclient creds_cinder = os_utils.get_credentials("cinder") cinder_client = cinderclient.Client('1', creds_cinder['username'], creds_cinder['api_key'], creds_cinder['project_id'], creds_cinder['auth_url'], service_type="volume") if not os_utils.update_cinder_quota(cinder_client, tenant_id, 20, 10, 150): step_failure( "init", "Failed to update cinder quota for tenant " + TENANT_NAME) # ############### CLOUDIFY INITIALISATION ################ cfy = orchestrator(vHello_DATA_DIR, CFY_INPUTS, logger) cfy.set_credentials(username=ks_creds['username'], password=ks_creds[ 'password'], tenant_name=ks_creds['tenant_name'], auth_url=ks_creds['auth_url']) logger.info("Collect flavor id for cloudify manager server") nova = nvclient.Client("2", **nv_creds) flavor_name = "m1.medium" flavor_id = os_utils.get_flavor_id(nova, flavor_name) for requirement in CFY_MANAGER_REQUIERMENTS: if requirement == 'ram_min': flavor_id = os_utils.get_flavor_id_by_ram_range( nova, CFY_MANAGER_REQUIERMENTS['ram_min'], 8196) if flavor_id == '': logger.error( "Failed to find %s flavor. " "Try with ram range default requirement !" % flavor_name) flavor_id = os_utils.get_flavor_id_by_ram_range(nova, 4000, 8196) if flavor_id == '': step_failure("orchestrator", "Failed to find required flavor for this deployment") cfy.set_flavor_id(flavor_id) image_name = "centos_7" image_id = os_utils.get_image_id(glance, image_name) for requirement in CFY_MANAGER_REQUIERMENTS: if requirement == 'os_image': image_id = os_utils.get_image_id( glance, CFY_MANAGER_REQUIERMENTS['os_image']) if image_id == '': step_failure( "orchestrator", "Error : Failed to find required OS image for cloudify manager") cfy.set_image_id(image_id) ext_net = os_utils.get_external_net(neutron) if not ext_net: step_failure("orchestrator", "Failed to get external network") cfy.set_external_network_name(ext_net) ns = functest_utils.get_resolvconf_ns() if ns: cfy.set_nameservers(ns) logger.info("Prepare virtualenv for cloudify-cli") cmd = "chmod +x " + vHello_DIR + "create_venv.sh" functest_utils.execute_command(cmd, logger) time.sleep(3) cmd = vHello_DIR + "create_venv.sh " + vHello_DATA_DIR functest_utils.execute_command(cmd, logger) cfy.download_manager_blueprint( CFY_MANAGER_BLUEPRINT['url'], CFY_MANAGER_BLUEPRINT['branch']) # ############### CLOUDIFY DEPLOYMENT ################ start_time_ts = time.time() end_time_ts = start_time_ts logger.info("Cloudify deployment Start Time:'%s'" % ( datetime.datetime.fromtimestamp(start_time_ts).strftime( '%Y-%m-%d %H:%M:%S'))) error = cfy.deploy_manager() if error: step_failure("orchestrator", error) end_time_ts = time.time() duration = round(end_time_ts - start_time_ts, 1) logger.info("Cloudify deployment duration:'%s'" % duration) set_result("orchestrator", duration, "") # ############### helloworld INITIALISATION ################ cw = helloworld(CW_INPUTS, cfy, logger) logger.info("Collect flavor id for all helloworld vm") nova = nvclient.Client("2", **nv_creds) flavor_name = "m1.small" flavor_id = os_utils.get_flavor_id(nova, flavor_name) for requirement in CW_REQUIERMENTS: if requirement == 'ram_min': flavor_id = os_utils.get_flavor_id_by_ram_range( nova, CW_REQUIERMENTS['ram_min'], 8196) if flavor_id == '': logger.error( "Failed to find %s flavor. Try with ram range " "default requirement !" % flavor_name) flavor_id = os_utils.get_flavor_id_by_ram_range(nova, 4000, 8196) if flavor_id == '': step_failure( "vHello", "Failed to find required flavor for this deployment") cw.set_flavor_id(flavor_id) image_name = "ubuntu_14.04" image_id = os_utils.get_image_id(glance, image_name) for requirement in CW_REQUIERMENTS: if requirement == 'os_image': image_id = os_utils.get_image_id( glance, CW_REQUIERMENTS['os_image']) if image_id == '': step_failure( "vHello", "Error : Failed to find required OS image for cloudify manager") cw.set_image_id(image_id) ext_net = os_utils.get_external_net(neutron) if not ext_net: step_failure("vHello", "Failed to get external network") cw.set_external_network_name(ext_net) # ############### helloworld DEPLOYMENT ################ start_time_ts = time.time() end_time_ts = start_time_ts logger.info("vHello VNF deployment Start Time:'%s'" % ( datetime.datetime.fromtimestamp(start_time_ts).strftime( '%Y-%m-%d %H:%M:%S'))) error = cw.deploy_vnf(CW_BLUEPRINT) if error: step_failure("vHello", error) end_time_ts = time.time() duration = round(end_time_ts - start_time_ts, 1) logger.info("vHello VNF deployment duration:'%s'" % duration) set_result("vHello", duration, "")