blob: 356a51bdc06abe1aa1effb247e513a93097ee290 [file] [log] [blame]
Artem Panchenko0594cd72017-06-12 13:25:26 +03001# 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 pytest
16
17from tcp_tests.helpers import ext
18from tcp_tests import logger
19from tcp_tests.managers import k8smanager
20
21LOG = logger.logger
22
23
24@pytest.fixture(scope='function')
25def k8s_actions(config, underlay, salt_deployed):
26 """Fixture that provides various actions for K8S
27
28 :param config: fixture provides oslo.config
29 :param underlay: fixture provides underlay manager
30 :param salt_deployed: fixture provides salt manager
31 :rtype: K8SManager
32
33 For use in tests or fixtures to deploy a custom K8S
34 """
35 return k8smanager.K8SManager(config, underlay, salt_deployed)
36
37
38@pytest.mark.revert_snapshot(ext.SNAPSHOT.k8s_deployed)
39@pytest.fixture(scope='function')
40def k8s_deployed(revert_snapshot, request, config, hardware, underlay,
Dennis Dmitrievb8115f52017-12-15 13:09:56 +020041 common_services_deployed, salt_deployed, k8s_actions):
Artem Panchenko0594cd72017-06-12 13:25:26 +030042 """Fixture to get or install k8s on environment
43
44 :param revert_snapshot: fixture that reverts snapshot that is specified
45 in test with @pytest.mark.revert_snapshot(<name>)
46 :param request: fixture provides pytest data
47 :param config: fixture provides oslo.config
48 :param hardware: fixture provides enviromnet manager
49 :param underlay: fixture provides underlay manager
50 :param common_services_deployed: fixture provides CommonServicesManager
51 :param k8s_actions: fixture provides K8SManager instance
52 :rtype: K8SManager
53
54 If config.k8s.k8s_installed is not set, this fixture assumes
55 that the k8s services were not installed, and do the following:
56 - install k8s services
57 - make snapshot with name 'k8s_deployed'
58 - return K8SManager instance
59
60 If config.k8s.k8s_installed was set, this fixture assumes that
61 the k8s services were already installed, and do the following:
62 - return K8SManager instance
63
64 If you want to revert 'k8s_deployed' snapshot, please use mark:
65 @pytest.mark.revert_snapshot("k8s_deployed")
66 """
67
68 # Deploy Kubernetes cluster
69 if not config.k8s.k8s_installed:
70 steps_path = config.k8s_deploy.k8s_steps_path
71 commands = underlay.read_template(steps_path)
72 k8s_actions.install(commands)
73 hardware.create_snapshot(ext.SNAPSHOT.k8s_deployed)
Dennis Dmitrievb8115f52017-12-15 13:09:56 +020074 salt_deployed.sync_time()
Artem Panchenko0594cd72017-06-12 13:25:26 +030075
Artem Panchenko501e67e2017-06-14 14:59:18 +030076 # Workaround for keepalived hang issue after env revert from snapshot
77 # see https://mirantis.jira.com/browse/PROD-12038
78 LOG.warning('Restarting keepalived service on controllers...')
79 k8s_actions._salt.local(tgt='ctl*', fun='cmd.run',
80 args='systemctl restart keepalived.service')
81
82 return k8s_actions