blob: 4a4ee1df9a6a7b145d0b36f22af4ee0b4a05cd06 [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 Dmitriev8cb2f412016-10-18 14:53:58 +030030 """Fixture that provides various actions for K8S
31
32 :param config: fixture provides oslo.config
33 :param underlay: fixture provides underlay manager
34 :rtype: K8SManager
35
36 For use in tests or fixtures to deploy a custom K8S
37 """
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020038 return common_services_manager.CommonServicesManager(config, underlay)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030039
40
41@pytest.fixture(scope='function')
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020042def common_services_deployed(revert_snapshot, request, config,
43 hardware, underlay, salt_deployed,
44 common_services_actions):
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030045 """Fixture to get or install TCP on environment
46
47 :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
51 :param tcp_actions: fixture provides TCPManager instance
52 :rtype: TCPManager
53
54 If config.tcp.tcp_host is not set, this fixture assumes that
55 the tcp cluster was not deployed, and do the following:
56 - deploy tcp cluster
57 - make snapshot with name 'tcp_deployed'
58 - return TCPCluster instance
59
60 If config.tcp.tcp_host was set, this fixture assumes that the tcp
61 cluster was already deployed, and do the following:
62 - return TCPCluster instance
63
64 If you want to revert 'tcp_deployed' snapshot, please use mark:
65 @pytest.mark.revert_snapshot("tcp_deployed")
66 """
67 # If no snapshot was reverted, then try to revert the snapshot
68 # that belongs to the fixture.
69 # Note: keep fixtures in strict dependences from each other!
70 if not revert_snapshot:
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020071 if hardware.has_snapshot(ext.SNAPSHOT.common_services_deployed) and \
72 hardware.has_snapshot_config(
73 ext.SNAPSHOT.common_services_deployed):
74 hardware.revert_snapshot(ext.SNAPSHOT.common_services_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030075
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020076 # Create Salt cluster
77 if not config.common_services.installed:
78 steps_path = config.common_services_deploy.common_services_steps_path
79 with underlay.yaml_editor(steps_path) as commands:
80 common_services_actions.install(commands.content)
81 hardware.create_snapshot(ext.SNAPSHOT.common_services_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030082
83 else:
84 # 1. hardware environment created and powered on
85 # 2. config.underlay.ssh contains SSH access to provisioned nodes
86 # (can be passed from external config with TESTS_CONFIGS variable)
87 # 3. config.tcp.* options contain access credentials to the already
88 # installed TCP API endpoint
89 pass
90
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020091 return common_services_actions