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
This commit is contained in:
Evgeny Antyshev 2016-02-16 09:48:57 +00:00
parent 8e93dc0f57
commit 9b77ae5183
3 changed files with 9 additions and 4 deletions

View File

@ -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()

View File

@ -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"]

View File

@ -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,