blob: 973e034d20fdff301c8dfe69d2e5ba2dbbc5049a [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
35 config_opts = settings_oslo.load_config(config_files)
36
Artem Panchenkodb0a97f2017-06-27 19:09:13 +030037 if os.path.isfile(config_opts.underlay.ssh_key_file):
38 LOG.debug('Loading SSH key from file: {0}'.format(
39 config_opts.underlay.ssh_key_file))
40 key_from_file = utils.load_keyfile(config_opts.underlay.ssh_key_file)
41 if key_from_file not in config_opts.underlay.ssh_keys:
42 config_opts.underlay.ssh_keys.append(key_from_file)
43 else:
44 if not config_opts.underlay.ssh_keys:
45 config_opts.underlay.ssh_keys.append(utils.generate_keys())
46 utils.dump_keyfile(config_opts.underlay.ssh_key_file,
47 config_opts.underlay.ssh_keys[0])
48 LOG.debug('Saving SSH key to file: {0}'.format(
49 config_opts.underlay.ssh_key_file))
50 utils.dump_keyfile(config_opts.underlay.ssh_key_file,
51 config_opts.underlay.ssh_keys[0])
52
Dennis Dmitriev6f59add2016-10-18 13:45:27 +030053 return config_opts