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