[k8s] Add base test for externaldns integration
- Add test for externaldns with coredns backend on basic
deployments.
- Add few core functions as remote executions of kubectl.
User-Story: https://mirantis.jira.com/browse/PROD-12826
Change-Id: I9230ddd75905759eb2d0ba8486ba896d2094cebb
diff --git a/tcp_tests/managers/k8smanager.py b/tcp_tests/managers/k8smanager.py
index f02c843..7d9b142 100644
--- a/tcp_tests/managers/k8smanager.py
+++ b/tcp_tests/managers/k8smanager.py
@@ -336,3 +336,48 @@
pillar='linux:network:fqdn')
return [self._K8SManager__underlay.host_by_node_name(node_name=v)
for pillar in k8s_masters_fqdn for k, v in pillar.items()]
+
+ def kubectl_run(self, name, image, port):
+ with self.__underlay.remote(
+ host=self.__config.k8s.kube_host) as remote:
+ result = remote.check_call(
+ "kubectl run {0} --image={1} --port={2}".format(
+ name, image, port
+ )
+ )
+ return result
+
+ def kubectl_expose(self, resource, name, port, type):
+ with self.__underlay.remote(
+ host=self.__config.k8s.kube_host) as remote:
+ result = remote.check_call(
+ "kubectl expose {0} {1} --port={2} --type={3}".format(
+ resource, name, port, type
+ )
+ )
+ return result
+
+ def kubectl_annotate(self, resource, name, annotaion):
+ with self.__underlay.remote(
+ host=self.__config.k8s.kube_host) as remote:
+ result = remote.check_call(
+ "kubectl annotate {0} {1} {3}".format(
+ resource, name, annotaion
+ )
+ )
+ return result
+
+ def get_svc_ip(self, name):
+ with self.__underlay.remote(
+ host=self.__config.k8s.kube_host) as remote:
+ result = remote.check_call(
+ "kubectl get svc --all-namespaces | grep {0} | "
+ "awk '{{print $2}}'".format(name)
+ )
+ return result['stdout'][0].strip()
+
+ def nslookup(self, host, src):
+ with self.__underlay.remote(
+ host=self.__config.k8s.kube_host) as remote:
+ remote.check_call("nslookup {0} {1}".format(host, src))
+
diff --git a/tcp_tests/settings_oslo.py b/tcp_tests/settings_oslo.py
index 741a487..cc50762 100644
--- a/tcp_tests/settings_oslo.py
+++ b/tcp_tests/settings_oslo.py
@@ -278,7 +278,15 @@
ct.Cfg('kubernetes_virtlet_enabled', ct.Boolean(),
help="", default=False),
ct.Cfg('kubernetes_virtlet_image', ct.String(),
- help="", default='mirantis/virtlet:v0.7.0')
+ help="", default='mirantis/virtlet:v0.7.0'),
+ ct.Cfg('kubernetes_externaldns_enabled', ct.Boolean(),
+ help="", default=False),
+ ct.Cfg('kubernetes_externaldns_image', ct.String(),
+ help="", default='mirantis/external-dns:latest'),
+ ct.Cfg('kubernetes_externaldns_provider', ct.String(),
+ help="", default='coredns'),
+ ct.Cfg('kubernetes_coredns_enabled', ct.Boolean(),
+ help="", default=False)
]
k8s_opts = [
diff --git a/tcp_tests/tests/system/test_k8s_actions.py b/tcp_tests/tests/system/test_k8s_actions.py
new file mode 100644
index 0000000..77ed04a
--- /dev/null
+++ b/tcp_tests/tests/system/test_k8s_actions.py
@@ -0,0 +1,61 @@
+# Copyright 2017 Mirantis, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import pytest
+
+from tcp_tests import logger
+from tcp_tests import settings
+
+LOG = logger.logger
+
+
+class TestMCPK8sActions(object):
+ """Test class for different k8s actions"""
+
+ @pytest.mark.fail_snapshot
+ def test_k8s_externaldns_coredns(self, show_step, config, k8s_deployed):
+ """Test externaldns integration with coredns
+
+ Scenario:
+ 1. Install k8s with externaldns addon enabled(including etcd, coredns)
+ 2. Start simple service
+ 3. Expose deployment
+ 4. Annotate service with domain name
+ 5. Try to get service using nslookup
+ """
+
+ if not (config.k8s_deploy.kubernetes_externaldns_enabled and
+ config.k8s_deploy.kubernetes_coredns_enabled):
+ pytest.skip("Test requires Externaldns and coredns addons enabled")
+
+ show_step(1)
+ k8sclient = k8s_deployed.api
+ assert k8sclient.nodes.list() is not None, "Can not get nodes list"
+
+ show_step(2)
+ name = 'test-nginx'
+ k8s_deployed.kubectl_run(name, 'nginx', '80')
+
+ show_step(3)
+ k8s_deployed.kubectl_expose('deployment', name, '80', 'ClusterIP')
+
+ hostname = "test.{0}.local".format(settings.LAB_CONFIG_NAME)
+ annotation = "\"external-dns.alpha.kubernetes.io/" \
+ "hostname={0}\"".format(hostname)
+ show_step(4)
+ k8s_deployed.kubectl_annotate('service', name, annotation)
+
+ show_step(5)
+ dns_host = k8s_deployed.get_svc_ip('coredns')
+ k8s_deployed.nslookup(hostname, dns_host)