blob: 1d28a5fe640bb6cfb693faaafd3e4dd9ac72dd49 [file] [log] [blame]
Victor Ryzhenkin14354ac2017-09-27 17:42:30 +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 pytest
16
17from tcp_tests import logger
18from tcp_tests import settings
19
20LOG = logger.logger
21
22
23class TestMCPK8sActions(object):
24 """Test class for different k8s actions"""
25
Tatyana Leontovichc411ec32017-10-09 14:48:00 +030026 @pytest.mark.grab_versions
Victor Ryzhenkin14354ac2017-09-27 17:42:30 +040027 @pytest.mark.fail_snapshot
Tatyana Leontovich071ce6a2017-10-24 18:08:10 +030028 @pytest.mark.cz8116
Dennis Dmitriev0f624a82018-06-11 12:57:13 +030029 @pytest.mark.k8s_calico
Victor Ryzhenkin14354ac2017-09-27 17:42:30 +040030 def test_k8s_externaldns_coredns(self, show_step, config, k8s_deployed):
31 """Test externaldns integration with coredns
32
33 Scenario:
34 1. Install k8s with externaldns addon enabled(including etcd, coredns)
35 2. Start simple service
36 3. Expose deployment
37 4. Annotate service with domain name
38 5. Try to get service using nslookup
39 """
40
41 if not (config.k8s_deploy.kubernetes_externaldns_enabled and
42 config.k8s_deploy.kubernetes_coredns_enabled):
43 pytest.skip("Test requires Externaldns and coredns addons enabled")
44
45 show_step(1)
46 k8sclient = k8s_deployed.api
47 assert k8sclient.nodes.list() is not None, "Can not get nodes list"
48
49 show_step(2)
50 name = 'test-nginx'
51 k8s_deployed.kubectl_run(name, 'nginx', '80')
52
53 show_step(3)
54 k8s_deployed.kubectl_expose('deployment', name, '80', 'ClusterIP')
55
Victor Ryzhenkin66d39372017-09-28 19:25:48 +040056 hostname = "test.{0}.local.".format(settings.LAB_CONFIG_NAME)
Victor Ryzhenkin14354ac2017-09-27 17:42:30 +040057 annotation = "\"external-dns.alpha.kubernetes.io/" \
58 "hostname={0}\"".format(hostname)
59 show_step(4)
60 k8s_deployed.kubectl_annotate('service', name, annotation)
61
62 show_step(5)
63 dns_host = k8s_deployed.get_svc_ip('coredns')
64 k8s_deployed.nslookup(hostname, dns_host)
Victor Ryzhenkin87a31422018-03-16 22:25:27 +040065
66 @pytest.mark.grab_versions
67 @pytest.mark.cncf_publisher(name=['e2e.log', 'junit_01.xml', 'version.txt',
68 'cncf_results.tar.gz'])
69 @pytest.mark.fail_snapshot
70 def test_k8s_cncf_certification(self, show_step, config, k8s_deployed,
71 cncf_log_helper):
72 """Run cncf e2e suite and provide files needed for pull request
73 to the CNCF repo
74
75 Scenario:
76 1. Run cncf from https://github.com/cncf/k8s-conformance
77 """
78
79 show_step(1)
80 k8s_deployed.start_k8s_cncf_verification()
Vladimir Jigulin62bcf462018-05-28 18:17:01 +040081
82 @pytest.mark.grap_versions
83 @pytest.mark.fail_snapshot
84 def test_k8s_chain_update(self, show_step, underlay, config, k8s_deployed,
85 k8s_chain_update_log_helper):
86 """Test for chain-upgrading k8s hypercube pool and checking it
87
88 Scenario:
89 1. Prepare salt on hosts
90 2. Setup controller nodes
91 3. Setup compute nodes
92 4. Setup Kubernetes cluster
93 5. Run and expose sample test service
94 6. Run conformance to check consistency
95 7. For every version in update chain:
96 Update cluster to new version, check test sample service
97 availability, run conformance
98 """
99
Vladimir Jigulin62bcf462018-05-28 18:17:01 +0400100 show_step(5)
Vladimir Jigulina6b018b2018-07-18 15:19:01 +0400101 sample = k8s_deployed.get_sample_deployment('test-dep-chain-upgrade')
102 sample.run()
103 sample.expose()
104 sample.wait_for_ready()
Vladimir Jigulin62bcf462018-05-28 18:17:01 +0400105
Vladimir Jigulina6b018b2018-07-18 15:19:01 +0400106 assert sample.is_service_available()
Vladimir Jigulin62bcf462018-05-28 18:17:01 +0400107
108 show_step(6)
109 k8s_deployed.run_conformance(log_out="k8s_conformance.log")
110
111 show_step(7)
112 chain_versions = config.k8s.k8s_update_chain.split(" ")
113 for version in chain_versions:
114 LOG.info("Chain update to '{}' version".format(version))
115 k8s_deployed.update_k8s_images(version)
116
117 LOG.info("Checking test service availability")
Vladimir Jigulina6b018b2018-07-18 15:19:01 +0400118 assert sample.is_service_available()
Vladimir Jigulin62bcf462018-05-28 18:17:01 +0400119
120 LOG.info("Running conformance on {} version".format(version))
121 log_name = "k8s_conformance_{}.log".format(version)
122 k8s_deployed.run_conformance(log_out=log_name, raise_on_err=False)
Vladimir Jigulina6b018b2018-07-18 15:19:01 +0400123
124 @pytest.mark.grap_versions
125 @pytest.mark.fail_snapshot
126 def test_k8s_metallb(self, show_step, config, k8s_deployed):
127 """Enable metallb in cluster and do basic tests
128
129 Scenario:
130 1. Setup Kubernetes cluster with enabled metallb
131 2. Check that metallb pods created in metallb-system namespace
132 3. Run 5 sample deployments
133 4. Expose deployments with type=LoadBalancer
134 5. Check services availability from outside of cluster
135 6. Run conformance
136 7. Check services availability from outside of cluster
137 """
138 show_step(1)
139 if not config.k8s_deploy.kubernetes_metallb_enabled:
140 pytest.skip("Test requires metallb addon enabled")
141
142 show_step(2)
143 pods = k8s_deployed.api.pods.list(namespace="metallb-system")
144
145 def is_pod_exists_with_prefix(prefix):
146 for pod in pods:
147 if pod.name.startswith(prefix) and pod.phase == 'Running':
148 return True
149 return False
150
151 assert is_pod_exists_with_prefix("controller")
152 assert is_pod_exists_with_prefix("speaker")
153
154 show_step(3)
155 samples = []
156 for i in range(5):
157 name = 'test-dep-metallb-{}'.format(i)
158 sample = k8s_deployed.get_sample_deployment(name)
159 sample.run()
160 samples.append(sample)
161
162 show_step(4)
163 for sample in samples:
164 sample.expose('LoadBalancer')
165 for sample in samples:
166 sample.wait_for_ready()
167
168 show_step(5)
169 for sample in samples:
170 assert sample.is_service_available(external=True)
171
172 show_step(6)
173 k8s_deployed.run_conformance()
174
175 show_step(7)
176 for sample in samples:
177 assert sample.is_service_available(external=True)