Unable to filter using same cidr value as used for subnet create

Bug #1831811 reported by Harald Jensås
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Medium
Harald Jensås

Bug Description

When subnets are created using a cidr the value provided is normalized/converted to a proper subnet

https://opendev.org/openstack/neutron/src/branch/master/neutron/db/db_base_plugin_v2.py#L818-L820

818 # turn the CIDR into a proper subnet
819 net = netaddr.IPNetwork(s['cidr'])
820 subnet['subnet']['cidr'] = '%s/%s' % (net.network, net.prefixlen)

I.e if the user create using `192.168.100.1/24` as the cidr the subnet create is successfull. The cidr is turned into the proper subnet `192.168.100.0/24` internally in the pre-commit.

When listing subnets and filtering using the same value for the cidr the return is an empty list. Example:

$ curl -s -H "X-Auth-Token: $(openstack token issue -c id -f value)" -H "Content-Type: application/json" http://192.168.122.103:9696/v2.0/subnets?cidr=192.168.100.1/24 | json_reformat
{
    "subnets": [

    ]
}

A user should be able to find the subnet by filtering using the same `192.168.100.1/24` value used when creating the subnet.

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/663464

Changed in neutron:
assignee: nobody → Harald Jensås (harald-jensas)
status: New → In Progress
Changed in neutron:
importance: Undecided → Medium
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

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

commit af773557323580c7b07bd41dd1f524e81530c939
Author: Harald Jensås <email address hidden>
Date: Thu Jun 6 03:06:17 2019 +0200

    Turn CIDR in query filter into proper subnet

    Use netaddr.IPNetwork to convert CIDRs in a query
    into proper subnets.

    When creating subnets the CIDR is converted into
    a proper subnet. i.e a subnet can be created with
    cidr=10.0.0.11/24 in the create request. On create
    the cidr is turned into a proper subnet resulting
    in a subnet with cidr=10.0.0.0/24.

    This change does the same to CIDRs when used as
    query filters during a list subnet request, so
    that the same value that was used to create the
    subnet can be used to find the subnet.

    Closes-Bug: #1831811
    Change-Id: I8ae478a03ceedc6c3b1ae1d40081b5e5158813e6

Changed in neutron:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (stable/stein)

Fix proposed to branch: stable/stein
Review: https://review.opendev.org/667541

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

Fix proposed to branch: stable/rocky
Review: https://review.opendev.org/667542

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

Fix proposed to branch: stable/queens
Review: https://review.opendev.org/667560

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

Reviewed: https://review.opendev.org/667541
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=350436991874bbec9cb9c846f6314c3a13098060
Submitter: Zuul
Branch: stable/stein

commit 350436991874bbec9cb9c846f6314c3a13098060
Author: Harald Jensås <email address hidden>
Date: Thu Jun 6 03:06:17 2019 +0200

    Turn CIDR in query filter into proper subnet

    Use netaddr.IPNetwork to convert CIDRs in a query
    into proper subnets.

    When creating subnets the CIDR is converted into
    a proper subnet. i.e a subnet can be created with
    cidr=10.0.0.11/24 in the create request. On create
    the cidr is turned into a proper subnet resulting
    in a subnet with cidr=10.0.0.0/24.

    This change does the same to CIDRs when used as
    query filters during a list subnet request, so
    that the same value that was used to create the
    subnet can be used to find the subnet.

    Closes-Bug: #1831811
    Change-Id: I8ae478a03ceedc6c3b1ae1d40081b5e5158813e6
    (cherry picked from commit af773557323580c7b07bd41dd1f524e81530c939)

tags: added: in-stable-stein
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (stable/queens)

Reviewed: https://review.opendev.org/667560
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=4ecfdb6fd0e89f3b0ff6ca345d18c0db66e2eaeb
Submitter: Zuul
Branch: stable/queens

commit 4ecfdb6fd0e89f3b0ff6ca345d18c0db66e2eaeb
Author: Harald Jensås <email address hidden>
Date: Thu Jun 6 03:06:17 2019 +0200

    Turn CIDR in query filter into proper subnet

    Use netaddr.IPNetwork to convert CIDRs in a query
    into proper subnets.

    When creating subnets the CIDR is converted into
    a proper subnet. i.e a subnet can be created with
    cidr=10.0.0.11/24 in the create request. On create
    the cidr is turned into a proper subnet resulting
    in a subnet with cidr=10.0.0.0/24.

    This change does the same to CIDRs when used as
    query filters during a list subnet request, so
    that the same value that was used to create the
    subnet can be used to find the subnet.

    Conflicts:
        neutron/db/db_base_plugin_common.py

    Closes-Bug: #1831811
    Change-Id: I8ae478a03ceedc6c3b1ae1d40081b5e5158813e6
    (cherry picked from commit af773557323580c7b07bd41dd1f524e81530c939)

tags: added: in-stable-queens
tags: added: in-stable-rocky
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (stable/rocky)

Reviewed: https://review.opendev.org/667542
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=efd09e6295db0a890ad45f894e649afa31f36522
Submitter: Zuul
Branch: stable/rocky

commit efd09e6295db0a890ad45f894e649afa31f36522
Author: Harald Jensås <email address hidden>
Date: Thu Jun 6 03:06:17 2019 +0200

    Turn CIDR in query filter into proper subnet

    Use netaddr.IPNetwork to convert CIDRs in a query
    into proper subnets.

    When creating subnets the CIDR is converted into
    a proper subnet. i.e a subnet can be created with
    cidr=10.0.0.11/24 in the create request. On create
    the cidr is turned into a proper subnet resulting
    in a subnet with cidr=10.0.0.0/24.

    This change does the same to CIDRs when used as
    query filters during a list subnet request, so
    that the same value that was used to create the
    subnet can be used to find the subnet.

    Conflicts:
        neutron/db/db_base_plugin_common.py

    Closes-Bug: #1831811
    Change-Id: I8ae478a03ceedc6c3b1ae1d40081b5e5158813e6
    (cherry picked from commit af773557323580c7b07bd41dd1f524e81530c939)

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 15.0.0.0b1

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

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 14.0.3

This issue was fixed in the openstack/neutron 14.0.3 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 13.0.5

This issue was fixed in the openstack/neutron 13.0.5 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 12.1.1

This issue was fixed in the openstack/neutron 12.1.1 release.

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.