Bug 2217389 - openstack server show <name> doesn't work if the instance name contains parentheses
Summary: openstack server show <name> doesn't work if the instance name contains paren...
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat OpenStack
Classification: Red Hat
Component: openstack-nova
Version: 16.2 (Train)
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
: ---
Assignee: OSP DFG:Compute
QA Contact: OSP DFG:Compute
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-06-26 07:01 UTC by yatanaka
Modified: 2023-07-26 02:27 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-07-05 09:25:11 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker OSP-26024 0 None None None 2023-06-26 07:05:15 UTC
Red Hat Knowledge Base (Solution) 7025737 0 None None None 2023-07-26 02:27:30 UTC

Description yatanaka 2023-06-26 07:01:13 UTC
Description of problem:

I created an instance whose name is "test(test)".

~~~
(yatanaka) [stack@undercloud ~]$ openstack server list 
+--------------------------------------+------------+--------+---------------------------------+--------------+-----------------+
| ID                                   | Name       | Status | Networks                        | Image        | Flavor          |
+--------------------------------------+------------+--------+---------------------------------+--------------+-----------------+
| 9e42a051-c2e1-4838-b469-61c95d4624f0 | test(test) | ACTIVE | yatanaka_network0=192.168.0.205 | rhel-8.2-290 | yatanaka_flavor |
+--------------------------------------+------------+--------+---------------------------------+--------------+-----------------+
~~~

However, openstack server show 'test(test)' doesn't work.
Nova API returns no instances.

~~~
(yatanaka) [stack@undercloud ~]$ openstack server show 'test(test)'
No server with a name or ID of 'test(test)' exists.

(yatanaka) [stack@undercloud ~]$ openstack server show 'test(test)' --debug
  :
REQ: curl -g -i -X GET http://10.0.0.100:8774/v2.1/servers?name=test%28test%29 -H "Accept: application/json" -H "OpenStack-API-Version: compute 2.79" -H "User-Agent: python-novaclient" -H "X-Auth-Token: {SHA256}1d261ced5fbcac0cb539fba7012e658f72cd6c9e988547240ed36868a4d94861" -H "X-OpenStack-Nova-API-Version: 2.79"
http://10.0.0.100:8774 "GET /v2.1/servers?name=test%28test%29 HTTP/1.1" 200 None
RESP: [200] Content-Encoding: gzip Content-Type: application/json Date: Mon, 26 Jun 2023 06:49:42 GMT OpenStack-API-Version: compute 2.79 Server: Apache Transfer-Encoding: chunked Vary: OpenStack-API-Version,X-OpenStack-Nova-API-Version,Accept-Encoding X-OpenStack-Nova-API-Version: 2.79 x-compute-request-id: req-ad079070-09f1-49c7-a91f-9a6d49d51abc x-openstack-request-id: req-ad079070-09f1-49c7-a91f-9a6d49d51abc
RESP BODY: {"servers": []}
GET call to compute for http://10.0.0.100:8774/v2.1/servers?name=test%28test%29 used request id req-ad079070-09f1-49c7-a91f-9a6d49d51abc
No server with a name or ID of 'test(test)' exists.
~~~

When I specify the UUID instead of the instance name, it works.

~~~
(yatanaka) [stack@undercloud ~]$ openstack server show 9e42a051-c2e1-4838-b469-61c95d4624f0 |head -n 5
+-------------------------------------+----------------------------------------------------------------------------------------------+
| Field                               | Value                                                                                        |
+-------------------------------------+----------------------------------------------------------------------------------------------+
| OS-DCF:diskConfig                   | MANUAL                                                                                       |
| OS-EXT-AZ:availability_zone         | AZ-overcloud-novacompute-2.yatanaka.example.com                                              |

  :
~~~

I noticed that the display_name is considered as a regular expression.

~~~
https://github.com/openstack/nova/blob/stable/train/nova/api/openstack/compute/schemas/servers.py#L596
        'name': parameter_types.common_query_regex_param,

https://github.com/openstack/nova/blob/f6620d48c86fb1c5034c09da6411ea46b4d9c2ed/nova/db/main/api.py#L1808-L1813
    # Filters for exact matches that we can do along with the SQL query...
    # For other filters that don't match this, we will do regexp matching
    exact_match_filter_names = ['project_id', 'user_id', 'image_ref',
                                'vm_state', 'instance_type_id', 'uuid',
                                'metadata', 'host', 'task_state',
                                'system_metadata', 'locked', 'hidden']

   ==> "display_name" is not in "exact_match_filter_names" variable.


<from general_log of mysql of my lab>
WHERE instances.deleted = 0 AND (instances.vm_state != 'soft-delete' OR instances.vm_state IS NULL) AND (instances.hidden = false OR instances.hidden IS NULL) AND instances.project_id = '118473aa7d8441c88c9a3bbd4e159041' AND (instances.display_name REGEXP 'test(test)') ......

  ==> REGEXP is used to find out the "display_name" in the SQL statement
~~~

Therefore, I tried escaping the parentheses using "\".
However, the same result was reproduced.

~~~
(yatanaka) [stack@undercloud ~]$ openstack server show 'test\(test\)'
No server with a name or ID of 'test\(test\)' exists.

(yatanaka) [stack@undercloud ~]$ openstack server show 'test\(test\)' --debug
  :
GET call to compute for http://10.0.0.100:8774/v2.1/servers/test%5C(test%5C) used request id req-880c505e-9864-4072-a548-14b29be12400
REQ: curl -g -i -X GET http://10.0.0.100:8774/v2.1/servers?name=test%5C%28test%5C%29 -H "Accept: application/json" -H "OpenStack-API-Version: compute 2.79" -H "User-Agent: python-novaclient" -H "X-Auth-Token: {SHA256}f62c990214d8411837bdb5ad145ceb1aa088f40b096138e92f700066a442913f" -H "X-OpenStack-Nova-API-Version: 2.79"
http://10.0.0.100:8774 "GET /v2.1/servers?name=test%5C%28test%5C%29 HTTP/1.1" 200 None
RESP: [200] Content-Encoding: gzip Content-Type: application/json Date: Mon, 26 Jun 2023 07:02:23 GMT OpenStack-API-Version: compute 2.79 Server: Apache Transfer-Encoding: chunked Vary: OpenStack-API-Version,X-OpenStack-Nova-API-Version,Accept-Encoding X-OpenStack-Nova-API-Version: 2.79 x-compute-request-id: req-bf1a3ea9-e598-4122-b2e5-3923ecc487b9 x-openstack-request-id: req-bf1a3ea9-e598-4122-b2e5-3923ecc487b9
RESP BODY: {"servers": [{"id": "9e42a051-c2e1-4838-b469-61c95d4624f0", "name": "test(test)", "links": [{"rel": "self", "href": "http://10.0.0.100:8774/v2.1/servers/9e42a051-c2e1-4838-b469-61c95d4624f0"}, {"rel": "bookmark", "href": "http://10.0.0.100:8774/servers/9e42a051-c2e1-4838-b469-61c95d4624f0"}]}]}
GET call to compute for http://10.0.0.100:8774/v2.1/servers?name=test%5C%28test%5C%29 used request id req-bf1a3ea9-e598-4122-b2e5-3923ecc487b9
No server with a name or ID of 'test\(test\)' exists.

(yatanaka) [stack@undercloud ~]$ openstack server show 'test\\(test\\)'
No server with a name or ID of 'test\\(test\\)' exists.

(yatanaka) [stack@undercloud ~]$ openstack server show 'test\\(test\\)' --debug 
  :
GET call to compute for http://10.0.0.100:8774/v2.1/servers/test%5C%5C(test%5C%5C) used request id req-95fb1b23-2015-402f-b782-c552721d61f6
REQ: curl -g -i -X GET http://10.0.0.100:8774/v2.1/servers?name=test%5C%5C%28test%5C%5C%29 -H "Accept: application/json" -H "OpenStack-API-Version: compute 2.79" -H "User-Agent: python-novaclient" -H "X-Auth-Token: {SHA256}21e077be8bb50c62eb4958047c16634899aa80f7288f985462394463e97ca1c0" -H "X-OpenStack-Nova-API-Version: 2.79"
http://10.0.0.100:8774 "GET /v2.1/servers?name=test%5C%5C%28test%5C%5C%29 HTTP/1.1" 200 None
RESP: [200] Content-Encoding: gzip Content-Type: application/json Date: Mon, 26 Jun 2023 07:03:11 GMT OpenStack-API-Version: compute 2.79 Server: Apache Transfer-Encoding: chunked Vary: OpenStack-API-Version,X-OpenStack-Nova-API-Version,Accept-Encoding X-OpenStack-Nova-API-Version: 2.79 x-compute-request-id: req-75ed5469-1074-4432-89c5-025d6fab01d6 x-openstack-request-id: req-75ed5469-1074-4432-89c5-025d6fab01d6
RESP BODY: {"servers": []}
GET call to compute for http://10.0.0.100:8774/v2.1/servers?name=test%5C%5C%28test%5C%5C%29 used request id req-75ed5469-1074-4432-89c5-025d6fab01d6
No server with a name or ID of 'test\\(test\\)' exists.
~~~

My customer is facing this issue.
As I mentioned, the workaround is using UUID instead of display_name.
But the customer wants to find instances using display_name rather than UUID.


Version-Release number of selected component (if applicable):
RHOSP 16.2.5 (My lab)
RHOSP 16.1 (My customer's envrionment)

How reproducible:

Steps to Reproduce:
1. create an instance whose name is "test(test)"
2. run "openstack server show 'test(test)'"
3.

Actual results:
openstack server show doesn't returns the instance information.

Expected results:
openstack server show returns the instance information.


Note You need to log in before you can comment on or make changes to this bug.