blob: f69c2478d9f44cb07cf635f89d9d4ac071df50a2 [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):
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030031 """Fixture that provides various actions for K8S
32
33 :param config: fixture provides oslo.config
34 :param underlay: fixture provides underlay manager
35 :rtype: K8SManager
36
37 For use in tests or fixtures to deploy a custom K8S
38 """
Dmitry Tyzhnenkobc0f8262017-04-28 15:39:26 +030039 return openstack_manager.OpenstackManager(config, underlay, salt_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030040
41
Dennis Dmitriev535869c2016-11-16 22:38:06 +020042@pytest.mark.revert_snapshot(ext.SNAPSHOT.openstack_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030043@pytest.fixture(scope='function')
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020044def openstack_deployed(revert_snapshot, request, config,
45 hardware, underlay, common_services_deployed,
46 openstack_actions):
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020047 """Fixture to get or install OpenStack services on environment
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030048
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020049 :param revert_snapshot: fixture that reverts snapshot that is specified
50 in test with @pytest.mark.revert_snapshot(<name>)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030051 :param request: fixture provides pytest data
52 :param config: fixture provides oslo.config
53 :param hardware: fixture provides enviromnet manager
54 :param underlay: fixture provides underlay manager
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020055 :param tcp_actions: fixture provides OpenstackManager instance
56 :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
61 - 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 Dmitriev2cbf2352016-11-11 15:34:21 +020068 If you want to revert 'openstack_deployed' snapshot, please use mark:
69 @pytest.mark.revert_snapshot("openstack_deployed")
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030070 """
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020071 # Create Salt cluster
Dennis Dmitriev2cbf2352016-11-11 15:34:21 +020072 if not config.openstack.openstack_installed:
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020073 steps_path = config.openstack_deploy.openstack_steps_path
Dennis Dmitriev99b26fe2017-04-26 12:34:44 +030074 commands = underlay.read_template(steps_path)
dis2b2d8632016-12-08 17:56:57 +020075 openstack_actions.install(commands)
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020076 hardware.create_snapshot(ext.SNAPSHOT.openstack_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030077
78 else:
79 # 1. hardware environment created and powered on
80 # 2. config.underlay.ssh contains SSH access to provisioned nodes
81 # (can be passed from external config with TESTS_CONFIGS variable)
82 # 3. config.tcp.* options contain access credentials to the already
83 # installed TCP API endpoint
84 pass
85
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020086 return openstack_actions
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030087
88
89@pytest.mark.revert_snapshot(ext.SNAPSHOT.openstack_deployed)
90@pytest.fixture(scope='function')
91def deploy_openstack(revert_snapshot, request, config,
92 hardware, underlay, common_services_deployed,
93 openstack_actions):
94 """Fixture to get or install OpenStack services on environment
95
96 :param revert_snapshot: fixture that reverts snapshot that is specified
97 in test with @pytest.mark.revert_snapshot(<name>)
98 :param request: fixture provides pytest data
99 :param config: fixture provides oslo.config
100 :param hardware: fixture provides enviromnet manager
101 :param underlay: fixture provides underlay manager
102 :param tcp_actions: fixture provides OpenstackManager instance
103 :rtype: OpenstackManager
104
105 If config.openstack.openstack_installed is not set, this fixture assumes
106 that the openstack services were not installed, and do the following:
107 - install openstack services
108 - make snapshot with name 'openstack_deployed'
109 - return OpenstackManager instance
110
111 If config.openstack.openstack_installed was set, this fixture assumes that
112 the openstack services were already installed, and do the following:
113 - return OpenstackManager instance
114
115 If you want to revert 'openstack_deployed' snapshot, please use mark:
116 @pytest.mark.revert_snapshot("openstack_deployed")
117 """
118 # Create Salt cluster
119 if not config.openstack.openstack_installed:
120 steps_path = config.openstack_deploy.openstack_steps_path
Dennis Dmitriev7f1ee042017-05-26 18:38:54 +0300121 commands = underlay.read_template(steps_path)
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +0300122 openstack_actions.install(commands)
123 hardware.create_snapshot(ext.SNAPSHOT.openstack_deployed)
124
125 else:
126 # 1. hardware environment created and powered on
127 # 2. config.underlay.ssh contains SSH access to provisioned nodes
128 # (can be passed from external config with TESTS_CONFIGS variable)
129 # 3. config.tcp.* options contain access credentials to the already
130 # installed TCP API endpoint
131 pass
132
133 return openstack_actions