blob: 7efd2960e95d3084b259d5095253f35fae0c02bf [file] [log] [blame]
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +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
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020016
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030017import pytest
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020018import yaml
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030019
20from tcp_tests import logger
21from tcp_tests.helpers import ext
22from tcp_tests import settings
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020023from tcp_tests.managers import saltmanager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030024
25LOG = logger.logger
26
27
28@pytest.fixture(scope='function')
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020029def salt_actions(config, underlay):
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020030 """Fixture that provides various actions for salt
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030031
32 :param config: fixture provides oslo.config
33 :param underlay: fixture provides underlay manager
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020034 :rtype: SaltManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030035 """
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020036 return saltmanager.SaltManager(config, underlay)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030037
38
Dennis Dmitriev535869c2016-11-16 22:38:06 +020039@pytest.mark.revert_snapshot(ext.SNAPSHOT.salt_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030040@pytest.fixture(scope='function')
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020041def salt_deployed(revert_snapshot, request, config,
42 hardware, underlay, salt_actions):
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020043 """Fixture to get or install salt service on environment
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030044
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020045 :param revert_snapshot: fixture that reverts snapshot that is specified
46 in test with @pytest.mark.revert_snapshot(<name>)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030047 :param request: fixture provides pytest data
48 :param config: fixture provides oslo.config
49 :param hardware: fixture provides enviromnet manager
50 :param underlay: fixture provides underlay manager
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020051 :param salt_actions: fixture provides SaltManager instance
52 :rtype: SaltManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030053
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020054 If config.salt.salt_master_host is not set, this fixture assumes that
55 the salt was not installed, and do the following:
56 - install salt master and salt minions
57 - make snapshot with name 'salt_deployed'
58 - return SaltManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030059
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020060 If config.salt.salt_master_host was set, this fixture assumes that the
61 salt was already deployed, and do the following:
62 - return SaltManager instance
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030063
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020064 If you want to revert 'salt_deployed' snapshot, please use mark:
65 @pytest.mark.revert_snapshot("salt_deployed")
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030066 """
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020067 # Create Salt cluster
68 if config.salt.salt_master_host == '0.0.0.0':
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030069 # Temporary workaround. Underlay should be extended with roles
70 salt_nodes = underlay.node_names()
71 config.salt.salt_master_host = \
72 underlay.host_by_node_name(salt_nodes[0])
73
74 commands = underlay.read_template(config.salt_deploy.salt_steps_path)
75 LOG.info("############ Executing command ####### {0}".format(commands))
dis2b2d8632016-12-08 17:56:57 +020076 salt_actions.install(commands)
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020077 hardware.create_snapshot(ext.SNAPSHOT.salt_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030078
79 else:
80 # 1. hardware environment created and powered on
81 # 2. config.underlay.ssh contains SSH access to provisioned nodes
82 # (can be passed from external config with TESTS_CONFIGS variable)
83 # 3. config.tcp.* options contain access credentials to the already
84 # installed TCP API endpoint
85 pass
86
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020087 return salt_actions