blob: 48e9125bfaf8a20f7c97289d5e2c2b2d988476fa [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
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030024
25LOG = logger.logger
26
27
28@pytest.fixture(scope='function')
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020029def openstack_actions(config, underlay):
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030030 """Fixture that provides various actions for K8S
31
32 :param config: fixture provides oslo.config
33 :param underlay: fixture provides underlay manager
34 :rtype: K8SManager
35
36 For use in tests or fixtures to deploy a custom K8S
37 """
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020038 return openstack_manager.OpenstackManager(config, underlay)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030039
40
41@pytest.fixture(scope='function')
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020042def openstack_deployed(revert_snapshot, request, config,
43 hardware, underlay, common_services_deployed,
44 openstack_actions):
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030045 """Fixture to get or install TCP on environment
46
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
51 :param tcp_actions: fixture provides TCPManager instance
52 :rtype: TCPManager
53
54 If config.tcp.tcp_host is not set, this fixture assumes that
55 the tcp cluster was not deployed, and do the following:
56 - deploy tcp cluster
57 - make snapshot with name 'tcp_deployed'
58 - return TCPCluster instance
59
60 If config.tcp.tcp_host was set, this fixture assumes that the tcp
61 cluster was already deployed, and do the following:
62 - return TCPCluster instance
63
64 If you want to revert 'tcp_deployed' snapshot, please use mark:
65 @pytest.mark.revert_snapshot("tcp_deployed")
66 """
67 # If no snapshot was reverted, then try to revert the snapshot
68 # that belongs to the fixture.
69 # Note: keep fixtures in strict dependences from each other!
70 if not revert_snapshot:
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020071 if hardware.has_snapshot(ext.SNAPSHOT.openstack_deployed) and \
72 hardware.has_snapshot_config(ext.SNAPSHOT.openstack_deployed):
73 hardware.revert_snapshot(ext.SNAPSHOT.openstack_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030074
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020075 # Create Salt cluster
76 if not config.openstack.installed:
77 steps_path = config.openstack_deploy.openstack_steps_path
78 with underlay.yaml_editor(steps_path) as commands:
79 openstack_actions.install(commands.content)
80 hardware.create_snapshot(ext.SNAPSHOT.openstack_deployed)
Dennis Dmitriev8cb2f412016-10-18 14:53:58 +030081
82 else:
83 # 1. hardware environment created and powered on
84 # 2. config.underlay.ssh contains SSH access to provisioned nodes
85 # (can be passed from external config with TESTS_CONFIGS variable)
86 # 3. config.tcp.* options contain access credentials to the already
87 # installed TCP API endpoint
88 pass
89
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020090 return openstack_actions