Listing SOFT_DELETED servers by vm_state does not work

Bug #1857447 reported by Fan Zhang on 2019-12-24
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Undecided
Fan Zhang

Bug Description

Description
===========

In nova api reference [1], we know that we can list instances by status or vm_state, note that vm_state should work for admin only. But actually, listing instances by vm_state does not work as excepted in queens 17.0.3. I checked the master branch, it should have the same issue.

I added some logs and did the following tests:

* searching by status:

curl -g -i -X GET http://<url>:<port>/v2.1/servers/detail?status=SOFT_DELETED

the logs:

Searching by: {'deleted': False, 'vm_state': ['soft-delete'], 'project_id': u'ddc5e1deb69b4b0a83a9cad2ba6dd4c6'} get_all /usr/lib/python2.7/site-packages/nova/compute/api.py:2384
Filters are {'deleted': False, 'vm_state': ['soft-delete'], 'project_id': u'ddc5e1deb69b4b0a83a9cad2ba6dd4c6'} get_all /usr/lib/python2.7/site-packages/nova/compute/api.py:2494

* searching by vm_state:

curl -g -i -X GET http://<url>:<port>/v2.1/servers/detail?vm_state=SOFT_DELETED

the logs:

Searching by: {'deleted': False, u'vm_state': u'SOFT_DELETED', 'project_id': u'ddc5e1deb69b4b0a83a9cad2ba6dd4c6'} get_all /usr/lib/python2.7/site-packages/nova/compute/api.py:2384
Filters are {'deleted': False, u'vm_state': u'SOFT_DELETED', 'project_id': u'ddc5e1deb69b4b0a83a9cad2ba6dd4c6'} get_all /usr/lib/python2.7/site-packages/nova/compute/api.py:2494

As you can see, nova does not process search option 'vm_state' the same way as search option 'status'. And we'll get no servers matched.

[root@hb02-control-10e114e194e30 ~]# openstack server show 19dbdabe-af94-4c4b-b4a0-78b6449a1a9e
+-------------------------------------+-----------------------------------------------------------+
| Field | Value |
+-------------------------------------+-----------------------------------------------------------+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-AZ:availability_zone | public |
| OS-EXT-SRV-ATTR:host | hb02-compute-10e114e194e21 |
| OS-EXT-SRV-ATTR:hypervisor_hostname | hb02-compute-10e114e194e21 |
| OS-EXT-SRV-ATTR:instance_name | instance-19dbdabe-af94-4c4b-b4a0-78b6449a1a9e |
| OS-EXT-STS:power_state | Shutdown |
| OS-EXT-STS:task_state | None |
| OS-EXT-STS:vm_state | soft-delete |
| OS-SRV-USG:launched_at | 2019-12-17T06:26:56.000000 |
| OS-SRV-USG:terminated_at | None |
| accessIPv4 | |
| accessIPv6 | |
| addresses | elbarco-net=12.1.0.3 |
| config_drive | True |
| created | 2019-12-17T06:26:48Z |
| flavor | 1c1g (9556168e-efc3-442c-ac18-976b2dab8e89) |
| hostId | 547e90398648cb4faf266d5d870e658022fd242a1d1412fa99437ca9 |
| id | 19dbdabe-af94-4c4b-b4a0-78b6449a1a9e |
| image | CentOS7.5 (7e8d8df8-de5c-42fc-b952-52ed058c584c) |
| key_name | None |
| name | elbarco-1 |
| project_id | 001a18cadd4b401e9fdeab6c411d9816 |
| properties | |
| security_groups | id='4abfcbbe-524f-411c-b12f-e6a3a719d060', name='default' |
| status | SOFT_DELETED |
| updated | 2019-12-24T14:54:50Z |
| user_id | 8f3e215075c54a998d334ca3582869e5 |
| volumes_attached | |
+-------------------------------------+-----------------------------------------------------------+
[root@hb02-control-10e114e194e30 ~]# curl -g -i -X GET http://<url>:<port>/v2.1/servers/detail?vm_state=SOFT_DELETED -H "OpenStack-API-Version: compute 2.61" -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-OpenStack-Nova-API-Version: 2.61" -H "X-Auth-Token: gAAAAABeAiTzjy8QaVrvfcjSGKhtyGBKHEqAt8FguFwBe7-bzq8c5LaYqhJOk0uqIVBbO_lKNT_8xl-OgukvXUFPJM_lB1jiwTPEm6R4C6UMuIZM_vK93oMK4wWyZIZ5IDHR5jQH2RajBrThnf6oc-jomAXn5rV-E1t-toQNbAK0JGDXuSkbbT4"
HTTP/1.1 200 OK
X-Openstack-Nova-Api-Version: 2.61
X-Compute-Request-Id: req-d91cf95f-4bef-48aa-abf1-2d350a33092f
X-Openstack-Request-Id: req-d91cf95f-4bef-48aa-abf1-2d350a33092f
Vary: X-OpenStack-Nova-API-Version
Openstack-Api-Version: compute 2.61
Date: Tue, 24 Dec 2019 14:55:12 GMT
Content-Type: application/json
content-length: 15

{"servers": []}

Related bug: https://bugs.launchpad.net/nova/+bug/1789455

References
==========

[1].https://docs.openstack.org/api-ref/compute/?expanded=delete-server-detail,force-delete-server-forcedelete-action-detail,list-servers-detail#list-server-request

Fan Zhang (fanzhang) on 2019-12-24
Changed in nova:
assignee: nobody → Fan Zhang (fanzhang)
Fan Zhang (fanzhang) on 2019-12-24
description: updated
description: updated
Fan Zhang (fanzhang) on 2019-12-24
description: updated

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

Changed in nova:
status: New → In Progress
Fan Zhang (fanzhang) on 2019-12-25
summary: - Listing servers by vm_state does not work
+ Listing SOFT_DELETED servers by vm_state does not work
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers