aboutsummaryrefslogtreecommitdiffstats
path: root/functest/opnfv_tests/features/doctor.py
blob: dbd803a6522d817d7f006b8924f71ac59d2f9633 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python
#
# Copyright (c) 2015 All rights reserved
# This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 0.1: This script boots the VM1 and allocates IP address from Nova
# Later, the VM2 boots then execute cloud-init to ping VM1.
# After successful ping, both the VMs are deleted.
# 0.2: measure test duration and publish results under json format
#
#
import argparse
import os
import time

import functest.utils.functest_logger as ft_logger
import functest.utils.functest_utils as functest_utils
import functest.utils.functest_constants as ft_constants

parser = argparse.ArgumentParser()
parser.add_argument("-r", "--report",
                    help="Create json result file",
                    action="store_true")
args = parser.parse_args()

functest_yaml = functest_utils.get_functest_yaml()

DOCTOR_REPO_DIR = ft_constants.DOCTOR_REPO_DIR
RESULTS_DIR = ft_constants.FUNCTEST_RESULTS_DIR

logger = ft_logger.Logger("doctor").getLogger()


def main():
    exit_code = -1

    # if the image name is explicitly set for the doctor suite, set it as
    # enviroment variable
    if 'doctor' in functest_yaml and 'image_name' in functest_yaml['doctor']:
        os.environ["IMAGE_NAME"] = functest_yaml['doctor']['image_name']

    cmd = 'cd %s/tests && ./run.sh' % DOCTOR_REPO_DIR
    log_file = RESULTS_DIR + "/doctor.log"

    start_time = time.time()

    ret = functest_utils.execute_command(cmd,
                                         info=True,
                                         output_file=log_file)

    stop_time = time.time()
    duration = round(stop_time - start_time, 1)
    if ret == 0:
        logger.info("Doctor test case OK")
        test_status = 'OK'
        exit_code = 0
    else:
        logger.info("Doctor test case FAILED")
        test_status = 'NOK'

    details = {
        'timestart': start_time,
        'duration': duration,
        'status': test_status,
    }
    status = "FAIL"
    if details['status'] == "OK":
        status = "PASS"
    functest_utils.logger_test_results("Doctor",
                                       "doctor-notification",
                                       status, details)
    if args.report:
        functest_utils.push_results_to_db("doctor",
                                          "doctor-notification",
                                          start_time,
                                          stop_time,
                                          status,
                                          details)
        logger.info("Doctor results pushed to DB")

    exit(exit_code)


if __name__ == '__main__':
    main()
################################################### ############################################################################ # BEGIN of main # while getopts "b:B:dfFHl:p:s:S:i:h" OPTION do case $OPTION in b) BASE_CONFIG_URI=${OPTARG} if [[ ! $BASE_CONFIG_URI == file://* ]] && \ [[ ! $BASE_CONFIG_URI == http://* ]] && \ [[ ! $BASE_CONFIG_URI == https://* ]] && \ [[ ! $BASE_CONFIG_URI == ftp://* ]]; then echo "-b $BASE_CONFIG_URI - Not given in URI style" usage exit 1 fi ;; B) PXE_BRIDGE="-b ${OPTARG}" ;; d) DRY_RUN=1 ;; f) USE_EXISTING_FUEL='-nf' ;; F) FUEL_CREATION_ONLY='-fo' ;; H) NO_HEALTH_CHECK='-nh' ;; l) TARGET_LAB=${OPTARG} ;; p) TARGET_POD=${OPTARG} ;; s) DEPLOY_SCENARIO=${OPTARG} ;; S) STORAGE_DIR="-s ${OPTARG}" ;; i) ISO=${OPTARG} if [[ ! $ISO == file://* ]] && \ [[ ! $ISO == http://* ]] && \ [[ ! $ISO == https://* ]] && \ [[ ! $ISO == ftp://* ]]; then echo "-i $ISO - Not given in URI style" usage exit 1 fi ;; h) usage exit 0 ;; *) echo "${OPTION} is not a valid argument" echo "Arguments not according to new argument style" echo "Trying old-style compatibility mode" pushd ${DEPLOY_DIR} > /dev/null python deploy.py "$@" popd > /dev/null exit 0 ;; esac done if [[ $EUID -ne 0 ]]; then echo "This script must be run as root" 1>&2 exit 1 fi if [ -z $BASE_CONFIG_URI ] || [ -z $TARGET_LAB ] || \ [ -z $TARGET_POD ] || [ -z $DEPLOY_SCENARIO ] || \ [ -z $ISO ]; then echo "Arguments not according to new argument style" echo "Trying old-style compatibility mode" pushd ${DEPLOY_DIR} > /dev/null python deploy.py "$@" popd > /dev/null exit 0 fi # Enable the automatic exit trap trap do_exit SIGINT SIGTERM EXIT # Set no restrictive umask so that Jenkins can removeeee any residuals umask 0000 clean pushd ${DEPLOY_DIR} > /dev/null # Prepare the deploy config files based on lab/pod information, deployment # scenario, etc. echo "python deploy-config.py -dha ${BASE_CONFIG_URI}/labs/${TARGET_LAB}/${TARGET_POD}/fuel/config/dha.yaml -deab file://${DEPLOY_DIR}/config/dea_base.yaml -deao ${BASE_CONFIG_URI}/labs/${TARGET_LAB}/${TARGET_POD}/fuel/config/dea-pod-override.yaml -scenario-base-uri file://${DEPLOY_DIR}/scenario -scenario ${DEPLOY_SCENARIO} -plugins file://${DEPLOY_DIR}/config/plugins -output ${SCRIPT_PATH}/config" python deploy-config.py -dha ${BASE_CONFIG_URI}/labs/${TARGET_LAB}/${TARGET_POD}/fuel/config/dha.yaml -deab file://${DEPLOY_DIR}/config/dea_base.yaml -deao ${BASE_CONFIG_URI}/labs/${TARGET_LAB}/${TARGET_POD}/fuel/config/dea-pod-override.yaml -scenario-base-uri file://${DEPLOY_DIR}/scenario -scenario ${DEPLOY_SCENARIO} -plugins file://${DEPLOY_DIR}/config/plugins -output ${SCRIPT_PATH}/config if [ $DRY_RUN -eq 0 ]; then # Download iso if it doesn't already exists locally if [[ $ISO == file://* ]]; then ISO=${ISO#file://} else mkdir -p ${SCRIPT_PATH}/ISO curl -o ${SCRIPT_PATH}/ISO/image.iso $ISO ISO=${SCRIPT_PATH}/ISO/image.iso fi # Start deployment echo "python deploy.py -s $STORAGE_DIR -b $PXE_BRIDGE $USE_EXISTING_FUEL $FUEL_CREATION_ONLY $NO_HEALTH_CHECK -dea ${SCRIPT_PATH}/config/dea.yaml -dha ${SCRIPT_PATH}/config/dha.yaml -iso $ISO" python deploy.py $STORAGE_DIR $PXE_BRIDGE $USE_EXISTING_FUEL $FUEL_CREATION_ONLY $NO_HEALTH_CHECK -dea ${SCRIPT_PATH}/config/dea.yaml -dha ${SCRIPT_PATH}/config/dha.yaml -iso $ISO fi popd > /dev/null # # END of main ############################################################################