blob: 8e92e776a00b2c61afd4ae065574c1095d5f33c0 [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')
Tatyana Leontoviche5ccdb32017-10-09 20:10:43 +030025def openstack_actions(config, hardware, 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 """
Tatyana Leontoviche5ccdb32017-10-09 20:10:43 +030036 return openstack_manager.OpenstackManager(config, underlay,
37 hardware, salt_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030038
39
Dennis Dmitriev535869c2016-11-16 22:38:06 +020040@pytest.mark.revert_snapshot(ext.SNAPSHOT.openstack_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030041@pytest.fixture(scope='function')
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020042def openstack_deployed(revert_snapshot, request, config,
43 hardware, underlay, common_services_deployed,
Dennis Dmitrievb8115f52017-12-15 13:09:56 +020044 salt_deployed, openstack_actions, rally):
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020045 """Fixture to get or install OpenStack services on environment
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030046
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020047 :param revert_snapshot: fixture that reverts snapshot that is specified
48 in test with @pytest.mark.revert_snapshot(<name>)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030049 :param request: fixture provides pytest data
50 :param config: fixture provides oslo.config
51 :param hardware: fixture provides enviromnet manager
52 :param underlay: fixture provides underlay manager
Artem Panchenko0594cd72017-06-12 13:25:26 +030053 :param common_services_deployed: fixture provides CommonServicesManager
54 :param openstack_actions: fixture provides OpenstackManager instance
Dennis Dmitriev2d643bc2017-12-04 12:23:47 +020055 :param rally: fixture provides RallyManager instance
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020056 :rtype: OpenstackManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030057
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020058 If config.openstack.openstack_installed is not set, this fixture assumes
59 that the openstack services were not installed, and do the following:
60 - install openstack services
Dennis Dmitriev2d643bc2017-12-04 12:23:47 +020061 - [optional] prepare docker with rally container
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020062 - make snapshot with name 'openstack_deployed'
63 - return OpenstackManager instance
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030064
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020065 If config.openstack.openstack_installed was set, this fixture assumes that
66 the openstack services were already installed, and do the following:
67 - return OpenstackManager instance
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030068
Dennis Dmitriev2d643bc2017-12-04 12:23:47 +020069 If you want to prepare 'rally', please use mark:
70 @pytest.mark.with_rally(rally_node=<str>,
71 prepare_openstack=<bool>,
72 prepare_tempest=<bool>)
73 :param rally_node: first chars of the node name where rally should
74 be started
75 :param prepare_openstack: if True, prepare OpenStack objects for
76 rally tasks: cirros image, private net04
77
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020078 If you want to revert 'openstack_deployed' snapshot, please use mark:
79 @pytest.mark.revert_snapshot("openstack_deployed")
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030080 """
Dennis Dmitriev2d643bc2017-12-04 12:23:47 +020081
Artem Panchenko0594cd72017-06-12 13:25:26 +030082 # Deploy Openstack cluster
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030083 if not config.openstack.openstack_installed:
84 steps_path = config.openstack_deploy.openstack_steps_path
Dennis Dmitriev7f1ee042017-05-26 18:38:54 +030085 commands = underlay.read_template(steps_path)
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030086 openstack_actions.install(commands)
Dennis Dmitriev2d643bc2017-12-04 12:23:47 +020087
88 # If @pytest.mark.with_rally() is set, then prepare Rally
89 # container for 'openstack_deployed' snapshot.
90 with_rally = request.keywords.get('with_rally', None)
91 if with_rally:
92 prepare_openstack = with_rally.kwargs.get("prepare_openstack",
93 False)
94 prepare_tempest = with_rally.kwargs.get("prepare_tempest", False)
95 if prepare_openstack:
96 rally.prepare_rally_task(target_node='ctl01')
97 if prepare_tempest:
98 rally.prepare_tempest_task()
99 rally.run_container()
100
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +0300101 hardware.create_snapshot(ext.SNAPSHOT.openstack_deployed)
Dennis Dmitrievb8115f52017-12-15 13:09:56 +0200102 salt_deployed.sync_time()
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +0300103
104 else:
105 # 1. hardware environment created and powered on
106 # 2. config.underlay.ssh contains SSH access to provisioned nodes
107 # (can be passed from external config with TESTS_CONFIGS variable)
108 # 3. config.tcp.* options contain access credentials to the already
109 # installed TCP API endpoint
110 pass
111
112 return openstack_actions