blob: 98463332f6e38291f2cc42d35a8e347556376e7e [file] [log] [blame]
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +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 oss_manager
24
25LOG = logger.logger
26
27
28@pytest.fixture(scope='function')
29def oss_actions(config, underlay, salt_actions):
30 """Fixture that provides various actions for OSS
31
32 :param config: fixture provides oslo.config
33 :param underlay: fixture provides underlay manager
34 :rtype: OSSManager
35 """
36 return oss_manager.OSSManager(config, underlay, salt_actions)
37
38
39@pytest.mark.revert_snapshot(ext.SNAPSHOT.oss_deployed)
40@pytest.fixture(scope='function')
41def oss_deployed(revert_snapshot, request, config,
42 hardware, underlay, salt_deployed,
43 oss_actions):
44 """Fixture to get or install OSS on the 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 oss_actions: fixture provides OSSManager instance
53 :rtype: OSSManager
54
55 If config.oss.oss_installed is not set, this
56 fixture assumes that the OSS were not installed
57 , and do the following:
58 - install OSS
59 - make snapshot with name 'oss_deployed'
60 - return OSSManager
61
62 If config.oss.oss_installed was set, this fixture
63 assumes that the OSS were already installed, and do
64 the following:
65 - return OSSManager instance
66
67 If you want to revert 'oss_deployed' snapshot, please use mark:
68 @pytest.mark.revert_snapshot("oss_deployed")
69 """
70 if not config.oss.oss_installed:
71 steps_path = config.oss_deploy.oss_steps_path
72 commands = underlay.read_template(steps_path)
73 oss_actions.install(commands)
74 hardware.create_snapshot(ext.SNAPSHOT.oss_deployed)
75
76 else:
77 # 1. hardware environment created and powered on
78 # 2. config.underlay.ssh contains SSH access to provisioned nodes
79 # (can be passed from external config with TESTS_CONFIGS variable)
80 # 3. config.tcp.* options contain access credentials to the already
81 # installed TCP API endpoint
82 pass
83
84 return oss_actions