openstack client does not pass prefixlen when creating subnet

Bug #1754062 reported by James Denton
22
This bug affects 4 people
Affects Status Importance Assigned to Milestone
OpenStack SDK
Fix Released
Undecided
Unassigned
neutron
High
Brian Haley

Bug Description

Version: Pike
OpenStack Client: 3.12.0

When testing Subnet Pool functionality, I found that the behavior between the openstack and neutron clients is different.

Subnet pool:

root@controller01:~# openstack subnet pool show MySubnetPool
+-------------------+--------------------------------------+
| Field | Value |
+-------------------+--------------------------------------+
| address_scope_id | None |
| created_at | 2018-03-07T13:18:22Z |
| default_prefixlen | 8 |
| default_quota | None |
| description | |
| id | e49703d8-27f4-4a16-9bf4-91a6cf00fff3 |
| ip_version | 4 |
| is_default | False |
| max_prefixlen | 32 |
| min_prefixlen | 8 |
| name | MySubnetPool |
| prefixes | 172.31.0.0/16 |
| project_id | 9233b6b4f6a54386af63c0a7b8f043c2 |
| revision_number | 0 |
| shared | False |
| tags | |
| updated_at | 2018-03-07T13:18:22Z |
+-------------------+--------------------------------------+

When attempting to create a /28 subnet from that pool with the openstack client, the following error is observed:

root@controller01:~# openstack subnet create \
> --subnet-pool MySubnetPool \
> --prefix-length 28 \
> --network MyVLANNetwork2 \
> MyFlatSubnetFromPool
HttpException: Internal Server Error (HTTP 500) (Request-ID: req-61b3f00a-9764-4bcb-899d-e85d66f54e5a), Failed to allocate subnet: Insufficient prefix space to allocate subnet size /8.

However, the same request is successful with the neutron client:

root@controller01:~# neutron subnet-create --subnetpool MySubnetPool --prefixlen 28 --name MySubnetFromPool MyVLANNetwork2
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
Created a new subnet:
+-------------------+-----------------------------------------------+
| Field | Value |
+-------------------+-----------------------------------------------+
| allocation_pools | {"start": "172.31.0.2", "end": "172.31.0.14"} |
| cidr | 172.31.0.0/28 |
| created_at | 2018-03-07T13:35:35Z |
| description | |
| dns_nameservers | |
| enable_dhcp | True |
| gateway_ip | 172.31.0.1 |
| host_routes | |
| id | 43cb9dda-1b7e-436d-9dc1-5312866a1b63 |
| ip_version | 4 |
| ipv6_address_mode | |
| ipv6_ra_mode | |
| name | MySubnetFromPool |
| network_id | e01ca743-607c-4a94-9176-b572a46fba84 |
| project_id | 9233b6b4f6a54386af63c0a7b8f043c2 |
| revision_number | 0 |
| service_types | |
| subnetpool_id | e49703d8-27f4-4a16-9bf4-91a6cf00fff3 |
| tags | |
| tenant_id | 9233b6b4f6a54386af63c0a7b8f043c2 |
| updated_at | 2018-03-07T13:35:35Z |
+-------------------+-----------------------------------------------+

The payload is different between these clients - the openstack client fails to send the prefixlen key.

openstack client:

REQ: curl -g -i -X POST http://controller01:9696/v2.0/subnets -H "User-Agent: openstacksdk/0.9.17 keystoneauth1/3.1.0 python-requests/2.18.1 CPython/2.7.12" -H "Content-Type: application/json" -H "X-Auth-Token: {SHA1}ec04a71699eee2c70dc4abb35037de272523fef0" -d '{"subnet": {"network_id": "e01ca743-607c-4a94-9176-b572a46fba84", "ip_version": 4, "name": "MyFlatSubnetFromPool", "subnetpool_id": "e49703d8-27f4-4a16-9bf4-91a6cf00fff3"}}'
http://controller01:9696 "POST /v2.0/subnets HTTP/1.1" 500 160

neutron client:

REQ: curl -g -i -X POST http://controller01:9696/v2.0/subnets -H "User-Agent: python-neutronclient" -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: {SHA1}b3b6f0fa14c2b28c5c9784f857ee753455c1d375" -d '{"subnet": {"network_id": "e01ca743-607c-4a94-9176-b572a46fba84", "prefixlen": "28", "ip_version": 4, "subnetpool_id": "e49703d8-27f4-4a16-9bf4-91a6cf00fff3", "name": "MySubnetFromPool"}}'

This appears to stem from prefixlen missing as a query parameter and property in the python-openstacksdk here:

https://github.com/openstack/python-openstacksdk/blob/master/openstack/network/v2/subnet.py#L32
https://github.com/openstack/python-openstacksdk/blob/master/openstack/network/v2/subnet.py#L43

The Neutron docs do not show prefixlen as a subnet as a valid property, which could be why:

https://developer.openstack.org/api-ref/network/v2/index.html#create-subnet

I was able to patch the openstack SDK in my environment and got the client to work. Please let me know if you have any questions!

Revision history for this message
Brian Haley (brian-haley) wrote :

So it looks like there are multiple issues here - the api-ref in neutron-lib is missing this field, and as you stated, the sdk is missing it probably because it's not listed. I'll ping someone to take a look at the api-ref. I'm not that familiar with the sdk but if you had a simple patch that helps feel free to post it and I'll take a look. Thanks.

Changed in neutron:
status: New → Confirmed
importance: Undecided → High
Revision history for this message
James Denton (james-denton) wrote :

Hi Brian,

Thanks for taking a look. Here is the patch in question:

https://review.openstack.org/550558

James

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

Fix proposed to branch: master
Review: https://review.openstack.org/550588

Changed in neutron:
assignee: nobody → Brian Haley (brian-haley)
status: Confirmed → In Progress
Revision history for this message
Brian Haley (brian-haley) wrote :

Just a comment since Amotoki commented in my neutron-lib api-ref change - when the subnetpool was created, the default_prefixlen value should have been specified (in this case at 28), that way callers don't need to specify it. I think it defaults to min_prefixlen if not specified. We still need to fix the bug...

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

Reviewed: https://review.openstack.org/550588
Committed: https://git.openstack.org/cgit/openstack/neutron-lib/commit/?id=ce10b9df28ece6daee1f199740b672aae707630b
Submitter: Zuul
Branch: master

commit ce10b9df28ece6daee1f199740b672aae707630b
Author: Brian Haley <email address hidden>
Date: Wed Mar 7 15:08:42 2018 -0500

    Add prefixlen to subnet api-ref for create actions

    Prefixlen is used in subnet creation when allocating a subnet
    from a subnet pool.

    Change-Id: I251944ca15434ed9b17deb829cca985cd94a0bd1
    Closes-bug: #1754062

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

This issue was fixed in the openstack/neutron-lib 1.14.0 release.

Revision history for this message
Francois Deppierraz (francois-ctrlaltdel) wrote :

I'm not sure this issue is actually fixed, I gave it a try today without any luck using the lastest python-openstackclient.

$ pip list | egrep "openstack|neutron"
openstacksdk (0.20.0)
python-neutronclient (6.11.0)
python-openstackclient (3.17.0)
python-openstacksdk (0.5.2)
$ openstack --version
openstack 3.17.0
$ openstack --debug subnet create --use-default-subnet-pool --prefix-length 24 --network test test
[...]
https://XXX:9696 "POST /v2.0/subnets HTTP/1.1" 201 593
RESP: [201] Connection: close Content-Length: 593 Content-Type: application/json; charset=UTF-8 Date: Mon, 17 Dec 2018 16:10:59 GMT X-Openstack-Request-Id: req-2744992c-5302-4f7a-9870-220e868d85a1
RESP BODY: {"subnet": {"description": "", "enable_dhcp": true, "network_id": "6b350cce-adf8-44fa-86b2-140670cc99b8", "tenant_id": "505f48f68ebc4d4f87cf64e56b40f3de", "created_at": "2018-12-17T16:10:59", "dns_nameservers": [], "updated_at": "2018-12-17T16:10:59", "gateway_ip": "X.X.X.X", "ipv6_ra_mode": null, "allocation_pools": [{"start": "X.X.X.X", "end": "X.X.X.X"}], "host_routes": [], "ip_version": 4, "ipv6_address_mode": null, "cidr": "X.X.X.X/26", "id": "6d75a4e9-31fd-4364-8352-050e3197dc56", "subnetpool_id": "d563bbd9-90c2-4ccb-af08-92339b05396c", "name": "test"}}
[...]
| cidr | X.X.X.X/26 |

Revision history for this message
James Denton (james-denton) wrote :

@Francois - This isn't completely fixed, yet, but a new patch set went up today.

Revision history for this message
Michal Arbet (michalarbet) wrote :

@James , could you please show me that patch ? Thanks

Revision history for this message
James Denton (james-denton) wrote :
Revision history for this message
Bernard Cafarelli (bcafarel) wrote :

Marking as fix released in openstacksdk with https://review.opendev.org/#/c/550558/

Changed in python-openstacksdk:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers