diff options
-rwxr-xr-x | ci/exec_test.sh | 20 | ||||
-rwxr-xr-x[-rw-r--r--] | ci/generate_report.py | 0 | ||||
-rw-r--r-- | docker/Dockerfile | 3 | ||||
-rwxr-xr-x | testcases/Controllers/ODL/OpenDaylightTesting.py | 67 | ||||
-rw-r--r-- | testcases/Controllers/ODL/odlreport2db.py | 133 | ||||
-rwxr-xr-x | testcases/OpenStack/vPing/vPing_userdata.py | 368 | ||||
-rwxr-xr-x | testcases/OpenStack/vPing/vping.py | 101 | ||||
-rw-r--r--[-rwxr-xr-x] | testcases/OpenStack/vPing/vping_util.py (renamed from testcases/OpenStack/vPing/vPing_ssh.py) | 393 | ||||
-rwxr-xr-x[-rw-r--r--] | testcases/features/multisite.py | 0 | ||||
-rwxr-xr-x | testcases/features/sfc/set-up-tacker.sh | 8 | ||||
-rwxr-xr-x[-rw-r--r--] | testcases/vnf/vRNC/parser.py | 0 |
11 files changed, 396 insertions, 697 deletions
diff --git a/ci/exec_test.sh b/ci/exec_test.sh index d7883307b..03eb2c873 100755 --- a/ci/exec_test.sh +++ b/ci/exec_test.sh @@ -73,28 +73,24 @@ function run_test(){ ${FUNCTEST_REPO_DIR}/testcases/OpenStack/healthcheck/healthcheck.sh ;; "vping_ssh") - python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/vPing/vPing_ssh.py $report + python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/vPing/vping.py -m ssh $report ;; "vping_userdata") - python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/vPing/vPing_userdata.py $report + python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/vPing/vping.py -m userdata $report ;; "odl") odl_tests - ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/OpenDaylightTesting.py \ - --keystoneip $keystone_ip --neutronip $neutron_ip \ - --osusername ${OS_USERNAME} --ostenantname ${OS_TENANT_NAME} \ - --ospassword ${OS_PASSWORD} \ - --odlip $odl_ip --odlwebport $odl_port - - # push results to the DB in case of CI if [[ "$report" == "-r" && -n "$DEPLOY_SCENARIO" && "$DEPLOY_SCENARIO" != "none" && -n "$INSTALLER_TYPE" && "$INSTALLER_TYPE" != "none" ]] && env | grep NODE_NAME > /dev/null; then - odl_logs="/home/opnfv/functest/results/odl/" - odl_path="${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/" - python ${odl_path}/odlreport2db.py -x ${odl_logs}/output.xml + args=-p fi + ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/OpenDaylightTesting.py \ + --keystoneip $keystone_ip --neutronip $neutron_ip \ + --osusername ${OS_USERNAME} --ostenantname ${OS_TENANT_NAME} \ + --ospassword ${OS_PASSWORD} \ + --odlip $odl_ip --odlwebport $odl_port ${args} ;; "tempest_smoke_serial") python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/tempest/run_tempest.py \ diff --git a/ci/generate_report.py b/ci/generate_report.py index 3ca2847bd..3ca2847bd 100644..100755 --- a/ci/generate_report.py +++ b/ci/generate_report.py diff --git a/docker/Dockerfile b/docker/Dockerfile index ce3f4ce51..a14bdc44e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -92,6 +92,9 @@ RUN pip install -r ${repos_dir}/functest/docker/requirements.pip RUN pip install -r ${repos_dir}/rally/requirements.txt RUN pip install -r ${repos_dir}/tempest/requirements.txt +RUN find ${repos_dir}/functest -name "*.py" |xargs grep __main__ |cut -d\: -f 1 |xargs chmod -c 755 +RUN find ${repos_dir}/functest -name "*.sh" |xargs grep \#\! |cut -d\: -f 1 |xargs chmod -c 755 + RUN /bin/bash ${repos_dir}/parser/tests/parser_install.sh ${repos_dir} RUN ${repos_dir}/rally/install_rally.sh --yes diff --git a/testcases/Controllers/ODL/OpenDaylightTesting.py b/testcases/Controllers/ODL/OpenDaylightTesting.py index 79e385a2d..74e3157dc 100755 --- a/testcases/Controllers/ODL/OpenDaylightTesting.py +++ b/testcases/Controllers/ODL/OpenDaylightTesting.py @@ -8,8 +8,33 @@ import shutil import sys from robot import run +from robot.api import ExecutionResult, ResultVisitor +from robot.errors import RobotError +from robot.utils.robottime import timestamp_to_secs import functest.utils.functest_logger as ft_logger +import functest.utils.functest_utils as ft_utils + + +class ODLResultVisitor(ResultVisitor): + + def __init__(self): + self._data = [] + + def visit_test(self, test): + output = {} + output['name'] = test.name + output['parent'] = test.parent.name + output['status'] = test.status + output['startime'] = test.starttime + output['endtime'] = test.endtime + output['critical'] = test.critical + output['text'] = test.message + output['elapsedtime'] = test.elapsedtime + self._data.append(output) + + def get_data(self): + return self._data class ODLTestCases: @@ -18,6 +43,7 @@ class ODLTestCases: odl_test_repo = repos + "odl_test/" neutron_suite_dir = odl_test_repo + "csit/suites/openstack/neutron/" basic_suite_dir = odl_test_repo + "csit/suites/integration/basic/" + res_dir = '/home/opnfv/functest/results/odl/' logger = ft_logger.Logger("opendaylight").getLogger() @classmethod @@ -70,19 +96,18 @@ class ODLTestCases: except KeyError as e: cls.logger.error("Cannot run ODL testcases. Please check", e) return False - res_dir = '/home/opnfv/functest/results/odl/' if (cls.copy_opnf_testcases() and cls.set_robotframework_vars(odlusername, odlpassword)): try: - os.makedirs(res_dir) + os.makedirs(cls.res_dir) except OSError: pass - stdout_file = res_dir + 'stdout.txt' + stdout_file = cls.res_dir + 'stdout.txt' with open(stdout_file, 'w') as stdout: result = run(*dirs, variable=variables, - output=res_dir + 'output.xml', - log=res_dir + 'log.html', - report=res_dir + 'report.html', + output=cls.res_dir + 'output.xml', + log=cls.res_dir + 'log.html', + report=cls.res_dir + 'report.html', stdout=stdout) with open(stdout_file, 'r') as stdout: @@ -92,6 +117,27 @@ class ODLTestCases: else: return False + @classmethod + def push_to_db(cls): + try: + result = ExecutionResult(cls.res_dir + 'output.xml') + visitor = ODLResultVisitor() + result.visit(visitor) + start_time = timestamp_to_secs(result.suite.starttime) + stop_time = timestamp_to_secs(result.suite.endtime) + details = {} + details['description'] = result.suite.name + details['tests'] = visitor.get_data() + if not ft_utils.push_results_to_db( + "functest", "odl", None, start_time, stop_time, + result.suite.status, details): + cls.logger.error("Cannot push ODL results to DB") + return False + else: + return True + except RobotError as e: + cls.logger.error("Run tests before publishing: %s" % e.message) + if __name__ == '__main__': parser = argparse.ArgumentParser() @@ -125,5 +171,12 @@ if __name__ == '__main__': parser.add_argument('-e', '--odlpassword', help='Password for ODL', default='admin') + parser.add_argument('-p', '--pushtodb', + help='Push results to DB', + action='store_true') + args = vars(parser.parse_args()) - sys.exit(ODLTestCases.run(**args)) + ODLTestCases.run(**args) + if args['pushtodb']: + sys.exit(not ODLTestCases.push_to_db()) + sys.exit(os.EX_OK) diff --git a/testcases/Controllers/ODL/odlreport2db.py b/testcases/Controllers/ODL/odlreport2db.py deleted file mode 100644 index 6b3fb913d..000000000 --- a/testcases/Controllers/ODL/odlreport2db.py +++ /dev/null @@ -1,133 +0,0 @@ -#!/usr/bin/python -# -# Authors: -# - peter.bandzi@cisco.com -# - morgan.richomme@orange.com -# -# src: Peter Bandzi -# https://github.com/pbandzi/parse-robot/blob/master/convert_robot_to_json.py -# -# Copyright (c) 2015 All rights reserved -# This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# - -import getopt -import json -import sys -import time -import xmltodict - -import functest.utils.functest_utils as functest_utils - - -def usage(): - print """Usage: - python odlreport2db.py --xml=<output.xml> --help - -x, --xml xml file generated by robot test - -h, --help this message - """ - sys.exit(2) - - -def populate_detail(test): - detail = {} - detail['name'] = test['@name'] - for x in ['status', 'critical', 'starttime', 'endtime']: - detail[x] = test['status']['@' + x] - if '#text' in test['status']: - detail['text'] = test['status']['#text'] - return detail - - -def parse_test(tests, details): - try: - for test in tests: - details.append(populate_detail(test)) - except TypeError: - # tests is not iterable - details.append(populate_detail(tests)) - return details - - -def parse_suites(suites): - data = {} - details = [] - for suite in suites: - a = suite['suite'] - if type(a) == list: - for b in a: - data['tests'] = parse_test(b['test'], details) - else: - data['tests'] = parse_test(a['test'], details) - - # data['details'] = parse_test(suite['test'], details) - # suites is not iterable - return data - - -def main(argv): - xml_file = None - try: - opts, args = getopt.getopt(argv, - 'x:h', - ['xml=', 'help']) - except getopt.GetoptError: - usage() - - for opt, arg in opts: - if opt in ('-x', '--xml'): - xml_file = arg - else: - usage() - - if xml_file is None: - usage() - - with open(xml_file, "r") as myfile: - xml_input = myfile.read().replace('\n', '') - - # dictionary populated with data from xml file - all_data = xmltodict.parse(xml_input)['robot'] - - try: - data = parse_suites(all_data['suite']['suite']) - data['description'] = all_data['suite']['@name'] - data['generator'] = all_data['@generator'] - - json.dumps(data, indent=4, separators=(',', ': ')) - - # success criteria for ODL = 100% of tests OK - status = "FAIL" - # TODO as part of the tests are executed before in the bash - # start and stoptime have no real meaning - start_time = time.time() - stop_time = start_time - tests_passed = 0 - tests_failed = 0 - for v in data['tests']: - if v['status'] == "PASS": - tests_passed += 1 - else: - tests_failed += 1 - - if (tests_failed < 1): - status = "PASS" - - functest_utils.push_results_to_db("functest", - "odl", - None, - start_time, - stop_time, - status, - data) - - except: - print("Error pushing ODL results into DB '%s'" % sys.exc_info()[0]) - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/testcases/OpenStack/vPing/vPing_userdata.py b/testcases/OpenStack/vPing/vPing_userdata.py deleted file mode 100755 index dd707bc8f..000000000 --- a/testcases/OpenStack/vPing/vPing_userdata.py +++ /dev/null @@ -1,368 +0,0 @@ -#!/usr/bin/python -# -# Copyright (c) 2015 All rights reserved -# This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# 0.1: This script boots the VM1 and allocates IP address from Nova -# Later, the VM2 boots then execute cloud-init to ping VM1. -# After successful ping, both the VMs are deleted. -# 0.2: measure test duration and publish results under json format -# 0.3: adapt push 2 DB after Test API refacroting -# -# - -import argparse -import datetime -import os -import pprint -import sys -import time -import functest.utils.functest_logger as ft_logger -import functest.utils.functest_utils as functest_utils -import functest.utils.openstack_utils as os_utils -import yaml - - -pp = pprint.PrettyPrinter(indent=4) - -parser = argparse.ArgumentParser() -image_exists = False - -parser.add_argument("-d", "--debug", help="Debug mode", action="store_true") -parser.add_argument("-r", "--report", - help="Create json result file", - action="store_true") - -args = parser.parse_args() - -""" logging configuration """ -logger = ft_logger.Logger("vping_userdata").getLogger() - -REPO_PATH = os.environ['repos_dir'] + '/functest/' -if not os.path.exists(REPO_PATH): - logger.error("Functest repository directory not found '%s'" % REPO_PATH) - exit(-1) - -with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f: - functest_yaml = yaml.safe_load(f) -f.close() - -HOME = os.environ['HOME'] + "/" -# vPing parameters -VM_BOOT_TIMEOUT = 180 -VM_DELETE_TIMEOUT = 100 -PING_TIMEOUT = functest_yaml.get("vping").get("ping_timeout") -TEST_DB = functest_yaml.get("results").get("test_db_url") -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("vping").get("image_name") -GLANCE_IMAGE_FILENAME = functest_yaml.get("general").get( - "openstack").get("image_file_name") -GLANCE_IMAGE_FORMAT = functest_yaml.get("general").get( - "openstack").get("image_disk_format") -GLANCE_IMAGE_PATH = functest_yaml.get("general").get("directories").get( - "dir_functest_data") + "/" + GLANCE_IMAGE_FILENAME - - -FLAVOR = functest_yaml.get("vping").get("vm_flavor") - -# NEUTRON Private Network parameters - -PRIVATE_NET_NAME = functest_yaml.get("vping").get( - "vping_private_net_name") -PRIVATE_SUBNET_NAME = functest_yaml.get("vping").get( - "vping_private_subnet_name") -PRIVATE_SUBNET_CIDR = functest_yaml.get("vping").get( - "vping_private_subnet_cidr") -ROUTER_NAME = functest_yaml.get("vping").get("vping_router_name") - -SECGROUP_NAME = functest_yaml.get("vping").get("vping_sg_name") -SECGROUP_DESCR = functest_yaml.get("vping").get("vping_sg_descr") - - -def pMsg(value): - """pretty printing""" - pp.pprint(value) - - -def waitVmActive(nova, vm): - - # sleep and wait for VM status change - sleep_time = 3 - count = VM_BOOT_TIMEOUT / sleep_time - while True: - status = os_utils.get_instance_status(nova, vm) - logger.debug("Status: %s" % status) - if status == "ACTIVE": - return True - if status == "ERROR" or status == "error": - return False - if count == 0: - logger.debug("Booting a VM timed out...") - return False - count -= 1 - time.sleep(sleep_time) - return False - - -def waitVmDeleted(nova, vm): - - # sleep and wait for VM status change - sleep_time = 3 - count = VM_DELETE_TIMEOUT / sleep_time - while True: - status = os_utils.get_instance_status(nova, vm) - if not status: - return True - elif count == 0: - logger.debug("Timeout") - return False - else: - # return False - count -= 1 - time.sleep(sleep_time) - return False - - -def create_security_group(neutron_client): - sg_id = os_utils.get_security_group_id(neutron_client, - SECGROUP_NAME) - if sg_id != '': - logger.info("Using existing security group '%s'..." % SECGROUP_NAME) - else: - logger.info("Creating security group '%s'..." % SECGROUP_NAME) - SECGROUP = os_utils.create_security_group(neutron_client, - SECGROUP_NAME, - SECGROUP_DESCR) - if not SECGROUP: - logger.error("Failed to create the security group...") - return False - - sg_id = SECGROUP['id'] - - logger.debug("Security group '%s' with ID=%s created successfully." - % (SECGROUP['name'], sg_id)) - - logger.debug("Adding ICMP rules in security group '%s'..." - % SECGROUP_NAME) - if not os_utils.create_secgroup_rule(neutron_client, sg_id, - 'ingress', 'icmp'): - logger.error("Failed to create the security group rule...") - return False - - logger.debug("Adding SSH rules in security group '%s'..." - % SECGROUP_NAME) - if not os_utils.create_secgroup_rule(neutron_client, sg_id, - 'ingress', 'tcp', - '22', '22'): - logger.error("Failed to create the security group rule...") - return False - - if not os_utils.create_secgroup_rule(neutron_client, sg_id, - 'egress', 'tcp', - '22', '22'): - logger.error("Failed to create the security group rule...") - return False - return sg_id - - -def main(): - - nova_client = os_utils.get_nova_client() - neutron_client = os_utils.get_neutron_client() - glance_client = os_utils.get_glance_client() - - EXIT_CODE = -1 - - image_id = None - flavor = None - - # Check if the given image exists - image_id = os_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME) - if image_id != '': - logger.info("Using existing image '%s'..." % GLANCE_IMAGE_NAME) - global image_exists - image_exists = True - else: - logger.info("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME, - GLANCE_IMAGE_PATH)) - image_id = os_utils.create_glance_image(glance_client, - GLANCE_IMAGE_NAME, - GLANCE_IMAGE_PATH, - GLANCE_IMAGE_FORMAT) - if not image_id: - logger.error("Failed to create a Glance image...") - exit(EXIT_CODE) - logger.debug("Image '%s' with ID=%s created successfully." - % (GLANCE_IMAGE_NAME, image_id)) - - network_dic = os_utils.create_network_full(neutron_client, - PRIVATE_NET_NAME, - PRIVATE_SUBNET_NAME, - ROUTER_NAME, - PRIVATE_SUBNET_CIDR) - if not network_dic: - logger.error( - "There has been a problem when creating the neutron network") - exit(EXIT_CODE) - network_id = network_dic["net_id"] - - create_security_group(neutron_client) - - # Check if the given flavor exists - try: - flavor = nova_client.flavors.find(name=FLAVOR) - logger.info("Flavor found '%s'" % FLAVOR) - except: - logger.error("Flavor '%s' not found." % FLAVOR) - logger.info("Available flavors are: ") - pMsg(nova_client.flavor.list()) - exit(-1) - - # Deleting instances if they exist - servers = nova_client.servers.list() - for server in servers: - if server.name == NAME_VM_1 or server.name == NAME_VM_2: - logger.info("Instance %s found. Deleting..." % server.name) - server.delete() - - # boot VM 1 - # basic boot - # tune (e.g. flavor, images, network) to your specific - # openstack configuration here - # we consider start time at VM1 booting - start_time = time.time() - stop_time = start_time - logger.info("vPing Start Time:'%s'" % ( - datetime.datetime.fromtimestamp(start_time).strftime( - '%Y-%m-%d %H:%M:%S'))) - - # create VM - logger.info("Creating instance '%s'..." % NAME_VM_1) - logger.debug( - "Configuration:\n name=%s \n flavor=%s \n image=%s \n " - "network=%s \n" % (NAME_VM_1, flavor, image_id, network_id)) - vm1 = nova_client.servers.create( - name=NAME_VM_1, - flavor=flavor, - image=image_id, - config_drive=True, - nics=[{"net-id": network_id}] - ) - - # wait until VM status is active - if not waitVmActive(nova_client, vm1): - - logger.error("Instance '%s' cannot be booted. Status is '%s'" % ( - NAME_VM_1, os_utils.get_instance_status(nova_client, vm1))) - exit(EXIT_CODE) - else: - logger.info("Instance '%s' is ACTIVE." % NAME_VM_1) - - # Retrieve IP of first VM - test_ip = vm1.networks.get(PRIVATE_NET_NAME)[0] - logger.debug("Instance '%s' got %s" % (NAME_VM_1, test_ip)) - - # boot VM 2 - # we will boot then execute a ping script with cloud-init - # the long chain corresponds to the ping procedure converted with base 64 - # tune (e.g. flavor, images, network) to your specific openstack - # configuration here - u = ("#!/bin/sh\n\nwhile true; do\n ping -c 1 %s 2>&1 >/dev/null\n " - "RES=$?\n if [ \"Z$RES\" = \"Z0\" ] ; then\n echo 'vPing OK'\n " - "break\n else\n echo 'vPing KO'\n fi\n sleep 1\ndone\n" % test_ip) - - # create VM - logger.info("Creating instance '%s'..." % NAME_VM_2) - logger.debug( - "Configuration:\n name=%s \n flavor=%s \n image=%s \n network=%s " - "\n userdata= \n%s" % ( - NAME_VM_2, flavor, image_id, network_id, u)) - vm2 = nova_client.servers.create( - name=NAME_VM_2, - flavor=flavor, - image=image_id, - nics=[{"net-id": network_id}], - config_drive=True, - userdata=u - ) - - if not waitVmActive(nova_client, vm2): - logger.error("Instance '%s' cannot be booted. Status is '%s'" % ( - NAME_VM_2, os_utils.get_instance_status(nova_client, vm2))) - exit(EXIT_CODE) - else: - logger.info("Instance '%s' is ACTIVE." % NAME_VM_2) - - logger.info("Waiting for ping...") - sec = 0 - metadata_tries = 0 - console_log = vm2.get_console_output() - duration = 0 - stop_time = time.time() - - while True: - time.sleep(1) - console_log = vm2.get_console_output() - # print "--"+console_log - # report if the test is failed - if "vPing OK" in console_log: - logger.info("vPing detected!") - - # we consider start time at VM1 booting - stop_time = time.time() - duration = round(stop_time - start_time, 1) - logger.info("vPing duration:'%s'" % duration) - EXIT_CODE = 0 - break - elif ("failed to read iid from metadata" in console_log or - metadata_tries > 5): - EXIT_CODE = -2 - break - elif sec == PING_TIMEOUT: - logger.info("Timeout reached.") - break - elif sec % 10 == 0: - if "request failed" in console_log: - logger.debug("It seems userdata is not supported in " - "nova boot. Waiting a bit...") - metadata_tries += 1 - else: - logger.debug("Pinging %s. Waiting for response..." % test_ip) - sec += 1 - - test_status = "FAIL" - if EXIT_CODE == 0: - logger.info("vPing OK") - test_status = "PASS" - elif EXIT_CODE == -2: - duration = 0 - logger.info("Userdata is not supported in nova boot. Aborting test...") - else: - duration = 0 - logger.error("vPing FAILED") - - if args.report: - try: - logger.debug("Pushing vPing userdata results into DB...") - functest_utils.push_results_to_db("functest", - "vping_userdata", - logger, - start_time, - stop_time, - test_status, - details={'timestart': start_time, - 'duration': duration, - 'status': test_status}) - except: - logger.error("Error pushing results into Database '%s'" - % sys.exc_info()[0]) - - exit(EXIT_CODE) - -if __name__ == '__main__': - main() diff --git a/testcases/OpenStack/vPing/vping.py b/testcases/OpenStack/vPing/vping.py new file mode 100755 index 000000000..039e7ec5a --- /dev/null +++ b/testcases/OpenStack/vPing/vping.py @@ -0,0 +1,101 @@ +#!/usr/bin/python +# +# Copyright (c) 2015 All rights reserved +# This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 0.1: This script boots the VM1 and allocates IP address from Nova +# Later, the VM2 boots then execute cloud-init to ping VM1. +# After successful ping, both the VMs are deleted. +# 0.2: measure test duration and publish results under json format +# 0.3: adapt push 2 DB after Test API refacroting +# +# +import datetime +import time + +import argparse +import functest.utils.functest_logger as ft_logger + +import vping_util as util + +parser = argparse.ArgumentParser() +image_exists = False + +parser.add_argument("-d", "--debug", help="Debug mode", action="store_true") +parser.add_argument("-r", "--report", + help="Create json result file", + action="store_true") +parser.add_argument("-m", "--mode", default='ssh', + help="vPing mode: userdata or ssh", + action="store") + +args = parser.parse_args() + +""" logging configuration """ +logger = ft_logger.Logger("vping_userdata").getLogger() + + +def main(): + if args.mode == 'ssh': + case = 'vping_ssh' + else: + case = 'vping_userdata' + + util.init(logger) + + util.check_repo_exist() + + vmname_1 = util.get_vmname_1() + vmname_2 = util.get_vmname_2() + + global image_exists + image_exists, image_id = util.create_image() + + flavor = util.get_flavor() + + network_id = util.create_network_full() + + sg_id = util.create_security_group() + + util.delete_exist_vms() + + start_time = time.time() + logger.info("vPing Start Time:'%s'" % ( + datetime.datetime.fromtimestamp(start_time).strftime( + '%Y-%m-%d %H:%M:%S'))) + + vm1 = util.boot_vm(case, + vmname_1, + image_id, + flavor, + network_id, + None, + sg_id) + test_ip = util.get_test_ip(vm1) + vm2 = util.boot_vm(case, + vmname_2, + image_id, + flavor, + network_id, + test_ip, + sg_id) + + EXIT_CODE, stop_time = util.do_vping(case, vm2, test_ip) + details = util.check_result(EXIT_CODE, + start_time, + stop_time) + util.push_result(args.report, + case, + start_time, + stop_time, + details) + + exit(EXIT_CODE) + + +if __name__ == '__main__': + main() diff --git a/testcases/OpenStack/vPing/vPing_ssh.py b/testcases/OpenStack/vPing/vping_util.py index 810f286f1..42ab699d9 100755..100644 --- a/testcases/OpenStack/vPing/vPing_ssh.py +++ b/testcases/OpenStack/vPing/vping_util.py @@ -1,79 +1,39 @@ -#!/usr/bin/python -# -# Copyright (c) 2015 All rights reserved -# This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# 0.1: This script boots the VM1 and allocates IP address from Nova -# Later, the VM2 boots then execute cloud-init to ping VM1. -# After successful ping, both the VMs are deleted. -# 0.2: measure test duration and publish results under json format -# 0.3: adapt push 2 DB after Test API refacroting -# -import argparse -import datetime import os -import pprint import re +import pprint import sys import time -import functest.utils.functest_logger as ft_logger -import functest.utils.functest_utils as functest_utils + +import functest.utils.functest_utils as ft_utils import functest.utils.openstack_utils as os_utils import paramiko from scp import SCPClient import yaml - -pp = pprint.PrettyPrinter(indent=4) - -parser = argparse.ArgumentParser() -image_exists = False - -parser.add_argument("-d", "--debug", help="Debug mode", action="store_true") -parser.add_argument("-r", "--report", - help="Create json result file", - action="store_true") - -args = parser.parse_args() - -""" logging configuration """ -logger = ft_logger.Logger("vping_ssh").getLogger() - -# paramiko.util.log_to_file("/var/log/paramiko.log") - REPO_PATH = os.environ['repos_dir'] + '/functest/' -if not os.path.exists(REPO_PATH): - logger.error("Functest repository directory not found '%s'" % REPO_PATH) - exit(-1) with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f: functest_yaml = yaml.safe_load(f) f.close() -HOME = os.environ['HOME'] + "/" -# vPing parameters +NAME_VM_1 = functest_yaml.get("vping").get("vm_name_1") +NAME_VM_2 = functest_yaml.get("vping").get("vm_name_2") + VM_BOOT_TIMEOUT = 180 VM_DELETE_TIMEOUT = 100 PING_TIMEOUT = functest_yaml.get("vping").get("ping_timeout") -TEST_DB = functest_yaml.get("results").get("test_db_url") -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("vping").get("image_name") -GLANCE_IMAGE_FILENAME = functest_yaml.get("general").get("openstack").get( - "image_file_name") -GLANCE_IMAGE_FORMAT = functest_yaml.get("general").get("openstack").get( - "image_disk_format") +GLANCE_IMAGE_FILENAME = functest_yaml.get("general").get( + "openstack").get("image_file_name") +GLANCE_IMAGE_FORMAT = functest_yaml.get("general").get( + "openstack").get("image_disk_format") GLANCE_IMAGE_PATH = functest_yaml.get("general").get("directories").get( "dir_functest_data") + "/" + GLANCE_IMAGE_FILENAME FLAVOR = functest_yaml.get("vping").get("vm_flavor") # NEUTRON Private Network parameters - PRIVATE_NET_NAME = functest_yaml.get("vping").get( "vping_private_net_name") PRIVATE_SUBNET_NAME = functest_yaml.get("vping").get( @@ -87,11 +47,44 @@ SECGROUP_NAME = functest_yaml.get("vping").get("vping_sg_name") SECGROUP_DESCR = functest_yaml.get("vping").get("vping_sg_descr") +neutron_client = None +glance_client = None +nova_client = None +logger = None + +pp = pprint.PrettyPrinter(indent=4) + + def pMsg(value): """pretty printing""" pp.pprint(value) +def check_repo_exist(): + if not os.path.exists(REPO_PATH): + logger.error("Functest repository not found '%s'" % REPO_PATH) + exit(-1) + + +def get_vmname_1(): + return NAME_VM_1 + + +def get_vmname_2(): + return NAME_VM_2 + + +def init(vping_logger): + global nova_client + nova_client = os_utils.get_nova_client() + global neutron_client + neutron_client = os_utils.get_neutron_client() + global glance_client + glance_client = os_utils.get_glance_client() + global logger + logger = vping_logger + + def waitVmActive(nova, vm): # sleep and wait for VM status change @@ -112,26 +105,7 @@ def waitVmActive(nova, vm): return False -def waitVmDeleted(nova, vm): - - # sleep and wait for VM status change - sleep_time = 3 - count = VM_DELETE_TIMEOUT / sleep_time - while True: - status = os_utils.get_instance_status(nova, vm) - if not status: - return True - elif count == 0: - logger.debug("Timeout") - return False - else: - # return False - count -= 1 - time.sleep(sleep_time) - return False - - -def create_security_group(neutron_client): +def create_security_group(): sg_id = os_utils.get_security_group_id(neutron_client, SECGROUP_NAME) if sg_id != '': @@ -159,8 +133,9 @@ def create_security_group(neutron_client): logger.debug("Adding SSH rules in security group '%s'..." % SECGROUP_NAME) - if not os_utils.create_secgroup_rule( - neutron_client, sg_id, 'ingress', 'tcp', '22', '22'): + if not os_utils.create_secgroup_rule(neutron_client, sg_id, + 'ingress', 'tcp', + '22', '22'): logger.error("Failed to create the security group rule...") return False @@ -171,21 +146,13 @@ def create_security_group(neutron_client): return sg_id -def main(): - nova_client = os_utils.get_nova_client() - neutron_client = os_utils.get_neutron_client() - glance_client = os_utils.get_glance_client() - +def create_image(): EXIT_CODE = -1 - image_id = None - flavor = None - # Check if the given image exists image_id = os_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME) if image_id != '': logger.info("Using existing image '%s'..." % GLANCE_IMAGE_NAME) - global image_exists image_exists = True else: logger.info("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME, @@ -199,99 +166,118 @@ def main(): exit(EXIT_CODE) logger.debug("Image '%s' with ID=%s created successfully." % (GLANCE_IMAGE_NAME, image_id)) + return image_exists, image_id - network_dic = os_utils.create_network_full(neutron_client, - PRIVATE_NET_NAME, - PRIVATE_SUBNET_NAME, - ROUTER_NAME, - PRIVATE_SUBNET_CIDR) - if not network_dic: - logger.error( - "There has been a problem when creating the neutron network") - exit(EXIT_CODE) - - network_id = network_dic["net_id"] - sg_id = create_security_group(neutron_client) +def get_flavor(): + EXIT_CODE = -1 # Check if the given flavor exists try: flavor = nova_client.flavors.find(name=FLAVOR) logger.info("Using existing Flavor '%s'..." % FLAVOR) + return flavor except: logger.error("Flavor '%s' not found." % FLAVOR) logger.info("Available flavors are: ") pMsg(nova_client.flavor.list()) exit(EXIT_CODE) - # Deleting instances if they exist + +def create_network_full(): + EXIT_CODE = -1 + + network_dic = os_utils.create_network_full(neutron_client, + PRIVATE_NET_NAME, + PRIVATE_SUBNET_NAME, + ROUTER_NAME, + PRIVATE_SUBNET_CIDR) + + if not network_dic: + logger.error( + "There has been a problem when creating the neutron network") + exit(EXIT_CODE) + network_id = network_dic["net_id"] + return network_id + + +def delete_exist_vms(): servers = nova_client.servers.list() for server in servers: if server.name == NAME_VM_1 or server.name == NAME_VM_2: logger.info("Instance %s found. Deleting..." % server.name) server.delete() - # boot VM 1 - start_time = time.time() - stop_time = start_time - logger.info("vPing Start Time:'%s'" % ( - datetime.datetime.fromtimestamp(start_time).strftime( - '%Y-%m-%d %H:%M:%S'))) - - logger.info("Creating instance '%s'..." % NAME_VM_1) - logger.debug( - "Configuration:\n name=%s \n flavor=%s \n image=%s \n " - "network=%s \n" % (NAME_VM_1, flavor, image_id, network_id)) - vm1 = nova_client.servers.create( - name=NAME_VM_1, - flavor=flavor, - image=image_id, - nics=[{"net-id": network_id}] - ) + +def is_userdata(case): + return case == 'vping_userdata' + + +def is_ssh(case): + return case == 'vping_ssh' + + +def boot_vm(case, name, image_id, flavor, network_id, test_ip, sg_id): + EXIT_CODE = -1 + + config = dict() + config['name'] = name + config['flavor'] = flavor + config['image'] = image_id + config['nics'] = [{"net-id": network_id}] + if is_userdata(case): + config['config_drive'] = True + if name == NAME_VM_2: + u = ("#!/bin/sh\n\n" + "while true; do\n" + " ping -c 1 %s 2>&1 >/dev/null\n" + " RES=$?\n" + " if [ \"Z$RES\" = \"Z0\" ] ; then\n" + " echo 'vPing OK'\n" + " break\n" + " else\n" + " echo 'vPing KO'\n" + " fi\n" + " sleep 1\n" + "done\n" % test_ip) + config['userdata'] = u + + logger.info("Creating instance '%s'..." % name) + logger.debug("Configuration: %s" % config) + vm = nova_client.servers.create(**config) # wait until VM status is active - if not waitVmActive(nova_client, vm1): - logger.error("Instance '%s' cannot be booted. Status is '%s'" % ( - NAME_VM_1, os_utils.get_instance_status(nova_client, vm1))) - exit(EXIT_CODE) - else: - logger.info("Instance '%s' is ACTIVE." % NAME_VM_1) - - # Retrieve IP of first VM - test_ip = vm1.networks.get(PRIVATE_NET_NAME)[0] - logger.debug("Instance '%s' got private ip '%s'." % (NAME_VM_1, test_ip)) - - logger.info("Adding '%s' to security group '%s'..." - % (NAME_VM_1, SECGROUP_NAME)) - os_utils.add_secgroup_to_instance(nova_client, vm1.id, sg_id) - - # boot VM 2 - logger.info("Creating instance '%s'..." % NAME_VM_2) - logger.debug( - "Configuration:\n name=%s \n flavor=%s \n image=%s \n " - "network=%s \n" % (NAME_VM_2, flavor, image_id, network_id)) - vm2 = nova_client.servers.create( - name=NAME_VM_2, - flavor=flavor, - image=image_id, - nics=[{"net-id": network_id}] - ) - - if not waitVmActive(nova_client, vm2): + if not waitVmActive(nova_client, vm): + logger.error("Instance '%s' cannot be booted. Status is '%s'" % ( - NAME_VM_2, os_utils.get_instance_status(nova_client, vm2))) + name, os_utils.get_instance_status(nova_client, vm))) exit(EXIT_CODE) else: - logger.info("Instance '%s' is ACTIVE." % NAME_VM_2) + logger.info("Instance '%s' is ACTIVE." % name) + + add_secgroup(name, vm.id, sg_id) - logger.info("Adding '%s' to security group '%s'..." % (NAME_VM_2, - SECGROUP_NAME)) - os_utils.add_secgroup_to_instance(nova_client, vm2.id, sg_id) + return vm + + +def get_test_ip(vm): + test_ip = vm.networks.get(PRIVATE_NET_NAME)[0] + logger.debug("Instance '%s' got %s" % (vm.name, test_ip)) + return test_ip + + +def add_secgroup(vmname, vm_id, sg_id): + logger.info("Adding '%s' to security group '%s'..." % + (vmname, SECGROUP_NAME)) + os_utils.add_secgroup_to_instance(nova_client, vm_id, sg_id) + + +def add_float_ip(vm): + EXIT_CODE = -1 logger.info("Creating floating IP for VM '%s'..." % NAME_VM_2) floatip_dic = os_utils.create_floating_ip(neutron_client) floatip = floatip_dic['fip_addr'] - # floatip_id = floatip_dic['fip_id'] if floatip is None: logger.error("Cannot create floating IP.") @@ -300,10 +286,16 @@ def main(): logger.info("Associating floating ip: '%s' to VM '%s' " % (floatip, NAME_VM_2)) - if not os_utils.add_floating_ip(nova_client, vm2.id, floatip): + if not os_utils.add_floating_ip(nova_client, vm.id, floatip): logger.error("Cannot associate floating IP to VM.") exit(EXIT_CODE) + return floatip + + +def establish_ssh(vm, floatip): + EXIT_CODE = -1 + logger.info("Trying to establish SSH connection to %s..." % floatip) username = 'cirros' password = 'cubswin:)' @@ -326,7 +318,7 @@ def main(): time.sleep(6) timeout -= 1 - console_log = vm2.get_console_output() + console_log = vm.get_console_output() # print each "Sending discover" captured on the console log if (len(re.findall("Sending discover", console_log)) > @@ -355,7 +347,13 @@ def main(): logger.error("Cannot establish connection to IP '%s'. Aborting" % floatip) exit(EXIT_CODE) + return ssh + +def transfer_ping_script(ssh, floatip): + EXIT_CODE = -1 + + logger.info("Trying to transfer ping.sh to %s..." % floatip) scp = SCPClient(ssh.get_transport()) ping_script = REPO_PATH + "testcases/OpenStack/vPing/ping.sh" @@ -371,14 +369,13 @@ def main(): for line in stdout.readlines(): print line + +def do_vping_ssh(ssh, test_ip): logger.info("Waiting for ping...") - sec = 0 - stop_time = time.time() - duration = 0 + sec = 0 cmd = '~/ping.sh ' + test_ip flag = False - status = "FAIL" while True: time.sleep(1) @@ -388,11 +385,6 @@ def main(): for line in output: if "vPing OK" in line: logger.info("vPing detected!") - status = "PASS" - # we consider start time at VM1 booting - stop_time = time.time() - duration = round(stop_time - start_time, 1) - logger.info("vPing duration:'%s' s." % duration) EXIT_CODE = 0 flag = True break @@ -405,30 +397,83 @@ def main(): break logger.debug("Pinging %s. Waiting for response..." % test_ip) sec += 1 + return EXIT_CODE, time.time() + + +def do_vping_userdata(vm, test_ip): + logger.info("Waiting for ping...") + EXIT_CODE = -1 + sec = 0 + metadata_tries = 0 + + while True: + time.sleep(1) + console_log = vm.get_console_output() + if "vPing OK" in console_log: + logger.info("vPing detected!") + EXIT_CODE = 0 + break + elif ("failed to read iid from metadata" in console_log or + metadata_tries > 5): + EXIT_CODE = -2 + break + elif sec == PING_TIMEOUT: + logger.info("Timeout reached.") + break + elif sec % 10 == 0: + if "request failed" in console_log: + logger.debug("It seems userdata is not supported in " + "nova boot. Waiting a bit...") + metadata_tries += 1 + else: + logger.debug("Pinging %s. Waiting for response..." % test_ip) + sec += 1 + + return EXIT_CODE, time.time() + + +def do_vping(case, vm, test_ip): + if is_userdata(case): + return do_vping_userdata(vm, test_ip) + else: + floatip = add_float_ip(vm) + ssh = establish_ssh(vm, floatip) + transfer_ping_script(ssh, floatip) + return do_vping_ssh(ssh, test_ip) + - if status == "PASS": +def check_result(code, start_time, stop_time): + test_status = "FAIL" + if code == 0: logger.info("vPing OK") + duration = round(stop_time - start_time, 1) + logger.info("vPing duration:'%s'" % duration) + test_status = "PASS" + elif code == -2: + duration = 0 + logger.info("Userdata is not supported in nova boot. Aborting test...") else: duration = 0 logger.error("vPing FAILED") - if args.report: + details = {'timestart': start_time, + 'duration': duration, + 'status': test_status} + + return details + + +def push_result(report, case, start_time, stop_time, details): + if report: try: - logger.debug("Pushing vPing SSH results into DB...") - functest_utils.push_results_to_db("functest", - "vping_ssh", - logger, - start_time, - stop_time, - status, - details={'timestart': start_time, - 'duration': duration, - 'status': status}) + logger.debug("Pushing vPing %s results into DB..." % case) + ft_utils.push_results_to_db('functest', + case, + logger, + start_time, + stop_time, + details['status'], + details=details) except: logger.error("Error pushing results into Database '%s'" % sys.exc_info()[0]) - - exit(EXIT_CODE) - -if __name__ == '__main__': - main() diff --git a/testcases/features/multisite.py b/testcases/features/multisite.py index 6d492182c..6d492182c 100644..100755 --- a/testcases/features/multisite.py +++ b/testcases/features/multisite.py diff --git a/testcases/features/sfc/set-up-tacker.sh b/testcases/features/sfc/set-up-tacker.sh index da2cb922e..e88893391 100755 --- a/testcases/features/sfc/set-up-tacker.sh +++ b/testcases/features/sfc/set-up-tacker.sh @@ -1,6 +1,8 @@ -git_commit=ee3046f24df0bfca7ee15501f6c06ad86dd462c2 -curl "https://gerrit.opnfv.org/gerrit/gitweb?p=fuel.git;a=blob_plain;\ -f=prototypes/sfc_tacker/poc.tacker-up.sh;hb=${git_commit}" > poc.tacker-up.sh +git clone https://gerrit.opnfv.org/gerrit/fuel fuel +pushd fuel +git checkout e7f7abc89161441548545f79f0299610c6e5b203 +popd +mv fuel/prototypes/sfc_tacker/poc.tacker-up.sh . bash poc.tacker-up.sh cat <<EOF > delete.sh diff --git a/testcases/vnf/vRNC/parser.py b/testcases/vnf/vRNC/parser.py index 40d28c49f..40d28c49f 100644..100755 --- a/testcases/vnf/vRNC/parser.py +++ b/testcases/vnf/vRNC/parser.py |