blob: a8dbe722eff8eb4c0df859b60e2900622dd5c184 [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
Victor Ryzhenkin14354ac2017-09-27 17:42:30 +040029 def test_k8s_externaldns_coredns(self, show_step, config, k8s_deployed):
30 """Test externaldns integration with coredns
31
32 Scenario:
33 1. Install k8s with externaldns addon enabled(including etcd, coredns)
34 2. Start simple service
35 3. Expose deployment
36 4. Annotate service with domain name
37 5. Try to get service using nslookup
38 """
39
40 if not (config.k8s_deploy.kubernetes_externaldns_enabled and
41 config.k8s_deploy.kubernetes_coredns_enabled):
42 pytest.skip("Test requires Externaldns and coredns addons enabled")
43
44 show_step(1)
45 k8sclient = k8s_deployed.api
46 assert k8sclient.nodes.list() is not None, "Can not get nodes list"
47
48 show_step(2)
49 name = 'test-nginx'
50 k8s_deployed.kubectl_run(name, 'nginx', '80')
51
52 show_step(3)
53 k8s_deployed.kubectl_expose('deployment', name, '80', 'ClusterIP')
54
Victor Ryzhenkin66d39372017-09-28 19:25:48 +040055 hostname = "test.{0}.local.".format(settings.LAB_CONFIG_NAME)
Victor Ryzhenkin14354ac2017-09-27 17:42:30 +040056 annotation = "\"external-dns.alpha.kubernetes.io/" \
57 "hostname={0}\"".format(hostname)
58 show_step(4)
59 k8s_deployed.kubectl_annotate('service', name, annotation)
60
61 show_step(5)
62 dns_host = k8s_deployed.get_svc_ip('coredns')
63 k8s_deployed.nslookup(hostname, dns_host)
Victor Ryzhenkin87a31422018-03-16 22:25:27 +040064
65 @pytest.mark.grab_versions
66 @pytest.mark.cncf_publisher(name=['e2e.log', 'junit_01.xml', 'version.txt',
67 'cncf_results.tar.gz'])
68 @pytest.mark.fail_snapshot
69 def test_k8s_cncf_certification(self, show_step, config, k8s_deployed,
70 cncf_log_helper):
71 """Run cncf e2e suite and provide files needed for pull request
72 to the CNCF repo
73
74 Scenario:
75 1. Run cncf from https://github.com/cncf/k8s-conformance
76 """
77
78 show_step(1)
79 k8s_deployed.start_k8s_cncf_verification()
Vladimir Jigulin62bcf462018-05-28 18:17:01 +040080
81 @pytest.mark.grap_versions
82 @pytest.mark.fail_snapshot
83 def test_k8s_chain_update(self, show_step, underlay, config, k8s_deployed,
84 k8s_chain_update_log_helper):
85 """Test for chain-upgrading k8s hypercube pool and checking it
86
87 Scenario:
88 1. Prepare salt on hosts
89 2. Setup controller nodes
90 3. Setup compute nodes
91 4. Setup Kubernetes cluster
92 5. Run and expose sample test service
93 6. Run conformance to check consistency
94 7. For every version in update chain:
95 Update cluster to new version, check test sample service
96 availability, run conformance
97 """
98
99 deployment_name = 'test-dep-chain-upgrade'
100
101 show_step(5)
102 k8s_deployed.kubectl_run(
103 deployment_name, 'gcr.io/google-samples/node-hello:1.0', '8080')
104 k8s_deployed.kubectl_expose(
105 'deployment', deployment_name, '8080', 'ClusterIP')
106 sample_service_ip = k8s_deployed.get_svc_ip(deployment_name, 'default')
107 k8s_deployed.wait_deploy_ready(deployment_name)
108
109 def check_is_test_service_available():
110 assert "Hello Kubernetes!" in k8s_deployed.curl(
111 "http://{}:{}".format(sample_service_ip, 8080))
112
113 check_is_test_service_available()
114
115 show_step(6)
116 k8s_deployed.run_conformance(log_out="k8s_conformance.log")
117
118 show_step(7)
119 chain_versions = config.k8s.k8s_update_chain.split(" ")
120 for version in chain_versions:
121 LOG.info("Chain update to '{}' version".format(version))
122 k8s_deployed.update_k8s_images(version)
123
124 LOG.info("Checking test service availability")
125 check_is_test_service_available()
126
127 LOG.info("Running conformance on {} version".format(version))
128 log_name = "k8s_conformance_{}.log".format(version)
129 k8s_deployed.run_conformance(log_out=log_name, raise_on_err=False)