Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +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 | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 15 | import pytest |
| 16 | |
| 17 | from tcp_tests import logger |
| 18 | from tcp_tests.helpers import ext |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 19 | from tcp_tests.managers import openstack_manager |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 20 | |
| 21 | LOG = logger.logger |
| 22 | |
| 23 | |
| 24 | @pytest.fixture(scope='function') |
Vladimir Jigulin | ee1faa5 | 2018-06-25 13:00:51 +0400 | [diff] [blame] | 25 | def openstack_actions(config, underlay, salt_deployed): |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 26 | """Fixture that provides various actions for OpenStack |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 27 | |
| 28 | :param config: fixture provides oslo.config |
Tatyana Leontovich | e5ccdb3 | 2017-10-09 20:10:43 +0300 | [diff] [blame] | 29 | :param config: fixture provides oslo.config |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 30 | :param underlay: fixture provides underlay manager |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 31 | :param salt_deployed: fixture provides salt manager |
| 32 | :rtype: OpenstackManager |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 33 | |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 34 | For use in tests or fixtures to deploy a custom OpenStack |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 35 | """ |
Vladimir Jigulin | ee1faa5 | 2018-06-25 13:00:51 +0400 | [diff] [blame] | 36 | return openstack_manager.OpenstackManager(config, underlay, salt_deployed) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 37 | |
| 38 | |
Dennis Dmitriev | 535869c | 2016-11-16 22:38:06 +0200 | [diff] [blame] | 39 | @pytest.mark.revert_snapshot(ext.SNAPSHOT.openstack_deployed) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 40 | @pytest.fixture(scope='function') |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 41 | def openstack_deployed(revert_snapshot, request, config, |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 42 | hardware, underlay, core_deployed, |
Dennis Dmitriev | b8115f5 | 2017-12-15 13:09:56 +0200 | [diff] [blame] | 43 | salt_deployed, openstack_actions, rally): |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 44 | """Fixture to get or install OpenStack services on environment |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 45 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 46 | :param revert_snapshot: fixture that reverts snapshot that is specified |
| 47 | in test with @pytest.mark.revert_snapshot(<name>) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 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 |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 52 | :param core_deployed: fixture provides CoreManager |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 53 | :param openstack_actions: fixture provides OpenstackManager instance |
Dennis Dmitriev | 2d643bc | 2017-12-04 12:23:47 +0200 | [diff] [blame] | 54 | :param rally: fixture provides RallyManager instance |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 55 | :rtype: OpenstackManager |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 56 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 57 | If config.openstack.openstack_installed is not set, this fixture assumes |
| 58 | that the openstack services were not installed, and do the following: |
| 59 | - install openstack services |
Dennis Dmitriev | 2d643bc | 2017-12-04 12:23:47 +0200 | [diff] [blame] | 60 | - [optional] prepare docker with rally container |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 61 | - make snapshot with name 'openstack_deployed' |
| 62 | - return OpenstackManager instance |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 63 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 64 | If config.openstack.openstack_installed was set, this fixture assumes that |
| 65 | the openstack services were already installed, and do the following: |
| 66 | - return OpenstackManager instance |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 67 | |
Dennis Dmitriev | 2d643bc | 2017-12-04 12:23:47 +0200 | [diff] [blame] | 68 | If you want to prepare 'rally', please use mark: |
| 69 | @pytest.mark.with_rally(rally_node=<str>, |
| 70 | prepare_openstack=<bool>, |
| 71 | prepare_tempest=<bool>) |
| 72 | :param rally_node: first chars of the node name where rally should |
| 73 | be started |
| 74 | :param prepare_openstack: if True, prepare OpenStack objects for |
| 75 | rally tasks: cirros image, private net04 |
| 76 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 77 | If you want to revert 'openstack_deployed' snapshot, please use mark: |
| 78 | @pytest.mark.revert_snapshot("openstack_deployed") |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 79 | """ |
Dennis Dmitriev | 2d643bc | 2017-12-04 12:23:47 +0200 | [diff] [blame] | 80 | |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 81 | # Deploy Openstack cluster |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 82 | if not config.openstack.openstack_installed: |
| 83 | steps_path = config.openstack_deploy.openstack_steps_path |
Dennis Dmitriev | 7f1ee04 | 2017-05-26 18:38:54 +0300 | [diff] [blame] | 84 | commands = underlay.read_template(steps_path) |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 85 | openstack_actions.install(commands) |
Dennis Dmitriev | 2d643bc | 2017-12-04 12:23:47 +0200 | [diff] [blame] | 86 | |
| 87 | # If @pytest.mark.with_rally() is set, then prepare Rally |
| 88 | # container for 'openstack_deployed' snapshot. |
| 89 | with_rally = request.keywords.get('with_rally', None) |
| 90 | if with_rally: |
| 91 | prepare_openstack = with_rally.kwargs.get("prepare_openstack", |
| 92 | False) |
| 93 | prepare_tempest = with_rally.kwargs.get("prepare_tempest", False) |
| 94 | if prepare_openstack: |
| 95 | rally.prepare_rally_task(target_node='ctl01') |
| 96 | if prepare_tempest: |
| 97 | rally.prepare_tempest_task() |
| 98 | rally.run_container() |
| 99 | |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 100 | hardware.create_snapshot(ext.SNAPSHOT.openstack_deployed) |
Dennis Dmitriev | b8115f5 | 2017-12-15 13:09:56 +0200 | [diff] [blame] | 101 | salt_deployed.sync_time() |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 102 | |
| 103 | else: |
| 104 | # 1. hardware environment created and powered on |
| 105 | # 2. config.underlay.ssh contains SSH access to provisioned nodes |
| 106 | # (can be passed from external config with TESTS_CONFIGS variable) |
| 107 | # 3. config.tcp.* options contain access credentials to the already |
| 108 | # installed TCP API endpoint |
| 109 | pass |
| 110 | |
| 111 | return openstack_actions |