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 common_services_manager |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 20 | |
| 21 | LOG = logger.logger |
| 22 | |
| 23 | |
| 24 | @pytest.fixture(scope='function') |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 25 | def common_services_actions(config, underlay, salt_actions): |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 26 | """Fixture that provides various actions for CommonServices |
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: CommonServicesManager |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 31 | """ |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 32 | return common_services_manager.CommonServicesManager(config, underlay, |
| 33 | salt_actions) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 34 | |
| 35 | |
Dennis Dmitriev | 535869c | 2016-11-16 22:38:06 +0200 | [diff] [blame] | 36 | @pytest.mark.revert_snapshot(ext.SNAPSHOT.common_services_deployed) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 37 | @pytest.fixture(scope='function') |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 38 | def common_services_deployed(revert_snapshot, request, config, |
| 39 | hardware, underlay, salt_deployed, |
| 40 | common_services_actions): |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 41 | """Fixture to get or install common services on the environment |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 42 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 43 | :param revert_snapshot: fixture that reverts snapshot that is specified |
| 44 | in test with @pytest.mark.revert_snapshot(<name>) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 45 | :param request: fixture provides pytest data |
| 46 | :param config: fixture provides oslo.config |
| 47 | :param hardware: fixture provides enviromnet manager |
| 48 | :param underlay: fixture provides underlay manager |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 49 | :param common_services_actions: fixture provides CommonServicesManager |
| 50 | instance |
| 51 | :rtype: CommonServicesManager |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 52 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 53 | If config.common_services.common_services_installed is not set, this |
| 54 | fixture assumes that the common services were not installed |
| 55 | , and do the following: |
| 56 | - install common services |
| 57 | - make snapshot with name 'common_services_deployed' |
| 58 | - return CommonServicesManager |
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 config.common_services.common_services_installed was set, this fixture |
| 61 | assumes that the common services were already installed, and do |
| 62 | the following: |
| 63 | - return CommonServicesManager instance |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 64 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 65 | If you want to revert 'common_services_deployed' snapshot, please use mark: |
| 66 | @pytest.mark.revert_snapshot("common_services_deployed") |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 67 | """ |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 68 | # Create Salt cluster |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 69 | if not config.common_services.common_services_installed: |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 70 | steps_path = config.common_services_deploy.common_services_steps_path |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 71 | commands = underlay.read_template(steps_path) |
dis | 2b2d863 | 2016-12-08 17:56:57 +0200 | [diff] [blame] | 72 | common_services_actions.install(commands) |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 73 | hardware.create_snapshot(ext.SNAPSHOT.common_services_deployed) |
Dennis Dmitriev | b8115f5 | 2017-12-15 13:09:56 +0200 | [diff] [blame] | 74 | salt_deployed.sync_time() |
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 common_services_actions |