blob: 7f4ce6095b1734808b28bbc91d0ad9f35e1dd921 [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
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030015import pytest
16
17from tcp_tests import logger
18from tcp_tests.helpers import ext
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020019from tcp_tests.managers import saltmanager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030020
21LOG = logger.logger
22
23
24@pytest.fixture(scope='function')
Dennis Dmitrievee5ef232018-08-31 13:53:18 +030025def salt_actions(config, underlay_actions):
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020026 """Fixture that provides various actions for salt
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030027
28 :param config: fixture provides oslo.config
29 :param underlay: fixture provides underlay manager
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020030 :rtype: SaltManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030031 """
Dennis Dmitrievee5ef232018-08-31 13:53:18 +030032 return saltmanager.SaltManager(config, underlay_actions)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030033
34
Dennis Dmitriev535869c2016-11-16 22:38:06 +020035@pytest.mark.revert_snapshot(ext.SNAPSHOT.salt_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030036@pytest.fixture(scope='function')
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020037def salt_deployed(revert_snapshot, request, config,
Dennis Dmitrievf0b2afe2018-02-28 13:25:02 +020038 hardware, underlay, salt_actions, snapshot, grab_versions):
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020039 """Fixture to get or install salt service on environment
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030040
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020041 :param revert_snapshot: fixture that reverts snapshot that is specified
42 in test with @pytest.mark.revert_snapshot(<name>)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030043 :param request: fixture provides pytest data
44 :param config: fixture provides oslo.config
45 :param hardware: fixture provides enviromnet manager
46 :param underlay: fixture provides underlay manager
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020047 :param salt_actions: fixture provides SaltManager instance
48 :rtype: SaltManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030049
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020050 If config.salt.salt_master_host is not set, this fixture assumes that
51 the salt was not installed, and do the following:
52 - install salt master and salt minions
53 - make snapshot with name 'salt_deployed'
54 - return SaltManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030055
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020056 If config.salt.salt_master_host was set, this fixture assumes that the
57 salt was already deployed, and do the following:
58 - return SaltManager instance
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030059
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020060 If you want to revert 'salt_deployed' snapshot, please use mark:
61 @pytest.mark.revert_snapshot("salt_deployed")
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030062 """
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020063 # Create Salt cluster
64 if config.salt.salt_master_host == '0.0.0.0':
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030065 # Temporary workaround. Underlay should be extended with roles
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030066 config.salt.salt_master_host = \
Tatyana Leontovichecd491d2017-09-13 13:51:12 +030067 underlay.host_by_node_role(
68 node_role=ext.UNDERLAY_NODE_ROLES.salt_master)
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030069
70 commands = underlay.read_template(config.salt_deploy.salt_steps_path)
71 LOG.info("############ Executing command ####### {0}".format(commands))
dis2b2d8632016-12-08 17:56:57 +020072 salt_actions.install(commands)
Dmitry Tyzhnenkob8641832017-11-07 17:02:47 +020073
74 salt_nodes = salt_actions.get_ssh_data()
75 config.underlay.ssh = config.underlay.ssh + \
76 [node for node in salt_nodes
77 if not any(node['node_name'] == n['node_name']
78 for n in config.underlay.ssh)]
Dennis Dmitrievcaa45892018-03-29 18:46:47 +030079 underlay.config_ssh = []
80 underlay.add_config_ssh(config.underlay.ssh)
Dmitry Tyzhnenkob8641832017-11-07 17:02:47 +020081
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020082 hardware.create_snapshot(ext.SNAPSHOT.salt_deployed)
Dennis Dmitrievb8115f52017-12-15 13:09:56 +020083 salt_actions.sync_time()
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030084
85 else:
86 # 1. hardware environment created and powered on
87 # 2. config.underlay.ssh contains SSH access to provisioned nodes
88 # (can be passed from external config with TESTS_CONFIGS variable)
89 # 3. config.tcp.* options contain access credentials to the already
90 # installed TCP API endpoint
91 pass
92
Dennis Dmitrievb8115f52017-12-15 13:09:56 +020093 salt_actions.sync_time()
94
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020095 return salt_actions