Bug 1902224

Summary: [OSP16.2] Nova API does not reject requests for 'os-aggregates' with invalid IDs
Product: Red Hat OpenStack Reporter: Stephen Finucane <stephenfin>
Component: openstack-novaAssignee: Stephen Finucane <stephenfin>
Status: CLOSED ERRATA QA Contact: OSP DFG:Compute <osp-dfg-compute>
Severity: medium Docs Contact:
Priority: low    
Version: 16.2 (Train)CC: apevec, dasmith, dsedgmen, eglynn, jhakimra, jpichon, kchamart, lhh, nova-maint, sbauza, sgordon, smooney, stephenfin, vromanso
Target Milestone: AlphaKeywords: Triaged
Target Release: 16.2 (Train on RHEL 8.4)   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: openstack-nova-20.4.2-2.20201202104907.81a3f4b.el8ost Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1901385
: 1902225 (view as bug list) Environment:
Last Closed: 2021-09-15 07:10:23 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1901385, 1902225    

Description Stephen Finucane 2020-11-27 12:32:46 UTC
+++ This bug was initially created as a clone of Bug #1901385 +++

Description of problem:
Nova api ignore aggregate names that starts with numbers if any aggregate id matches the numbers.
For example an 'openstack show aggregate 8test' returns the aggregate with the id 8 and not the aggregate 8test.


Version-Release number of selected component (if applicable):
RHOSP 13 z13

How reproducible:
Every time

Steps to Reproduce:
1. create aggregate that starts with the id of another aggregate

Actual results:

openstack aggregate show 8test
+-------------------+----------------------------+
| Field             | Value                      |
+-------------------+----------------------------+
| availability_zone | None                       |
| created_at        | 2020-11-25T01:28:01.000000 |
| deleted           | False                      |
| deleted_at        | None                       |
| hosts             | []                         |
| id                | 8                          |
| name              | 5to3-test                  |
| properties        |                            |
| updated_at        | None                       |
+-------------------+----------------------------+

Expected results:
openstack aggregate show 8test
+-------------------+----------------------------+
| Field             | Value                      |
+-------------------+----------------------------+
| availability_zone | None                       |
| created_at        | 2020-11-25T01:32:00.000000 |
| deleted           | False                      |
| deleted_at        | None                       |
| hosts             | []                         |
| id                | 14                         |
| name              | 8test                      |
| properties        |                            |
| updated_at        | None                       |
+-------------------+----------------------------+

Additional info:
This seems to be caused because when you access the API with a name the API returns a 404 and then a second call is made that retrieves a list of aggregates

But if this names starts with a number, the API seems to slurp the number and ignore the rest of the text. 
If this number contains a valid ID it returns the results.

If there is no aggregate that matches the number it returns the results as expected

~~~
REQ: curl -g -i -X GET https://overcloud.redhat.local:13774/v2.1/os-aggregates/8test -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-Auth-Token: {SHA1}b795ba2b399ceb203b43554464bb42071e61cce2"
Starting new HTTPS connection (1): overcloud.redhat.local
https://overcloud.redhat.local:13774 "GET /v2.1/os-aggregates/8test HTTP/1.1" 200 159
RESP: [200] Date: Wed, 25 Nov 2020 01:32:10 GMT Server: Apache OpenStack-API-Version: compute 2.1 X-OpenStack-Nova-API-Version: 2.1 Vary: OpenStack-API-Version,X-OpenStack-Nova-API-Version,Accept-Encoding x-openstack-request-id: req-4c597909-3469-4389-99a5-fd022f32290f x-compute-request-id: req-4c597909-3469-4389-99a5-fd022f32290f Content-Encoding: gzip Content-Length: 159 Content-Type: application/json 
RESP BODY: {"aggregate": {"name": "5to3-test", "availability_zone": null, "deleted": false, "created_at": "2020-11-25T01:28:01.000000", "updated_at": null, "hosts": [], "deleted_at": null, "id": 8, "metadata": {}}}

GET call to compute for https://overcloud.redhat.local:13774/v2.1/os-aggregates/8test used request id req-4c597909-3469-4389-99a5-fd022f32290f
+-------------------+----------------------------+
| Field             | Value                      |
+-------------------+----------------------------+
| availability_zone | None                       |
| created_at        | 2020-11-25T01:28:01.000000 |
| deleted           | False                      |
| deleted_at        | None                       |
| hosts             | []                         |
| id                | 8                          |
| name              | 5to3-test                  |
| properties        |                            |
| updated_at        | None                       |
+-------------------+----------------------------+
clean_up ShowAggregate: 
END return value: 0
~~~

~~~
REQ: curl -g -i -X GET https://overcloud.redhat.local:13774/v2.1/os-aggregates/test -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-Auth-Token: {SHA1}29711e93fbc3ad59efb61dbcb5223669a39a8dc0"
Starting new HTTPS connection (1): overcloud.redhat.local
https://overcloud.redhat.local:13774 "GET /v2.1/os-aggregates/test HTTP/1.1" 404 80
RESP: [404] Date: Wed, 25 Nov 2020 01:34:09 GMT Server: Apache OpenStack-API-Version: compute 2.1 X-OpenStack-Nova-API-Version: 2.1 Vary: OpenStack-API-Version,X-OpenStack-Nova-API-Version x-openstack-request-id: req-e0b7a956-a23e-4e7c-a432-dc4a3a5b7951 x-compute-request-id: req-e0b7a956-a23e-4e7c-a432-dc4a3a5b7951 Content-Length: 80 Content-Type: application/json; charset=UTF-8 
RESP BODY: {"itemNotFound": {"message": "Aggregate test could not be found.", "code": 404}}

GET call to compute for https://overcloud.redhat.local:13774/v2.1/os-aggregates/test used request id req-e0b7a956-a23e-4e7c-a432-dc4a3a5b7951
REQ: curl -g -i -X GET https://overcloud.redhat.local:13774/v2.1/os-aggregates -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-Auth-Token: {SHA1}29711e93fbc3ad59efb61dbcb5223669a39a8dc0"
https://overcloud.redhat.local:13774 "GET /v2.1/os-aggregates HTTP/1.1" 200 221
RESP: [200] Date: Wed, 25 Nov 2020 01:34:09 GMT Server: Apache OpenStack-API-Version: compute 2.1 X-OpenStack-Nova-API-Version: 2.1 Vary: OpenStack-API-Version,X-OpenStack-Nova-API-Version,Accept-Encoding x-openstack-request-id: req-555691d2-8dc8-4110-b740-68a18f8bf992 x-compute-request-id: req-555691d2-8dc8-4110-b740-68a18f8bf992 Content-Encoding: gzip Content-Length: 221 Content-Type: application/json 
RESP BODY: {"aggregates": [{"name": "1to3-test", "availability_zone": null, "deleted": false, "created_at": "2020-11-25T01:27:43.000000", "updated_at": null, "hosts": [], "deleted_at": null, "id": 2, "metadata": {}}, {"name": "2to3-test", "availability_zone": null, "deleted": false, "created_at": "2020-11-25T01:27:53.000000", "updated_at": null, "hosts": [], "deleted_at": null, "id": 5, "metadata": {}}, {"name": "5to3-test", "availability_zone": null, "deleted": false, "created_at": "2020-11-25T01:28:01.000000", "updated_at": null, "hosts": [], "deleted_at": null, "id": 8, "metadata": {}}, {"name": "8and3-test", "availability_zone": null, "deleted": false, "created_at": "2020-11-25T01:31:10.000000", "updated_at": null, "hosts": [], "deleted_at": null, "id": 11, "metadata": {}}, {"name": "8test", "availability_zone": null, "deleted": false, "created_at": "2020-11-25T01:32:00.000000", "updated_at": null, "hosts": [], "deleted_at": null, "id": 14, "metadata": {}}, {"name": "test", "availability_zone": null, "deleted": false, "created_at": "2020-11-25T01:34:01.000000", "updated_at": null, "hosts": [], "deleted_at": null, "id": 17, "metadata": {}}]}

GET call to compute for https://overcloud.redhat.local:13774/v2.1/os-aggregates used request id req-555691d2-8dc8-4110-b740-68a18f8bf992
+-------------------+----------------------------+
| Field             | Value                      |
+-------------------+----------------------------+
| availability_zone | None                       |
| created_at        | 2020-11-25T01:34:01.000000 |
| deleted           | False                      |
| deleted_at        | None                       |
| hosts             | []                         |
| id                | 17                         |
| name              | test                       |
| properties        |                            |
| updated_at        | None                       |
+-------------------+----------------------------+
clean_up ShowAggregate: 
END return value: 0



https://overcloud.redhat.local:13774 "GET /v2.1/os-aggregates/7test HTTP/1.1" 404 81
RESP: [404] Date: Wed, 25 Nov 2020 01:58:49 GMT Server: Apache OpenStack-API-Version: compute 2.1 X-OpenStack-Nova-API-Version: 2.1 Vary: OpenStack-API-Version,X-OpenStack-Nova-API-Version x-openstack-request-id: req-870c502b-45c5-46ec-b27e-85fc7bfbdb5c x-compute-request-id: req-870c502b-45c5-46ec-b27e-85fc7bfbdb5c Content-Length: 81 Content-Type: application/json; charset=UTF-8 
RESP BODY: {"itemNotFound": {"message": "Aggregate 7test could not be found.", "code": 404}}

GET call to compute for https://overcloud.redhat.local:13774/v2.1/os-aggregates/7test used request id req-870c502b-45c5-46ec-b27e-85fc7bfbdb5c
REQ: curl -g -i -X GET https://overcloud.redhat.local:13774/v2.1/os-aggregates -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-Auth-Token: {SHA1}6e695b5426a9bcd86f7d34520ba8b92e23db817b"
https://overcloud.redhat.local:13774 "GET /v2.1/os-aggregates HTTP/1.1" 200 236
RESP: [200] Date: Wed, 25 Nov 2020 01:58:50 GMT Server: Apache OpenStack-API-Version: compute 2.1 X-OpenStack-Nova-API-Version: 2.1 Vary: OpenStack-API-Version,X-OpenStack-Nova-API-Version,Accept-Encoding x-openstack-request-id: req-1704be8a-5032-446c-8f3e-250cf3f3ab3b x-compute-request-id: req-1704be8a-5032-446c-8f3e-250cf3f3ab3b Content-Encoding: gzip Content-Length: 236 Content-Type: application/json 
RESP BODY: {"aggregates": [{"name": "1to3-test", "availability_zone": null, "deleted": false, "created_at": "2020-11-25T01:27:43.000000", "updated_at": null, "hosts": [], "deleted_at": null, "id": 2, "metadata": {}}, {"name": "2to3-test", "availability_zone": null, "deleted": false, "created_at": "2020-11-25T01:27:53.000000", "updated_at": null, "hosts": [], "deleted_at": null, "id": 5, "metadata": {}}, {"name": "5to3-test", "availability_zone": null, "deleted": false, "created_at": "2020-11-25T01:28:01.000000", "updated_at": null, "hosts": [], "deleted_at": null, "id": 8, "metadata": {}}, {"name": "8and3-test", "availability_zone": null, "deleted": false, "created_at": "2020-11-25T01:31:10.000000", "updated_at": null, "hosts": [], "deleted_at": null, "id": 11, "metadata": {}}, {"name": "8test", "availability_zone": null, "deleted": false, "created_at": "2020-11-25T01:32:00.000000", "updated_at": null, "hosts": [], "deleted_at": null, "id": 14, "metadata": {}}, {"name": "test", "availability_zone": null, "deleted": false, "created_at": "2020-11-25T01:34:01.000000", "updated_at": null, "hosts": [], "deleted_at": null, "id": 17, "metadata": {}}, {"name": "7test", "availability_zone": null, "deleted": false, "created_at": "2020-11-25T01:58:31.000000", "updated_at": null, "hosts": [], "deleted_at": null, "id": 20, "metadata": {}}]}

GET call to compute for https://overcloud.redhat.local:13774/v2.1/os-aggregates used request id req-1704be8a-5032-446c-8f3e-250cf3f3ab3b
+-------------------+----------------------------+
| Field             | Value                      |
+-------------------+----------------------------+
| availability_zone | None                       |
| created_at        | 2020-11-25T01:58:31.000000 |
| deleted           | False                      |
| deleted_at        | None                       |
| hosts             | []                         |
| id                | 20                         |
| name              | 7test                      |
| properties        |                            |
| updated_at        | None                       |
+-------------------+----------------------------+
clean_up ShowAggregate: 
END return value: 0
~~~

Comment 14 errata-xmlrpc 2021-09-15 07:10:23 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Red Hat OpenStack Platform (RHOSP) 16.2 enhancement advisory), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2021:3483