flaws in neutronv2's _get_port_id_by_fixed_address method

Bug #1778870 reported by Mike Chen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Confirmed
Low
Mike Chen

Bug Description

Problem description:
When doing associcate-floating-ip to an instance, we will call the following method
https://github.com/openstack/nova/blob/master/nova/network/neutronv2/api.py#L1869
def _get_port_id_by_fixed_address(self, client,
                                      instance, address):
        """Return port_id from a fixed address."""
        zone = 'compute:%s' % instance.availability_zone
        search_opts = {'device_id': instance.uuid,
                       'device_owner': zone}
        data = client.list_ports(**search_opts)
        ports = data['ports']
        port_id = None
        for p in ports:
            for ip in p['fixed_ips']:
                if ip['ip_address'] == address:
                    port_id = p['id']
                    break
        if not port_id:
            raise exception.FixedIpNotFoundForAddress(address=address)
        return port_id

to get the port id from the fixed ip the floating ip is to be associated with.
This method will return the last matched port that has the provided fixed ip, only neglecting
the fact that multiple ports can satisfy the condition.

That is, we can
1. create an instance on subnetA with allocated fixed ip 10.0.0.2/24 (portA)
2. create a portB on subnetB with fixed ip 10.0.0.2/24
3. associate portB to the instance
then the instance has portA and portB with the same address 10.0.0.2/24 on it.

Desired outcome:
The method _get_port_id_by_fixed_address should be aware of this circumstance and address
it in some way.

Tags: neutron
Mike Chen (chenn2)
Changed in nova:
assignee: nobody → Chen (chenn2)
melanie witt (melwitt)
tags: added: neutron
jichenjc (jichenjc)
Changed in nova:
status: New → Confirmed
importance: Undecided → Low
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.