From 39d5bf3765a76f995ff7c67d1f53a39532e7de5f Mon Sep 17 00:00:00 2001 From: Itzik Brown Date: Thu, 12 Jul 2018 12:17:31 +0300 Subject: [PATCH] Using port id instead of port name in get_pod_port Getting the port id from the annotations of the pod Change-Id: I4aad6efe453f846360b65533898ae2373bbb2dbf --- kuryr_tempest_plugin/tests/scenario/base.py | 27 ++++++--------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/kuryr_tempest_plugin/tests/scenario/base.py b/kuryr_tempest_plugin/tests/scenario/base.py index 020f23a0..d319a333 100644 --- a/kuryr_tempest_plugin/tests/scenario/base.py +++ b/kuryr_tempest_plugin/tests/scenario/base.py @@ -11,7 +11,7 @@ # 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 json import time from oslo_log import log as logging @@ -113,24 +113,11 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest): return pod.status.phase def get_pod_port(self, pod_name, namespace="default"): - # TODO(gcheresh) get pod port using container id, as kuryr this would - # depend on port_debug kuryr feature - full_port_name = str(namespace) + "/" + str(pod_name) - port_list = self.os_admin.ports_client.list_ports() - found_ports = [] - for port in port_list['ports']: - if full_port_name == port['name']: - return port - if pod_name == port['name']: - found_ports.append(port) - # To maintain backwards compatibility with the old naming we also check - # for matchings without namespace at the port name. - # Note, if there is more than one port with the same name, we have no - # way to differentiate them unless the namespace is used at the port - # name, since kubernetes will avoid having pods with the same name - # under the same namespace - if len(found_ports) == 1: - return found_ports[0] + 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']) + return kuryr_if['eth0']['versioned_object.data']['id'] def exec_command_in_pod(self, pod_name, command, namespace="default"): api = self.k8s_client.CoreV1Api() @@ -143,7 +130,7 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest): pod_fip = self.os_admin.floating_ips_client.create_floatingip( floating_network_id=ext_net_id, tenant_id=self.get_project_id(), - port_id=self.get_pod_port(pod_name, namespace)['id']) + port_id=self.get_pod_port(pod_name, namespace)) self.pod_fips.append(pod_fip) return pod_fip