Victor Ryzhenkin | 14354ac | 2017-09-27 17:42:30 +0400 | [diff] [blame] | 1 | # 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 | |
| 15 | import pytest |
| 16 | |
| 17 | from tcp_tests import logger |
| 18 | from tcp_tests import settings |
| 19 | |
| 20 | LOG = logger.logger |
| 21 | |
| 22 | |
| 23 | class TestMCPK8sActions(object): |
| 24 | """Test class for different k8s actions""" |
| 25 | |
Tatyana Leontovich | c411ec3 | 2017-10-09 14:48:00 +0300 | [diff] [blame^] | 26 | @pytest.mark.grab_versions |
Victor Ryzhenkin | 14354ac | 2017-09-27 17:42:30 +0400 | [diff] [blame] | 27 | @pytest.mark.fail_snapshot |
| 28 | def test_k8s_externaldns_coredns(self, show_step, config, k8s_deployed): |
| 29 | """Test externaldns integration with coredns |
| 30 | |
| 31 | Scenario: |
| 32 | 1. Install k8s with externaldns addon enabled(including etcd, coredns) |
| 33 | 2. Start simple service |
| 34 | 3. Expose deployment |
| 35 | 4. Annotate service with domain name |
| 36 | 5. Try to get service using nslookup |
| 37 | """ |
| 38 | |
| 39 | if not (config.k8s_deploy.kubernetes_externaldns_enabled and |
| 40 | config.k8s_deploy.kubernetes_coredns_enabled): |
| 41 | pytest.skip("Test requires Externaldns and coredns addons enabled") |
| 42 | |
| 43 | show_step(1) |
| 44 | k8sclient = k8s_deployed.api |
| 45 | assert k8sclient.nodes.list() is not None, "Can not get nodes list" |
| 46 | |
| 47 | show_step(2) |
| 48 | name = 'test-nginx' |
| 49 | k8s_deployed.kubectl_run(name, 'nginx', '80') |
| 50 | |
| 51 | show_step(3) |
| 52 | k8s_deployed.kubectl_expose('deployment', name, '80', 'ClusterIP') |
| 53 | |
Victor Ryzhenkin | 66d3937 | 2017-09-28 19:25:48 +0400 | [diff] [blame] | 54 | hostname = "test.{0}.local.".format(settings.LAB_CONFIG_NAME) |
Victor Ryzhenkin | 14354ac | 2017-09-27 17:42:30 +0400 | [diff] [blame] | 55 | annotation = "\"external-dns.alpha.kubernetes.io/" \ |
| 56 | "hostname={0}\"".format(hostname) |
| 57 | show_step(4) |
| 58 | k8s_deployed.kubectl_annotate('service', name, annotation) |
| 59 | |
| 60 | show_step(5) |
| 61 | dns_host = k8s_deployed.get_svc_ip('coredns') |
| 62 | k8s_deployed.nslookup(hostname, dns_host) |