Fix test in order to work with new kuryrport CRD.

Currently, all the information was stored within the pod annotations,
and so the tests are utilizing annotations. With upcoming annotation to
CRD transition, in order to get the VIF information we need to also
check the CRD.

Change-Id: If639b63dcf660ed709623c8d5f788026619c895c
This commit is contained in:
Roman Dobosz 2020-07-20 13:09:34 +00:00
parent 6760376f17
commit 8456f2fe16
1 changed files with 29 additions and 11 deletions

View File

@ -43,6 +43,7 @@ KURYR_CRD_GROUP = 'openstack.org'
KURYR_CRD_VERSION = 'v1' KURYR_CRD_VERSION = 'v1'
KURYR_NET_CRD_PLURAL = 'kuryrnets' KURYR_NET_CRD_PLURAL = 'kuryrnets'
KURYR_NETWORK_CRD_PLURAL = 'kuryrnetworks' KURYR_NETWORK_CRD_PLURAL = 'kuryrnetworks'
KURYR_PORT_CRD_PLURAL = 'kuryrports'
KURYR_NET_POLICY_CRD_PLURAL = 'kuryrnetpolicies' KURYR_NET_POLICY_CRD_PLURAL = 'kuryrnetpolicies'
K8S_ANNOTATION_PREFIX = 'openstack.org/kuryr' K8S_ANNOTATION_PREFIX = 'openstack.org/kuryr'
K8S_ANNOTATION_LBAAS_STATE = K8S_ANNOTATION_PREFIX + '-lbaas-state' K8S_ANNOTATION_LBAAS_STATE = K8S_ANNOTATION_PREFIX + '-lbaas-state'
@ -272,19 +273,36 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest):
container_name=container_name) container_name=container_name)
def get_pod_port(self, pod_name, namespace="default"): def get_pod_port(self, pod_name, namespace="default"):
pod = self.k8s_client.CoreV1Api().read_namespaced_pod_status( try:
namespace=namespace, name=pod_name) # TODO(gryf): Current approach is to look at the KuryrPort CRD,
kuryr_if = json.loads(pod.metadata.annotations[ # and if it doesn't exists, fallback to check the pod annotations
'openstack.org/kuryr-vif']) crd = (self.k8s_client.CustomObjectsApi()
.get_namespaced_custom_object(group=KURYR_CRD_GROUP,
version=KURYR_CRD_VERSION,
namespace=namespace,
plural=KURYR_PORT_CRD_PLURAL,
name=pod_name))
vif = [v['vif'].get('versioned_object.data', {}).get('id')
for k, v in crd['spec']['vifs'].items() if v.get('default')]
if vif and vif[0]:
return vif[0]
else:
return None
except kubernetes.client.rest.ApiException:
pod = self.k8s_client.CoreV1Api().read_namespaced_pod_status(
namespace=namespace, name=pod_name)
kuryr_if = json.loads(pod.metadata.annotations[
'openstack.org/kuryr-vif'])
# FIXME(dulek): We need this compatibility code to run stable/queens. # FIXME(dulek): We need this compatibility code to run
# Remove this once it's no longer supported. # stable/queens. Remove this once it's no longer
if 'eth0' in kuryr_if: # supported.
kuryr_if = kuryr_if['eth0'] if 'eth0' in kuryr_if:
elif kuryr_if.get('versioned_object.name') == 'PodState': kuryr_if = kuryr_if['eth0']
kuryr_if = kuryr_if['versioned_object.data']['default_vif'] elif kuryr_if.get('versioned_object.name') == 'PodState':
kuryr_if = kuryr_if['versioned_object.data']['default_vif']
return kuryr_if['versioned_object.data']['id'] return kuryr_if['versioned_object.data']['id']
@classmethod @classmethod
def get_pod_node_name(cls, pod_name, namespace="default"): def get_pod_node_name(cls, pod_name, namespace="default"):