Dennis Dmitriev | f3f90a5 | 2017-08-10 14:37:05 +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 | f3f90a5 | 2017-08-10 14:37:05 +0300 | [diff] [blame] | 15 | import pytest |
Dennis Dmitriev | f3f90a5 | 2017-08-10 14:37:05 +0300 | [diff] [blame] | 16 | |
| 17 | from tcp_tests import logger |
| 18 | from tcp_tests.helpers import ext |
Dennis Dmitriev | f3f90a5 | 2017-08-10 14:37:05 +0300 | [diff] [blame] | 19 | from tcp_tests.managers import decapod_manager |
| 20 | |
| 21 | LOG = logger.logger |
| 22 | |
| 23 | |
| 24 | @pytest.fixture(scope='function') |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 25 | def decapod_actions(config, underlay_actions, salt_actions): |
Dennis Dmitriev | f3f90a5 | 2017-08-10 14:37:05 +0300 | [diff] [blame] | 26 | """Fixture that provides various actions for Decapod |
| 27 | |
| 28 | :param config: fixture provides oslo.config |
| 29 | :param underlay: fixture provides underlay manager |
| 30 | :rtype: DecapodManager |
| 31 | """ |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 32 | return decapod_manager.DecapodManager(config, underlay_actions, |
| 33 | salt_actions) |
Dennis Dmitriev | f3f90a5 | 2017-08-10 14:37:05 +0300 | [diff] [blame] | 34 | |
| 35 | |
| 36 | @pytest.mark.revert_snapshot(ext.SNAPSHOT.decapod_deployed) |
| 37 | @pytest.fixture(scope='function') |
| 38 | def decapod_deployed(revert_snapshot, request, config, |
| 39 | hardware, underlay, salt_deployed, |
| 40 | decapod_actions): |
| 41 | """Fixture to get or install Decapod on the environment |
| 42 | |
| 43 | :param revert_snapshot: fixture that reverts snapshot that is specified |
| 44 | in test with @pytest.mark.revert_snapshot(<name>) |
| 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 |
| 49 | :param decapod_actions: fixture provides DecapodManager instance |
| 50 | :rtype: DecapodManager |
| 51 | |
| 52 | If config.decapod.decapod_installed is not set, this |
| 53 | fixture assumes that the Decapod were not installed |
| 54 | , and do the following: |
| 55 | - install Decapod |
| 56 | - make snapshot with name 'decapod_deployed' |
| 57 | - return DecapodManager |
| 58 | |
| 59 | If config.decapod.decapod_installed was set, this fixture |
| 60 | assumes that the Decapod were already installed, and do |
| 61 | the following: |
| 62 | - return DecapodManager instance |
| 63 | |
| 64 | If you want to revert 'decapod_deployed' snapshot, please use mark: |
| 65 | @pytest.mark.revert_snapshot("decapod_deployed") |
| 66 | """ |
| 67 | if not config.decapod.decapod_installed: |
| 68 | steps_path = config.decapod_deploy.decapod_steps_path |
| 69 | commands = underlay.read_template(steps_path) |
| 70 | decapod_actions.install(commands) |
| 71 | hardware.create_snapshot(ext.SNAPSHOT.decapod_deployed) |
Dennis Dmitriev | b8115f5 | 2017-12-15 13:09:56 +0200 | [diff] [blame] | 72 | salt_deployed.sync_time() |
Dennis Dmitriev | f3f90a5 | 2017-08-10 14:37:05 +0300 | [diff] [blame] | 73 | |
| 74 | else: |
| 75 | # 1. hardware environment created and powered on |
| 76 | # 2. config.underlay.ssh contains SSH access to provisioned nodes |
| 77 | # (can be passed from external config with TESTS_CONFIGS variable) |
| 78 | # 3. config.tcp.* options contain access credentials to the already |
| 79 | # installed TCP API endpoint |
| 80 | pass |
| 81 | |
| 82 | return decapod_actions |