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 | |
| 15 | import os |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 16 | |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 17 | import pytest |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 18 | import yaml |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 19 | |
| 20 | from tcp_tests import logger |
| 21 | from tcp_tests.helpers import ext |
| 22 | from tcp_tests import settings |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 23 | from tcp_tests.managers import common_services_manager |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 24 | |
| 25 | LOG = logger.logger |
| 26 | |
| 27 | |
| 28 | @pytest.fixture(scope='function') |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 29 | def common_services_actions(config, underlay): |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 30 | """Fixture that provides various actions for K8S |
| 31 | |
| 32 | :param config: fixture provides oslo.config |
| 33 | :param underlay: fixture provides underlay manager |
| 34 | :rtype: K8SManager |
| 35 | |
| 36 | For use in tests or fixtures to deploy a custom K8S |
| 37 | """ |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 38 | return common_services_manager.CommonServicesManager(config, underlay) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 39 | |
| 40 | |
| 41 | @pytest.fixture(scope='function') |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 42 | def common_services_deployed(revert_snapshot, request, config, |
| 43 | hardware, underlay, salt_deployed, |
| 44 | common_services_actions): |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 45 | """Fixture to get or install TCP on environment |
| 46 | |
| 47 | :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 |
| 51 | :param tcp_actions: fixture provides TCPManager instance |
| 52 | :rtype: TCPManager |
| 53 | |
| 54 | If config.tcp.tcp_host is not set, this fixture assumes that |
| 55 | the tcp cluster was not deployed, and do the following: |
| 56 | - deploy tcp cluster |
| 57 | - make snapshot with name 'tcp_deployed' |
| 58 | - return TCPCluster instance |
| 59 | |
| 60 | If config.tcp.tcp_host was set, this fixture assumes that the tcp |
| 61 | cluster was already deployed, and do the following: |
| 62 | - return TCPCluster instance |
| 63 | |
| 64 | If you want to revert 'tcp_deployed' snapshot, please use mark: |
| 65 | @pytest.mark.revert_snapshot("tcp_deployed") |
| 66 | """ |
| 67 | # If no snapshot was reverted, then try to revert the snapshot |
| 68 | # that belongs to the fixture. |
| 69 | # Note: keep fixtures in strict dependences from each other! |
| 70 | if not revert_snapshot: |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 71 | if hardware.has_snapshot(ext.SNAPSHOT.common_services_deployed) and \ |
| 72 | hardware.has_snapshot_config( |
| 73 | ext.SNAPSHOT.common_services_deployed): |
| 74 | hardware.revert_snapshot(ext.SNAPSHOT.common_services_deployed) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 75 | |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 76 | # Create Salt cluster |
| 77 | if not config.common_services.installed: |
| 78 | steps_path = config.common_services_deploy.common_services_steps_path |
| 79 | with underlay.yaml_editor(steps_path) as commands: |
| 80 | common_services_actions.install(commands.content) |
| 81 | hardware.create_snapshot(ext.SNAPSHOT.common_services_deployed) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 82 | |
| 83 | else: |
| 84 | # 1. hardware environment created and powered on |
| 85 | # 2. config.underlay.ssh contains SSH access to provisioned nodes |
| 86 | # (can be passed from external config with TESTS_CONFIGS variable) |
| 87 | # 3. config.tcp.* options contain access credentials to the already |
| 88 | # installed TCP API endpoint |
| 89 | pass |
| 90 | |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 91 | return common_services_actions |