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') |
Dmitry Tyzhnenko | bc0f826 | 2017-04-28 15:39:26 +0300 | [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 |
| 29 | :param underlay: fixture provides underlay manager |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 30 | :param salt_deployed: fixture provides salt manager |
| 31 | :rtype: OpenstackManager |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 32 | |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 33 | For use in tests or fixtures to deploy a custom OpenStack |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 34 | """ |
Dmitry Tyzhnenko | bc0f826 | 2017-04-28 15:39:26 +0300 | [diff] [blame] | 35 | return openstack_manager.OpenstackManager(config, underlay, salt_deployed) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 36 | |
| 37 | |
Dennis Dmitriev | 535869c | 2016-11-16 22:38:06 +0200 | [diff] [blame] | 38 | @pytest.mark.revert_snapshot(ext.SNAPSHOT.openstack_deployed) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 39 | @pytest.fixture(scope='function') |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 40 | def openstack_deployed(revert_snapshot, request, config, |
| 41 | hardware, underlay, common_services_deployed, |
| 42 | openstack_actions): |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 43 | """Fixture to get or install OpenStack services on environment |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 44 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 45 | :param revert_snapshot: fixture that reverts snapshot that is specified |
| 46 | in test with @pytest.mark.revert_snapshot(<name>) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 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 |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 51 | :param common_services_deployed: fixture provides CommonServicesManager |
| 52 | :param openstack_actions: fixture provides OpenstackManager instance |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 53 | :rtype: OpenstackManager |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 54 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 55 | If config.openstack.openstack_installed is not set, this fixture assumes |
| 56 | that the openstack services were not installed, and do the following: |
| 57 | - install openstack services |
| 58 | - make snapshot with name 'openstack_deployed' |
| 59 | - return OpenstackManager instance |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 60 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 61 | If config.openstack.openstack_installed was set, this fixture assumes that |
| 62 | the openstack services were already installed, and do the following: |
| 63 | - return OpenstackManager instance |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 64 | |
Dennis Dmitriev | 2cbf235 | 2016-11-11 15:34:21 +0200 | [diff] [blame] | 65 | If you want to revert 'openstack_deployed' snapshot, please use mark: |
| 66 | @pytest.mark.revert_snapshot("openstack_deployed") |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 67 | """ |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 68 | # Deploy Openstack cluster |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 69 | if not config.openstack.openstack_installed: |
| 70 | steps_path = config.openstack_deploy.openstack_steps_path |
Dennis Dmitriev | 7f1ee04 | 2017-05-26 18:38:54 +0300 | [diff] [blame] | 71 | commands = underlay.read_template(steps_path) |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 72 | openstack_actions.install(commands) |
| 73 | hardware.create_snapshot(ext.SNAPSHOT.openstack_deployed) |
| 74 | |
| 75 | else: |
| 76 | # 1. hardware environment created and powered on |
| 77 | # 2. config.underlay.ssh contains SSH access to provisioned nodes |
| 78 | # (can be passed from external config with TESTS_CONFIGS variable) |
| 79 | # 3. config.tcp.* options contain access credentials to the already |
| 80 | # installed TCP API endpoint |
| 81 | pass |
| 82 | |
| 83 | return openstack_actions |