blob: 57fb656ea9be91fca837478b2370b6da6dba5693 [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
dis2b2d8632016-12-08 17:56:57 +020022from tcp_tests.helpers import utils
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030023from tcp_tests import settings
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020024from tcp_tests.managers import saltmanager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030025
26LOG = logger.logger
27
28
29@pytest.fixture(scope='function')
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020030def salt_actions(config, underlay):
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020031 """Fixture that provides various actions for salt
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030032
33 :param config: fixture provides oslo.config
34 :param underlay: fixture provides underlay manager
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020035 :rtype: SaltManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030036 """
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020037 return saltmanager.SaltManager(config, underlay)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030038
39
Dennis Dmitriev535869c2016-11-16 22:38:06 +020040@pytest.mark.revert_snapshot(ext.SNAPSHOT.salt_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030041@pytest.fixture(scope='function')
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020042def salt_deployed(revert_snapshot, request, config,
43 hardware, underlay, salt_actions):
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020044 """Fixture to get or install salt service on environment
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030045
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020046 :param revert_snapshot: fixture that reverts snapshot that is specified
47 in test with @pytest.mark.revert_snapshot(<name>)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030048 :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
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020052 :param salt_actions: fixture provides SaltManager instance
53 :rtype: SaltManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030054
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020055 If config.salt.salt_master_host is not set, this fixture assumes that
56 the salt was not installed, and do the following:
57 - install salt master and salt minions
58 - make snapshot with name 'salt_deployed'
59 - return SaltManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030060
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020061 If config.salt.salt_master_host was set, this fixture assumes that the
62 salt was already deployed, and do the following:
63 - return SaltManager instance
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030064
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020065 If you want to revert 'salt_deployed' snapshot, please use mark:
66 @pytest.mark.revert_snapshot("salt_deployed")
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030067 """
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020068 # Create Salt cluster
69 if config.salt.salt_master_host == '0.0.0.0':
dis2b2d8632016-12-08 17:56:57 +020070 commands = utils.read_template(config.salt_deploy.salt_steps_path)
Tatyana Leontovich14f6a1a2017-04-04 17:30:58 +030071 LOG.info("##################Executing command ####### {0}".format(commands))
dis2b2d8632016-12-08 17:56:57 +020072 salt_actions.install(commands)
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020073 hardware.create_snapshot(ext.SNAPSHOT.salt_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030074
75 else:
76 # 1. hardware environment created and powered on
77 # 2. config.underlay.ssh contains SSH access to provisioned nodes
78 # (can be passed from external config with TESTS_CONFIGS variable)
79 # 3. config.tcp.* options contain access credentials to the already
80 # installed TCP API endpoint
81 pass
82
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020083 return salt_actions