1 | #!/usr/bin/python3 |
---|
2 | # PYTHON_ARGCOMPLETE_OK |
---|
3 | |
---|
4 | # Copyright 2019 Fiona Klute |
---|
5 | # |
---|
6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
---|
7 | # you may not use this file except in compliance with the License. |
---|
8 | # You may obtain a copy of the License at |
---|
9 | # |
---|
10 | # http://www.apache.org/licenses/LICENSE-2.0 |
---|
11 | # |
---|
12 | # Unless required by applicable law or agreed to in writing, software |
---|
13 | # distributed under the License is distributed on an "AS IS" BASIS, |
---|
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
15 | # See the License for the specific language governing permissions and |
---|
16 | # limitations under the License. |
---|
17 | |
---|
18 | import yaml |
---|
19 | |
---|
20 | from mgstest.tests import TestConnection |
---|
21 | |
---|
22 | if __name__ == "__main__": |
---|
23 | import argparse |
---|
24 | parser = argparse.ArgumentParser( |
---|
25 | description='Send HTTP requests through gnutls-cli', |
---|
26 | formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
---|
27 | parser.add_argument('host', nargs='?', help='Access the specified host', |
---|
28 | default='localhost') |
---|
29 | parser.add_argument('-p', '--port', type=int, |
---|
30 | help='Access the specified port', default='8000') |
---|
31 | parser.add_argument('--test-config', type=argparse.FileType('r'), |
---|
32 | required=True, help='load YAML test configuration') |
---|
33 | |
---|
34 | # enable bash completion if argcomplete is available |
---|
35 | try: |
---|
36 | import argcomplete |
---|
37 | argcomplete.autocomplete(parser) |
---|
38 | except ImportError: |
---|
39 | pass |
---|
40 | |
---|
41 | args = parser.parse_args() |
---|
42 | |
---|
43 | conns = None |
---|
44 | |
---|
45 | config = yaml.load(args.test_config, Loader=yaml.Loader) |
---|
46 | if type(config) is TestConnection: |
---|
47 | conns = [config] |
---|
48 | elif type(config) is list: |
---|
49 | # assume list elements are connections |
---|
50 | conns = config |
---|
51 | else: |
---|
52 | raise TypeError(f'Unsupported configuration: {config!r}') |
---|
53 | print(conns) |
---|
54 | |
---|
55 | for test_conn in conns: |
---|
56 | test_conn.run(host=args.host, port=args.port) |
---|