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 |
dis | 2b2d863 | 2016-12-08 17:56:57 +0200 | [diff] [blame] | 22 | from tcp_tests.helpers import utils |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 23 | from tcp_tests import settings |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 24 | from tcp_tests.managers import openstack_manager |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 25 | |
| 26 | LOG = logger.logger |
| 27 | |
| 28 | |
| 29 | @pytest.fixture(scope='function') |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 30 | def openstack_actions(config, underlay): |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 31 | """Fixture that provides various actions for K8S |
| 32 | |
| 33 | :param config: fixture provides oslo.config |
| 34 | :param underlay: fixture provides underlay manager |
| 35 | :rtype: K8SManager |
| 36 | |
| 37 | For use in tests or fixtures to deploy a custom K8S |
| 38 | """ |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 39 | return openstack_manager.OpenstackManager(config, underlay) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 40 | |
| 41 | |
Dennis Dmitriev | 535869c | 2016-11-16 22:38:06 +0200 | [diff] [blame] | 42 | @pytest.mark.revert_snapshot(ext.SNAPSHOT.openstack_deployed) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 43 | @pytest.fixture(scope='function') |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 44 | def openstack_deployed(revert_snapshot, request, config, |
| 45 | hardware, underlay, common_services_deployed, |
| 46 | openstack_actions): |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 47 | """Fixture to get or install OpenStack services on environment |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 48 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 49 | :param revert_snapshot: fixture that reverts snapshot that is specified |
| 50 | in test with @pytest.mark.revert_snapshot(<name>) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 51 | :param request: fixture provides pytest data |
| 52 | :param config: fixture provides oslo.config |
| 53 | :param hardware: fixture provides enviromnet manager |
| 54 | :param underlay: fixture provides underlay manager |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 55 | :param tcp_actions: fixture provides OpenstackManager instance |
| 56 | :rtype: OpenstackManager |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 57 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 58 | If config.openstack.openstack_installed is not set, this fixture assumes |
| 59 | that the openstack services were not installed, and do the following: |
| 60 | - install openstack services |
| 61 | - make snapshot with name 'openstack_deployed' |
| 62 | - return OpenstackManager instance |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 63 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 64 | If config.openstack.openstack_installed was set, this fixture assumes that |
| 65 | the openstack services were already installed, and do the following: |
| 66 | - return OpenstackManager instance |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 67 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 68 | If you want to revert 'openstack_deployed' snapshot, please use mark: |
| 69 | @pytest.mark.revert_snapshot("openstack_deployed") |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 70 | """ |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 71 | # Create Salt cluster |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 72 | if not config.openstack.openstack_installed: |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 73 | steps_path = config.openstack_deploy.openstack_steps_path |
dis | 2b2d863 | 2016-12-08 17:56:57 +0200 | [diff] [blame] | 74 | commands = utils.read_template(steps_path) |
| 75 | openstack_actions.install(commands) |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 76 | hardware.create_snapshot(ext.SNAPSHOT.openstack_deployed) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 77 | |
| 78 | else: |
| 79 | # 1. hardware environment created and powered on |
| 80 | # 2. config.underlay.ssh contains SSH access to provisioned nodes |
| 81 | # (can be passed from external config with TESTS_CONFIGS variable) |
| 82 | # 3. config.tcp.* options contain access credentials to the already |
| 83 | # installed TCP API endpoint |
| 84 | pass |
| 85 | |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 86 | return openstack_actions |