Tatyana Leontovich | c8b8ca2 | 2017-05-19 13: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 | |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 15 | |
| 16 | import pytest |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 17 | |
| 18 | from tcp_tests import logger |
| 19 | from tcp_tests.helpers import ext |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 20 | from tcp_tests.managers import sl_manager |
| 21 | from tcp_tests.helpers import utils |
| 22 | |
| 23 | LOG = logger.logger |
| 24 | |
| 25 | |
| 26 | @pytest.fixture(scope='function') |
| 27 | def sl_actions(config, underlay, salt_deployed): |
| 28 | """Fixture that provides various actions for K8S |
| 29 | |
| 30 | :param config: fixture provides oslo.config |
| 31 | :param underlay: fixture provides underlay manager |
| 32 | :rtype: SLManager |
| 33 | |
| 34 | For use in tests or fixtures to deploy a custom K8S |
| 35 | """ |
| 36 | return sl_manager.SLManager(config, underlay, salt_deployed) |
| 37 | |
| 38 | |
| 39 | @pytest.mark.revert_snapshot(ext.SNAPSHOT.sl_deployed) |
| 40 | @pytest.fixture(scope='function') |
| 41 | def sl_deployed(revert_snapshot, request, config, |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 42 | hardware, underlay, common_services_deployed, |
| 43 | sl_actions): |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 44 | """Fixture to get or install SL services on environment |
| 45 | |
| 46 | :param revert_snapshot: fixture that reverts snapshot that is specified |
| 47 | in test with @pytest.mark.revert_snapshot(<name>) |
| 48 | :param request: fixture provides pytest data |
| 49 | :param config: fixture provides oslo.config |
| 50 | :param hardware: fixture provides enviromnet manager |
| 51 | :param underlay: fixture provides underlay manager |
| 52 | :param tcp_actions: fixture provides SLManager instance |
| 53 | :rtype: SLManager |
| 54 | """ |
| 55 | # Create Salt cluster |
| 56 | if not config.stack_light.sl_installed: |
| 57 | steps_path = config.sl_deploy.sl_steps_path |
| 58 | commands = underlay.read_template(steps_path) |
| 59 | sl_actions.install(commands) |
| 60 | hardware.create_snapshot(ext.SNAPSHOT.sl_deployed) |
| 61 | |
| 62 | else: |
| 63 | # 1. hardware environment created and powered on |
| 64 | # 2. config.underlay.ssh contains SSH access to provisioned nodes |
| 65 | # (can be passed from external config with TESTS_CONFIGS variable) |
| 66 | # 3. config.tcp.* options contain access credentials to the already |
| 67 | # installed TCP API endpoint |
| 68 | pass |
| 69 | |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 70 | # Workaround for keepalived hang issue after env revert from snapshot |
| 71 | # see https://mirantis.jira.com/browse/PROD-12038 |
| 72 | LOG.warning('Restarting keepalived service on controllers...') |
| 73 | sl_actions._salt.local(tgt='ctl*', fun='cmd.run', |
| 74 | args='systemctl restart keepalived.service') |
Tatyana Leontovich | b57ec13 | 2017-07-27 17:16:42 +0300 | [diff] [blame] | 75 | LOG.warning('Restarting keepalived service on mon nodes...') |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 76 | sl_actions._salt.local(tgt='mon*', fun='cmd.run', |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 77 | args='systemctl restart keepalived.service') |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 78 | return sl_actions |
| 79 | |
| 80 | |
| 81 | @pytest.mark.revert_snapshot(ext.SNAPSHOT.sl_deployed) |
| 82 | @pytest.fixture(scope='function') |
| 83 | def deploy_sl(revert_snapshot, request, config, |
| 84 | hardware, underlay, common_services_deployed, |
| 85 | sl_actions): |
| 86 | """Fixture to get or install OpenStack services on environment |
| 87 | |
| 88 | :param revert_snapshot: fixture that reverts snapshot that is specified |
| 89 | in test with @pytest.mark.revert_snapshot(<name>) |
| 90 | :param request: fixture provides pytest data |
| 91 | :param config: fixture provides oslo.config |
| 92 | :param hardware: fixture provides enviromnet manager |
| 93 | :param underlay: fixture provides underlay manager |
| 94 | :param tcp_actions: fixture provides OpenstackManager instance |
| 95 | :rtype: SLManager |
| 96 | |
| 97 | If you want to revert 'sl_deployed' snapshot, please use mark: |
| 98 | @pytest.mark.revert_snapshot("sl_deployed") |
| 99 | """ |
| 100 | # Create Salt cluster |
| 101 | if not config.stack_light.sl_installed: |
| 102 | steps_path = config.sl_deploy.sl_steps_path |
| 103 | commands = utils.read_template(steps_path) |
| 104 | sl_actions.install(commands) |
| 105 | hardware.create_snapshot(ext.SNAPSHOT.sl_deployed) |
| 106 | |
| 107 | else: |
| 108 | # 1. hardware environment created and powered on |
| 109 | # 2. config.underlay.ssh contains SSH access to provisioned nodes |
| 110 | # (can be passed from external config with TESTS_CONFIGS variable) |
| 111 | # 3. config.tcp.* options contain access credentials to the already |
| 112 | # installed TCP API endpoint |
| 113 | pass |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 114 | # Workaround for keepalived hang issue after env revert from snapshot |
| 115 | # see https://mirantis.jira.com/browse/PROD-12038 |
| 116 | LOG.warning('Restarting keepalived service on controllers...') |
| 117 | sl_actions._salt.local(tgt='ctl*', fun='cmd.run', |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 118 | args='systemctl restart keepalived.service') |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 119 | sl_actions._salt.local(tgt='mon*', fun='cmd.run', |
| 120 | args='systemctl restart keepalived.service') |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 121 | return sl_actions |