delete useless image_exists in vping
[functest.git] / testcases / OpenStack / vPing / vping.py
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2015 All rights reserved
4 # This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # 0.1: This script boots the VM1 and allocates IP address from Nova
11 # Later, the VM2 boots then execute cloud-init to ping VM1.
12 # After successful ping, both the VMs are deleted.
13 # 0.2: measure test duration and publish results under json format
14 # 0.3: adapt push 2 DB after Test API refacroting
15 #
16 #
17 import datetime
18 import time
19
20 import argparse
21 import functest.utils.functest_logger as ft_logger
22
23 import vping_util as util
24
25 parser = argparse.ArgumentParser()
26 parser.add_argument("-d", "--debug", help="Debug mode", action="store_true")
27 parser.add_argument("-r", "--report",
28                     help="Create json result file",
29                     action="store_true")
30 parser.add_argument("-m", "--mode", default='ssh',
31                     help="vPing mode: userdata or ssh",
32                     action="store")
33
34 args = parser.parse_args()
35
36 """ logging configuration """
37 logger = ft_logger.Logger("vping_userdata").getLogger()
38
39
40 def main():
41     if args.mode == 'ssh':
42         case = 'vping_ssh'
43     else:
44         case = 'vping_userdata'
45
46     util.init(logger)
47
48     util.check_repo_exist()
49
50     vmname_1 = util.get_vmname_1()
51     vmname_2 = util.get_vmname_2()
52
53     image_id = util.create_image()
54
55     flavor = util.get_flavor()
56
57     network_id = util.create_network_full()
58
59     sg_id = util.create_security_group()
60
61     util.delete_exist_vms()
62
63     start_time = time.time()
64     logger.info("vPing Start Time:'%s'" % (
65         datetime.datetime.fromtimestamp(start_time).strftime(
66             '%Y-%m-%d %H:%M:%S')))
67
68     vm1 = util.boot_vm(case,
69                        vmname_1,
70                        image_id,
71                        flavor,
72                        network_id,
73                        None,
74                        sg_id)
75     test_ip = util.get_test_ip(vm1)
76     vm2 = util.boot_vm(case,
77                        vmname_2,
78                        image_id,
79                        flavor,
80                        network_id,
81                        test_ip,
82                        sg_id)
83
84     EXIT_CODE, stop_time = util.do_vping(case, vm2, test_ip)
85     details = util.check_result(EXIT_CODE,
86                                 start_time,
87                                 stop_time)
88     util.push_result(args.report,
89                      case,
90                      start_time,
91                      stop_time,
92                      details)
93
94     exit(EXIT_CODE)
95
96
97 if __name__ == '__main__':
98     main()