[k8s] Adjust externaldns test functions
- Use ctl hostname instead of k8s.kube_host due kube_host
is an ip address of keepalived k8s api.
- Discover ctl with specific role 'k8s_controller'
- Fix nit with awk field
- Fix nit with format fields
User-Story:https://mirantis.jira.com/browse/PROD-12826
Change-Id: I52d89b4d3994338a800eed4f6b5555cad6bdedc8
diff --git a/tcp_tests/helpers/ext.py b/tcp_tests/helpers/ext.py
index f7b8005..99baaff 100644
--- a/tcp_tests/helpers/ext.py
+++ b/tcp_tests/helpers/ext.py
@@ -26,6 +26,7 @@
'salt_master',
'salt_minion',
'k8s_virtlet',
+ 'k8s_controller',
'decapod_mon',
'decapod_osd',
'decapod_all',
diff --git a/tcp_tests/managers/k8smanager.py b/tcp_tests/managers/k8smanager.py
index d84fd73..87e3eaf 100644
--- a/tcp_tests/managers/k8smanager.py
+++ b/tcp_tests/managers/k8smanager.py
@@ -17,8 +17,11 @@
import yaml
from devops.helpers import helpers
+from devops.error import DevopsCalledProcessError
from tcp_tests import logger
+from tcp_tests.helpers import ext
+from tcp_tests.helpers.utils import retry
from tcp_tests.managers.execute_commands import ExecuteCommandsMixin
from tcp_tests.managers.k8s import cluster
from k8sclient.client.rest import ApiException
@@ -80,6 +83,12 @@
default_namespace='default')
return self._api_client
+ @property
+ def ctl_host(self):
+ nodes = [node for node in self.__config.underlay.ssh if
+ ext.UNDERLAY_NODE_ROLES.k8s_controller in node['roles']]
+ return nodes[0]['node_name']
+
def get_pod_phase(self, pod_name, namespace=None):
return self.api.pods.get(
name=pod_name, namespace=namespace).phase
@@ -296,7 +305,7 @@
params = ' '.join(["-f {}".format(p) for p in path])
cmd = 'kubectl create {params}'.format(params=params)
with self.__underlay.remote(
- host=self.__config.k8s.kube_host) as remote:
+ node_name=self.ctl_host) as remote:
LOG.info("Running command '{cmd}' on node {node}".format(
cmd=cmd,
node=remote.hostname)
@@ -315,7 +324,7 @@
def get_running_pods_by_ssh(self, pod_name, namespace=None):
with self.__underlay.remote(
- host=self.__config.k8s.kube_host) as remote:
+ node_name=self.ctl_host) as remote:
result = remote.check_call("kubectl get pods --namespace {} |"
" grep {} | awk '{{print $1 \" \""
" $3}}'".format(namespace,
@@ -331,7 +340,7 @@
def run_conformance(self, timeout=60 * 60):
with self.__underlay.remote(
- host=self.__config.k8s.kube_host) as remote:
+ node_name=self.ctl_host) as remote:
result = remote.check_call(
"docker run --rm --net=host -e API_SERVER="
"'http://127.0.0.1:8080' {}".format(
@@ -347,7 +356,7 @@
def kubectl_run(self, name, image, port):
with self.__underlay.remote(
- host=self.__config.k8s.kube_host) as remote:
+ node_name=self.ctl_host) as remote:
result = remote.check_call(
"kubectl run {0} --image={1} --port={2}".format(
name, image, port
@@ -357,7 +366,7 @@
def kubectl_expose(self, resource, name, port, type):
with self.__underlay.remote(
- host=self.__config.k8s.kube_host) as remote:
+ node_name=self.ctl_host) as remote:
result = remote.check_call(
"kubectl expose {0} {1} --port={2} --type={3}".format(
resource, name, port, type
@@ -365,27 +374,28 @@
)
return result
- def kubectl_annotate(self, resource, name, annotaion):
+ def kubectl_annotate(self, resource, name, annotation):
with self.__underlay.remote(
- host=self.__config.k8s.kube_host) as remote:
+ node_name=self.ctl_host) as remote:
result = remote.check_call(
- "kubectl annotate {0} {1} {3}".format(
- resource, name, annotaion
+ "kubectl annotate {0} {1} {2}".format(
+ resource, name, annotation
)
)
return result
- def get_svc_ip(self, name):
+ def get_svc_ip(self, name, namespace='kube-system'):
with self.__underlay.remote(
- host=self.__config.k8s.kube_host) as remote:
+ node_name=self.ctl_host) as remote:
result = remote.check_call(
- "kubectl get svc --all-namespaces | grep {0} | "
- "awk '{{print $2}}'".format(name)
+ "kubectl get svc {0} -n {1} | "
+ "awk '{{print $2}}' | tail -1".format(name, namespace)
)
return result['stdout'][0].strip()
+ @retry(300, exception=DevopsCalledProcessError)
def nslookup(self, host, src):
with self.__underlay.remote(
- host=self.__config.k8s.kube_host) as remote:
+ node_name=self.ctl_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 cc50762..8a04c85 100644
--- a/tcp_tests/settings_oslo.py
+++ b/tcp_tests/settings_oslo.py
@@ -94,7 +94,8 @@
help="Node roles managed by underlay in the environment",
default=[ext.UNDERLAY_NODE_ROLES.salt_master,
ext.UNDERLAY_NODE_ROLES.salt_minion,
- ext.UNDERLAY_NODE_ROLES.k8s_virtlet, ]),
+ ext.UNDERLAY_NODE_ROLES.k8s_virtlet,
+ ext.UNDERLAY_NODE_ROLES.k8s_controller]),
ct.Cfg('bootstrap_timeout', ct.Integer(),
help="Timeout of waiting SSH for nodes with specified roles",
default=480),
diff --git a/tcp_tests/templates/virtual-mcp11-k8s-calico-minimal/underlay.yaml b/tcp_tests/templates/virtual-mcp11-k8s-calico-minimal/underlay.yaml
index f494419..805a05f 100644
--- a/tcp_tests/templates/virtual-mcp11-k8s-calico-minimal/underlay.yaml
+++ b/tcp_tests/templates/virtual-mcp11-k8s-calico-minimal/underlay.yaml
@@ -128,7 +128,7 @@
- private
- name: {{ HOSTNAME_CTL01 }}
- role: salt_minion
+ role: k8s_controller
params:
vcpu: !os_env SLAVE_NODE_CPU, 2
memory: !os_env SLAVE_NODE_MEMORY, 4096
diff --git a/tcp_tests/templates/virtual-mcp11-k8s-calico/underlay.yaml b/tcp_tests/templates/virtual-mcp11-k8s-calico/underlay.yaml
index b75127a..658660c 100644
--- a/tcp_tests/templates/virtual-mcp11-k8s-calico/underlay.yaml
+++ b/tcp_tests/templates/virtual-mcp11-k8s-calico/underlay.yaml
@@ -142,7 +142,7 @@
- private
- name: {{ HOSTNAME_CTL01 }}
- role: salt_minion
+ role: k8s_controller
params:
vcpu: !os_env SLAVE_NODE_CPU, 2
memory: !os_env SLAVE_NODE_MEMORY, 2048
diff --git a/tcp_tests/templates/virtual-mcp11-k8s-contrail/underlay.yaml b/tcp_tests/templates/virtual-mcp11-k8s-contrail/underlay.yaml
index 240b50b..786fea0 100644
--- a/tcp_tests/templates/virtual-mcp11-k8s-contrail/underlay.yaml
+++ b/tcp_tests/templates/virtual-mcp11-k8s-contrail/underlay.yaml
@@ -199,7 +199,7 @@
- admin
- name: {{ HOSTNAME_CTL01 }}
- role: salt_minion
+ role: k8s_controller
params:
vcpu: !os_env SLAVE_NODE_CPU, 2
memory: !os_env SLAVE_NODE_MEMORY, 2048
diff --git a/tcp_tests/tests/system/test_k8s_actions.py b/tcp_tests/tests/system/test_k8s_actions.py
index 77ed04a..ae3fa89 100644
--- a/tcp_tests/tests/system/test_k8s_actions.py
+++ b/tcp_tests/tests/system/test_k8s_actions.py
@@ -50,7 +50,7 @@
show_step(3)
k8s_deployed.kubectl_expose('deployment', name, '80', 'ClusterIP')
- hostname = "test.{0}.local".format(settings.LAB_CONFIG_NAME)
+ hostname = "test.{0}.local.".format(settings.LAB_CONFIG_NAME)
annotation = "\"external-dns.alpha.kubernetes.io/" \
"hostname={0}\"".format(hostname)
show_step(4)