Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 1 | # 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 Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 15 | import pytest |
| 16 | |
| 17 | from tcp_tests import logger |
| 18 | from tcp_tests.helpers import ext |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 19 | from tcp_tests.managers import saltmanager |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 20 | |
| 21 | LOG = logger.logger |
| 22 | |
| 23 | |
| 24 | @pytest.fixture(scope='function') |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 25 | def salt_actions(config, underlay): |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 26 | """Fixture that provides various actions for salt |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 27 | |
| 28 | :param config: fixture provides oslo.config |
| 29 | :param underlay: fixture provides underlay manager |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 30 | :rtype: SaltManager |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 31 | """ |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 32 | return saltmanager.SaltManager(config, underlay) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 33 | |
| 34 | |
Dennis Dmitriev | 535869c | 2016-11-16 22:38:06 +0200 | [diff] [blame] | 35 | @pytest.mark.revert_snapshot(ext.SNAPSHOT.salt_deployed) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 36 | @pytest.fixture(scope='function') |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 37 | def salt_deployed(revert_snapshot, request, config, |
| 38 | hardware, underlay, salt_actions): |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 39 | """Fixture to get or install salt service on environment |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 40 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 41 | :param revert_snapshot: fixture that reverts snapshot that is specified |
| 42 | in test with @pytest.mark.revert_snapshot(<name>) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 43 | :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 Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 47 | :param salt_actions: fixture provides SaltManager instance |
| 48 | :rtype: SaltManager |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 49 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 50 | 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 Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 55 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 56 | 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 Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 59 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 60 | If you want to revert 'salt_deployed' snapshot, please use mark: |
| 61 | @pytest.mark.revert_snapshot("salt_deployed") |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 62 | """ |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 63 | # Create Salt cluster |
| 64 | if config.salt.salt_master_host == '0.0.0.0': |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 65 | # Temporary workaround. Underlay should be extended with roles |
| 66 | salt_nodes = underlay.node_names() |
| 67 | config.salt.salt_master_host = \ |
Tatyana Leontovich | ecd491d | 2017-09-13 13:51:12 +0300 | [diff] [blame^] | 68 | underlay.host_by_node_role( |
| 69 | node_role=ext.UNDERLAY_NODE_ROLES.salt_master) |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 70 | |
| 71 | commands = underlay.read_template(config.salt_deploy.salt_steps_path) |
| 72 | LOG.info("############ Executing command ####### {0}".format(commands)) |
dis | 2b2d863 | 2016-12-08 17:56:57 +0200 | [diff] [blame] | 73 | salt_actions.install(commands) |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 74 | hardware.create_snapshot(ext.SNAPSHOT.salt_deployed) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 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 | |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 84 | return salt_actions |