Multi worker tests

Checking pod to pod connectivity where the pods are on the same node
and on different nodes

Change-Id: I090b7a4e9257bed5724f35be20e64cf9b8f62259
Depends-On: Id72b248848f685634b47f275a6565a48d4f4b9d7
This commit is contained in:
Itzik Brown 2018-09-16 06:43:35 +00:00
parent 05f95fe3a6
commit bec3f7fe63
4 changed files with 94 additions and 2 deletions

View File

@ -67,4 +67,6 @@ kuryr_k8s_opts = [
"Pods"),
cfg.BoolOpt("test_udp_services", default=False,
help="Whether or not service UDP tests will be running"),
cfg.BoolOpt("multi_worker_setup", default=False, help="Whether or not we "
"have a multi-worker setup"),
]

View File

@ -101,8 +101,8 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest):
@classmethod
def create_pod(cls, name=None, labels=None, image='kuryr/demo',
namespace="default", annotations=None,
wait_for_status=True):
namespace="default", annotations=None, wait_for_status=True,
affinity=None):
if not name:
name = data_utils.rand_name(prefix='kuryr-pod')
pod = cls.k8s_client.V1Pod()
@ -115,6 +115,7 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest):
spec = cls.k8s_client.V1PodSpec(containers=[container])
pod.spec = spec
pod.spec.affinity = affinity
cls.k8s_client.CoreV1Api().create_namespaced_pod(namespace=namespace,
body=pod)
status = ""
@ -217,6 +218,15 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest):
return kuryr_if['versioned_object.data']['id']
@classmethod
def get_pod_node_name(cls, pod_name, namespace="default"):
pod_list = cls.k8s_client.CoreV1Api().list_namespaced_pod(
namespace=namespace, field_selector='metadata.name=%s' % pod_name)
if not pod_list.items:
return None
else:
return pod_list.items[0].spec.node_name
def exec_command_in_pod(self, pod_name, command, namespace="default",
stderr=False, container=None,
req_timeout=10, f_timeout=2):
@ -894,3 +904,21 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest):
name, conf_to_update, section,
namespace, **kwargs)
self.restart_kuryr_controller()
def create_two_pods_affinity_setup(self, labels, affinity=None):
"""Setup of two pods
Create a pod with one label and a second pod
with an affinity parameter. For example, to
make sure the second pod will land on the same
node as the first one.
"""
pod_name_list = []
pod1_name, pod1 = self.create_pod(labels=labels)
pod2_name, pod2 = self.create_pod(affinity=affinity)
self.addCleanup(self.delete_pod, pod1_name)
self.addCleanup(self.delete_pod, pod2_name)
pod_name_list.extend((pod1_name, pod2_name))
return pod_name_list

View File

@ -13,3 +13,7 @@
# limitations under the License.
POD_OUTPUT = 'HELLO! I AM ALIVE!!!'
HA_ENDPOINT_NAME = 'kuryr-controller'
POD_AFFINITY = {'requiredDuringSchedulingIgnoredDuringExecution': [
{'labelSelector': {'matchExpressions': [
{'operator': 'In', 'values': ['demo'], 'key': 'type'}]},
'topologyKey': 'kubernetes.io/hostname'}]}

View File

@ -0,0 +1,58 @@
# Copyright 2018 Red Hat, 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.
from oslo_log import log as logging
from tempest import config
from tempest.lib import decorators
from kuryr_tempest_plugin.tests.scenario import base
from kuryr_tempest_plugin.tests.scenario import consts
LOG = logging.getLogger(__name__)
CONF = config.CONF
class TestCrossPingScenarioMultiWorker(base.BaseKuryrScenarioTest):
@classmethod
def skip_checks(cls):
super(TestCrossPingScenarioMultiWorker, cls).skip_checks()
if not CONF.kuryr_kubernetes.multi_worker_setup:
raise cls.skipException("Multi node workers are not available")
def _test_cross_ping_multi_worker(self, same_node=True):
if same_node:
pod_name_list = self.create_two_pods_affinity_setup(
labels={'type': 'demo'},
affinity={'podAffinity': consts.POD_AFFINITY})
self.assertEqual(self.get_pod_node_name(pod_name_list[0]),
self.get_pod_node_name(pod_name_list[1]))
else:
pod_name_list = self.create_two_pods_affinity_setup(
labels={'type': 'demo'},
affinity={'podAntiAffinity': consts.POD_AFFINITY})
self.assertNotEqual(self.get_pod_node_name(pod_name_list[0]),
self.get_pod_node_name(pod_name_list[1]))
pod_ip = self.get_pod_ip(pod_name_list[1])
cmd = [
"/bin/sh", "-c", "ping -c 4 {dst_ip}>/dev/null ; echo $?".format(
dst_ip=pod_ip)]
self.assertEqual(self.exec_command_in_pod(pod_name_list[0], cmd), '0')
@decorators.idempotent_id('7d036b6d-b5cf-47e9-a0c0-7696240a1c5e')
def test_pod_pod_ping_different_host(self):
self._test_cross_ping_multi_worker(same_node=False)
@decorators.idempotent_id('bddf5441-1244-449d-a125-b5fddfb1a2a9')
def test_pod_pod_ping_same_node(self):
self._test_cross_ping_multi_worker(same_node=True)