blob: 27b8a1ffa5496a4987a558edd2d6ab6da706259c [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
16import pytest
17
18from tcp_tests import logger
19from tcp_tests.helpers import ext
20from tcp_tests import settings
21from tcp_tests.managers import tcpmanager
22
23LOG = logger.logger
24
25
26@pytest.fixture(scope='function')
27def tcp_actions(config, underlay):
28 """Fixture that provides various actions for K8S
29
30 :param config: fixture provides oslo.config
31 :param underlay: fixture provides underlay manager
32 :rtype: K8SManager
33
34 For use in tests or fixtures to deploy a custom K8S
35 """
36 return tcpmanager.TCPManager(config, underlay)
37
38
39@pytest.fixture(scope='function')
40def tcpcluster(revert_snapshot, request, config,
41 hardware, underlay, tcp_actions):
42 """Fixture to get or install TCP on environment
43
44 :param request: fixture provides pytest data
45 :param config: fixture provides oslo.config
46 :param hardware: fixture provides enviromnet manager
47 :param underlay: fixture provides underlay manager
48 :param tcp_actions: fixture provides TCPManager instance
49 :rtype: TCPManager
50
51 If config.tcp.tcp_host is not set, this fixture assumes that
52 the tcp cluster was not deployed, and do the following:
53 - deploy tcp cluster
54 - make snapshot with name 'tcp_deployed'
55 - return TCPCluster instance
56
57 If config.tcp.tcp_host was set, this fixture assumes that the tcp
58 cluster was already deployed, and do the following:
59 - return TCPCluster instance
60
61 If you want to revert 'tcp_deployed' snapshot, please use mark:
62 @pytest.mark.revert_snapshot("tcp_deployed")
63 """
64 # If no snapshot was reverted, then try to revert the snapshot
65 # that belongs to the fixture.
66 # Note: keep fixtures in strict dependences from each other!
67 if not revert_snapshot:
68 if hardware.has_snapshot(ext.SNAPSHOT.tcp_deployed) and \
69 hardware.has_snapshot_config(ext.SNAPSHOT.tcp_deployed):
70 hardware.revert_snapshot(ext.SNAPSHOT.tcp_deployed)
71
72 # Create TCP cluster
73 if config.tcp.tcp_host == '0.0.0.0':
74
75 tcp_actions.install_tcp()
76 hardware.create_snapshot(ext.SNAPSHOT.tcp_deployed)
77
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
86 return tcp_actions