github.com/SUSE/skuba@v1.4.17/ci/infra/testrunner/tests/conftest.py (about) 1 import pytest 2 3 import platforms 4 from kubectl import Kubectl 5 from skuba import Skuba 6 from utils import BaseConfig 7 from tests.utils import (check_pods_ready, wait) 8 9 10 def pytest_addoption(parser): 11 """ 12 Adds the option pytest option list. 13 This options can be used to initilize fixtures. 14 """ 15 parser.addoption("--vars", action="store", help="vars yaml") 16 parser.addoption("--platform", action="store", help="target platform") 17 parser.addoption("--skip-setup", 18 choices=['provisioned', 'bootstrapped', 'deployed'], 19 help="Skip the given setup step.\n" 20 "'provisioned' For when you have already provisioned the nodes.\n" 21 "'bootstrapped' For when you have already bootstrapped the cluster.\n" 22 "'deployed' For when you already have a fully deployed cluster.") 23 24 25 @pytest.fixture 26 def provision(request, platform): 27 if request.config.getoption("skip_setup") in ['provisioned', 'bootstrapped', 'deployed']: 28 return 29 30 def cleanup(): 31 platform.gather_logs() 32 platform.cleanup() 33 34 request.addfinalizer(cleanup) 35 36 platform.provision() 37 38 39 @pytest.fixture 40 def bootstrap(request, provision, skuba): 41 42 if request.config.getoption("skip_setup") in ['bootstrapped', 'deployed']: 43 return 44 45 skuba.cluster_init() 46 skuba.node_bootstrap() 47 48 49 @pytest.fixture 50 def deployment(request, bootstrap, skuba, kubectl): 51 if request.config.getoption("skip_setup") == 'deployed': 52 return 53 54 skuba.join_nodes() 55 wait(check_pods_ready, 56 kubectl, 57 namespace="kube-system", 58 wait_delay=60, 59 wait_timeout=10, 60 wait_backoff=60, 61 wait_elapsed=60*30, 62 wait_allow=(AssertionError)) 63 64 65 @pytest.fixture 66 def conf(request): 67 """Builds a conf object from a yaml file""" 68 path = request.config.getoption("vars") 69 return BaseConfig(path) 70 71 72 @pytest.fixture 73 def target(request): 74 """Returns the target platform""" 75 platform = request.config.getoption("platform") 76 return platform 77 78 79 @pytest.fixture 80 def skuba(conf, target): 81 return Skuba(conf, target) 82 83 84 @pytest.fixture 85 def kubectl(conf): 86 return Kubectl(conf) 87 88 89 @pytest.fixture 90 def platform(conf, target): 91 platform = platforms.get_platform(conf, target) 92 return platform 93 94 95 @pytest.fixture 96 def setup(request, platform, skuba): 97 def cleanup(): 98 # if platform was not allocated, gather_logs may fail. Ignore. 99 try: 100 platform.gather_logs() 101 finally: 102 platform.cleanup() 103 104 request.addfinalizer(cleanup) 105 106 platform.provision(num_master=3, num_worker=3)