log error when create neutron port with wrong subnet

Bug #1844607 reported by zhengyong
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Low
zhengyong

Bug Description

With Neutron Newton version

There are two networks named share_net and test1 in my env, each with one subnet. When I create port in share_net, but specify subnet_id of the test1's subnet, not the subnet of share_net. Create port failed, but log is "Failed to create port on network 8fd6c0d1-e499-4e29-9786-dadb377f9939, because fixed_ips included invalid subnet d213e64e-045e-4941-a4bd-ffc049ad792c."

Here we can see network 8fd6c0d1-e499-4e29-9786-dadb377f9939 is test1, subnet d213e64e-045e-4941-a4bd-ffc049ad792c is the subnet of test1. The log is confused, actually it should log network 311a12a8-6824-4348-b5b5-80068a0c3785 with invalid subnet d213e64e-045e-4941-a4bd-ffc049ad792c.

()[root@busybox-openstack-85c44df77f-xk2rx /]# neutron net-list
+--------------------------------------+----------------------------------------------------+-------------------------------------------------------+
| id | name | subnets |
+--------------------------------------+----------------------------------------------------+-------------------------------------------------------+
| 311a12a8-6824-4348-b5b5-80068a0c3785 | share_net | ef7e9220-d478-48f7-819e-80143621f233 192.168.20.0/24 |
| 8fd6c0d1-e499-4e29-9786-dadb377f9939 | test1 | d213e64e-045e-4941-a4bd-ffc049ad792c 192.168.20.0/24 |
+--------------------------------------+----------------------------------------------------+-------------------------------------------------------+

()[root@busybox-openstack-85c44df77f-xk2rx /]# neutron port-create --name nic1 --fixed-ip subnet_id=d213e64e-045e-4941-a4bd-ffc049ad792c 311a12a8-6824-4348-b5b5-80068a0c3785

Invalid input for operation: Failed to create port on network 8fd6c0d1-e499-4e29-9786-dadb377f9939, because fixed_ips included invalid subnet d213e64e-045e-4941-a4bd-ffc049ad792c.
Neutron server returns request_ids: ['req-e32df57b-0756-4b88-b042-a0b67ccd7fe7']

after inspect code, I found the function code is:

    def _get_subnet_for_fixed_ip(self, context, fixed, subnets):
        # Subnets are all the subnets belonging to the same network.
        if not subnets:
            msg = _('IP allocation requires subnets for network')
            raise exc.InvalidInput(error_message=msg)

        if 'subnet_id' in fixed:
            def get_matching_subnet():
                for subnet in subnets:
                    if subnet['id'] == fixed['subnet_id']:
                        return subnet
            subnet = get_matching_subnet()
            if not subnet:
                subnet = self._get_subnet(context, fixed['subnet_id'])
                msg = (_("Failed to create port on network %(network_id)s"
                         ", because fixed_ips included invalid subnet "
                         "%(subnet_id)s") %
                       {'network_id': subnet['network_id'],
                        'subnet_id': fixed['subnet_id']})
                raise exc.InvalidInput(error_message=msg)
this function, it use “'network_id': subnet['network_id'] ”, actually it should use the network passed from api.

master branch also have this problem: https://github.com/openstack/neutron/blob/master/neutron/db/ipam_backend_mixin.py#382

Tags: l3-ipam-dhcp
zhengyong (zhengy23)
Changed in neutron:
assignee: nobody → zhengyong (zhengy23)
description: updated
tags: added: l3-ipam-dhcp
Changed in neutron:
importance: Undecided → Low
status: New → Confirmed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (master)

Fix proposed to branch: master
Review: https://review.opendev.org/683273

Changed in neutron:
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

Reviewed: https://review.opendev.org/683273
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=cae66a4d8d13deda74db806d733c2ac39ea2e849
Submitter: Zuul
Branch: master

commit cae66a4d8d13deda74db806d733c2ac39ea2e849
Author: zhengyong <zhengy23@163.com>
Date: Mon Nov 11 10:15:49 2019 +0800

    Revise log when create port failed

    Log network_id passed from api rather than subnet['network_id']

    Change-Id: Ia36635014e827b4a321dbdce22f605c76cc88390
    Closes-Bug: #1844607

Changed in neutron:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 16.0.0.0b1

This issue was fixed in the openstack/neutron 16.0.0.0b1 development milestone.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (master)

Fix proposed to branch: master
Review: https://review.opendev.org/723813

zhengyong (zhengy23)
Changed in neutron:
status: Fix Released → In Progress
Revision history for this message
Akihiro Motoki (amotoki) wrote :

Note: [1] (in comment #2) was reverted by [2]. That's the reason that the status was changed to "In Progress" again.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

Reviewed: https://review.opendev.org/723813
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=e07b6d81080be49e49ca143ed16316eeede7d5e5
Submitter: Zuul
Branch: master

commit e07b6d81080be49e49ca143ed16316eeede7d5e5
Author: zhengyong <zhengy23@163.com>
Date: Tue Apr 28 14:05:23 2020 +0800

    Revising log with wrong network_id when create port failed

    Log network_id passed from api rather than subnet['network_id']

    Change-Id: I8151253be1ca42bbf4b49f904751565783723769
    Closes-Bug: #1844607

Changed in neutron:
status: In Progress → Fix Released
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.