summaryrefslogtreecommitdiffstats
path: root/testcases/OpenStack/vPing/vping.py
blob: 90f6645681372887bf7b55ae8c044108b20ffa3c (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
90
91
92
93
94
95
96
97
#!/usr/bin/python
#
# Copyright (c) 2015 All rights reserved
# This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 0.1: This script boots the VM1 and allocates IP address from Nova
# Later, the VM2 boots then execute cloud-init to ping VM1.
# After successful ping, both the VMs are deleted.
# 0.2: measure test duration and publish results under json format
# 0.3: adapt push 2 DB after Test API refacroting
#
#
import datetime
import time

import argparse
import functest.utils.functest_logger as ft_logger

import vping_util as util

parser = argparse.ArgumentParser()
parser.add_argument("-d", "--debug", help="Debug mode", action="store_true")
parser.add_argument("-r", "--report",
                    help="Create json result file",
                    action="store_true")
parser.add_argument("-m", "--mode", default='ssh',
                    help="vPing mode: userdata or ssh",
                    action="store")

args = parser.parse_args()


def main():
    if args.mode == 'ssh':
        case = 'vping_ssh'
    else:
        case = 'vping_userdata'

    logger = ft_logger.Logger(case).getLogger()

    util.init(logger)

    util.check_repo_exist()

    vmname_1 = util.get_vmname_1()
    vmname_2 = util.get_vmname_2()

    image_id = util.create_image()

    flavor = util.get_flavor()

    network_id = util.create_network_full()

    sg_id = util.create_security_group()

    util.delete_exist_vms()

    start_time = time.time()
    logger.info("vPing Start Time:'%s'" % (
        datetime.datetime.fromtimestamp(start_time).strftime(
            '%Y-%m-%d %H:%M:%S')))

    vm1 = util.boot_vm(case,
                       vmname_1,
                       image_id,
                       flavor,
                       network_id,
                       None,
                       sg_id)
    test_ip = util.get_test_ip(vm1)
    vm2 = util.boot_vm(case,
                       vmname_2,
                       image_id,
                       flavor,
                       network_id,
                       test_ip,
                       sg_id)

    EXIT_CODE, stop_time = util.do_vping(case, vm2, test_ip)
    details = util.check_result(EXIT_CODE,
                                start_time,
                                stop_time)
    util.push_result(args.report,
                     case,
                     start_time,
                     stop_time,
                     details)

    exit(EXIT_CODE)


if __name__ == '__main__':
    main()