blob: f907055b68b4e241deff89a39a84a7c1596ef069 [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')
Tatyana Leontovichb57ec132017-07-27 17:16:42 +030075 LOG.warning('Restarting keepalived service on mon nodes...')
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030076 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
77 args='systemctl restart keepalived.service')
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030078 return sl_actions
79
80
81@pytest.mark.revert_snapshot(ext.SNAPSHOT.sl_deployed)
82@pytest.fixture(scope='function')
83def deploy_sl(revert_snapshot, request, config,
84 hardware, underlay, common_services_deployed,
85 sl_actions):
86 """Fixture to get or install OpenStack services on environment
87
88 :param revert_snapshot: fixture that reverts snapshot that is specified
89 in test with @pytest.mark.revert_snapshot(<name>)
90 :param request: fixture provides pytest data
91 :param config: fixture provides oslo.config
92 :param hardware: fixture provides enviromnet manager
93 :param underlay: fixture provides underlay manager
94 :param tcp_actions: fixture provides OpenstackManager instance
95 :rtype: SLManager
96
97 If you want to revert 'sl_deployed' snapshot, please use mark:
98 @pytest.mark.revert_snapshot("sl_deployed")
99 """
100 # Create Salt cluster
101 if not config.stack_light.sl_installed:
102 steps_path = config.sl_deploy.sl_steps_path
103 commands = utils.read_template(steps_path)
104 sl_actions.install(commands)
105 hardware.create_snapshot(ext.SNAPSHOT.sl_deployed)
106
107 else:
108 # 1. hardware environment created and powered on
109 # 2. config.underlay.ssh contains SSH access to provisioned nodes
110 # (can be passed from external config with TESTS_CONFIGS variable)
111 # 3. config.tcp.* options contain access credentials to the already
112 # installed TCP API endpoint
113 pass
Tatyana Leontovich09b7b012017-07-10 12:53:45 +0300114 # Workaround for keepalived hang issue after env revert from snapshot
115 # see https://mirantis.jira.com/browse/PROD-12038
116 LOG.warning('Restarting keepalived service on controllers...')
117 sl_actions._salt.local(tgt='ctl*', fun='cmd.run',
118 args='systemctl restart keepalived.service')
119 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
120 args='systemctl restart keepalived.service')
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +0300121 return sl_actions