blob: 6d7d2e91b29dd3900a2c2a668a83b7b42ab6b919 [file] [log] [blame]
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +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
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030015
16import pytest
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030017
18from tcp_tests import logger
19from tcp_tests.helpers import ext
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030020from tcp_tests.managers import sl_manager
21from tcp_tests.helpers import utils
22
23LOG = logger.logger
24
25
26@pytest.fixture(scope='function')
27def sl_actions(config, underlay, salt_deployed):
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: SLManager
33
34 For use in tests or fixtures to deploy a custom K8S
35 """
36 return sl_manager.SLManager(config, underlay, salt_deployed)
37
38
39@pytest.mark.revert_snapshot(ext.SNAPSHOT.sl_deployed)
40@pytest.fixture(scope='function')
41def sl_deployed(revert_snapshot, request, config,
42 hardware, underlay, common_services_deployed,
43 sl_actions):
44 """Fixture to get or install SL services on environment
45
46 :param revert_snapshot: fixture that reverts snapshot that is specified
47 in test with @pytest.mark.revert_snapshot(<name>)
48 :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
52 :param tcp_actions: fixture provides SLManager instance
53 :rtype: SLManager
54 """
55 # Create Salt cluster
56 if not config.stack_light.sl_installed:
57 steps_path = config.sl_deploy.sl_steps_path
58 commands = underlay.read_template(steps_path)
59 sl_actions.install(commands)
60 hardware.create_snapshot(ext.SNAPSHOT.sl_deployed)
61
62 else:
63 # 1. hardware environment created and powered on
64 # 2. config.underlay.ssh contains SSH access to provisioned nodes
65 # (can be passed from external config with TESTS_CONFIGS variable)
66 # 3. config.tcp.* options contain access credentials to the already
67 # installed TCP API endpoint
68 pass
69
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030070 # Workaround for keepalived hang issue after env revert from snapshot
71 # see https://mirantis.jira.com/browse/PROD-12038
72 LOG.warning('Restarting keepalived service on controllers...')
73 sl_actions._salt.local(tgt='ctl*', fun='cmd.run',
74 args='systemctl restart keepalived.service')
75 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
76 args='systemctl restart keepalived.service')
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030077 return sl_actions
78
79
80@pytest.mark.revert_snapshot(ext.SNAPSHOT.sl_deployed)
81@pytest.fixture(scope='function')
82def deploy_sl(revert_snapshot, request, config,
83 hardware, underlay, common_services_deployed,
84 sl_actions):
85 """Fixture to get or install OpenStack services on environment
86
87 :param revert_snapshot: fixture that reverts snapshot that is specified
88 in test with @pytest.mark.revert_snapshot(<name>)
89 :param request: fixture provides pytest data
90 :param config: fixture provides oslo.config
91 :param hardware: fixture provides enviromnet manager
92 :param underlay: fixture provides underlay manager
93 :param tcp_actions: fixture provides OpenstackManager instance
94 :rtype: SLManager
95
96 If you want to revert 'sl_deployed' snapshot, please use mark:
97 @pytest.mark.revert_snapshot("sl_deployed")
98 """
99 # Create Salt cluster
100 if not config.stack_light.sl_installed:
101 steps_path = config.sl_deploy.sl_steps_path
102 commands = utils.read_template(steps_path)
103 sl_actions.install(commands)
104 hardware.create_snapshot(ext.SNAPSHOT.sl_deployed)
105
106 else:
107 # 1. hardware environment created and powered on
108 # 2. config.underlay.ssh contains SSH access to provisioned nodes
109 # (can be passed from external config with TESTS_CONFIGS variable)
110 # 3. config.tcp.* options contain access credentials to the already
111 # installed TCP API endpoint
112 pass
Tatyana Leontovich09b7b012017-07-10 12:53:45 +0300113 # Workaround for keepalived hang issue after env revert from snapshot
114 # see https://mirantis.jira.com/browse/PROD-12038
115 LOG.warning('Restarting keepalived service on controllers...')
116 sl_actions._salt.local(tgt='ctl*', fun='cmd.run',
117 args='systemctl restart keepalived.service')
118 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
119 args='systemctl restart keepalived.service')
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300120 return sl_actions