[618ee14] | 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 | |
---|
[0cfe818] | 18 | import contextlib |
---|
[e3e0de1] | 19 | import os |
---|
[b0695c6] | 20 | import yaml |
---|
[618ee14] | 21 | |
---|
[c96a965] | 22 | from mgstest.tests import run_test_conf |
---|
[618ee14] | 23 | |
---|
| 24 | if __name__ == "__main__": |
---|
| 25 | import argparse |
---|
| 26 | parser = argparse.ArgumentParser( |
---|
| 27 | description='Send HTTP requests through gnutls-cli', |
---|
| 28 | formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
---|
[e3e0de1] | 29 | parser.add_argument('host', nargs='?', default=None, |
---|
| 30 | help='Access this host. Overrides TEST_TARGET, ' |
---|
| 31 | 'but not the test configuration file.') |
---|
| 32 | parser.add_argument('-p', '--port', default=None, |
---|
| 33 | help='Access this port. Overrides TEST_PORT, ' |
---|
| 34 | 'but not the test configuration file.') |
---|
[42097fb] | 35 | parser.add_argument('--timeout', type=float, |
---|
| 36 | help='Timeout for HTTP requests', default='5.0') |
---|
[d5f5356] | 37 | parser.add_argument('--test-config', type=argparse.FileType('r'), |
---|
[2e736df] | 38 | required=True, help='load YAML test configuration') |
---|
[618ee14] | 39 | |
---|
| 40 | # enable bash completion if argcomplete is available |
---|
| 41 | try: |
---|
| 42 | import argcomplete |
---|
| 43 | argcomplete.autocomplete(parser) |
---|
| 44 | except ImportError: |
---|
| 45 | pass |
---|
| 46 | |
---|
| 47 | args = parser.parse_args() |
---|
| 48 | |
---|
[e3e0de1] | 49 | if args.host: |
---|
| 50 | os.environ['TEST_TARGET'] = args.host |
---|
| 51 | if args.port: |
---|
| 52 | os.environ['TEST_PORT'] = args.port |
---|
| 53 | |
---|
[0cfe818] | 54 | with contextlib.closing(args.test_config): |
---|
[b0695c6] | 55 | test_conf = yaml.load(args.test_config, Loader=yaml.Loader) |
---|
| 56 | run_test_conf(test_conf, args.timeout) |
---|