Merge "Get NIC name by "ip -o link""

This commit is contained in:
Jenkins 2016-03-10 12:02:35 +00:00 committed by Gerrit Code Review
commit 271b340572
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

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