From 68d29b6f6e71df6b4f177cd417f98d9e977f8893 Mon Sep 17 00:00:00 2001 From: "jose.lausuch" Date: Tue, 17 May 2016 21:36:56 +0200 Subject: Change 'testcases' directory structure JIRA: FUNCTEST-226 - Remove all 'CI' subdirs - Remove VIM dir and have OpenStack dir within /testcases/ - Split rally and tempest in 2 different dirs Change-Id: Icfc76d18a84f7a18d93ae1a5ec7dc7a560bb7ce9 Signed-off-by: jose.lausuch --- .../CI/custom_tests/neutron/010__networks.robot | 56 ---- .../ODL/CI/custom_tests/neutron/020__subnets.robot | 56 ---- .../ODL/CI/custom_tests/neutron/030__ports.robot | 56 ---- .../CI/custom_tests/neutron/040__delete_ports.txt | 37 --- .../custom_tests/neutron/050__delete_subnets.txt | 37 --- .../custom_tests/neutron/060__delete_networks.txt | 37 --- testcases/Controllers/ODL/CI/odlreport2db.py | 165 ------------ testcases/Controllers/ODL/CI/start_tests.sh | 97 ------- testcases/Controllers/ODL/CI/test_list.txt | 5 - .../ODL/custom_tests/neutron/010__networks.robot | 56 ++++ .../ODL/custom_tests/neutron/020__subnets.robot | 56 ++++ .../ODL/custom_tests/neutron/030__ports.robot | 56 ++++ .../ODL/custom_tests/neutron/040__delete_ports.txt | 37 +++ .../custom_tests/neutron/050__delete_subnets.txt | 37 +++ .../custom_tests/neutron/060__delete_networks.txt | 37 +++ testcases/Controllers/ODL/odlreport2db.py | 165 ++++++++++++ testcases/Controllers/ODL/start_tests.sh | 97 +++++++ testcases/Controllers/ODL/test_list.txt | 5 + testcases/Controllers/ONOS/Teston/CI/Readme.txt | 5 - testcases/Controllers/ONOS/Teston/CI/__init__.py | 0 .../ONOS/Teston/CI/adapters/__init__.py | 0 .../Controllers/ONOS/Teston/CI/adapters/client.py | 88 ------- .../ONOS/Teston/CI/adapters/connection.py | 196 -------------- .../ONOS/Teston/CI/adapters/environment.py | 281 --------------------- .../ONOS/Teston/CI/adapters/foundation.py | 104 -------- .../Controllers/ONOS/Teston/CI/dependencies/onos | 29 --- testcases/Controllers/ONOS/Teston/CI/log/gitignore | 0 .../Controllers/ONOS/Teston/CI/onosfunctest.py | 208 --------------- testcases/Controllers/ONOS/Teston/Readme.txt | 5 + testcases/Controllers/ONOS/Teston/__init__.py | 0 .../Controllers/ONOS/Teston/adapters/__init__.py | 0 .../Controllers/ONOS/Teston/adapters/client.py | 88 +++++++ .../Controllers/ONOS/Teston/adapters/connection.py | 196 ++++++++++++++ .../ONOS/Teston/adapters/environment.py | 281 +++++++++++++++++++++ .../Controllers/ONOS/Teston/adapters/foundation.py | 104 ++++++++ .../Controllers/ONOS/Teston/dependencies/onos | 29 +++ testcases/Controllers/ONOS/Teston/log/gitignore | 0 testcases/Controllers/ONOS/Teston/onosfunctest.py | 208 +++++++++++++++ 38 files changed, 1457 insertions(+), 1457 deletions(-) delete mode 100644 testcases/Controllers/ODL/CI/custom_tests/neutron/010__networks.robot delete mode 100644 testcases/Controllers/ODL/CI/custom_tests/neutron/020__subnets.robot delete mode 100644 testcases/Controllers/ODL/CI/custom_tests/neutron/030__ports.robot delete mode 100644 testcases/Controllers/ODL/CI/custom_tests/neutron/040__delete_ports.txt delete mode 100644 testcases/Controllers/ODL/CI/custom_tests/neutron/050__delete_subnets.txt delete mode 100644 testcases/Controllers/ODL/CI/custom_tests/neutron/060__delete_networks.txt delete mode 100644 testcases/Controllers/ODL/CI/odlreport2db.py delete mode 100755 testcases/Controllers/ODL/CI/start_tests.sh delete mode 100644 testcases/Controllers/ODL/CI/test_list.txt create mode 100644 testcases/Controllers/ODL/custom_tests/neutron/010__networks.robot create mode 100644 testcases/Controllers/ODL/custom_tests/neutron/020__subnets.robot create mode 100644 testcases/Controllers/ODL/custom_tests/neutron/030__ports.robot create mode 100644 testcases/Controllers/ODL/custom_tests/neutron/040__delete_ports.txt create mode 100644 testcases/Controllers/ODL/custom_tests/neutron/050__delete_subnets.txt create mode 100644 testcases/Controllers/ODL/custom_tests/neutron/060__delete_networks.txt create mode 100644 testcases/Controllers/ODL/odlreport2db.py create mode 100755 testcases/Controllers/ODL/start_tests.sh create mode 100644 testcases/Controllers/ODL/test_list.txt delete mode 100644 testcases/Controllers/ONOS/Teston/CI/Readme.txt delete mode 100644 testcases/Controllers/ONOS/Teston/CI/__init__.py delete mode 100644 testcases/Controllers/ONOS/Teston/CI/adapters/__init__.py delete mode 100644 testcases/Controllers/ONOS/Teston/CI/adapters/client.py delete mode 100644 testcases/Controllers/ONOS/Teston/CI/adapters/connection.py delete mode 100644 testcases/Controllers/ONOS/Teston/CI/adapters/environment.py delete mode 100644 testcases/Controllers/ONOS/Teston/CI/adapters/foundation.py delete mode 100644 testcases/Controllers/ONOS/Teston/CI/dependencies/onos delete mode 100644 testcases/Controllers/ONOS/Teston/CI/log/gitignore delete mode 100644 testcases/Controllers/ONOS/Teston/CI/onosfunctest.py create mode 100644 testcases/Controllers/ONOS/Teston/Readme.txt create mode 100644 testcases/Controllers/ONOS/Teston/__init__.py create mode 100644 testcases/Controllers/ONOS/Teston/adapters/__init__.py create mode 100644 testcases/Controllers/ONOS/Teston/adapters/client.py create mode 100644 testcases/Controllers/ONOS/Teston/adapters/connection.py create mode 100644 testcases/Controllers/ONOS/Teston/adapters/environment.py create mode 100644 testcases/Controllers/ONOS/Teston/adapters/foundation.py create mode 100644 testcases/Controllers/ONOS/Teston/dependencies/onos create mode 100644 testcases/Controllers/ONOS/Teston/log/gitignore create mode 100644 testcases/Controllers/ONOS/Teston/onosfunctest.py (limited to 'testcases/Controllers') diff --git a/testcases/Controllers/ODL/CI/custom_tests/neutron/010__networks.robot b/testcases/Controllers/ODL/CI/custom_tests/neutron/010__networks.robot deleted file mode 100644 index 583a6a153..000000000 --- a/testcases/Controllers/ODL/CI/custom_tests/neutron/010__networks.robot +++ /dev/null @@ -1,56 +0,0 @@ -*** Settings *** -Documentation Checking Network created in OpenStack are pushed to OpenDaylight -Suite Setup Create Session OSSession http://${NEUTRON}:9696 headers=${X-AUTH} -Suite Teardown Delete All Sessions -Library SSHLibrary -Library Collections -Library OperatingSystem -Library RequestsLibrary -Library ../../../libraries/Common.py -Variables ../../../variables/Variables.py - -*** Variables *** -${ODLREST} /controller/nb/v2/neutron/networks -${OSREST} /v2.0/networks -${postNet} {"network":{"name":"odl_network","admin_state_up":true}} - -*** Test Cases *** -Check OpenStack Networks - [Documentation] Checking OpenStack Neutron for known networks - [Tags] Network Neutron OpenStack - Log ${X-AUTH} - ${resp} get OSSession ${OSREST} - Should be Equal As Strings ${resp.status_code} 200 - ${OSResult} To Json ${resp.content} - Set Suite Variable ${OSResult} - Log ${OSResult} - -Check OpenDaylight Networks - [Documentation] Checking OpenDaylight Neutron API for Known Networks - [Tags] Network Neutron OpenDaylight - Create Session ODLSession http://${CONTROLLER}:${PORT} headers=${HEADERS} auth=${AUTH} - ${resp} get ODLSession ${ODLREST} - Should be Equal As Strings ${resp.status_code} 200 - ${ODLResult} To Json ${resp.content} - Set Suite Variable ${ODLResult} - Log ${ODLResult} - -Create Network - [Documentation] Create new network in OpenStack - [Tags] Create Network OpenStack Neutron - Log ${postNet} - ${resp} post OSSession ${OSREST} data=${postNet} - Should be Equal As Strings ${resp.status_code} 201 - ${result} To JSON ${resp.content} - ${result} Get From Dictionary ${result} network - ${NETID} Get From Dictionary ${result} id - Log ${result} - Log ${NETID} - Set Global Variable ${NETID} - sleep 2 - -Check Network - [Documentation] Check Network created in OpenDaylight - [Tags] Check Network OpenDaylight - ${resp} get ODLSession ${ODLREST}/${NetID} - Should be Equal As Strings ${resp.status_code} 200 diff --git a/testcases/Controllers/ODL/CI/custom_tests/neutron/020__subnets.robot b/testcases/Controllers/ODL/CI/custom_tests/neutron/020__subnets.robot deleted file mode 100644 index 5f5b82440..000000000 --- a/testcases/Controllers/ODL/CI/custom_tests/neutron/020__subnets.robot +++ /dev/null @@ -1,56 +0,0 @@ -*** Settings *** -Documentation Checking Subnets created in OpenStack are pushed to OpenDaylight -Suite Setup Create Session OSSession http://${NEUTRON}:9696 headers=${X-AUTH} -Suite Teardown Delete All Sessions -Library SSHLibrary -Library Collections -Library OperatingSystem -Library RequestsLibrary -Library ../../../libraries/Common.py -Variables ../../../variables/Variables.py - -*** Variables *** -${ODLREST} /controller/nb/v2/neutron/subnets -${OSREST} /v2.0/subnets -${data} {"subnet":{"network_id":"${NETID}","ip_version":4,"cidr":"172.16.64.0/24","allocation_pools":[{"start":"172.16.64.20","end":"172.16.64.120"}]}} - -*** Test Cases *** -Check OpenStack Subnets - [Documentation] Checking OpenStack Neutron for known Subnets - [Tags] Subnets Neutron OpenStack - Log ${X-AUTH} - ${resp} get OSSession ${OSREST} - Should be Equal As Strings ${resp.status_code} 200 - ${OSResult} To Json ${resp.content} - Set Suite Variable ${OSResult} - Log ${OSResult} - -Check OpenDaylight subnets - [Documentation] Checking OpenDaylight Neutron API for Known Subnets - [Tags] Subnets Neutron OpenDaylight - Create Session ODLSession http://${CONTROLLER}:${PORT} headers=${HEADERS} auth=${AUTH} - ${resp} get ODLSession ${ODLREST} - Should be Equal As Strings ${resp.status_code} 200 - ${ODLResult} To Json ${resp.content} - Set Suite Variable ${ODLResult} - Log ${ODLResult} - -Create New subnet - [Documentation] Create new subnet in OpenStack - [Tags] Create Subnet OpenStack Neutron - Log ${data} - ${resp} post OSSession ${OSREST} data=${data} - Should be Equal As Strings ${resp.status_code} 201 - ${result} To JSON ${resp.content} - ${result} Get From Dictionary ${result} subnet - ${SUBNETID} Get From Dictionary ${result} id - Log ${result} - Log ${SUBNETID} - Set Global Variable ${SUBNETID} - sleep 2 - -Check New subnet - [Documentation] Check new subnet created in OpenDaylight - [Tags] Check subnet OpenDaylight - ${resp} get ODLSession ${ODLREST}/${SUBNETID} - Should be Equal As Strings ${resp.status_code} 200 diff --git a/testcases/Controllers/ODL/CI/custom_tests/neutron/030__ports.robot b/testcases/Controllers/ODL/CI/custom_tests/neutron/030__ports.robot deleted file mode 100644 index 8b75733b7..000000000 --- a/testcases/Controllers/ODL/CI/custom_tests/neutron/030__ports.robot +++ /dev/null @@ -1,56 +0,0 @@ -*** Settings *** -Documentation Checking Port created in OpenStack are pushed to OpenDaylight -Suite Setup Create Session OSSession http://${NEUTRON}:9696 headers=${X-AUTH} -Suite Teardown Delete All Sessions -Library SSHLibrary -Library Collections -Library OperatingSystem -Library RequestsLibrary -Library ../../../libraries/Common.py -Variables ../../../variables/Variables.py - -*** Variables *** -${ODLREST} /controller/nb/v2/neutron/ports -${OSREST} /v2.0/ports -${data} {"port":{"network_id":"${NETID}","admin_state_up": true}} - -*** Test Cases *** -Check OpenStack ports - [Documentation] Checking OpenStack Neutron for known ports - [Tags] Ports Neutron OpenStack - Log ${X-AUTH} - ${resp} get OSSession ${OSREST} - Should be Equal As Strings ${resp.status_code} 200 - ${OSResult} To Json ${resp.content} - Set Suite Variable ${OSResult} - Log ${OSResult} - -Check OpenDaylight ports - [Documentation] Checking OpenDaylight Neutron API for Known Ports - [Tags] Ports Neutron OpenDaylight - Create Session ODLSession http://${CONTROLLER}:${PORT} headers=${HEADERS} auth=${AUTH} - ${resp} get ODLSession ${ODLREST} - Should be Equal As Strings ${resp.status_code} 200 - ${ODLResult} To Json ${resp.content} - Set Suite Variable ${ODLResult} - Log ${ODLResult} - -Create New Port - [Documentation] Create new port in OpenStack - [Tags] Create port OpenStack Neutron - Log ${data} - ${resp} post OSSession ${OSREST} data=${data} - Should be Equal As Strings ${resp.status_code} 201 - ${result} To JSON ${resp.content} - ${result} Get From Dictionary ${result} port - ${PORTID} Get From Dictionary ${result} id - Log ${result} - Log ${PORTID} - Set Global Variable ${PORTID} - sleep 2 - -Check New Port - [Documentation] Check new subnet created in OpenDaylight - [Tags] Check subnet OpenDaylight - ${resp} get ODLSession ${ODLREST}/${PORTID} - Should be Equal As Strings ${resp.status_code} 200 diff --git a/testcases/Controllers/ODL/CI/custom_tests/neutron/040__delete_ports.txt b/testcases/Controllers/ODL/CI/custom_tests/neutron/040__delete_ports.txt deleted file mode 100644 index f10298839..000000000 --- a/testcases/Controllers/ODL/CI/custom_tests/neutron/040__delete_ports.txt +++ /dev/null @@ -1,37 +0,0 @@ -*** Settings *** -Documentation Checking Port deleted in OpenStack are deleted also in OpenDaylight -Suite Setup Create Session OSSession http://${NEUTRON}:9696 headers=${X-AUTH} -Suite Teardown Delete All Sessions -Library SSHLibrary -Library Collections -Library OperatingSystem -Library ../../../libraries/RequestsLibrary.py -Library ../../../libraries/Common.py -Variables ../../../variables/Variables.py - -*** Variables *** -${ODLREST} /controller/nb/v2/neutron/ports -${OSREST} /v2.0/ports/${PORTID} -${data} {"port":{"network_id":"${NETID}","admin_state_up": true}} - -*** Test Cases *** -Delete New Port - [Documentation] Delete previously created port in OpenStack - [Tags] Delete port OpenStack Neutron - Log ${data} - ${resp} delete OSSession ${OSREST} - Should be Equal As Strings ${resp.status_code} 204 - Log ${resp.content} - sleep 2 - -Check Port Deleted - [Documentation] Check port deleted in OpenDaylight - [Tags] Check port deleted OpenDaylight - Create Session ODLSession http://${CONTROLLER}:${PORT} headers=${HEADERS} auth=${AUTH} - ${resp} get ODLSession ${ODLREST} - Should be Equal As Strings ${resp.status_code} 200 - ${ODLResult} To Json ${resp.content} - Set Suite Variable ${ODLResult} - Log ${ODLResult} - ${resp} get ODLSession ${ODLREST}/${PORTID} - Should be Equal As Strings ${resp.status_code} 404 diff --git a/testcases/Controllers/ODL/CI/custom_tests/neutron/050__delete_subnets.txt b/testcases/Controllers/ODL/CI/custom_tests/neutron/050__delete_subnets.txt deleted file mode 100644 index fb619825b..000000000 --- a/testcases/Controllers/ODL/CI/custom_tests/neutron/050__delete_subnets.txt +++ /dev/null @@ -1,37 +0,0 @@ -*** Settings *** -Documentation Checking Subnets deleted in OpenStack are deleted also in OpenDaylight -Suite Setup Create Session OSSession http://${NEUTRON}:9696 headers=${X-AUTH} -Suite Teardown Delete All Sessions -Library SSHLibrary -Library Collections -Library OperatingSystem -Library ../../../libraries/RequestsLibrary.py -Library ../../../libraries/Common.py -Variables ../../../variables/Variables.py - -*** Variables *** -${ODLREST} /controller/nb/v2/neutron/subnets -${OSREST} /v2.0/subnets/${SUBNETID} -${data} {"subnet":{"network_id":"${NETID}","ip_version":4,"cidr":"172.16.64.0/24","allocation_pools":[{"start":"172.16.64.20","end":"172.16.64.120"}]}} - -*** Test Cases *** -Delete New subnet - [Documentation] Delete previously created subnet in OpenStack - [Tags] Delete Subnet OpenStack Neutron - Log ${data} - ${resp} delete OSSession ${OSREST} - Should be Equal As Strings ${resp.status_code} 204 - Log ${resp.content} - sleep 2 - -Check New subnet deleted - [Documentation] Check subnet deleted in OpenDaylight - [Tags] Check subnet deleted OpenDaylight - Create Session ODLSession http://${CONTROLLER}:${PORT} headers=${HEADERS} auth=${AUTH} - ${resp} get ODLSession ${ODLREST} - Should be Equal As Strings ${resp.status_code} 200 - ${ODLResult} To Json ${resp.content} - Set Suite Variable ${ODLResult} - Log ${ODLResult} - ${resp} get ODLSession ${ODLREST}/${SUBNETID} - Should be Equal As Strings ${resp.status_code} 404 diff --git a/testcases/Controllers/ODL/CI/custom_tests/neutron/060__delete_networks.txt b/testcases/Controllers/ODL/CI/custom_tests/neutron/060__delete_networks.txt deleted file mode 100644 index 528fbfca2..000000000 --- a/testcases/Controllers/ODL/CI/custom_tests/neutron/060__delete_networks.txt +++ /dev/null @@ -1,37 +0,0 @@ -*** Settings *** -Documentation Checking Network deleted in OpenStack are deleted also in OpenDaylight -Suite Setup Create Session OSSession http://${NEUTRON}:9696 headers=${X-AUTH} -Suite Teardown Delete All Sessions -Library SSHLibrary -Library Collections -Library OperatingSystem -Library ../../../libraries/RequestsLibrary.py -Library ../../../libraries/Common.py -Variables ../../../variables/Variables.py - -*** Variables *** -${ODLREST} /controller/nb/v2/neutron/networks -${OSREST} /v2.0/networks/${NETID} -${postNet} {"network":{"name":"odl_network","admin_state_up":true}} - -*** Test Cases *** -Delete Network - [Documentation] Delete network in OpenStack - [Tags] Delete Network OpenStack Neutron - Log ${postNet} - ${resp} delete OSSession ${OSREST} - Should be Equal As Strings ${resp.status_code} 204 - Log ${resp.content} - sleep 2 - -Check Network deleted - [Documentation] Check Network deleted in OpenDaylight - [Tags] Check Network OpenDaylight - Create Session ODLSession http://${CONTROLLER}:${PORT} headers=${HEADERS} auth=${AUTH} - ${resp} get ODLSession ${ODLREST} - Should be Equal As Strings ${resp.status_code} 200 - ${ODLResult} To Json ${resp.content} - Set Suite Variable ${ODLResult} - Log ${ODLResult} - ${resp} get ODLSession ${ODLREST}/${NetID} - Should be Equal As Strings ${resp.status_code} 404 diff --git a/testcases/Controllers/ODL/CI/odlreport2db.py b/testcases/Controllers/ODL/CI/odlreport2db.py deleted file mode 100644 index 50c8b096e..000000000 --- a/testcases/Controllers/ODL/CI/odlreport2db.py +++ /dev/null @@ -1,165 +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 -# -# 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 -# -# - -import getopt -import json -import os -import sys -import xmltodict -import yaml - -import functest.utils.functest_utils as functest_utils - - -def usage(): - print """Usage: - get-json-from-robot.py --xml= --pod= - --installer= --database= - --scenaro=SCENARIO - -x, --xml xml file generated by robot test - -p, --pod POD name where the test come from - -i, --installer - -s, --scenario - -h, --help this message - """ - sys.exit(2) - - -def populate_detail(test): - detail = {} - detail['test_name'] = test['@name'] - detail['test_status'] = test['status'] - detail['test_doc'] = test['doc'] - 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 = [] - try: - for suite in suites: - data['details'] = parse_test(suite['test'], details) - except TypeError: - # suites is not iterable - data['details'] = parse_test(suites['test'], details) - return data - - -def main(argv): - try: - opts, args = getopt.getopt(argv, - 'x:p:i:s:h', - ['xml=', 'pod=', - 'installer=', - 'scenario=', - 'help']) - except getopt.GetoptError: - usage() - - for opt, arg in opts: - if opt in ('-h', '--help'): - usage() - elif opt in ('-x', '--xml'): - xml_file = arg - elif opt in ('-p', '--pod'): - pod = arg - elif opt in ('-i', '--installer'): - installer = arg - elif opt in ('-s', '--scenario'): - scenario = arg - else: - 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'] - - data = parse_suites(all_data['suite']['suite']) - data['description'] = all_data['suite']['@name'] - data['version'] = all_data['@generator'] - data['test_project'] = "functest" - data['case_name'] = "ODL" - data['pod_name'] = pod - data['installer'] = installer - - json.dumps(data, indent=4, separators=(',', ': ')) - - # Only used from container, we can set up absolute path - with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f: - functest_yaml = yaml.safe_load(f) - f.close() - - database = functest_yaml.get("results").get("test_db_url") - build_tag = functest_utils.get_build_tag() - - try: - # example: - # python odlreport2db.py -x ~/Pictures/Perso/odl/output3.xml - # -i fuel - # -p opnfv-jump-2 - # -s os-odl_l2-ha - version = functest_utils.get_version() - - # success criteria for ODL = 100% of tests OK - status = "failed" - try: - tests_passed = 0 - tests_failed = 0 - for v in data['details']: - if v['test_status']['@status'] == "PASS": - tests_passed += 1 - else: - tests_failed += 1 - - if (tests_failed < 1): - status = "passed" - except: - print("Unable to set criteria" % sys.exc_info()[0]) - functest_utils.push_results_to_db(database, - "functest", - data['case_name'], - None, - data['pod_name'], - version, - scenario, - status, - build_tag, - data) - except: - print("Error pushing results into Database '%s'" % sys.exc_info()[0]) - - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/testcases/Controllers/ODL/CI/start_tests.sh b/testcases/Controllers/ODL/CI/start_tests.sh deleted file mode 100755 index 3800b6307..000000000 --- a/testcases/Controllers/ODL/CI/start_tests.sh +++ /dev/null @@ -1,97 +0,0 @@ -#!/bin/bash -# it includes python2.7 virtual env with robot packages and git -# -# 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 -# - -BASEDIR=`dirname $0` -RESULTS_DIR='/home/opnfv/functest/results/odl/' -REPO_DIR='/home/opnfv/repos/odl_integration' -#TODO: read this form config_functest.yaml - -# Colors -green='\033[0;32m' -light_green='\033[1;32m' -red='\033[1;31m' -nc='\033[0m' # No Color - -usage="Script for starting ODL tests. Tests to be executed are specified in test_list.txt file. - -usage: -[var=value] bash $(basename "$0") [-h] - -where: - -h show this help text - var one of the following: ODL_IP, ODL_PORT, USR_NAME, PASS, NEUTRON_IP - value new value for var - -example: - ODL_IP=oscontro1 ODL_PORT=8080 bash $(basename "$0")" - -while getopts ':h' option; do - case "$option" in - h) echo "$usage" - exit - ;; - \?) printf "illegal option: -%s\n" "$OPTARG" >&2 - echo "$usage" >&2 - exit 1 - ;; - esac -done - -echo -e "${green}Current environment parameters for ODL suite.${nc}" -# Following vars might be also specified as CLI params -set -x -ODL_IP=${ODL_IP:-'192.168.1.5'} -ODL_PORT=${ODL_PORT:-8081} -USR_NAME=${USR_NAME:-'neutron'} -PASS=${PASS:-'octopus'} -NEUTRON_IP=${NEUTRON_IP:-192.168.0.68} -KEYSTONE_IP=${KEYSTONE_IP:-192.168.0.69} -set +x - -init_file=${REPO_DIR}/test/csit/suites/openstack/neutron/__init__.robot -# Change openstack password for admin tenant in neutron suite -sed -i "s/\"password\": \".*\"/\"password\": \"${PASS}\"/" $init_file - -# Add Start Suite and Teardown Suite -if [[ ! `grep 'Suite Teardown' ${init_file}` ]]; then - sed -i "/^Documentation.*/a Suite Teardown Stop Suite" $init_file - sed -i "/^Documentation.*/a Suite Setup Start Suite" $init_file -fi - -# add custom tests to suite, if there are more custom tests needed this will be reworked -echo -e "${green}Copy custom tests to suite.${nc}" -cp -vf ${BASEDIR}/custom_tests/neutron/* ${REPO_DIR}/test/csit/suites/openstack/neutron/ - -# List of tests are specified in test_list.txt -# those are relative paths to test directories from integartion suite -echo -e "${green}Executing chosen tests.${nc}" -test_num=0 -while read line -do - # skip comments - [[ ${line:0:1} == "#" ]] && continue - # skip empty lines - [[ -z "${line}" ]] && continue - - ((test_num++)) - echo -e "${light_green}Starting test: $line ${nc}" - pybot -v OPENSTACK:${KEYSTONE_IP} -v NEUTRON:${NEUTRON_IP} -v PORT:${ODL_PORT} -v CONTROLLER:${ODL_IP} ${REPO_DIR}/$line - mkdir -p $RESULTS_DIR/logs/${test_num} - mv log.html $RESULTS_DIR/logs/${test_num}/ - mv report.html $RESULTS_DIR/logs/${test_num}/ - mv output.xml $RESULTS_DIR/logs/${test_num}/ -done < ${BASEDIR}/test_list.txt - -# create final report which includes all partial test reports -for i in $(seq $test_num); do - rebot_params="$rebot_params $RESULTS_DIR/logs/$i/output.xml" -done - -echo -e "${green}Final report is located:${nc}" -rebot $rebot_params diff --git a/testcases/Controllers/ODL/CI/test_list.txt b/testcases/Controllers/ODL/CI/test_list.txt deleted file mode 100644 index ad791e553..000000000 --- a/testcases/Controllers/ODL/CI/test_list.txt +++ /dev/null @@ -1,5 +0,0 @@ -# List of tests` which will be executed by script start_test.sh -# You can specify path to specific robot test file or directory (in that case all tests from directory will be executed) - -test/csit/suites/integration/basic/ -test/csit/suites/openstack/neutron/ diff --git a/testcases/Controllers/ODL/custom_tests/neutron/010__networks.robot b/testcases/Controllers/ODL/custom_tests/neutron/010__networks.robot new file mode 100644 index 000000000..583a6a153 --- /dev/null +++ b/testcases/Controllers/ODL/custom_tests/neutron/010__networks.robot @@ -0,0 +1,56 @@ +*** Settings *** +Documentation Checking Network created in OpenStack are pushed to OpenDaylight +Suite Setup Create Session OSSession http://${NEUTRON}:9696 headers=${X-AUTH} +Suite Teardown Delete All Sessions +Library SSHLibrary +Library Collections +Library OperatingSystem +Library RequestsLibrary +Library ../../../libraries/Common.py +Variables ../../../variables/Variables.py + +*** Variables *** +${ODLREST} /controller/nb/v2/neutron/networks +${OSREST} /v2.0/networks +${postNet} {"network":{"name":"odl_network","admin_state_up":true}} + +*** Test Cases *** +Check OpenStack Networks + [Documentation] Checking OpenStack Neutron for known networks + [Tags] Network Neutron OpenStack + Log ${X-AUTH} + ${resp} get OSSession ${OSREST} + Should be Equal As Strings ${resp.status_code} 200 + ${OSResult} To Json ${resp.content} + Set Suite Variable ${OSResult} + Log ${OSResult} + +Check OpenDaylight Networks + [Documentation] Checking OpenDaylight Neutron API for Known Networks + [Tags] Network Neutron OpenDaylight + Create Session ODLSession http://${CONTROLLER}:${PORT} headers=${HEADERS} auth=${AUTH} + ${resp} get ODLSession ${ODLREST} + Should be Equal As Strings ${resp.status_code} 200 + ${ODLResult} To Json ${resp.content} + Set Suite Variable ${ODLResult} + Log ${ODLResult} + +Create Network + [Documentation] Create new network in OpenStack + [Tags] Create Network OpenStack Neutron + Log ${postNet} + ${resp} post OSSession ${OSREST} data=${postNet} + Should be Equal As Strings ${resp.status_code} 201 + ${result} To JSON ${resp.content} + ${result} Get From Dictionary ${result} network + ${NETID} Get From Dictionary ${result} id + Log ${result} + Log ${NETID} + Set Global Variable ${NETID} + sleep 2 + +Check Network + [Documentation] Check Network created in OpenDaylight + [Tags] Check Network OpenDaylight + ${resp} get ODLSession ${ODLREST}/${NetID} + Should be Equal As Strings ${resp.status_code} 200 diff --git a/testcases/Controllers/ODL/custom_tests/neutron/020__subnets.robot b/testcases/Controllers/ODL/custom_tests/neutron/020__subnets.robot new file mode 100644 index 000000000..5f5b82440 --- /dev/null +++ b/testcases/Controllers/ODL/custom_tests/neutron/020__subnets.robot @@ -0,0 +1,56 @@ +*** Settings *** +Documentation Checking Subnets created in OpenStack are pushed to OpenDaylight +Suite Setup Create Session OSSession http://${NEUTRON}:9696 headers=${X-AUTH} +Suite Teardown Delete All Sessions +Library SSHLibrary +Library Collections +Library OperatingSystem +Library RequestsLibrary +Library ../../../libraries/Common.py +Variables ../../../variables/Variables.py + +*** Variables *** +${ODLREST} /controller/nb/v2/neutron/subnets +${OSREST} /v2.0/subnets +${data} {"subnet":{"network_id":"${NETID}","ip_version":4,"cidr":"172.16.64.0/24","allocation_pools":[{"start":"172.16.64.20","end":"172.16.64.120"}]}} + +*** Test Cases *** +Check OpenStack Subnets + [Documentation] Checking OpenStack Neutron for known Subnets + [Tags] Subnets Neutron OpenStack + Log ${X-AUTH} + ${resp} get OSSession ${OSREST} + Should be Equal As Strings ${resp.status_code} 200 + ${OSResult} To Json ${resp.content} + Set Suite Variable ${OSResult} + Log ${OSResult} + +Check OpenDaylight subnets + [Documentation] Checking OpenDaylight Neutron API for Known Subnets + [Tags] Subnets Neutron OpenDaylight + Create Session ODLSession http://${CONTROLLER}:${PORT} headers=${HEADERS} auth=${AUTH} + ${resp} get ODLSession ${ODLREST} + Should be Equal As Strings ${resp.status_code} 200 + ${ODLResult} To Json ${resp.content} + Set Suite Variable ${ODLResult} + Log ${ODLResult} + +Create New subnet + [Documentation] Create new subnet in OpenStack + [Tags] Create Subnet OpenStack Neutron + Log ${data} + ${resp} post OSSession ${OSREST} data=${data} + Should be Equal As Strings ${resp.status_code} 201 + ${result} To JSON ${resp.content} + ${result} Get From Dictionary ${result} subnet + ${SUBNETID} Get From Dictionary ${result} id + Log ${result} + Log ${SUBNETID} + Set Global Variable ${SUBNETID} + sleep 2 + +Check New subnet + [Documentation] Check new subnet created in OpenDaylight + [Tags] Check subnet OpenDaylight + ${resp} get ODLSession ${ODLREST}/${SUBNETID} + Should be Equal As Strings ${resp.status_code} 200 diff --git a/testcases/Controllers/ODL/custom_tests/neutron/030__ports.robot b/testcases/Controllers/ODL/custom_tests/neutron/030__ports.robot new file mode 100644 index 000000000..8b75733b7 --- /dev/null +++ b/testcases/Controllers/ODL/custom_tests/neutron/030__ports.robot @@ -0,0 +1,56 @@ +*** Settings *** +Documentation Checking Port created in OpenStack are pushed to OpenDaylight +Suite Setup Create Session OSSession http://${NEUTRON}:9696 headers=${X-AUTH} +Suite Teardown Delete All Sessions +Library SSHLibrary +Library Collections +Library OperatingSystem +Library RequestsLibrary +Library ../../../libraries/Common.py +Variables ../../../variables/Variables.py + +*** Variables *** +${ODLREST} /controller/nb/v2/neutron/ports +${OSREST} /v2.0/ports +${data} {"port":{"network_id":"${NETID}","admin_state_up": true}} + +*** Test Cases *** +Check OpenStack ports + [Documentation] Checking OpenStack Neutron for known ports + [Tags] Ports Neutron OpenStack + Log ${X-AUTH} + ${resp} get OSSession ${OSREST} + Should be Equal As Strings ${resp.status_code} 200 + ${OSResult} To Json ${resp.content} + Set Suite Variable ${OSResult} + Log ${OSResult} + +Check OpenDaylight ports + [Documentation] Checking OpenDaylight Neutron API for Known Ports + [Tags] Ports Neutron OpenDaylight + Create Session ODLSession http://${CONTROLLER}:${PORT} headers=${HEADERS} auth=${AUTH} + ${resp} get ODLSession ${ODLREST} + Should be Equal As Strings ${resp.status_code} 200 + ${ODLResult} To Json ${resp.content} + Set Suite Variable ${ODLResult} + Log ${ODLResult} + +Create New Port + [Documentation] Create new port in OpenStack + [Tags] Create port OpenStack Neutron + Log ${data} + ${resp} post OSSession ${OSREST} data=${data} + Should be Equal As Strings ${resp.status_code} 201 + ${result} To JSON ${resp.content} + ${result} Get From Dictionary ${result} port + ${PORTID} Get From Dictionary ${result} id + Log ${result} + Log ${PORTID} + Set Global Variable ${PORTID} + sleep 2 + +Check New Port + [Documentation] Check new subnet created in OpenDaylight + [Tags] Check subnet OpenDaylight + ${resp} get ODLSession ${ODLREST}/${PORTID} + Should be Equal As Strings ${resp.status_code} 200 diff --git a/testcases/Controllers/ODL/custom_tests/neutron/040__delete_ports.txt b/testcases/Controllers/ODL/custom_tests/neutron/040__delete_ports.txt new file mode 100644 index 000000000..f10298839 --- /dev/null +++ b/testcases/Controllers/ODL/custom_tests/neutron/040__delete_ports.txt @@ -0,0 +1,37 @@ +*** Settings *** +Documentation Checking Port deleted in OpenStack are deleted also in OpenDaylight +Suite Setup Create Session OSSession http://${NEUTRON}:9696 headers=${X-AUTH} +Suite Teardown Delete All Sessions +Library SSHLibrary +Library Collections +Library OperatingSystem +Library ../../../libraries/RequestsLibrary.py +Library ../../../libraries/Common.py +Variables ../../../variables/Variables.py + +*** Variables *** +${ODLREST} /controller/nb/v2/neutron/ports +${OSREST} /v2.0/ports/${PORTID} +${data} {"port":{"network_id":"${NETID}","admin_state_up": true}} + +*** Test Cases *** +Delete New Port + [Documentation] Delete previously created port in OpenStack + [Tags] Delete port OpenStack Neutron + Log ${data} + ${resp} delete OSSession ${OSREST} + Should be Equal As Strings ${resp.status_code} 204 + Log ${resp.content} + sleep 2 + +Check Port Deleted + [Documentation] Check port deleted in OpenDaylight + [Tags] Check port deleted OpenDaylight + Create Session ODLSession http://${CONTROLLER}:${PORT} headers=${HEADERS} auth=${AUTH} + ${resp} get ODLSession ${ODLREST} + Should be Equal As Strings ${resp.status_code} 200 + ${ODLResult} To Json ${resp.content} + Set Suite Variable ${ODLResult} + Log ${ODLResult} + ${resp} get ODLSession ${ODLREST}/${PORTID} + Should be Equal As Strings ${resp.status_code} 404 diff --git a/testcases/Controllers/ODL/custom_tests/neutron/050__delete_subnets.txt b/testcases/Controllers/ODL/custom_tests/neutron/050__delete_subnets.txt new file mode 100644 index 000000000..fb619825b --- /dev/null +++ b/testcases/Controllers/ODL/custom_tests/neutron/050__delete_subnets.txt @@ -0,0 +1,37 @@ +*** Settings *** +Documentation Checking Subnets deleted in OpenStack are deleted also in OpenDaylight +Suite Setup Create Session OSSession http://${NEUTRON}:9696 headers=${X-AUTH} +Suite Teardown Delete All Sessions +Library SSHLibrary +Library Collections +Library OperatingSystem +Library ../../../libraries/RequestsLibrary.py +Library ../../../libraries/Common.py +Variables ../../../variables/Variables.py + +*** Variables *** +${ODLREST} /controller/nb/v2/neutron/subnets +${OSREST} /v2.0/subnets/${SUBNETID} +${data} {"subnet":{"network_id":"${NETID}","ip_version":4,"cidr":"172.16.64.0/24","allocation_pools":[{"start":"172.16.64.20","end":"172.16.64.120"}]}} + +*** Test Cases *** +Delete New subnet + [Documentation] Delete previously created subnet in OpenStack + [Tags] Delete Subnet OpenStack Neutron + Log ${data} + ${resp} delete OSSession ${OSREST} + Should be Equal As Strings ${resp.status_code} 204 + Log ${resp.content} + sleep 2 + +Check New subnet deleted + [Documentation] Check subnet deleted in OpenDaylight + [Tags] Check subnet deleted OpenDaylight + Create Session ODLSession http://${CONTROLLER}:${PORT} headers=${HEADERS} auth=${AUTH} + ${resp} get ODLSession ${ODLREST} + Should be Equal As Strings ${resp.status_code} 200 + ${ODLResult} To Json ${resp.content} + Set Suite Variable ${ODLResult} + Log ${ODLResult} + ${resp} get ODLSession ${ODLREST}/${SUBNETID} + Should be Equal As Strings ${resp.status_code} 404 diff --git a/testcases/Controllers/ODL/custom_tests/neutron/060__delete_networks.txt b/testcases/Controllers/ODL/custom_tests/neutron/060__delete_networks.txt new file mode 100644 index 000000000..528fbfca2 --- /dev/null +++ b/testcases/Controllers/ODL/custom_tests/neutron/060__delete_networks.txt @@ -0,0 +1,37 @@ +*** Settings *** +Documentation Checking Network deleted in OpenStack are deleted also in OpenDaylight +Suite Setup Create Session OSSession http://${NEUTRON}:9696 headers=${X-AUTH} +Suite Teardown Delete All Sessions +Library SSHLibrary +Library Collections +Library OperatingSystem +Library ../../../libraries/RequestsLibrary.py +Library ../../../libraries/Common.py +Variables ../../../variables/Variables.py + +*** Variables *** +${ODLREST} /controller/nb/v2/neutron/networks +${OSREST} /v2.0/networks/${NETID} +${postNet} {"network":{"name":"odl_network","admin_state_up":true}} + +*** Test Cases *** +Delete Network + [Documentation] Delete network in OpenStack + [Tags] Delete Network OpenStack Neutron + Log ${postNet} + ${resp} delete OSSession ${OSREST} + Should be Equal As Strings ${resp.status_code} 204 + Log ${resp.content} + sleep 2 + +Check Network deleted + [Documentation] Check Network deleted in OpenDaylight + [Tags] Check Network OpenDaylight + Create Session ODLSession http://${CONTROLLER}:${PORT} headers=${HEADERS} auth=${AUTH} + ${resp} get ODLSession ${ODLREST} + Should be Equal As Strings ${resp.status_code} 200 + ${ODLResult} To Json ${resp.content} + Set Suite Variable ${ODLResult} + Log ${ODLResult} + ${resp} get ODLSession ${ODLREST}/${NetID} + Should be Equal As Strings ${resp.status_code} 404 diff --git a/testcases/Controllers/ODL/odlreport2db.py b/testcases/Controllers/ODL/odlreport2db.py new file mode 100644 index 000000000..50c8b096e --- /dev/null +++ b/testcases/Controllers/ODL/odlreport2db.py @@ -0,0 +1,165 @@ +#!/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 +# +# 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 +# +# + +import getopt +import json +import os +import sys +import xmltodict +import yaml + +import functest.utils.functest_utils as functest_utils + + +def usage(): + print """Usage: + get-json-from-robot.py --xml= --pod= + --installer= --database= + --scenaro=SCENARIO + -x, --xml xml file generated by robot test + -p, --pod POD name where the test come from + -i, --installer + -s, --scenario + -h, --help this message + """ + sys.exit(2) + + +def populate_detail(test): + detail = {} + detail['test_name'] = test['@name'] + detail['test_status'] = test['status'] + detail['test_doc'] = test['doc'] + 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 = [] + try: + for suite in suites: + data['details'] = parse_test(suite['test'], details) + except TypeError: + # suites is not iterable + data['details'] = parse_test(suites['test'], details) + return data + + +def main(argv): + try: + opts, args = getopt.getopt(argv, + 'x:p:i:s:h', + ['xml=', 'pod=', + 'installer=', + 'scenario=', + 'help']) + except getopt.GetoptError: + usage() + + for opt, arg in opts: + if opt in ('-h', '--help'): + usage() + elif opt in ('-x', '--xml'): + xml_file = arg + elif opt in ('-p', '--pod'): + pod = arg + elif opt in ('-i', '--installer'): + installer = arg + elif opt in ('-s', '--scenario'): + scenario = arg + else: + 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'] + + data = parse_suites(all_data['suite']['suite']) + data['description'] = all_data['suite']['@name'] + data['version'] = all_data['@generator'] + data['test_project'] = "functest" + data['case_name'] = "ODL" + data['pod_name'] = pod + data['installer'] = installer + + json.dumps(data, indent=4, separators=(',', ': ')) + + # Only used from container, we can set up absolute path + with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f: + functest_yaml = yaml.safe_load(f) + f.close() + + database = functest_yaml.get("results").get("test_db_url") + build_tag = functest_utils.get_build_tag() + + try: + # example: + # python odlreport2db.py -x ~/Pictures/Perso/odl/output3.xml + # -i fuel + # -p opnfv-jump-2 + # -s os-odl_l2-ha + version = functest_utils.get_version() + + # success criteria for ODL = 100% of tests OK + status = "failed" + try: + tests_passed = 0 + tests_failed = 0 + for v in data['details']: + if v['test_status']['@status'] == "PASS": + tests_passed += 1 + else: + tests_failed += 1 + + if (tests_failed < 1): + status = "passed" + except: + print("Unable to set criteria" % sys.exc_info()[0]) + functest_utils.push_results_to_db(database, + "functest", + data['case_name'], + None, + data['pod_name'], + version, + scenario, + status, + build_tag, + data) + except: + print("Error pushing results into Database '%s'" % sys.exc_info()[0]) + + +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/testcases/Controllers/ODL/start_tests.sh b/testcases/Controllers/ODL/start_tests.sh new file mode 100755 index 000000000..3800b6307 --- /dev/null +++ b/testcases/Controllers/ODL/start_tests.sh @@ -0,0 +1,97 @@ +#!/bin/bash +# it includes python2.7 virtual env with robot packages and git +# +# 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 +# + +BASEDIR=`dirname $0` +RESULTS_DIR='/home/opnfv/functest/results/odl/' +REPO_DIR='/home/opnfv/repos/odl_integration' +#TODO: read this form config_functest.yaml + +# Colors +green='\033[0;32m' +light_green='\033[1;32m' +red='\033[1;31m' +nc='\033[0m' # No Color + +usage="Script for starting ODL tests. Tests to be executed are specified in test_list.txt file. + +usage: +[var=value] bash $(basename "$0") [-h] + +where: + -h show this help text + var one of the following: ODL_IP, ODL_PORT, USR_NAME, PASS, NEUTRON_IP + value new value for var + +example: + ODL_IP=oscontro1 ODL_PORT=8080 bash $(basename "$0")" + +while getopts ':h' option; do + case "$option" in + h) echo "$usage" + exit + ;; + \?) printf "illegal option: -%s\n" "$OPTARG" >&2 + echo "$usage" >&2 + exit 1 + ;; + esac +done + +echo -e "${green}Current environment parameters for ODL suite.${nc}" +# Following vars might be also specified as CLI params +set -x +ODL_IP=${ODL_IP:-'192.168.1.5'} +ODL_PORT=${ODL_PORT:-8081} +USR_NAME=${USR_NAME:-'neutron'} +PASS=${PASS:-'octopus'} +NEUTRON_IP=${NEUTRON_IP:-192.168.0.68} +KEYSTONE_IP=${KEYSTONE_IP:-192.168.0.69} +set +x + +init_file=${REPO_DIR}/test/csit/suites/openstack/neutron/__init__.robot +# Change openstack password for admin tenant in neutron suite +sed -i "s/\"password\": \".*\"/\"password\": \"${PASS}\"/" $init_file + +# Add Start Suite and Teardown Suite +if [[ ! `grep 'Suite Teardown' ${init_file}` ]]; then + sed -i "/^Documentation.*/a Suite Teardown Stop Suite" $init_file + sed -i "/^Documentation.*/a Suite Setup Start Suite" $init_file +fi + +# add custom tests to suite, if there are more custom tests needed this will be reworked +echo -e "${green}Copy custom tests to suite.${nc}" +cp -vf ${BASEDIR}/custom_tests/neutron/* ${REPO_DIR}/test/csit/suites/openstack/neutron/ + +# List of tests are specified in test_list.txt +# those are relative paths to test directories from integartion suite +echo -e "${green}Executing chosen tests.${nc}" +test_num=0 +while read line +do + # skip comments + [[ ${line:0:1} == "#" ]] && continue + # skip empty lines + [[ -z "${line}" ]] && continue + + ((test_num++)) + echo -e "${light_green}Starting test: $line ${nc}" + pybot -v OPENSTACK:${KEYSTONE_IP} -v NEUTRON:${NEUTRON_IP} -v PORT:${ODL_PORT} -v CONTROLLER:${ODL_IP} ${REPO_DIR}/$line + mkdir -p $RESULTS_DIR/logs/${test_num} + mv log.html $RESULTS_DIR/logs/${test_num}/ + mv report.html $RESULTS_DIR/logs/${test_num}/ + mv output.xml $RESULTS_DIR/logs/${test_num}/ +done < ${BASEDIR}/test_list.txt + +# create final report which includes all partial test reports +for i in $(seq $test_num); do + rebot_params="$rebot_params $RESULTS_DIR/logs/$i/output.xml" +done + +echo -e "${green}Final report is located:${nc}" +rebot $rebot_params diff --git a/testcases/Controllers/ODL/test_list.txt b/testcases/Controllers/ODL/test_list.txt new file mode 100644 index 000000000..ad791e553 --- /dev/null +++ b/testcases/Controllers/ODL/test_list.txt @@ -0,0 +1,5 @@ +# List of tests` which will be executed by script start_test.sh +# You can specify path to specific robot test file or directory (in that case all tests from directory will be executed) + +test/csit/suites/integration/basic/ +test/csit/suites/openstack/neutron/ diff --git a/testcases/Controllers/ONOS/Teston/CI/Readme.txt b/testcases/Controllers/ONOS/Teston/CI/Readme.txt deleted file mode 100644 index 7393f59a1..000000000 --- a/testcases/Controllers/ONOS/Teston/CI/Readme.txt +++ /dev/null @@ -1,5 +0,0 @@ -1.This is a basic test run about onos,we will make them better and better -2.This test include two suites: -(1)Test northbound(network/subnet/ports create/update/delete) -(2)Ovsdb test,default configuration,openflow connection,vm go onlines. -3.Later we will make a framework to do this test \ No newline at end of file diff --git a/testcases/Controllers/ONOS/Teston/CI/__init__.py b/testcases/Controllers/ONOS/Teston/CI/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/testcases/Controllers/ONOS/Teston/CI/adapters/__init__.py b/testcases/Controllers/ONOS/Teston/CI/adapters/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/testcases/Controllers/ONOS/Teston/CI/adapters/client.py b/testcases/Controllers/ONOS/Teston/CI/adapters/client.py deleted file mode 100644 index 77de092e4..000000000 --- a/testcases/Controllers/ONOS/Teston/CI/adapters/client.py +++ /dev/null @@ -1,88 +0,0 @@ -""" -Description: - This file is used to run testcase - lanqinglong@huawei.com - -# -# 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 -# -""" -from environment import environment -import time -import pexpect -import requests -import json - - -class client(environment): - - def __init__(self): - environment.__init__(self) - self.loginfo = environment() - self.testcase = '' - - def RunScript(self, handle, testname, timeout=300): - """ - Run ONOS Test Script - Parameters: - testname: ONOS Testcase Name - masterusername: The server username of running ONOS - masterpassword: The server password of running ONOS - """ - self.testcase = testname - self.ChangeTestCasePara(testname, self.masterusername, - self.masterpassword) - runhandle = handle - runtest = (self.home + "/OnosSystemTest/TestON/bin/cli.py run " + - testname) - runhandle.sendline(runtest) - circletime = 0 - lastshowscreeninfo = '' - while True: - Result = runhandle.expect(["PEXPECT]#", pexpect.EOF, - pexpect.TIMEOUT]) - curshowscreeninfo = runhandle.before - if(len(lastshowscreeninfo) != len(curshowscreeninfo)): - self.loginfo.log(str(curshowscreeninfo) - [len(lastshowscreeninfo)::]) - lastshowscreeninfo = curshowscreeninfo - if Result == 0: - print "Done!" - return - time.sleep(1) - circletime += 1 - if circletime > timeout: - break - self.loginfo.log("Timeout when running the test, please check!") - - def onosstart(self): - # This is the compass run machine user&pass,you need to modify - - print "Test Begin....." - self.OnosConnectionSet() - masterhandle = self.SSHlogin(self.localhost, self.masterusername, - self.masterpassword) - self.OnosEnvSetup(masterhandle) - return masterhandle - - def onosclean(self, handle): - self.SSHRelease(handle) - self.loginfo.log('Release onos handle Successful') - - def push_results_to_db(self, payload, pushornot=1): - if pushornot != 1: - return 1 - url = self.Result_DB + "/results" - params = {"project_name": "functest", "case_name": "ONOS-" + - self.testcase, "pod_name": 'huawei-build-2', - "details": payload} - - headers = {'Content-Type': 'application/json'} - try: - r = requests.post(url, data=json.dumps(params), headers=headers) - self.loginfo.log(r) - except: - self.loginfo.log('Error pushing results into Database') diff --git a/testcases/Controllers/ONOS/Teston/CI/adapters/connection.py b/testcases/Controllers/ONOS/Teston/CI/adapters/connection.py deleted file mode 100644 index 16f2ef32c..000000000 --- a/testcases/Controllers/ONOS/Teston/CI/adapters/connection.py +++ /dev/null @@ -1,196 +0,0 @@ -""" -Description: - This file is used to make connections - Include ssh & exchange public-key to each other so that - it can run without password - - lanqinglong@huawei.com - -# -# 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 os -import pexpect -import re -from foundation import foundation - - -class connection(foundation): - - def __init__(self): - foundation.__init__(self) - self.loginfo = foundation() - - def AddKnownHost(self, handle, ipaddr, username, password): - """ - Add an user to known host,so that onos can login in with onos $ipaddr. - parameters: - ipaddr: ip address - username: login user name - password: login password - """ - print("Now Adding an user to known hosts " + ipaddr) - login = handle - login.sendline("ssh -l %s -p 8101 %s" % (username, ipaddr)) - index = 0 - while index != 2: - index = login.expect(['assword:', 'yes/no', pexpect.EOF, - pexpect.TIMEOUT]) - if index == 0: - login.sendline(password) - login.sendline("logout") - index = login.expect(["closed", pexpect.EOF]) - if index == 0: - self.loginfo.log("Add SSH Known Host Success!") - break - else: - self.loginfo.log("Add SSH Known Host Failed! " - "Please Check!") - break - login.prompt() - - if index == 1: - login.sendline('yes') - - def GetEnvValue(self, handle, envname): - """ - os.getenv only returns current user value - GetEnvValue returns a environment value of - current handle - eg: GetEnvValue(handle,'HOME') - """ - envhandle = handle - envhandle.sendline('echo $' + envname) - envhandle.prompt() - reg = envname + '\r\n(.*)\r' - envaluereg = re.compile(reg) - envalue = envaluereg.search(envhandle.before) - if envalue: - return envalue.groups()[0] - else: - return None - - def Gensshkey(self, handle): - """ - Generate ssh keys, used for some server have no sshkey. - """ - print "Now Generating SSH keys..." - # Here file name may be id_rsa or id_ecdsa or others - # So here will have a judgement - keysub = handle - filepath = self.GetEnvValue(keysub, 'HOME') + '/.ssh' - filelist = os.listdir(filepath) - for item in filelist: - if 'id' in item: - self.loginfo.log("SSH keys are exsit in ssh directory.") - return True - keysub.sendline("ssh-keygen -t rsa") - Result = 0 - while Result != 2: - Result = keysub.expect(["Overwrite", "Enter", pexpect.EOF, - 'PEXPECT]#', pexpect.TIMEOUT]) - if Result == 0: - keysub.sendline("y") - if Result == 1 or Result == 2: - keysub.sendline("\n") - if Result == 3: - self.loginfo.log("Generate SSH key success.") - keysub.prompt() - break - if Result == 4: - self.loginfo.log("Generate SSH key failed.") - keysub.prompt() - break - - def GetRootAuth(self, password): - """ - Get root user - parameters: - password: root login password - """ - print("Now changing to user root") - login = pexpect.spawn("su - root") - index = 0 - while index != 2: - index = login.expect(['assword:', "failure", - pexpect.EOF, pexpect.TIMEOUT]) - if index == 0: - login.sendline(password) - if index == 1: - self.loginfo.log("Change user to root failed.") - - login.interact() - - def ReleaseRootAuth(self): - """ - Exit root user. - """ - print("Now Release user root") - login = pexpect.spawn("exit") - index = login.expect(['logout', pexpect.EOF, pexpect.TIMEOUT]) - if index == 0: - self.loginfo.log("Release root user success.") - if index == 1: - self.loginfo.log("Release root user failed.") - - login.interact() - - def AddEnvIntoBashrc(self, envalue): - """ - Add Env var into /etc/profile. - parameters: - envalue: environment value to add - """ - print "Now Adding bash environment" - fileopen = open("/etc/profile", 'r') - findContext = 1 - while findContext: - findContext = fileopen.readline() - result = findContext.find(envalue) - if result != -1: - break - fileopen.close - if result == -1: - envAdd = open("/etc/profile", 'a+') - envAdd.writelines("\n" + envalue) - envAdd.close() - self.loginfo.log("Add env to bashrc success!") - - def OnosRootPathChange(self, onospath): - """ - Change ONOS root path in file:bash_profile - onospath: path of onos root - """ - print "Now Changing ONOS Root Path" - filepath = onospath + 'onos/tools/dev/bash_profile' - line = open(filepath, 'r').readlines() - lenall = len(line) - 1 - for i in range(lenall): - if "export ONOS_ROOT" in line[i]: - line[i] = 'export ONOS_ROOT=' + onospath + 'onos\n' - NewFile = open(filepath, 'w') - NewFile.writelines(line) - NewFile.close - print "Done!" - - def OnosConnectionSet(self): - """ - Intergrate for ONOS connection setup - """ - if self.masterusername == 'root': - filepath = '/root/' - else: - filepath = '/home/' + self.masterusername + '/' - filepath = os.path.join(filepath, "onos/tools/dev/bash_profile") - self.AddEnvIntoBashrc("source " + filepath + "\n") - self.AddEnvIntoBashrc("export OCT=" + self.OCT) - self.AddEnvIntoBashrc("export OC1=" + self.OC1) - self.AddEnvIntoBashrc("export OC2=" + self.OC2) - self.AddEnvIntoBashrc("export OC3=" + self.OC3) - self.AddEnvIntoBashrc("export OCN=" + self.OCN) - self.AddEnvIntoBashrc("export OCN2=" + self.OCN2) - self.AddEnvIntoBashrc("export localhost=" + self.localhost) diff --git a/testcases/Controllers/ONOS/Teston/CI/adapters/environment.py b/testcases/Controllers/ONOS/Teston/CI/adapters/environment.py deleted file mode 100644 index 49f7f9632..000000000 --- a/testcases/Controllers/ONOS/Teston/CI/adapters/environment.py +++ /dev/null @@ -1,281 +0,0 @@ -""" -Description: - This file is used to setup the running environment - Include Download code,setup environment variable - Set onos running config - Set user name/password - Onos-push-keys and so on - lanqinglong@huawei.com - -# -# 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 os -import time -import pexpect -import re -import sys -import pxssh -from connection import connection - - -class environment(connection): - - def __init__(self): - connection.__init__(self) - self.loginfo = connection() - self.masterhandle = '' - self.home = '' - - def DownLoadCode(self, handle, codeurl): - """ - Download Code use 'git clone' - parameters: - handle: current working handle - codeurl: clone code url - """ - print "Now loading test codes! Please wait in patient..." - originalfolder = sys.path[0] - print originalfolder - gitclone = handle - gitclone.sendline("git clone " + codeurl) - index = 0 - # increment = 0 - while index != 1 or index != 4: - index = gitclone.expect(['already exists', - 'esolving deltas: 100%', - 'eceiving objects', - 'Already up-to-date', - 'npacking objects: 100%', pexpect.EOF]) - - filefolder = self.home + '/' + codeurl.split('/')[-1].split('.')[0] - if index == 0: - os.chdir(filefolder) - os.system('git pull') - os.chdir(originalfolder) - self.loginfo.log('Download code success!') - break - elif index == 1 or index == 4: - self.loginfo.log('Download code success!') - gitclone.sendline("mkdir onos") - gitclone.prompt() - gitclone.sendline("cp -rf " + filefolder + "/tools onos/") - gitclone.prompt() - break - elif index == 2: - os.write(1, gitclone.before) - sys.stdout.flush() - else: - self.loginfo.log('Download code failed!') - self.loginfo.log('Information before' + gitclone.before) - break - gitclone.prompt() - - def InstallDefaultSoftware(self, handle): - """ - Install default software - parameters: - handle(input): current working handle - """ - print "Now Cleaning test environment" - handle.sendline("sudo apt-get install -y mininet") - handle.prompt() - handle.sendline("sudo pip install configobj") - handle.prompt() - handle.sendline("sudo apt-get install -y sshpass") - handle.prompt() - handle.sendline("OnosSystemTest/TestON/bin/cleanup.sh") - handle.prompt() - time.sleep(5) - self.loginfo.log('Clean environment success!') - - def OnosPushKeys(self, handle, cmd, password): - """ - Using onos-push-keys to make ssh device without password - parameters: - handle(input): working handle - cmd(input): onos-push-keys xxx(xxx is device) - password(input): login in password - """ - print "Now Pushing Onos Keys:" + cmd - Pushkeys = handle - Pushkeys.sendline(cmd) - Result = 0 - while Result != 2: - Result = Pushkeys.expect(["(yes/no)", "assword:", "PEXPECT]#", - pexpect.EOF, pexpect.TIMEOUT]) - if(Result == 0): - Pushkeys.sendline("yes") - if(Result == 1): - Pushkeys.sendline(password) - if(Result == 2): - self.loginfo.log("ONOS Push keys Success!") - break - if(Result == 3): - self.loginfo.log("ONOS Push keys Error!") - break - time.sleep(2) - Pushkeys.prompt() - print "Done!" - - def SetOnosEnvVar(self, handle, masterpass, agentpass): - """ - Setup onos pushkeys to all devices(3+2) - parameters: - handle(input): current working handle - masterpass: scripts running server's password - agentpass: onos cluster&compute node password - """ - print "Now Setting test environment" - for host in self.hosts: - print "try to connect " + str(host) - result = self.CheckSshNoPasswd(host) - if not result: - print ("ssh lgin failed,try to copy master publickey" + - "to agent " + str(host)) - self.CopyPublicKey(host) - self.OnosPushKeys(handle, "onos-push-keys " + self.OCT, masterpass) - self.OnosPushKeys(handle, "onos-push-keys " + self.OC1, agentpass) - self.OnosPushKeys(handle, "onos-push-keys " + self.OC2, agentpass) - self.OnosPushKeys(handle, "onos-push-keys " + self.OC3, agentpass) - self.OnosPushKeys(handle, "onos-push-keys " + self.OCN, agentpass) - self.OnosPushKeys(handle, "onos-push-keys " + self.OCN2, agentpass) - - def CheckSshNoPasswd(self, host): - """ - Check master can connect agent with no password - """ - login = pexpect.spawn("ssh " + str(host)) - index = 4 - while index == 4: - index = login.expect(['(yes/no)', '>|#|\$', - pexpect.EOF, pexpect.TIMEOUT]) - if index == 0: - login.sendline("yes") - index = 4 - if index == 1: - self.loginfo.log("ssh connect to " + str(host) + - " success,no need to copy ssh public key") - return True - login.interact() - return False - - def ChangeOnosName(self, user, password): - """ - Change onos name in envDefault file - Because some command depend on this - parameters: - user: onos&compute node user - password: onos&compute node password - """ - print "Now Changing ONOS name&password" - filepath = self.home + '/onos/tools/build/envDefaults' - line = open(filepath, 'r').readlines() - lenall = len(line) - 1 - for i in range(lenall): - if "ONOS_USER=" in line[i]: - line[i] = line[i].replace("sdn", user) - if "ONOS_GROUP" in line[i]: - line[i] = line[i].replace("sdn", user) - if "ONOS_PWD" in line[i]: - line[i] = line[i].replace("rocks", password) - NewFile = open(filepath, 'w') - NewFile.writelines(line) - NewFile.close - print "Done!" - - def ChangeTestCasePara(self, testcase, user, password): - """ - When running test script, there's something need \ - to change in every test folder's *.param & *.topo files - user: onos&compute node user - password: onos&compute node password - """ - print "Now Changing " + testcase + " name&password" - if self.masterusername == 'root': - filepath = '/root/' - else: - filepath = '/home/' + self.masterusername + '/' - filepath = (filepath + "OnosSystemTest/TestON/tests/" + - testcase + "/" + testcase + ".topo") - line = open(filepath, 'r').readlines() - lenall = len(line) - 1 - for i in range(lenall - 2): - if("localhost" in line[i]) or ("OCT" in line[i]): - line[i + 1] = re.sub(">\w+", ">" + user, line[i + 1]) - line[i + 2] = re.sub(">\w+", ">" + password, line[i + 2]) - if ("OC1" in line[i] or "OC2" in line[i] or "OC3" in line[i] or - "OCN" in line[i] or "OCN2" in line[i]): - line[i + 1] = re.sub(">\w+", ">root", line[i + 1]) - line[i + 2] = re.sub(">\w+", ">root", line[i + 2]) - NewFile = open(filepath, 'w') - NewFile.writelines(line) - NewFile.close - - def SSHlogin(self, ipaddr, username, password): - """ - SSH login provide a connection to destination. - parameters: - ipaddr: ip address - username: login user name - password: login password - return: handle - """ - login = pxssh.pxssh() - login.login(ipaddr, username, password, original_prompt='[$#>]') - # send command ls -l - login.sendline('ls -l') - # match prompt - login.prompt() - print("SSH login " + ipaddr + " success!") - return login - - def SSHRelease(self, handle): - # Release ssh - handle.logout() - - def CopyOnostoTestbin(self): - sourcefile = self.cipath + '/dependencies/onos' - destifile = self.home + '/onos/tools/test/bin/' - os.system('pwd') - runcommand = 'cp ' + sourcefile + ' ' + destifile - os.system(runcommand) - - def CopyPublicKey(self, host): - output = os.popen('cat /root/.ssh/id_rsa.pub') - publickey = output.read().strip('\n') - tmphandle = self.SSHlogin(self.installer_master, - self.installer_master_username, - self.installer_master_password) - tmphandle.sendline("ssh " + host + " -T \'echo " + - str(publickey) + ">>/root/.ssh/authorized_keys\'") - tmphandle.prompt() - self.SSHRelease(tmphandle) - print "Add OCT PublicKey to " + host + " success" - - def OnosEnvSetup(self, handle): - """ - Onos Environment Setup function - """ - self.Gensshkey(handle) - self.home = self.GetEnvValue(handle, 'HOME') - self.AddKnownHost(handle, self.OC1, "karaf", "karaf") - self.AddKnownHost(handle, self.OC2, "karaf", "karaf") - self.AddKnownHost(handle, self.OC3, "karaf", "karaf") - self.DownLoadCode(handle, - 'https://github.com/sunyulin/OnosSystemTest.git') - # self.DownLoadCode(handle, 'https://gerrit.onosproject.org/onos') - if self.masterusername == 'root': - filepath = '/root/' - else: - filepath = '/home/' + self.masterusername + '/' - self.OnosRootPathChange(filepath) - self.CopyOnostoTestbin() - self.ChangeOnosName(self.agentusername, self.agentpassword) - self.InstallDefaultSoftware(handle) - self.SetOnosEnvVar(handle, self.masterpassword, self.agentpassword) diff --git a/testcases/Controllers/ONOS/Teston/CI/adapters/foundation.py b/testcases/Controllers/ONOS/Teston/CI/adapters/foundation.py deleted file mode 100644 index 47605eb74..000000000 --- a/testcases/Controllers/ONOS/Teston/CI/adapters/foundation.py +++ /dev/null @@ -1,104 +0,0 @@ -""" -Description: - This file include basis functions - lanqinglong@huawei.com - -# -# 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 logging -import os -import time -import yaml -import re -import datetime - - -class foundation: - - def __init__(self): - - # currentpath = os.getcwd() - REPO_PATH = os.environ['repos_dir'] + '/functest/' - currentpath = REPO_PATH + 'testcases/Controllers/ONOS/Teston/CI' - self.cipath = currentpath - self.logdir = os.path.join(currentpath, 'log') - self.workhome = currentpath[0: currentpath.rfind('testcases') - 1] - self.Result_DB = '' - filename = time.strftime('%Y-%m-%d-%H-%M-%S') + '.log' - self.logfilepath = os.path.join(self.logdir, filename) - self.starttime = datetime.datetime.now() - - def log(self, loginfo): - """ - Record log in log directory for deploying test environment - parameters: - loginfo(input): record info - """ - logging.basicConfig(level=logging.INFO, - format='%(asctime)s %(filename)s:%(message)s', - datefmt='%d %b %Y %H:%M:%S', - filename=self.logfilepath, - filemode='w') - filelog = logging.FileHandler(self.logfilepath) - logging.getLogger('Functest').addHandler(filelog) - print loginfo - logging.info(loginfo) - - def getdefaultpara(self): - """ - Get Default Parameters value - """ - with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f: - functest_yaml = yaml.safe_load(f) - - self.Result_DB = str(functest_yaml.get("results").get("test_db_url")) - self.masterusername = str(functest_yaml.get("ONOS").get("general"). - get('onosbench_username')) - self.masterpassword = str(functest_yaml.get("ONOS").get("general"). - get("onosbench_password")) - self.agentusername = str(functest_yaml.get("ONOS").get("general"). - get("onoscli_username")) - self.agentpassword = str(functest_yaml.get("ONOS").get("general"). - get("onoscli_password")) - self.runtimeout = functest_yaml.get("ONOS").get("general").get( - "runtimeout") - self.OCT = str(functest_yaml.get("ONOS").get("environment").get("OCT")) - self.OC1 = str(functest_yaml.get("ONOS").get("environment").get("OC1")) - self.OC2 = str(functest_yaml.get("ONOS").get("environment").get("OC2")) - self.OC3 = str(functest_yaml.get("ONOS").get("environment").get("OC3")) - self.OCN = str(functest_yaml.get("ONOS").get("environment").get("OCN")) - self.OCN2 = str(functest_yaml.get("ONOS"). - get("environment").get("OCN2")) - self.installer_master = str(functest_yaml.get("ONOS"). - get("environment").get("installer_master")) - self.installer_master_username = str(functest_yaml.get("ONOS"). - get("environment"). - get("installer_master_username")) - self.installer_master_password = str(functest_yaml.get("ONOS"). - get("environment"). - get("installer_master_password")) - self.hosts = [self.OC1, self.OCN, self.OCN2] - self.localhost = self.OCT - - def GetResult(self): - cmd = "cat " + self.logfilepath + " | grep Fail" - Resultbuffer = os.popen(cmd).read() - duration = datetime.datetime.now() - self.starttime - time.sleep(2) - - if re.search("[1-9]+", Resultbuffer): - self.log("Testcase Fails\n" + Resultbuffer) - Result = "POK" - else: - self.log("Testcases Pass") - Result = "OK" - payload = {'timestart': str(self.starttime), - 'duration': str(duration), 'status': Result} - - return payload diff --git a/testcases/Controllers/ONOS/Teston/CI/dependencies/onos b/testcases/Controllers/ONOS/Teston/CI/dependencies/onos deleted file mode 100644 index bb02fa899..000000000 --- a/testcases/Controllers/ONOS/Teston/CI/dependencies/onos +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -# ----------------------------------------------------------------------------- -# ONOS remote command-line client. -# ----------------------------------------------------------------------------- -# -# 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 -# - -[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 -. /root/.bashrc -. $ONOS_ROOT/tools/build/envDefaults -. $ONOS_ROOT/tools/test/bin/find-node.sh - -[ "$1" = "-w" ] && shift && onos-wait-for-start $1 - -[ -n "$1" ] && OCI=$(find_node $1) && shift - -if which client 1>/dev/null 2>&1 && [ -z "$ONOS_USE_SSH" ]; then - # Use Karaf client only if we can and are allowed to - unset KARAF_HOME - client -h $OCI -u karaf "$@" 2>/dev/null -else - # Otherwise use raw ssh; strict checking is off for dev environments only - #ssh -p 8101 -o StrictHostKeyChecking=no $OCI "$@" - sshpass -p karaf ssh -l karaf -p 8101 $OCI "$@" -fi diff --git a/testcases/Controllers/ONOS/Teston/CI/log/gitignore b/testcases/Controllers/ONOS/Teston/CI/log/gitignore deleted file mode 100644 index e69de29bb..000000000 diff --git a/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py b/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py deleted file mode 100644 index 1e278e6a1..000000000 --- a/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py +++ /dev/null @@ -1,208 +0,0 @@ -""" -Description: This test is to run onos Teston VTN scripts - -List of test cases: -CASE1 - Northbound NBI test network/subnet/ports -CASE2 - Ovsdb test&Default configuration&Vm go online - -lanqinglong@huawei.com -# -# 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 argparse -import datetime -import os -import re -import time -import yaml - -import functest.utils.functest_logger as ft_logger -import functest.utils.functest_utils as functest_utils - -parser = argparse.ArgumentParser() -parser.add_argument("-i", "--installer", help="Installer type") -args = parser.parse_args() -""" logging configuration """ -logger = ft_logger.Logger("onos").getLogger() - -with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f: - functest_yaml = yaml.safe_load(f) -f.close() - -# onos parameters -TEST_DB = functest_yaml.get("results").get("test_db_url") -ONOS_REPO_PATH = functest_yaml.get("general").get("directories").get( - "dir_repos") -ONOS_CONF_DIR = functest_yaml.get("general").get("directories").get( - "dir_functest_conf") -REPO_PATH = ONOS_REPO_PATH + '/functest/' -if not os.path.exists(REPO_PATH): - logger.error("Functest repository directory not found '%s'" % REPO_PATH) - exit(-1) - -ONOSCI_PATH = REPO_PATH + 'testcases/Controllers/ONOS/Teston/CI/' -starttime = datetime.datetime.now() - -HOME = os.environ['HOME'] + "/" - - -def RunScript(testname): - """ - Run ONOS Test Script - Parameters: - testname: ONOS Testcase Name - """ - runtest = ONOSCI_PATH + "OnosSystemTest/TestON/bin/cli.py run " + testname - logger.debug("Run script " + testname) - os.system(runtest) - - -def DownloadCodes(url="https://github.com/sunyulin/OnosSystemTest.git"): - """ - Download Onos Teston codes - Parameters: - url: github url - """ - downloadcode = "git clone " + url + " " + ONOSCI_PATH + "OnosSystemTest" - logger.debug("Download Onos Teston codes " + url) - os.system(downloadcode) - - -def GetResult(): - LOGPATH = ONOSCI_PATH + "OnosSystemTest/TestON/logs" - cmd = "grep -rnh " + "Fail" + " " + LOGPATH - Resultbuffer = os.popen(cmd).read() - # duration = datetime.datetime.now() - starttime - time.sleep(2) - - if re.search("\s+[1-9]+\s+", Resultbuffer): - logger.debug("Testcase Fails\n" + Resultbuffer) - # Result = "Failed" - else: - logger.debug("Testcases Success") - # Result = "Success" - # payload={'timestart': str(starttime), - # 'duration': str(duration), - # 'status': Result} - cmd = "grep -rnh 'Execution Time' " + LOGPATH - Resultbuffer = os.popen(cmd).read() - time1 = Resultbuffer[114:128] - time2 = Resultbuffer[28:42] - cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNB_*" - Resultbuffer = os.popen(cmd).read() - if Resultbuffer.find('100%') >= 0: - result1 = 'Success' - else: - result1 = 'Failed' - cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNBL3*" - Resultbuffer = os.popen(cmd).read() - if Resultbuffer.find('100%') >= 0: - result2 = 'Success' - else: - result2 = 'Failed' - status1 = [] - status2 = [] - cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNB_*" - Resultbuffer = os.popen(cmd).read() - pattern = re.compile("

([^-]+) - ([^-]+) - (\S*)

") - # res = pattern.search(Resultbuffer).groups() - res = pattern.findall(Resultbuffer) - i = 0 - for index in range(len(res)): - status1.append({'Case name:': res[i][0] + res[i][1], - 'Case result': res[i][2]}) - i = i + 1 - cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNBL3*" - Resultbuffer = os.popen(cmd).read() - pattern = re.compile("

([^-]+) - ([^-]+) - (\S*)

") - # res = pattern.search(Resultbuffer).groups() - res = pattern.findall(Resultbuffer) - i = 0 - for index in range(len(res)): - status2.append({'Case name:': res[i][0] + res[i][1], - 'Case result': res[i][2]}) - i = i + 1 - payload = {'timestart': str(starttime), - 'FUNCvirNet': {'duration': time1, - 'result': result1, - 'status': status1}, - 'FUNCvirNetL3': {'duration': time2, - 'result': result2, - 'status': status2}} - return payload - - -def SetOnosIp(): - cmd = "openstack catalog show network | grep publicURL" - cmd_output = os.popen(cmd).read() - OC1 = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group() - os.environ['OC1'] = OC1 - time.sleep(2) - logger.debug("ONOS IP is " + OC1) - - -def SetOnosIpForJoid(): - cmd = "env | grep SDN_CONTROLLER" - cmd_output = os.popen(cmd).read() - OC1 = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group() - os.environ['OC1'] = OC1 - time.sleep(2) - logger.debug("ONOS IP is " + OC1) - - -def CleanOnosTest(): - TESTONPATH = ONOSCI_PATH + "OnosSystemTest/" - cmd = "rm -rf " + TESTONPATH - os.system(cmd) - time.sleep(2) - logger.debug("Clean ONOS Teston") - - -def main(): - - DownloadCodes() - if args.installer == "joid": - logger.debug("Installer is Joid") - SetOnosIpForJoid() - else: - SetOnosIp() - RunScript("FUNCvirNetNB") - RunScript("FUNCvirNetNBL3") - - try: - logger.debug("Push result into DB") - # TODO check path result for the file - scenario = functest_utils.get_scenario(logger) - version = functest_utils.get_version(logger) - result = GetResult() - - # ONOS success criteria = all tests OK - # i.e. FUNCvirNet & FUNCvirNetL3 - status = "failed" - try: - if (result['FUNCvirNet']['result'] == "Success" and - result['FUNCvirNetL3']['result'] == "Success"): - status = "passed" - except: - logger.error("Unable to set ONOS criteria") - - pod_name = functest_utils.get_pod_name(logger) - build_tag = functest_utils.get_build_tag(logger) - functest_utils.push_results_to_db(TEST_DB, - "functest", - "ONOS", - logger, pod_name, version, scenario, - status, build_tag, payload=result) - except: - logger.error("Error pushing results into Database") - - CleanOnosTest() - - -if __name__ == '__main__': - main() diff --git a/testcases/Controllers/ONOS/Teston/Readme.txt b/testcases/Controllers/ONOS/Teston/Readme.txt new file mode 100644 index 000000000..7393f59a1 --- /dev/null +++ b/testcases/Controllers/ONOS/Teston/Readme.txt @@ -0,0 +1,5 @@ +1.This is a basic test run about onos,we will make them better and better +2.This test include two suites: +(1)Test northbound(network/subnet/ports create/update/delete) +(2)Ovsdb test,default configuration,openflow connection,vm go onlines. +3.Later we will make a framework to do this test \ No newline at end of file diff --git a/testcases/Controllers/ONOS/Teston/__init__.py b/testcases/Controllers/ONOS/Teston/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/testcases/Controllers/ONOS/Teston/adapters/__init__.py b/testcases/Controllers/ONOS/Teston/adapters/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/testcases/Controllers/ONOS/Teston/adapters/client.py b/testcases/Controllers/ONOS/Teston/adapters/client.py new file mode 100644 index 000000000..77de092e4 --- /dev/null +++ b/testcases/Controllers/ONOS/Teston/adapters/client.py @@ -0,0 +1,88 @@ +""" +Description: + This file is used to run testcase + lanqinglong@huawei.com + +# +# 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 +# +""" +from environment import environment +import time +import pexpect +import requests +import json + + +class client(environment): + + def __init__(self): + environment.__init__(self) + self.loginfo = environment() + self.testcase = '' + + def RunScript(self, handle, testname, timeout=300): + """ + Run ONOS Test Script + Parameters: + testname: ONOS Testcase Name + masterusername: The server username of running ONOS + masterpassword: The server password of running ONOS + """ + self.testcase = testname + self.ChangeTestCasePara(testname, self.masterusername, + self.masterpassword) + runhandle = handle + runtest = (self.home + "/OnosSystemTest/TestON/bin/cli.py run " + + testname) + runhandle.sendline(runtest) + circletime = 0 + lastshowscreeninfo = '' + while True: + Result = runhandle.expect(["PEXPECT]#", pexpect.EOF, + pexpect.TIMEOUT]) + curshowscreeninfo = runhandle.before + if(len(lastshowscreeninfo) != len(curshowscreeninfo)): + self.loginfo.log(str(curshowscreeninfo) + [len(lastshowscreeninfo)::]) + lastshowscreeninfo = curshowscreeninfo + if Result == 0: + print "Done!" + return + time.sleep(1) + circletime += 1 + if circletime > timeout: + break + self.loginfo.log("Timeout when running the test, please check!") + + def onosstart(self): + # This is the compass run machine user&pass,you need to modify + + print "Test Begin....." + self.OnosConnectionSet() + masterhandle = self.SSHlogin(self.localhost, self.masterusername, + self.masterpassword) + self.OnosEnvSetup(masterhandle) + return masterhandle + + def onosclean(self, handle): + self.SSHRelease(handle) + self.loginfo.log('Release onos handle Successful') + + def push_results_to_db(self, payload, pushornot=1): + if pushornot != 1: + return 1 + url = self.Result_DB + "/results" + params = {"project_name": "functest", "case_name": "ONOS-" + + self.testcase, "pod_name": 'huawei-build-2', + "details": payload} + + headers = {'Content-Type': 'application/json'} + try: + r = requests.post(url, data=json.dumps(params), headers=headers) + self.loginfo.log(r) + except: + self.loginfo.log('Error pushing results into Database') diff --git a/testcases/Controllers/ONOS/Teston/adapters/connection.py b/testcases/Controllers/ONOS/Teston/adapters/connection.py new file mode 100644 index 000000000..16f2ef32c --- /dev/null +++ b/testcases/Controllers/ONOS/Teston/adapters/connection.py @@ -0,0 +1,196 @@ +""" +Description: + This file is used to make connections + Include ssh & exchange public-key to each other so that + it can run without password + + lanqinglong@huawei.com + +# +# 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 os +import pexpect +import re +from foundation import foundation + + +class connection(foundation): + + def __init__(self): + foundation.__init__(self) + self.loginfo = foundation() + + def AddKnownHost(self, handle, ipaddr, username, password): + """ + Add an user to known host,so that onos can login in with onos $ipaddr. + parameters: + ipaddr: ip address + username: login user name + password: login password + """ + print("Now Adding an user to known hosts " + ipaddr) + login = handle + login.sendline("ssh -l %s -p 8101 %s" % (username, ipaddr)) + index = 0 + while index != 2: + index = login.expect(['assword:', 'yes/no', pexpect.EOF, + pexpect.TIMEOUT]) + if index == 0: + login.sendline(password) + login.sendline("logout") + index = login.expect(["closed", pexpect.EOF]) + if index == 0: + self.loginfo.log("Add SSH Known Host Success!") + break + else: + self.loginfo.log("Add SSH Known Host Failed! " + "Please Check!") + break + login.prompt() + + if index == 1: + login.sendline('yes') + + def GetEnvValue(self, handle, envname): + """ + os.getenv only returns current user value + GetEnvValue returns a environment value of + current handle + eg: GetEnvValue(handle,'HOME') + """ + envhandle = handle + envhandle.sendline('echo $' + envname) + envhandle.prompt() + reg = envname + '\r\n(.*)\r' + envaluereg = re.compile(reg) + envalue = envaluereg.search(envhandle.before) + if envalue: + return envalue.groups()[0] + else: + return None + + def Gensshkey(self, handle): + """ + Generate ssh keys, used for some server have no sshkey. + """ + print "Now Generating SSH keys..." + # Here file name may be id_rsa or id_ecdsa or others + # So here will have a judgement + keysub = handle + filepath = self.GetEnvValue(keysub, 'HOME') + '/.ssh' + filelist = os.listdir(filepath) + for item in filelist: + if 'id' in item: + self.loginfo.log("SSH keys are exsit in ssh directory.") + return True + keysub.sendline("ssh-keygen -t rsa") + Result = 0 + while Result != 2: + Result = keysub.expect(["Overwrite", "Enter", pexpect.EOF, + 'PEXPECT]#', pexpect.TIMEOUT]) + if Result == 0: + keysub.sendline("y") + if Result == 1 or Result == 2: + keysub.sendline("\n") + if Result == 3: + self.loginfo.log("Generate SSH key success.") + keysub.prompt() + break + if Result == 4: + self.loginfo.log("Generate SSH key failed.") + keysub.prompt() + break + + def GetRootAuth(self, password): + """ + Get root user + parameters: + password: root login password + """ + print("Now changing to user root") + login = pexpect.spawn("su - root") + index = 0 + while index != 2: + index = login.expect(['assword:', "failure", + pexpect.EOF, pexpect.TIMEOUT]) + if index == 0: + login.sendline(password) + if index == 1: + self.loginfo.log("Change user to root failed.") + + login.interact() + + def ReleaseRootAuth(self): + """ + Exit root user. + """ + print("Now Release user root") + login = pexpect.spawn("exit") + index = login.expect(['logout', pexpect.EOF, pexpect.TIMEOUT]) + if index == 0: + self.loginfo.log("Release root user success.") + if index == 1: + self.loginfo.log("Release root user failed.") + + login.interact() + + def AddEnvIntoBashrc(self, envalue): + """ + Add Env var into /etc/profile. + parameters: + envalue: environment value to add + """ + print "Now Adding bash environment" + fileopen = open("/etc/profile", 'r') + findContext = 1 + while findContext: + findContext = fileopen.readline() + result = findContext.find(envalue) + if result != -1: + break + fileopen.close + if result == -1: + envAdd = open("/etc/profile", 'a+') + envAdd.writelines("\n" + envalue) + envAdd.close() + self.loginfo.log("Add env to bashrc success!") + + def OnosRootPathChange(self, onospath): + """ + Change ONOS root path in file:bash_profile + onospath: path of onos root + """ + print "Now Changing ONOS Root Path" + filepath = onospath + 'onos/tools/dev/bash_profile' + line = open(filepath, 'r').readlines() + lenall = len(line) - 1 + for i in range(lenall): + if "export ONOS_ROOT" in line[i]: + line[i] = 'export ONOS_ROOT=' + onospath + 'onos\n' + NewFile = open(filepath, 'w') + NewFile.writelines(line) + NewFile.close + print "Done!" + + def OnosConnectionSet(self): + """ + Intergrate for ONOS connection setup + """ + if self.masterusername == 'root': + filepath = '/root/' + else: + filepath = '/home/' + self.masterusername + '/' + filepath = os.path.join(filepath, "onos/tools/dev/bash_profile") + self.AddEnvIntoBashrc("source " + filepath + "\n") + self.AddEnvIntoBashrc("export OCT=" + self.OCT) + self.AddEnvIntoBashrc("export OC1=" + self.OC1) + self.AddEnvIntoBashrc("export OC2=" + self.OC2) + self.AddEnvIntoBashrc("export OC3=" + self.OC3) + self.AddEnvIntoBashrc("export OCN=" + self.OCN) + self.AddEnvIntoBashrc("export OCN2=" + self.OCN2) + self.AddEnvIntoBashrc("export localhost=" + self.localhost) diff --git a/testcases/Controllers/ONOS/Teston/adapters/environment.py b/testcases/Controllers/ONOS/Teston/adapters/environment.py new file mode 100644 index 000000000..49f7f9632 --- /dev/null +++ b/testcases/Controllers/ONOS/Teston/adapters/environment.py @@ -0,0 +1,281 @@ +""" +Description: + This file is used to setup the running environment + Include Download code,setup environment variable + Set onos running config + Set user name/password + Onos-push-keys and so on + lanqinglong@huawei.com + +# +# 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 os +import time +import pexpect +import re +import sys +import pxssh +from connection import connection + + +class environment(connection): + + def __init__(self): + connection.__init__(self) + self.loginfo = connection() + self.masterhandle = '' + self.home = '' + + def DownLoadCode(self, handle, codeurl): + """ + Download Code use 'git clone' + parameters: + handle: current working handle + codeurl: clone code url + """ + print "Now loading test codes! Please wait in patient..." + originalfolder = sys.path[0] + print originalfolder + gitclone = handle + gitclone.sendline("git clone " + codeurl) + index = 0 + # increment = 0 + while index != 1 or index != 4: + index = gitclone.expect(['already exists', + 'esolving deltas: 100%', + 'eceiving objects', + 'Already up-to-date', + 'npacking objects: 100%', pexpect.EOF]) + + filefolder = self.home + '/' + codeurl.split('/')[-1].split('.')[0] + if index == 0: + os.chdir(filefolder) + os.system('git pull') + os.chdir(originalfolder) + self.loginfo.log('Download code success!') + break + elif index == 1 or index == 4: + self.loginfo.log('Download code success!') + gitclone.sendline("mkdir onos") + gitclone.prompt() + gitclone.sendline("cp -rf " + filefolder + "/tools onos/") + gitclone.prompt() + break + elif index == 2: + os.write(1, gitclone.before) + sys.stdout.flush() + else: + self.loginfo.log('Download code failed!') + self.loginfo.log('Information before' + gitclone.before) + break + gitclone.prompt() + + def InstallDefaultSoftware(self, handle): + """ + Install default software + parameters: + handle(input): current working handle + """ + print "Now Cleaning test environment" + handle.sendline("sudo apt-get install -y mininet") + handle.prompt() + handle.sendline("sudo pip install configobj") + handle.prompt() + handle.sendline("sudo apt-get install -y sshpass") + handle.prompt() + handle.sendline("OnosSystemTest/TestON/bin/cleanup.sh") + handle.prompt() + time.sleep(5) + self.loginfo.log('Clean environment success!') + + def OnosPushKeys(self, handle, cmd, password): + """ + Using onos-push-keys to make ssh device without password + parameters: + handle(input): working handle + cmd(input): onos-push-keys xxx(xxx is device) + password(input): login in password + """ + print "Now Pushing Onos Keys:" + cmd + Pushkeys = handle + Pushkeys.sendline(cmd) + Result = 0 + while Result != 2: + Result = Pushkeys.expect(["(yes/no)", "assword:", "PEXPECT]#", + pexpect.EOF, pexpect.TIMEOUT]) + if(Result == 0): + Pushkeys.sendline("yes") + if(Result == 1): + Pushkeys.sendline(password) + if(Result == 2): + self.loginfo.log("ONOS Push keys Success!") + break + if(Result == 3): + self.loginfo.log("ONOS Push keys Error!") + break + time.sleep(2) + Pushkeys.prompt() + print "Done!" + + def SetOnosEnvVar(self, handle, masterpass, agentpass): + """ + Setup onos pushkeys to all devices(3+2) + parameters: + handle(input): current working handle + masterpass: scripts running server's password + agentpass: onos cluster&compute node password + """ + print "Now Setting test environment" + for host in self.hosts: + print "try to connect " + str(host) + result = self.CheckSshNoPasswd(host) + if not result: + print ("ssh lgin failed,try to copy master publickey" + + "to agent " + str(host)) + self.CopyPublicKey(host) + self.OnosPushKeys(handle, "onos-push-keys " + self.OCT, masterpass) + self.OnosPushKeys(handle, "onos-push-keys " + self.OC1, agentpass) + self.OnosPushKeys(handle, "onos-push-keys " + self.OC2, agentpass) + self.OnosPushKeys(handle, "onos-push-keys " + self.OC3, agentpass) + self.OnosPushKeys(handle, "onos-push-keys " + self.OCN, agentpass) + self.OnosPushKeys(handle, "onos-push-keys " + self.OCN2, agentpass) + + def CheckSshNoPasswd(self, host): + """ + Check master can connect agent with no password + """ + login = pexpect.spawn("ssh " + str(host)) + index = 4 + while index == 4: + index = login.expect(['(yes/no)', '>|#|\$', + pexpect.EOF, pexpect.TIMEOUT]) + if index == 0: + login.sendline("yes") + index = 4 + if index == 1: + self.loginfo.log("ssh connect to " + str(host) + + " success,no need to copy ssh public key") + return True + login.interact() + return False + + def ChangeOnosName(self, user, password): + """ + Change onos name in envDefault file + Because some command depend on this + parameters: + user: onos&compute node user + password: onos&compute node password + """ + print "Now Changing ONOS name&password" + filepath = self.home + '/onos/tools/build/envDefaults' + line = open(filepath, 'r').readlines() + lenall = len(line) - 1 + for i in range(lenall): + if "ONOS_USER=" in line[i]: + line[i] = line[i].replace("sdn", user) + if "ONOS_GROUP" in line[i]: + line[i] = line[i].replace("sdn", user) + if "ONOS_PWD" in line[i]: + line[i] = line[i].replace("rocks", password) + NewFile = open(filepath, 'w') + NewFile.writelines(line) + NewFile.close + print "Done!" + + def ChangeTestCasePara(self, testcase, user, password): + """ + When running test script, there's something need \ + to change in every test folder's *.param & *.topo files + user: onos&compute node user + password: onos&compute node password + """ + print "Now Changing " + testcase + " name&password" + if self.masterusername == 'root': + filepath = '/root/' + else: + filepath = '/home/' + self.masterusername + '/' + filepath = (filepath + "OnosSystemTest/TestON/tests/" + + testcase + "/" + testcase + ".topo") + line = open(filepath, 'r').readlines() + lenall = len(line) - 1 + for i in range(lenall - 2): + if("localhost" in line[i]) or ("OCT" in line[i]): + line[i + 1] = re.sub(">\w+", ">" + user, line[i + 1]) + line[i + 2] = re.sub(">\w+", ">" + password, line[i + 2]) + if ("OC1" in line[i] or "OC2" in line[i] or "OC3" in line[i] or + "OCN" in line[i] or "OCN2" in line[i]): + line[i + 1] = re.sub(">\w+", ">root", line[i + 1]) + line[i + 2] = re.sub(">\w+", ">root", line[i + 2]) + NewFile = open(filepath, 'w') + NewFile.writelines(line) + NewFile.close + + def SSHlogin(self, ipaddr, username, password): + """ + SSH login provide a connection to destination. + parameters: + ipaddr: ip address + username: login user name + password: login password + return: handle + """ + login = pxssh.pxssh() + login.login(ipaddr, username, password, original_prompt='[$#>]') + # send command ls -l + login.sendline('ls -l') + # match prompt + login.prompt() + print("SSH login " + ipaddr + " success!") + return login + + def SSHRelease(self, handle): + # Release ssh + handle.logout() + + def CopyOnostoTestbin(self): + sourcefile = self.cipath + '/dependencies/onos' + destifile = self.home + '/onos/tools/test/bin/' + os.system('pwd') + runcommand = 'cp ' + sourcefile + ' ' + destifile + os.system(runcommand) + + def CopyPublicKey(self, host): + output = os.popen('cat /root/.ssh/id_rsa.pub') + publickey = output.read().strip('\n') + tmphandle = self.SSHlogin(self.installer_master, + self.installer_master_username, + self.installer_master_password) + tmphandle.sendline("ssh " + host + " -T \'echo " + + str(publickey) + ">>/root/.ssh/authorized_keys\'") + tmphandle.prompt() + self.SSHRelease(tmphandle) + print "Add OCT PublicKey to " + host + " success" + + def OnosEnvSetup(self, handle): + """ + Onos Environment Setup function + """ + self.Gensshkey(handle) + self.home = self.GetEnvValue(handle, 'HOME') + self.AddKnownHost(handle, self.OC1, "karaf", "karaf") + self.AddKnownHost(handle, self.OC2, "karaf", "karaf") + self.AddKnownHost(handle, self.OC3, "karaf", "karaf") + self.DownLoadCode(handle, + 'https://github.com/sunyulin/OnosSystemTest.git') + # self.DownLoadCode(handle, 'https://gerrit.onosproject.org/onos') + if self.masterusername == 'root': + filepath = '/root/' + else: + filepath = '/home/' + self.masterusername + '/' + self.OnosRootPathChange(filepath) + self.CopyOnostoTestbin() + self.ChangeOnosName(self.agentusername, self.agentpassword) + self.InstallDefaultSoftware(handle) + self.SetOnosEnvVar(handle, self.masterpassword, self.agentpassword) diff --git a/testcases/Controllers/ONOS/Teston/adapters/foundation.py b/testcases/Controllers/ONOS/Teston/adapters/foundation.py new file mode 100644 index 000000000..47605eb74 --- /dev/null +++ b/testcases/Controllers/ONOS/Teston/adapters/foundation.py @@ -0,0 +1,104 @@ +""" +Description: + This file include basis functions + lanqinglong@huawei.com + +# +# 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 logging +import os +import time +import yaml +import re +import datetime + + +class foundation: + + def __init__(self): + + # currentpath = os.getcwd() + REPO_PATH = os.environ['repos_dir'] + '/functest/' + currentpath = REPO_PATH + 'testcases/Controllers/ONOS/Teston/CI' + self.cipath = currentpath + self.logdir = os.path.join(currentpath, 'log') + self.workhome = currentpath[0: currentpath.rfind('testcases') - 1] + self.Result_DB = '' + filename = time.strftime('%Y-%m-%d-%H-%M-%S') + '.log' + self.logfilepath = os.path.join(self.logdir, filename) + self.starttime = datetime.datetime.now() + + def log(self, loginfo): + """ + Record log in log directory for deploying test environment + parameters: + loginfo(input): record info + """ + logging.basicConfig(level=logging.INFO, + format='%(asctime)s %(filename)s:%(message)s', + datefmt='%d %b %Y %H:%M:%S', + filename=self.logfilepath, + filemode='w') + filelog = logging.FileHandler(self.logfilepath) + logging.getLogger('Functest').addHandler(filelog) + print loginfo + logging.info(loginfo) + + def getdefaultpara(self): + """ + Get Default Parameters value + """ + with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f: + functest_yaml = yaml.safe_load(f) + + self.Result_DB = str(functest_yaml.get("results").get("test_db_url")) + self.masterusername = str(functest_yaml.get("ONOS").get("general"). + get('onosbench_username')) + self.masterpassword = str(functest_yaml.get("ONOS").get("general"). + get("onosbench_password")) + self.agentusername = str(functest_yaml.get("ONOS").get("general"). + get("onoscli_username")) + self.agentpassword = str(functest_yaml.get("ONOS").get("general"). + get("onoscli_password")) + self.runtimeout = functest_yaml.get("ONOS").get("general").get( + "runtimeout") + self.OCT = str(functest_yaml.get("ONOS").get("environment").get("OCT")) + self.OC1 = str(functest_yaml.get("ONOS").get("environment").get("OC1")) + self.OC2 = str(functest_yaml.get("ONOS").get("environment").get("OC2")) + self.OC3 = str(functest_yaml.get("ONOS").get("environment").get("OC3")) + self.OCN = str(functest_yaml.get("ONOS").get("environment").get("OCN")) + self.OCN2 = str(functest_yaml.get("ONOS"). + get("environment").get("OCN2")) + self.installer_master = str(functest_yaml.get("ONOS"). + get("environment").get("installer_master")) + self.installer_master_username = str(functest_yaml.get("ONOS"). + get("environment"). + get("installer_master_username")) + self.installer_master_password = str(functest_yaml.get("ONOS"). + get("environment"). + get("installer_master_password")) + self.hosts = [self.OC1, self.OCN, self.OCN2] + self.localhost = self.OCT + + def GetResult(self): + cmd = "cat " + self.logfilepath + " | grep Fail" + Resultbuffer = os.popen(cmd).read() + duration = datetime.datetime.now() - self.starttime + time.sleep(2) + + if re.search("[1-9]+", Resultbuffer): + self.log("Testcase Fails\n" + Resultbuffer) + Result = "POK" + else: + self.log("Testcases Pass") + Result = "OK" + payload = {'timestart': str(self.starttime), + 'duration': str(duration), 'status': Result} + + return payload diff --git a/testcases/Controllers/ONOS/Teston/dependencies/onos b/testcases/Controllers/ONOS/Teston/dependencies/onos new file mode 100644 index 000000000..bb02fa899 --- /dev/null +++ b/testcases/Controllers/ONOS/Teston/dependencies/onos @@ -0,0 +1,29 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# ONOS remote command-line client. +# ----------------------------------------------------------------------------- +# +# 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 +# + +[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 +. /root/.bashrc +. $ONOS_ROOT/tools/build/envDefaults +. $ONOS_ROOT/tools/test/bin/find-node.sh + +[ "$1" = "-w" ] && shift && onos-wait-for-start $1 + +[ -n "$1" ] && OCI=$(find_node $1) && shift + +if which client 1>/dev/null 2>&1 && [ -z "$ONOS_USE_SSH" ]; then + # Use Karaf client only if we can and are allowed to + unset KARAF_HOME + client -h $OCI -u karaf "$@" 2>/dev/null +else + # Otherwise use raw ssh; strict checking is off for dev environments only + #ssh -p 8101 -o StrictHostKeyChecking=no $OCI "$@" + sshpass -p karaf ssh -l karaf -p 8101 $OCI "$@" +fi diff --git a/testcases/Controllers/ONOS/Teston/log/gitignore b/testcases/Controllers/ONOS/Teston/log/gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/testcases/Controllers/ONOS/Teston/onosfunctest.py b/testcases/Controllers/ONOS/Teston/onosfunctest.py new file mode 100644 index 000000000..07ecacc5d --- /dev/null +++ b/testcases/Controllers/ONOS/Teston/onosfunctest.py @@ -0,0 +1,208 @@ +""" +Description: This test is to run onos Teston VTN scripts + +List of test cases: +CASE1 - Northbound NBI test network/subnet/ports +CASE2 - Ovsdb test&Default configuration&Vm go online + +lanqinglong@huawei.com +# +# 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 argparse +import datetime +import os +import re +import time +import yaml + +import functest.utils.functest_logger as ft_logger +import functest.utils.functest_utils as functest_utils + +parser = argparse.ArgumentParser() +parser.add_argument("-i", "--installer", help="Installer type") +args = parser.parse_args() +""" logging configuration """ +logger = ft_logger.Logger("onos").getLogger() + +with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f: + functest_yaml = yaml.safe_load(f) +f.close() + +# onos parameters +TEST_DB = functest_yaml.get("results").get("test_db_url") +ONOS_REPO_PATH = functest_yaml.get("general").get("directories").get( + "dir_repos") +ONOS_CONF_DIR = functest_yaml.get("general").get("directories").get( + "dir_functest_conf") +REPO_PATH = ONOS_REPO_PATH + '/functest/' +if not os.path.exists(REPO_PATH): + logger.error("Functest repository directory not found '%s'" % REPO_PATH) + exit(-1) + +ONOSCI_PATH = REPO_PATH + 'testcases/Controllers/ONOS/Teston/' +starttime = datetime.datetime.now() + +HOME = os.environ['HOME'] + "/" + + +def RunScript(testname): + """ + Run ONOS Test Script + Parameters: + testname: ONOS Testcase Name + """ + runtest = ONOSCI_PATH + "OnosSystemTest/TestON/bin/cli.py run " + testname + logger.debug("Run script " + testname) + os.system(runtest) + + +def DownloadCodes(url="https://github.com/sunyulin/OnosSystemTest.git"): + """ + Download Onos Teston codes + Parameters: + url: github url + """ + downloadcode = "git clone " + url + " " + ONOSCI_PATH + "OnosSystemTest" + logger.debug("Download Onos Teston codes " + url) + os.system(downloadcode) + + +def GetResult(): + LOGPATH = ONOSCI_PATH + "OnosSystemTest/TestON/logs" + cmd = "grep -rnh " + "Fail" + " " + LOGPATH + Resultbuffer = os.popen(cmd).read() + # duration = datetime.datetime.now() - starttime + time.sleep(2) + + if re.search("\s+[1-9]+\s+", Resultbuffer): + logger.debug("Testcase Fails\n" + Resultbuffer) + # Result = "Failed" + else: + logger.debug("Testcases Success") + # Result = "Success" + # payload={'timestart': str(starttime), + # 'duration': str(duration), + # 'status': Result} + cmd = "grep -rnh 'Execution Time' " + LOGPATH + Resultbuffer = os.popen(cmd).read() + time1 = Resultbuffer[114:128] + time2 = Resultbuffer[28:42] + cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNB_*" + Resultbuffer = os.popen(cmd).read() + if Resultbuffer.find('100%') >= 0: + result1 = 'Success' + else: + result1 = 'Failed' + cmd = "grep -rnh 'Success Percentage' " + LOGPATH + "/FUNCvirNetNBL3*" + Resultbuffer = os.popen(cmd).read() + if Resultbuffer.find('100%') >= 0: + result2 = 'Success' + else: + result2 = 'Failed' + status1 = [] + status2 = [] + cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNB_*" + Resultbuffer = os.popen(cmd).read() + pattern = re.compile("

([^-]+) - ([^-]+) - (\S*)

") + # res = pattern.search(Resultbuffer).groups() + res = pattern.findall(Resultbuffer) + i = 0 + for index in range(len(res)): + status1.append({'Case name:': res[i][0] + res[i][1], + 'Case result': res[i][2]}) + i = i + 1 + cmd = "grep -rnh 'h3' " + LOGPATH + "/FUNCvirNetNBL3*" + Resultbuffer = os.popen(cmd).read() + pattern = re.compile("

([^-]+) - ([^-]+) - (\S*)

") + # res = pattern.search(Resultbuffer).groups() + res = pattern.findall(Resultbuffer) + i = 0 + for index in range(len(res)): + status2.append({'Case name:': res[i][0] + res[i][1], + 'Case result': res[i][2]}) + i = i + 1 + payload = {'timestart': str(starttime), + 'FUNCvirNet': {'duration': time1, + 'result': result1, + 'status': status1}, + 'FUNCvirNetL3': {'duration': time2, + 'result': result2, + 'status': status2}} + return payload + + +def SetOnosIp(): + cmd = "openstack catalog show network | grep publicURL" + cmd_output = os.popen(cmd).read() + OC1 = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group() + os.environ['OC1'] = OC1 + time.sleep(2) + logger.debug("ONOS IP is " + OC1) + + +def SetOnosIpForJoid(): + cmd = "env | grep SDN_CONTROLLER" + cmd_output = os.popen(cmd).read() + OC1 = re.search(r"\d+\.\d+\.\d+\.\d+", cmd_output).group() + os.environ['OC1'] = OC1 + time.sleep(2) + logger.debug("ONOS IP is " + OC1) + + +def CleanOnosTest(): + TESTONPATH = ONOSCI_PATH + "OnosSystemTest/" + cmd = "rm -rf " + TESTONPATH + os.system(cmd) + time.sleep(2) + logger.debug("Clean ONOS Teston") + + +def main(): + + DownloadCodes() + if args.installer == "joid": + logger.debug("Installer is Joid") + SetOnosIpForJoid() + else: + SetOnosIp() + RunScript("FUNCvirNetNB") + RunScript("FUNCvirNetNBL3") + + try: + logger.debug("Push result into DB") + # TODO check path result for the file + scenario = functest_utils.get_scenario(logger) + version = functest_utils.get_version(logger) + result = GetResult() + + # ONOS success criteria = all tests OK + # i.e. FUNCvirNet & FUNCvirNetL3 + status = "failed" + try: + if (result['FUNCvirNet']['result'] == "Success" and + result['FUNCvirNetL3']['result'] == "Success"): + status = "passed" + except: + logger.error("Unable to set ONOS criteria") + + pod_name = functest_utils.get_pod_name(logger) + build_tag = functest_utils.get_build_tag(logger) + functest_utils.push_results_to_db(TEST_DB, + "functest", + "ONOS", + logger, pod_name, version, scenario, + status, build_tag, payload=result) + except: + logger.error("Error pushing results into Database") + + CleanOnosTest() + + +if __name__ == '__main__': + main() -- cgit 1.2.3-korg