blob: ddbb8c9a0d64652d55e0609515246b8745029fbf [file] [log] [blame]
Dennis Dmitrievf3f90a52017-08-10 14: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 decapod_manager
24
25LOG = logger.logger
26
27
28@pytest.fixture(scope='function')
29def decapod_actions(config, underlay, salt_actions):
30 """Fixture that provides various actions for Decapod
31
32 :param config: fixture provides oslo.config
33 :param underlay: fixture provides underlay manager
34 :rtype: DecapodManager
35 """
36 return decapod_manager.DecapodManager(config, underlay, salt_actions)
37
38
39@pytest.mark.revert_snapshot(ext.SNAPSHOT.decapod_deployed)
40@pytest.fixture(scope='function')
41def decapod_deployed(revert_snapshot, request, config,
42 hardware, underlay, salt_deployed,
43 decapod_actions):
44 """Fixture to get or install Decapod 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 decapod_actions: fixture provides DecapodManager instance
53 :rtype: DecapodManager
54
55 If config.decapod.decapod_installed is not set, this
56 fixture assumes that the Decapod were not installed
57 , and do the following:
58 - install Decapod
59 - make snapshot with name 'decapod_deployed'
60 - return DecapodManager
61
62 If config.decapod.decapod_installed was set, this fixture
63 assumes that the Decapod were already installed, and do
64 the following:
65 - return DecapodManager instance
66
67 If you want to revert 'decapod_deployed' snapshot, please use mark:
68 @pytest.mark.revert_snapshot("decapod_deployed")
69 """
70 if not config.decapod.decapod_installed:
71 steps_path = config.decapod_deploy.decapod_steps_path
72 commands = underlay.read_template(steps_path)
73 decapod_actions.install(commands)
74 hardware.create_snapshot(ext.SNAPSHOT.decapod_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 decapod_actions