forked from ricardobranco777/hawk_test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hawk_test.py
147 lines (121 loc) · 5.17 KB
/
hawk_test.py
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/python3
# Copyright (C) 2019 SUSE LLC
"""HAWK GUI interface Selenium test: tests hawk GUI with Selenium using firefox or chrome"""
import argparse
import ipaddress
import socket
import sys
from pyvirtualdisplay import Display
from hawk_test_driver import HawkTestDriver
from hawk_test_results import ResultSet
from hawk_test_ssh import HawkTestSSH
def hostname(string):
try:
socket.getaddrinfo(string, 1)
return string
except socket.gaierror:
raise argparse.ArgumentTypeError(f"Unknown host: {string}") # pylint: disable=raise-missing-from
def cidr_address(string):
try:
ipaddress.ip_network(string, False)
return string
except ValueError as exc:
raise argparse.ArgumentTypeError(f"Invalid CIDR address: {string}") from exc
def port(string):
if string.isdigit() and 1 <= int(string) <= 65535:
return string
raise argparse.ArgumentTypeError(f"Invalid port number: {string}") from ValueError
def parse_args():
parser = argparse.ArgumentParser(description='HAWK GUI interface Selenium test')
parser.add_argument('-b', '--browser', default='firefox', choices=['firefox', 'chrome', 'chromium'],
help='Browser to use in the test')
parser.add_argument('-H', '--host', default='localhost', type=hostname,
help='Host or IP address where HAWK is running')
parser.add_argument('-S', '--slave', type=hostname,
help='Host or IP address of the slave')
parser.add_argument('-I', '--virtual-ip', type=cidr_address,
help='Virtual IP address in CIDR notation')
parser.add_argument('-P', '--port', default='7630', type=port,
help='TCP port where HAWK is running')
parser.add_argument('-s', '--secret',
help='root SSH Password of the HAWK node')
parser.add_argument('-r', '--results',
help='Generate hawk_test.results file')
parser.add_argument('--xvfb', action='store_true',
help='Use Xvfb. Headless mode')
args = parser.parse_args()
return args
def main():
args = parse_args()
if args.xvfb:
global DISPLAY # pylint: disable=global-statement
DISPLAY = Display()
DISPLAY.start()
# Initialize results set
results = ResultSet()
results.add_ssh_tests()
# Establish SSH connection to verify status
ssh = HawkTestSSH(args.host, args.secret)
# Get version from /etc/os-release
test_version = ssh.ssh.exec_command("grep ^VERSION= /etc/os-release")[1].read().decode().strip().split("=")[1].strip('"')
# Create driver instance
browser = HawkTestDriver(addr=args.host, port=args.port,
browser=args.browser, headless=args.xvfb,
version=test_version)
# Resources to create
cluster = 'Anderes'
primitive = 'cool_primitive'
clone = 'cool_clone'
group = 'cool_group'
# Tests to perform
if args.virtual_ip:
browser.test('test_add_virtual_ip', results, args.virtual_ip)
browser.test('test_remove_virtual_ip', results)
else:
results.set_test_status('test_add_virtual_ip', 'skipped')
results.set_test_status('test_remove_virtual_ip', 'skipped')
browser.test('test_set_stonith_maintenance', results)
ssh.verify_stonith_in_maintenance(results)
browser.test('test_disable_stonith_maintenance', results)
browser.test('test_view_details_first_node', results)
browser.test('test_clear_state_first_node', results)
browser.test('test_set_first_node_maintenance', results)
ssh.verify_node_maintenance(results)
browser.test('test_disable_maintenance_first_node', results)
browser.test('test_add_new_cluster', results, cluster)
browser.test('test_remove_cluster', results, cluster)
browser.test('test_click_on_history', results)
browser.test('test_generate_report', results)
browser.test('test_click_on_command_log', results)
browser.test('test_click_on_status', results)
browser.test('test_add_primitive', results, primitive)
ssh.verify_primitive(primitive, test_version, results)
browser.test('test_remove_primitive', results, primitive)
ssh.verify_primitive_removed(primitive, results)
browser.test('test_add_clone', results, clone)
browser.test('test_remove_clone', results, clone)
browser.test('test_add_group', results, group)
browser.test('test_remove_group', results, group)
browser.test('test_click_around_edit_conf', results)
if args.slave:
browser.addr = args.slave
browser.test('test_fencing', results)
else:
results.set_test_status('test_fencing', 'skipped')
# Save results if run with -r or --results
if args.results:
results.logresults(args.results)
return results.get_failed_tests_total()
if __name__ == "__main__":
import warnings
warnings.filterwarnings(action='ignore', module='.*paramiko.*')
DISPLAY = None
try:
sys.exit(main())
except KeyboardInterrupt:
if DISPLAY is not None:
DISPLAY.stop()
sys.exit(1)
finally:
if DISPLAY is not None:
DISPLAY.stop()