blob: ae3b9e8c5f8ee2fe942f241d31a79d10c391677a [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
15import os
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020016
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030017import pytest
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020018import yaml
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030019
20from tcp_tests import logger
21from tcp_tests.helpers import ext
22from tcp_tests import settings
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020023from tcp_tests.managers import openstack_manager
Dmitry Tyzhnenkobc0f8262017-04-28 15:39:26 +030024from tcp_tests.helpers import utils
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030025
26LOG = logger.logger
27
28
29@pytest.fixture(scope='function')
Dmitry Tyzhnenkobc0f8262017-04-28 15:39:26 +030030def openstack_actions(config, underlay, salt_deployed):
Artem Panchenko0594cd72017-06-12 13:25:26 +030031 """Fixture that provides various actions for OpenStack
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030032
33 :param config: fixture provides oslo.config
34 :param underlay: fixture provides underlay manager
Artem Panchenko0594cd72017-06-12 13:25:26 +030035 :param salt_deployed: fixture provides salt manager
36 :rtype: OpenstackManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030037
Artem Panchenko0594cd72017-06-12 13:25:26 +030038 For use in tests or fixtures to deploy a custom OpenStack
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030039 """
Dmitry Tyzhnenkobc0f8262017-04-28 15:39:26 +030040 return openstack_manager.OpenstackManager(config, underlay, salt_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030041
42
Dennis Dmitriev535869c2016-11-16 22:38:06 +020043@pytest.mark.revert_snapshot(ext.SNAPSHOT.openstack_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030044@pytest.fixture(scope='function')
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020045def openstack_deployed(revert_snapshot, request, config,
46 hardware, underlay, common_services_deployed,
47 openstack_actions):
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020048 """Fixture to get or install OpenStack services on environment
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030049
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020050 :param revert_snapshot: fixture that reverts snapshot that is specified
51 in test with @pytest.mark.revert_snapshot(<name>)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030052 :param request: fixture provides pytest data
53 :param config: fixture provides oslo.config
54 :param hardware: fixture provides enviromnet manager
55 :param underlay: fixture provides underlay manager
Artem Panchenko0594cd72017-06-12 13:25:26 +030056 :param common_services_deployed: fixture provides CommonServicesManager
57 :param openstack_actions: fixture provides OpenstackManager instance
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020058 :rtype: OpenstackManager
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030059
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020060 If config.openstack.openstack_installed is not set, this fixture assumes
61 that the openstack services were not installed, and do the following:
62 - install openstack services
63 - make snapshot with name 'openstack_deployed'
64 - return OpenstackManager instance
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030065
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020066 If config.openstack.openstack_installed was set, this fixture assumes that
67 the openstack services were already installed, and do the following:
68 - return OpenstackManager instance
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030069
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020070 If you want to revert 'openstack_deployed' snapshot, please use mark:
71 @pytest.mark.revert_snapshot("openstack_deployed")
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030072 """
Artem Panchenko0594cd72017-06-12 13:25:26 +030073 # Deploy Openstack cluster
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030074 if not config.openstack.openstack_installed:
75 steps_path = config.openstack_deploy.openstack_steps_path
Dennis Dmitriev7f1ee042017-05-26 18:38:54 +030076 commands = underlay.read_template(steps_path)
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030077 openstack_actions.install(commands)
78 hardware.create_snapshot(ext.SNAPSHOT.openstack_deployed)
79
80 else:
81 # 1. hardware environment created and powered on
82 # 2. config.underlay.ssh contains SSH access to provisioned nodes
83 # (can be passed from external config with TESTS_CONFIGS variable)
84 # 3. config.tcp.* options contain access credentials to the already
85 # installed TCP API endpoint
86 pass
87
88 return openstack_actions