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 | |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 38 | @pytest.mark.revert_snapshot(ext.SNAPSHOT.stacklight_deployed) |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 39 | @pytest.fixture(scope='function') |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 40 | def stacklight_deployed(revert_snapshot, request, config, |
| 41 | hardware, underlay, core_deployed, |
| 42 | salt_deployed, 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 |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 55 | if not config.stack_light.stacklight_installed: |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 56 | steps_path = config.sl_deploy.sl_steps_path |
| 57 | commands = underlay.read_template(steps_path) |
| 58 | sl_actions.install(commands) |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 59 | hardware.create_snapshot(ext.SNAPSHOT.stacklight_deployed) |
Dennis Dmitriev | b8115f5 | 2017-12-15 13:09:56 +0200 | [diff] [blame] | 60 | salt_deployed.sync_time() |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 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 | |
| 70 | return sl_actions |
| 71 | |
| 72 | |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 73 | @pytest.mark.revert_snapshot(ext.SNAPSHOT.stacklight_deployed) |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 74 | @pytest.fixture(scope='function') |
Dennis Dmitriev | 17b9a9e | 2017-11-29 15:04:28 +0200 | [diff] [blame] | 75 | def sl_os_deployed(revert_snapshot, |
| 76 | openstack_deployed, |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 77 | stacklight_deployed): |
Dennis Dmitriev | 17b9a9e | 2017-11-29 15:04:28 +0200 | [diff] [blame] | 78 | """Fixture to get or install SL and OpenStack services on environment |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 79 | |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 80 | Uses fixtures openstack_deployed and stacklight_deployed, |
| 81 | with 'stacklight_deployed' top-level snapshot. |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 82 | |
Dennis Dmitriev | 17b9a9e | 2017-11-29 15:04:28 +0200 | [diff] [blame] | 83 | Returns SLManager instance object |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 84 | """ |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 85 | return stacklight_deployed |