blob: 8026e5ba2ec099f3847ace8bc648e9acf4f12a38 [file] [log] [blame]
Dennis Dmitriev6f59add2016-10-18 13:45:27 +03001# 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.
14import os
15
16import pytest
17
Artem Panchenkodb0a97f2017-06-27 19:09:13 +030018from tcp_tests import logger
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030019from tcp_tests import settings_oslo
Artem Panchenkodb0a97f2017-06-27 19:09:13 +030020from tcp_tests.helpers import utils
21
22LOG = logger.logger
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030023
24
25@pytest.fixture(scope='session')
26def config():
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020027 """Get the global config options from oslo.config INI file"""
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030028 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 Dmitriev4174e1e2019-04-12 13:50:16 +030035 LOG.info("\n" + "-" * 10 + " Initialize oslo.config variables with "
36 "defaults from environment" + "-" * 10)
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030037 config_opts = settings_oslo.load_config(config_files)
38
Artem Panchenkodb0a97f2017-06-27 19:09:13 +030039 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 Dmitriev6f59add2016-10-18 13:45:27 +030055 return config_opts