blob: 301800ec27034abbabcdd260607100e0c2f25645 [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
vrovachevbc2f5ce2017-05-22 19:37:24 +040015import pytest
vrovachevbc2f5ce2017-05-22 19:37:24 +040016
17from tcp_tests import logger
18from tcp_tests.helpers import ext
vrovachevbc2f5ce2017-05-22 19:37:24 +040019from tcp_tests.managers import virtlet_manager
20
21LOG = logger.logger
22
23
24@pytest.fixture(scope='function')
Artem Panchenko0594cd72017-06-12 13:25:26 +030025def virtlet_actions(config, underlay):
vrovachevbc2f5ce2017-05-22 19:37:24 +040026 """Fixture that provides various actions for Virtlet project
27
28 :param config: fixture provides oslo.config
29 :param underlay: fixture provides underlay manager
30 :rtype: VirtletManager
31 """
Artem Panchenko0594cd72017-06-12 13:25:26 +030032 return virtlet_manager.VirtletManager(config, underlay)
vrovachevbc2f5ce2017-05-22 19:37:24 +040033
34
35@pytest.mark.revert_snapshot(ext.SNAPSHOT.virtlet_deployed)
36@pytest.fixture(scope='function')
Artem Panchenko0594cd72017-06-12 13:25:26 +030037def virtlet_deployed(revert_snapshot, config, hardware, underlay,
38 k8s_deployed, virtlet_actions):
vrovachevbc2f5ce2017-05-22 19:37:24 +040039 """Fixture to get or install Virtlet project on the environment
40
41 :param revert_snapshot: fixture that reverts snapshot that is specified
42 in test with @pytest.mark.revert_snapshot(<name>)
vrovachevbc2f5ce2017-05-22 19:37:24 +040043 :param config: fixture provides oslo.config
44 :param hardware: fixture provides enviromnet manager
45 :param underlay: fixture provides underlay manager
Artem Panchenko0594cd72017-06-12 13:25:26 +030046 :param k8s_deployed: fixture provides K8SManager instance
vrovachevbc2f5ce2017-05-22 19:37:24 +040047 :param virtlet_actions: fixture provides VirtletManager instance
48 :rtype: VirtletManager
49
50 If config.virtlet.virtlet_installed is not set, this
51 fixture assumes that the Virtlet project was not installed,
52 and do the following:
53 - install Virtlet project
54 - make snapshot with name 'virtlet_deployed'
55 - return VirtletManager
56
57 If config.virtlet.virtlet_installed was set, this fixture assumes that
58 the Virtlet project was already installed, and do the following:
59 - return VirtletManager instance
60
61 If you want to revert 'virtlet_deployed' snapshot, please use mark:
62 @pytest.mark.revert_snapshot("virtlet_deployed")
63 """
Artem Panchenko0594cd72017-06-12 13:25:26 +030064 # Deploy Virtlet for Kubernetes
vrovachevbc2f5ce2017-05-22 19:37:24 +040065 if not config.virtlet.virtlet_installed:
66 steps_path = config.virtlet_deploy.virtlet_steps_path
67 commands = underlay.read_template(steps_path)
68 virtlet_actions.install(commands)
69 hardware.create_snapshot(ext.SNAPSHOT.virtlet_deployed)
70
71 else:
72 # 1. hardware environment created and powered on
73 # 2. config.underlay.ssh contains SSH access to provisioned nodes
74 # (can be passed from external config with TESTS_CONFIGS variable)
75 # 3. config.tcp.* options contain access credentials to the already
76 # installed TCP API endpoint
77 pass
78
79 return virtlet_actions