Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 1 | # Copyright 2016 Mirantis, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | import os |
| 15 | |
| 16 | import pytest |
| 17 | |
Artem Panchenko | db0a97f | 2017-06-27 19:09:13 +0300 | [diff] [blame] | 18 | from tcp_tests import logger |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 19 | from tcp_tests import settings_oslo |
Artem Panchenko | db0a97f | 2017-06-27 19:09:13 +0300 | [diff] [blame] | 20 | from tcp_tests.helpers import utils |
| 21 | |
| 22 | LOG = logger.logger |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 23 | |
| 24 | |
| 25 | @pytest.fixture(scope='session') |
| 26 | def config(): |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 27 | """Get the global config options from oslo.config INI file""" |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 28 | config_files = [] |
| 29 | |
| 30 | tests_configs = os.environ.get('TESTS_CONFIGS', None) |
| 31 | if tests_configs: |
| 32 | for test_config in tests_configs.split(','): |
| 33 | config_files.append(test_config) |
| 34 | |
Dennis Dmitriev | 4174e1e | 2019-04-12 13:50:16 +0300 | [diff] [blame] | 35 | LOG.info("\n" + "-" * 10 + " Initialize oslo.config variables with " |
| 36 | "defaults from environment" + "-" * 10) |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 37 | config_opts = settings_oslo.load_config(config_files) |
| 38 | |
Artem Panchenko | db0a97f | 2017-06-27 19:09:13 +0300 | [diff] [blame] | 39 | if os.path.isfile(config_opts.underlay.ssh_key_file): |
| 40 | LOG.debug('Loading SSH key from file: {0}'.format( |
| 41 | config_opts.underlay.ssh_key_file)) |
| 42 | key_from_file = utils.load_keyfile(config_opts.underlay.ssh_key_file) |
| 43 | if key_from_file not in config_opts.underlay.ssh_keys: |
| 44 | config_opts.underlay.ssh_keys.append(key_from_file) |
| 45 | else: |
| 46 | if not config_opts.underlay.ssh_keys: |
| 47 | config_opts.underlay.ssh_keys.append(utils.generate_keys()) |
| 48 | utils.dump_keyfile(config_opts.underlay.ssh_key_file, |
| 49 | config_opts.underlay.ssh_keys[0]) |
| 50 | LOG.debug('Saving SSH key to file: {0}'.format( |
| 51 | config_opts.underlay.ssh_key_file)) |
| 52 | utils.dump_keyfile(config_opts.underlay.ssh_key_file, |
| 53 | config_opts.underlay.ssh_keys[0]) |
| 54 | |
Dennis Dmitriev | 6f59add | 2016-10-18 13:45:27 +0300 | [diff] [blame] | 55 | return config_opts |