Fix test_port_security_macspoofing_port
Fix test logic to add ip back after interface up/down.
Related-Prod: PRODX-27727
Change-Id: I2ef44d989fcf94b199fd960119e9c9f8c6de4509
(cherry picked from commit 8f09b9ada2bddb2d6b2891e0a3e9ed018b445a32)
diff --git a/tempest/scenario/test_network_basic_ops.py b/tempest/scenario/test_network_basic_ops.py
index 7b819e0..e50193e 100644
--- a/tempest/scenario/test_network_basic_ops.py
+++ b/tempest/scenario/test_network_basic_ops.py
@@ -240,6 +240,26 @@
network=self.new_net,
gateway_ip=None)
+ def _assign_nic_ip_address_by_port(self, ssh_client, port, device):
+ ip_output = ssh_client.exec_command('ip a')
+ ip_address = port['fixed_ips'][0]['ip_address']
+ ip_mask = CONF.network.project_network_mask_bits
+ # check if the address is not already in use, if not, set it
+ if ' ' + ip_address + '/' + str(ip_mask) not in ip_output:
+ try:
+ ssh_client.exec_command("sudo ip addr add %s/%s dev %s" % (
+ ip_address, ip_mask, device))
+ ssh_client.exec_command("sudo ip link set %s up" % device)
+ except exceptions.SSHExecCommandFailed as exc:
+ if 'RTNETLINK answers: File exists' in str(exc):
+ LOG.debug(
+ 'IP address %(ip_address)s is already set in device '
+ '%(device)s\nPrevious "ip a" output: %(ip_output)s',
+ {'ip_address': ip_address, 'device': device,
+ 'ip_output': ip_output})
+ else:
+ raise exc
+
def _hotplug_server(self):
old_floating_ip, server = self.floating_ip_tuple
ip_address = old_floating_ip['floating_ip_address']
@@ -293,24 +313,7 @@
% CONF.network.build_timeout)
_, new_nic = self.diff_list[0]
- ip_output = ssh_client.exec_command('ip a')
- ip_address = new_port['fixed_ips'][0]['ip_address']
- ip_mask = CONF.network.project_network_mask_bits
- # check if the address is not already in use, if not, set it
- if ' ' + ip_address + '/' + str(ip_mask) not in ip_output:
- try:
- ssh_client.exec_command("sudo ip addr add %s/%s dev %s" % (
- ip_address, ip_mask, new_nic))
- ssh_client.exec_command("sudo ip link set %s up" % new_nic)
- except exceptions.SSHExecCommandFailed as exc:
- if 'RTNETLINK answers: File exists' in str(exc):
- LOG.debug(
- 'IP address %(ip_address)s is already set in device '
- '%(device)s\nPrevious "ip a" output: %(ip_output)s',
- {'ip_address': ip_address, 'device': new_nic,
- 'ip_output': ip_output})
- else:
- raise exc
+ self._assign_nic_ip_address_by_port(ssh_client, new_port, new_nic)
def _get_server_nics(self, ssh_client):
reg = re.compile(r'(?P<num>\d+): (?P<nic_name>\w+)[@]?.*:')
@@ -912,6 +915,7 @@
).format(ip_address=ip_address, nic=spoof_nic)
ssh_client.exec_command(cmd)
+ self._assign_nic_ip_address_by_port(ssh_client, spoof_port, spoof_nic)
new_mac = ssh_client.get_mac_address(nic=spoof_nic)
self.assertEqual(spoof_mac, new_mac)