blob: 21c0e5d06760c4e6ef2745f75e6c34c2ef6cec29 [file] [log] [blame]
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +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.
14
15import os
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020016
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030017import pytest
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020018import yaml
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030019
20from tcp_tests import logger
21from tcp_tests.helpers import ext
22from tcp_tests import settings
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020023from tcp_tests.managers import common_services_manager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030024
25LOG = logger.logger
26
27
28@pytest.fixture(scope='function')
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020029def common_services_actions(config, underlay):
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020030 """Fixture that provides various actions for CommonServices
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030031
32 :param config: fixture provides oslo.config
33 :param underlay: fixture provides underlay manager
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020034 :rtype: CommonServicesManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030035 """
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020036 return common_services_manager.CommonServicesManager(config, underlay)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030037
38
Dennis Dmitriev535869c2016-11-16 22:38:06 +020039@pytest.mark.revert_snapshot(ext.SNAPSHOT.common_services_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030040@pytest.fixture(scope='function')
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020041def common_services_deployed(revert_snapshot, request, config,
42 hardware, underlay, salt_deployed,
43 common_services_actions):
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020044 """Fixture to get or install common services on the environment
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030045
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020046 :param revert_snapshot: fixture that reverts snapshot that is specified
47 in test with @pytest.mark.revert_snapshot(<name>)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030048 :param request: fixture provides pytest data
49 :param config: fixture provides oslo.config
50 :param hardware: fixture provides enviromnet manager
51 :param underlay: fixture provides underlay manager
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020052 :param common_services_actions: fixture provides CommonServicesManager
53 instance
54 :rtype: CommonServicesManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030055
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020056 If config.common_services.common_services_installed is not set, this
57 fixture assumes that the common services were not installed
58 , and do the following:
59 - install common services
60 - make snapshot with name 'common_services_deployed'
61 - return CommonServicesManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030062
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020063 If config.common_services.common_services_installed was set, this fixture
64 assumes that the common services were already installed, and do
65 the following:
66 - return CommonServicesManager instance
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030067
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020068 If you want to revert 'common_services_deployed' snapshot, please use mark:
69 @pytest.mark.revert_snapshot("common_services_deployed")
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030070 """
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020071 # Create Salt cluster
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020072 if not config.common_services.common_services_installed:
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020073 steps_path = config.common_services_deploy.common_services_steps_path
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030074 commands = underlay.read_template(steps_path)
dis2b2d8632016-12-08 17:56:57 +020075 common_services_actions.install(commands)
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020076 hardware.create_snapshot(ext.SNAPSHOT.common_services_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030077
78 else:
79 # 1. hardware environment created and powered on
80 # 2. config.underlay.ssh contains SSH access to provisioned nodes
81 # (can be passed from external config with TESTS_CONFIGS variable)
82 # 3. config.tcp.* options contain access credentials to the already
83 # installed TCP API endpoint
84 pass
85
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020086 return common_services_actions