diff --git a/tempest/common/utils/linux/remote_client.py b/tempest/common/utils/linux/remote_client.py index 7c551155e9..4fdf6a4b8e 100644 --- a/tempest/common/utils/linux/remote_client.py +++ b/tempest/common/utils/linux/remote_client.py @@ -109,6 +109,15 @@ class RemoteClient(remote_client.RemoteClient): LOG.debug('(get_nic_name_by_ip) Command result: %s', nic) return nic.strip().strip(":").split('@')[0].lower() + def get_nic_ip_addresses(self, nic_name, ip_version=None): + cmd = "ip " + if ip_version: + cmd += "-%s " % ip_version + cmd += "-o addr | awk '/%s/ {print $4}'" % nic_name + ip_addresses = self.exec_command(cmd) + LOG.debug('(get_nic_ip_address): Command result: %s', ip_addresses) + return ip_addresses.strip().split() + def _get_dns_servers(self): cmd = 'cat /etc/resolv.conf' resolve_file = self.exec_command(cmd).strip().split('\n') diff --git a/tempest/scenario/test_network_basic_ops.py b/tempest/scenario/test_network_basic_ops.py index cbe8c2080d..cbe4122151 100644 --- a/tempest/scenario/test_network_basic_ops.py +++ b/tempest/scenario/test_network_basic_ops.py @@ -897,10 +897,17 @@ class TestNetworkBasicOps(manager.NetworkScenarioTest): self.check_remote_connectivity(ssh_client, dest=peer_address, nic=spoof_nic, should_succeed=True) # Set a mac address by making nic down temporary + spoof_ip_addresses = ssh_client.get_nic_ip_addresses(spoof_nic) cmd = ("sudo ip link set {nic} down;" "sudo ip link set dev {nic} address {mac};" - "sudo ip link set {nic} up").format(nic=spoof_nic, - mac=spoof_mac) + "sudo ip link set {nic} up;" + "sudo ip address flush dev {nic};").format(nic=spoof_nic, + mac=spoof_mac) + for ip_address in spoof_ip_addresses: + cmd += ( + "sudo ip addr add {ip_address} dev {nic};" + ).format(ip_address=ip_address, nic=spoof_nic) + ssh_client.exec_command(cmd) new_mac = ssh_client.get_mac_address(nic=spoof_nic)