blob: 82b7c882cfa35097ea8a73f44014738ef1780b51 [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
15import os
16
17import pytest
18import yaml
19
20from tcp_tests import logger
21from tcp_tests.helpers import ext
22from tcp_tests import settings
23from tcp_tests.managers import sl_manager
24from tcp_tests.helpers import utils
25
26LOG = logger.logger
27
28
29@pytest.fixture(scope='function')
30def sl_actions(config, underlay, salt_deployed):
31 """Fixture that provides various actions for K8S
32
33 :param config: fixture provides oslo.config
34 :param underlay: fixture provides underlay manager
35 :rtype: SLManager
36
37 For use in tests or fixtures to deploy a custom K8S
38 """
39 return sl_manager.SLManager(config, underlay, salt_deployed)
40
41
42@pytest.mark.revert_snapshot(ext.SNAPSHOT.sl_deployed)
43@pytest.fixture(scope='function')
44def sl_deployed(revert_snapshot, request, config,
45 hardware, underlay, common_services_deployed,
46 sl_actions):
47 """Fixture to get or install SL services on environment
48
49 :param revert_snapshot: fixture that reverts snapshot that is specified
50 in test with @pytest.mark.revert_snapshot(<name>)
51 :param request: fixture provides pytest data
52 :param config: fixture provides oslo.config
53 :param hardware: fixture provides enviromnet manager
54 :param underlay: fixture provides underlay manager
55 :param tcp_actions: fixture provides SLManager instance
56 :rtype: SLManager
57 """
58 # Create Salt cluster
59 if not config.stack_light.sl_installed:
60 steps_path = config.sl_deploy.sl_steps_path
61 commands = underlay.read_template(steps_path)
62 sl_actions.install(commands)
63 hardware.create_snapshot(ext.SNAPSHOT.sl_deployed)
64
65 else:
66 # 1. hardware environment created and powered on
67 # 2. config.underlay.ssh contains SSH access to provisioned nodes
68 # (can be passed from external config with TESTS_CONFIGS variable)
69 # 3. config.tcp.* options contain access credentials to the already
70 # installed TCP API endpoint
71 pass
72
73 return sl_actions
74
75
76@pytest.mark.revert_snapshot(ext.SNAPSHOT.sl_deployed)
77@pytest.fixture(scope='function')
78def deploy_sl(revert_snapshot, request, config,
79 hardware, underlay, common_services_deployed,
80 sl_actions):
81 """Fixture to get or install OpenStack services on environment
82
83 :param revert_snapshot: fixture that reverts snapshot that is specified
84 in test with @pytest.mark.revert_snapshot(<name>)
85 :param request: fixture provides pytest data
86 :param config: fixture provides oslo.config
87 :param hardware: fixture provides enviromnet manager
88 :param underlay: fixture provides underlay manager
89 :param tcp_actions: fixture provides OpenstackManager instance
90 :rtype: SLManager
91
92 If you want to revert 'sl_deployed' snapshot, please use mark:
93 @pytest.mark.revert_snapshot("sl_deployed")
94 """
95 # Create Salt cluster
96 if not config.stack_light.sl_installed:
97 steps_path = config.sl_deploy.sl_steps_path
98 commands = utils.read_template(steps_path)
99 sl_actions.install(commands)
100 hardware.create_snapshot(ext.SNAPSHOT.sl_deployed)
101
102 else:
103 # 1. hardware environment created and powered on
104 # 2. config.underlay.ssh contains SSH access to provisioned nodes
105 # (can be passed from external config with TESTS_CONFIGS variable)
106 # 3. config.tcp.* options contain access credentials to the already
107 # installed TCP API endpoint
108 pass
109
110 return sl_actions