blob: f70a201dbfa9cac36424cb7e7ef2f38b0a045a4d [file] [log] [blame]
vrovachevbc2f5ce2017-05-22 19:37:24 +04001# Copyright 2017 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
16
17import pytest
18import yaml
19
20from tcp_tests import logger
21from tcp_tests.helpers import ext
22from tcp_tests import settings
23from tcp_tests.managers import virtlet_manager
24
25LOG = logger.logger
26
27
28@pytest.fixture(scope='function')
29def virtlet_actions(config, underlay, salt_actions):
30 """Fixture that provides various actions for Virtlet project
31
32 :param config: fixture provides oslo.config
33 :param underlay: fixture provides underlay manager
34 :rtype: VirtletManager
35 """
36 return virtlet_manager.VirtletManager(config, underlay, salt_actions)
37
38
39@pytest.mark.revert_snapshot(ext.SNAPSHOT.virtlet_deployed)
40@pytest.fixture(scope='function')
41def virtlet_deployed(revert_snapshot, request, config,
42 hardware, underlay, common_services_deployed,
43 virtlet_actions):
44 """Fixture to get or install Virtlet project on the environment
45
46 :param revert_snapshot: fixture that reverts snapshot that is specified
47 in test with @pytest.mark.revert_snapshot(<name>)
48 :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
52 :param virtlet_actions: fixture provides VirtletManager instance
53 :rtype: VirtletManager
54
55 If config.virtlet.virtlet_installed is not set, this
56 fixture assumes that the Virtlet project was not installed,
57 and do the following:
58 - install Virtlet project
59 - make snapshot with name 'virtlet_deployed'
60 - return VirtletManager
61
62 If config.virtlet.virtlet_installed was set, this fixture assumes that
63 the Virtlet project was already installed, and do the following:
64 - return VirtletManager instance
65
66 If you want to revert 'virtlet_deployed' snapshot, please use mark:
67 @pytest.mark.revert_snapshot("virtlet_deployed")
68 """
69 # Create Salt cluster
70 if not config.virtlet.virtlet_installed:
71 steps_path = config.virtlet_deploy.virtlet_steps_path
72 commands = underlay.read_template(steps_path)
73 virtlet_actions.install(commands)
74 hardware.create_snapshot(ext.SNAPSHOT.virtlet_deployed)
75
76 else:
77 # 1. hardware environment created and powered on
78 # 2. config.underlay.ssh contains SSH access to provisioned nodes
79 # (can be passed from external config with TESTS_CONFIGS variable)
80 # 3. config.tcp.* options contain access credentials to the already
81 # installed TCP API endpoint
82 pass
83
84 return virtlet_actions