Make `body` arg conditional when deleting service

kubernetes package in stable/queens is constrained to 4.0.0 version.
That version doesn't support `body` argument passed to
delete_namespaced_service and fails. This commit fixes that by making
passing this argument conditional on kubernetes package version.

Change-Id: Iaff1f569e99a88a8d8ff81aa4e0c4c7bedb94585
This commit is contained in:
Michał Dulko 2018-05-22 11:14:40 +02:00
parent cec652300d
commit ea65d96173
1 changed files with 15 additions and 5 deletions

View File

@ -18,6 +18,7 @@ from oslo_log import log as logging
import requests
import kubernetes
from kubernetes import client as k8s_client
from kubernetes import config as k8s_config
from kubernetes.stream import stream
@ -175,11 +176,20 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest):
@classmethod
def delete_service(cls, service_name, namespace="default"):
delete_options = cls.k8s_client.V1DeleteOptions()
cls.k8s_client.CoreV1Api().delete_namespaced_service(
name=service_name,
namespace=namespace,
body=delete_options)
# FIXME(dulek): This is needed to support tempest plugin on
# stable/queens as kubernetes package is constrainted to
# 4.0.0 there and it doesn't accept ``body`` parameter.
# Remove this once stable/queens becomes unsupported.
if kubernetes.__version__ == '4.0.0':
cls.k8s_client.CoreV1Api().delete_namespaced_service(
name=service_name,
namespace=namespace)
else:
delete_options = cls.k8s_client.V1DeleteOptions()
cls.k8s_client.CoreV1Api().delete_namespaced_service(
name=service_name,
namespace=namespace,
body=delete_options)
@classmethod
def get_service_ip(