From 9b77ae5183b4e02d8b26784be024d9ca8ace8699 Mon Sep 17 00:00:00 2001 From: Evgeny Antyshev Date: Tue, 16 Feb 2016 09:48:57 +0000 Subject: [PATCH] Get NIC name by "ip -o link" "ip -o addr" doesn't include MAC address for Ubuntu 14 and CentOS 7. "ip -o link" is a good substitute, since we're not looking for IP addresses in this procedure. Initial procedure is called "get_nic_name_by_ip", and the new is "get_nic_name_by_mac" Change-Id: Id070a51a3b496b8b746e27f7833f61282b25736e --- tempest/common/utils/linux/remote_client.py | 9 +++++++-- tempest/scenario/test_network_basic_ops.py | 2 +- tempest/scenario/test_network_v6.py | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tempest/common/utils/linux/remote_client.py b/tempest/common/utils/linux/remote_client.py index 8f5faef21c..adb9b1a5c8 100644 --- a/tempest/common/utils/linux/remote_client.py +++ b/tempest/common/utils/linux/remote_client.py @@ -102,7 +102,12 @@ class RemoteClient(object): cmd = "ip addr %s| awk '/ether/ {print $2}'" % show_nic return self.exec_command(cmd).strip().lower() - def get_nic_name(self, address): + def get_nic_name_by_mac(self, address): + cmd = "ip -o link | awk '/%s/ {print $2}'" % address + nic = self.exec_command(cmd) + return nic.strip().strip(":").lower() + + def get_nic_name_by_ip(self, address): cmd = "ip -o addr | awk '/%s/ {print $2}'" % address nic = self.exec_command(cmd) return nic.strip().strip(":").lower() @@ -142,7 +147,7 @@ class RemoteClient(object): def _renew_lease_udhcpc(self, fixed_ip=None): """Renews DHCP lease via udhcpc client. """ file_path = '/var/run/udhcpc.' - nic_name = self.get_nic_name(fixed_ip) + nic_name = self.get_nic_name_by_ip(fixed_ip) pid = self.exec_command('cat {path}{nic}.pid'. format(path=file_path, nic=nic_name)) pid = pid.strip() diff --git a/tempest/scenario/test_network_basic_ops.py b/tempest/scenario/test_network_basic_ops.py index 79a5099c02..63c844b82d 100644 --- a/tempest/scenario/test_network_basic_ops.py +++ b/tempest/scenario/test_network_basic_ops.py @@ -777,7 +777,7 @@ class TestNetworkBasicOps(manager.NetworkScenarioTest): private_key = self._get_server_key(server) ssh_client = self.get_remote_client(fip.floating_ip_address, private_key=private_key) - spoof_nic = ssh_client.get_nic_name(spoof_port["mac_address"]) + spoof_nic = ssh_client.get_nic_name_by_mac(spoof_port["mac_address"]) dhcp_ports = self._list_ports(device_owner="network:dhcp", network_id=self.new_net["id"]) new_net_dhcp = dhcp_ports[0]["fixed_ips"][0]["ip_address"] diff --git a/tempest/scenario/test_network_v6.py b/tempest/scenario/test_network_v6.py index fc33dd9dd5..66c8ade803 100644 --- a/tempest/scenario/test_network_v6.py +++ b/tempest/scenario/test_network_v6.py @@ -145,7 +145,7 @@ class TestGettingAddress(manager.NetworkScenarioTest): "ports: %s") % (self.network_v6, ports)) mac6 = ports[0] - ssh.set_nic_state(ssh.get_nic_name(mac6)) + ssh.set_nic_state(ssh.get_nic_name_by_mac(mac6)) def _prepare_and_test(self, address6_mode, n_subnets6=1, dualnet=False): net_list = self.prepare_network(address6_mode=address6_mode,