blob: 480a5487f6370be62d7375cd28b7985e177864ab [file] [log] [blame]
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +03001# 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 Dmitriev8cb2f412016-10-18 14:53:58 +030015import pytest
16
17from tcp_tests import logger
18from tcp_tests.helpers import ext
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020019from tcp_tests.managers import openstack_manager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030020
21LOG = logger.logger
22
23
24@pytest.fixture(scope='function')
Vladimir Jigulinee1faa52018-06-25 13:00:51 +040025def openstack_actions(config, underlay, salt_deployed):
Artem Panchenko0594cd72017-06-12 13:25:26 +030026 """Fixture that provides various actions for OpenStack
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030027
28 :param config: fixture provides oslo.config
Tatyana Leontoviche5ccdb32017-10-09 20:10:43 +030029 :param config: fixture provides oslo.config
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030030 :param underlay: fixture provides underlay manager
Artem Panchenko0594cd72017-06-12 13:25:26 +030031 :param salt_deployed: fixture provides salt manager
32 :rtype: OpenstackManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030033
Artem Panchenko0594cd72017-06-12 13:25:26 +030034 For use in tests or fixtures to deploy a custom OpenStack
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030035 """
Vladimir Jigulinee1faa52018-06-25 13:00:51 +040036 return openstack_manager.OpenstackManager(config, underlay, salt_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030037
38
Dennis Dmitriev535869c2016-11-16 22:38:06 +020039@pytest.mark.revert_snapshot(ext.SNAPSHOT.openstack_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030040@pytest.fixture(scope='function')
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020041def openstack_deployed(revert_snapshot, request, config,
Dennis Dmitrievea48cf52018-07-18 18:04:39 +030042 hardware, underlay, core_deployed,
Dennis Dmitrievb8115f52017-12-15 13:09:56 +020043 salt_deployed, openstack_actions, rally):
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020044 """Fixture to get or install OpenStack services on environment
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030045
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020046 :param revert_snapshot: fixture that reverts snapshot that is specified
47 in test with @pytest.mark.revert_snapshot(<name>)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030048 :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 Dmitrievea48cf52018-07-18 18:04:39 +030052 :param core_deployed: fixture provides CoreManager
Artem Panchenko0594cd72017-06-12 13:25:26 +030053 :param openstack_actions: fixture provides OpenstackManager instance
Dennis Dmitriev2d643bc2017-12-04 12:23:47 +020054 :param rally: fixture provides RallyManager instance
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020055 :rtype: OpenstackManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030056
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020057 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 Dmitriev2d643bc2017-12-04 12:23:47 +020060 - [optional] prepare docker with rally container
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020061 - make snapshot with name 'openstack_deployed'
62 - return OpenstackManager instance
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030063
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020064 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 Dmitriev8cb2f412016-10-18 14:53:58 +030067
Dennis Dmitriev2d643bc2017-12-04 12:23:47 +020068 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 Dmitriev2cbf2352016-11-11 15:34:21 +020077 If you want to revert 'openstack_deployed' snapshot, please use mark:
78 @pytest.mark.revert_snapshot("openstack_deployed")
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030079 """
Dennis Dmitriev2d643bc2017-12-04 12:23:47 +020080
Artem Panchenko0594cd72017-06-12 13:25:26 +030081 # Deploy Openstack cluster
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030082 if not config.openstack.openstack_installed:
83 steps_path = config.openstack_deploy.openstack_steps_path
Dennis Dmitriev7f1ee042017-05-26 18:38:54 +030084 commands = underlay.read_template(steps_path)
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030085 openstack_actions.install(commands)
Dennis Dmitriev2d643bc2017-12-04 12:23:47 +020086
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 Tyzhnenko2b730a02017-04-07 19:31:32 +0300100 hardware.create_snapshot(ext.SNAPSHOT.openstack_deployed)
Dennis Dmitrievb8115f52017-12-15 13:09:56 +0200101 salt_deployed.sync_time()
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +0300102
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