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 |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 21 | |
| 22 | LOG = logger.logger |
| 23 | |
| 24 | |
| 25 | @pytest.fixture(scope='function') |
| 26 | def sl_actions(config, underlay, salt_deployed): |
| 27 | """Fixture that provides various actions for K8S |
| 28 | |
| 29 | :param config: fixture provides oslo.config |
| 30 | :param underlay: fixture provides underlay manager |
| 31 | :rtype: SLManager |
| 32 | |
| 33 | For use in tests or fixtures to deploy a custom K8S |
| 34 | """ |
| 35 | return sl_manager.SLManager(config, underlay, salt_deployed) |
| 36 | |
| 37 | |
| 38 | @pytest.mark.revert_snapshot(ext.SNAPSHOT.sl_deployed) |
| 39 | @pytest.fixture(scope='function') |
| 40 | def sl_deployed(revert_snapshot, request, config, |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 41 | hardware, underlay, common_services_deployed, |
| 42 | sl_actions): |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 43 | """Fixture to get or install SL services on environment |
| 44 | |
| 45 | :param revert_snapshot: fixture that reverts snapshot that is specified |
| 46 | in test with @pytest.mark.revert_snapshot(<name>) |
| 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 SLManager instance |
| 52 | :rtype: SLManager |
| 53 | """ |
Dennis Dmitriev | 17b9a9e | 2017-11-29 15:04:28 +0200 | [diff] [blame^] | 54 | # Deploy SL services |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 55 | if not config.stack_light.sl_installed: |
| 56 | steps_path = config.sl_deploy.sl_steps_path |
| 57 | commands = underlay.read_template(steps_path) |
| 58 | sl_actions.install(commands) |
| 59 | hardware.create_snapshot(ext.SNAPSHOT.sl_deployed) |
| 60 | |
| 61 | else: |
| 62 | # 1. hardware environment created and powered on |
| 63 | # 2. config.underlay.ssh contains SSH access to provisioned nodes |
| 64 | # (can be passed from external config with TESTS_CONFIGS variable) |
| 65 | # 3. config.tcp.* options contain access credentials to the already |
| 66 | # installed TCP API endpoint |
| 67 | pass |
| 68 | |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 69 | # Workaround for keepalived hang issue after env revert from snapshot |
| 70 | # see https://mirantis.jira.com/browse/PROD-12038 |
| 71 | LOG.warning('Restarting keepalived service on controllers...') |
| 72 | sl_actions._salt.local(tgt='ctl*', fun='cmd.run', |
| 73 | args='systemctl restart keepalived.service') |
Tatyana Leontovich | b57ec13 | 2017-07-27 17:16:42 +0300 | [diff] [blame] | 74 | LOG.warning('Restarting keepalived service on mon nodes...') |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 75 | sl_actions._salt.local(tgt='mon*', fun='cmd.run', |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 76 | args='systemctl restart keepalived.service') |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 77 | return sl_actions |
| 78 | |
| 79 | |
| 80 | @pytest.mark.revert_snapshot(ext.SNAPSHOT.sl_deployed) |
| 81 | @pytest.fixture(scope='function') |
Dennis Dmitriev | 17b9a9e | 2017-11-29 15:04:28 +0200 | [diff] [blame^] | 82 | def sl_os_deployed(revert_snapshot, |
| 83 | openstack_deployed, |
| 84 | sl_deployed): |
| 85 | """Fixture to get or install SL and OpenStack services on environment |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 86 | |
Dennis Dmitriev | 17b9a9e | 2017-11-29 15:04:28 +0200 | [diff] [blame^] | 87 | Uses fixtures openstack_deployed and sl_deployed, with 'sl_deployed' |
| 88 | top-level snapshot. |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 89 | |
Dennis Dmitriev | 17b9a9e | 2017-11-29 15:04:28 +0200 | [diff] [blame^] | 90 | Returns SLManager instance object |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 91 | """ |
Dennis Dmitriev | 17b9a9e | 2017-11-29 15:04:28 +0200 | [diff] [blame^] | 92 | return sl_deployed |