blob: ed00574f98bd19011a7a43dca0a6fed2dd54e809 [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
39@pytest.fixture(scope='function')
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020040def common_services_deployed(revert_snapshot, request, config,
41 hardware, underlay, salt_deployed,
42 common_services_actions):
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020043 """Fixture to get or install common services on the environment
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030044
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020045 :param revert_snapshot: fixture that reverts snapshot that is specified
46 in test with @pytest.mark.revert_snapshot(<name>)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030047 :param request: fixture provides pytest data
48 :param config: fixture provides oslo.config
49 :param hardware: fixture provides enviromnet manager
50 :param underlay: fixture provides underlay manager
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020051 :param common_services_actions: fixture provides CommonServicesManager
52 instance
53 :rtype: CommonServicesManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030054
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020055 If config.common_services.common_services_installed is not set, this
56 fixture assumes that the common services were not installed
57 , and do the following:
58 - install common services
59 - make snapshot with name 'common_services_deployed'
60 - return CommonServicesManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030061
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020062 If config.common_services.common_services_installed was set, this fixture
63 assumes that the common services were already installed, and do
64 the following:
65 - return CommonServicesManager instance
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030066
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020067 If you want to revert 'common_services_deployed' snapshot, please use mark:
68 @pytest.mark.revert_snapshot("common_services_deployed")
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030069 """
70 # If no snapshot was reverted, then try to revert the snapshot
71 # that belongs to the fixture.
72 # Note: keep fixtures in strict dependences from each other!
73 if not revert_snapshot:
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020074 if hardware.has_snapshot(ext.SNAPSHOT.common_services_deployed) and \
75 hardware.has_snapshot_config(
76 ext.SNAPSHOT.common_services_deployed):
77 hardware.revert_snapshot(ext.SNAPSHOT.common_services_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030078
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020079 # Create Salt cluster
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020080 if not config.common_services.common_services_installed:
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020081 steps_path = config.common_services_deploy.common_services_steps_path
82 with underlay.yaml_editor(steps_path) as commands:
83 common_services_actions.install(commands.content)
84 hardware.create_snapshot(ext.SNAPSHOT.common_services_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030085
86 else:
87 # 1. hardware environment created and powered on
88 # 2. config.underlay.ssh contains SSH access to provisioned nodes
89 # (can be passed from external config with TESTS_CONFIGS variable)
90 # 3. config.tcp.* options contain access credentials to the already
91 # installed TCP API endpoint
92 pass
93
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020094 return common_services_actions