blob: ab57efcf8de09bc815f409a3750d284fab20c56b [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
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
100 deployment_name = 'test-dep-chain-upgrade'
101
102 show_step(5)
103 k8s_deployed.kubectl_run(
104 deployment_name, 'gcr.io/google-samples/node-hello:1.0', '8080')
105 k8s_deployed.kubectl_expose(
106 'deployment', deployment_name, '8080', 'ClusterIP')
107 sample_service_ip = k8s_deployed.get_svc_ip(deployment_name, 'default')
108 k8s_deployed.wait_deploy_ready(deployment_name)
109
Vladimir Jigulin96bdcb02018-06-08 08:28:26 +0400110 # workaround for PROD-20720
111 time.sleep(30)
112
Vladimir Jigulin62bcf462018-05-28 18:17:01 +0400113 def check_is_test_service_available():
114 assert "Hello Kubernetes!" in k8s_deployed.curl(
115 "http://{}:{}".format(sample_service_ip, 8080))
116
117 check_is_test_service_available()
118
119 show_step(6)
120 k8s_deployed.run_conformance(log_out="k8s_conformance.log")
121
122 show_step(7)
123 chain_versions = config.k8s.k8s_update_chain.split(" ")
124 for version in chain_versions:
125 LOG.info("Chain update to '{}' version".format(version))
126 k8s_deployed.update_k8s_images(version)
127
128 LOG.info("Checking test service availability")
129 check_is_test_service_available()
130
131 LOG.info("Running conformance on {} version".format(version))
132 log_name = "k8s_conformance_{}.log".format(version)
133 k8s_deployed.run_conformance(log_out=log_name, raise_on_err=False)