| Dennis Dmitriev | eac3aab | 2017-07-12 16:36:41 +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 | eac3aab | 2017-07-12 16:36:41 +0300 | [diff] [blame] | 15 | import pytest | 
| Dennis Dmitriev | eac3aab | 2017-07-12 16:36:41 +0300 | [diff] [blame] | 16 |  | 
|  | 17 | from tcp_tests import logger | 
|  | 18 | from tcp_tests.helpers import ext | 
| Dennis Dmitriev | eac3aab | 2017-07-12 16:36:41 +0300 | [diff] [blame] | 19 | from tcp_tests.managers import oss_manager | 
|  | 20 |  | 
|  | 21 | LOG = logger.logger | 
|  | 22 |  | 
|  | 23 |  | 
|  | 24 | @pytest.fixture(scope='function') | 
|  | 25 | def oss_actions(config, underlay, salt_actions): | 
|  | 26 | """Fixture that provides various actions for OSS | 
|  | 27 |  | 
|  | 28 | :param config: fixture provides oslo.config | 
|  | 29 | :param underlay: fixture provides underlay manager | 
|  | 30 | :rtype: OSSManager | 
|  | 31 | """ | 
|  | 32 | return oss_manager.OSSManager(config, underlay, salt_actions) | 
|  | 33 |  | 
|  | 34 |  | 
|  | 35 | @pytest.mark.revert_snapshot(ext.SNAPSHOT.oss_deployed) | 
|  | 36 | @pytest.fixture(scope='function') | 
|  | 37 | def oss_deployed(revert_snapshot, request, config, | 
|  | 38 | hardware, underlay, salt_deployed, | 
|  | 39 | oss_actions): | 
|  | 40 | """Fixture to get or install OSS on the environment | 
|  | 41 |  | 
|  | 42 | :param revert_snapshot: fixture that reverts snapshot that is specified | 
|  | 43 | in test with @pytest.mark.revert_snapshot(<name>) | 
|  | 44 | :param request: fixture provides pytest data | 
|  | 45 | :param config: fixture provides oslo.config | 
|  | 46 | :param hardware: fixture provides enviromnet manager | 
|  | 47 | :param underlay: fixture provides underlay manager | 
|  | 48 | :param oss_actions: fixture provides OSSManager instance | 
|  | 49 | :rtype: OSSManager | 
|  | 50 |  | 
|  | 51 | If config.oss.oss_installed is not set, this | 
|  | 52 | fixture assumes that the OSS were not installed | 
|  | 53 | , and do the following: | 
|  | 54 | - install OSS | 
|  | 55 | - make snapshot with name 'oss_deployed' | 
|  | 56 | - return OSSManager | 
|  | 57 |  | 
|  | 58 | If config.oss.oss_installed was set, this fixture | 
|  | 59 | assumes that the OSS were already installed, and do | 
|  | 60 | the following: | 
|  | 61 | - return OSSManager instance | 
|  | 62 |  | 
|  | 63 | If you want to revert 'oss_deployed' snapshot, please use mark: | 
|  | 64 | @pytest.mark.revert_snapshot("oss_deployed") | 
|  | 65 | """ | 
|  | 66 | if not config.oss.oss_installed: | 
|  | 67 | steps_path = config.oss_deploy.oss_steps_path | 
|  | 68 | commands = underlay.read_template(steps_path) | 
|  | 69 | oss_actions.install(commands) | 
|  | 70 | hardware.create_snapshot(ext.SNAPSHOT.oss_deployed) | 
| Dennis Dmitriev | b8115f5 | 2017-12-15 13:09:56 +0200 | [diff] [blame] | 71 | salt_deployed.sync_time() | 
| Dennis Dmitriev | eac3aab | 2017-07-12 16:36:41 +0300 | [diff] [blame] | 72 |  | 
|  | 73 | else: | 
|  | 74 | # 1. hardware environment created and powered on | 
|  | 75 | # 2. config.underlay.ssh contains SSH access to provisioned nodes | 
|  | 76 | #    (can be passed from external config with TESTS_CONFIGS variable) | 
|  | 77 | # 3. config.tcp.* options contain access credentials to the already | 
|  | 78 | #    installed TCP API endpoint | 
|  | 79 | pass | 
|  | 80 |  | 
|  | 81 | return oss_actions | 
| Dennis Dmitriev | 0f08d9a | 2017-12-19 02:27:59 +0200 | [diff] [blame] | 82 |  | 
|  | 83 |  | 
|  | 84 | @pytest.mark.revert_snapshot(ext.SNAPSHOT.oss_deployed) | 
|  | 85 | @pytest.fixture(scope='function') | 
|  | 86 | def oss_sl_os_deployed(revert_snapshot, | 
|  | 87 | sl_os_deployed, | 
|  | 88 | oss_deployed): | 
|  | 89 | """Fixture to get or install SL and OpenStack services on environment | 
|  | 90 |  | 
| Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame^] | 91 | Uses fixtures openstack_deployed and stacklight_deployed, | 
|  | 92 | with 'stacklight_deployed' top-level snapshot. | 
| Dennis Dmitriev | 0f08d9a | 2017-12-19 02:27:59 +0200 | [diff] [blame] | 93 |  | 
|  | 94 | Returns SLManager instance object | 
|  | 95 | """ | 
|  | 96 | return oss_deployed |