diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index c54cb8bfb8..5391d95e15 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -38,7 +38,6 @@ CONF = nova.conf.CONF LOG = logging.getLogger(__name__) QUOTAS = quota.QUOTAS - POWER_ON = 'POWER_ON' POWER_OFF = 'POWER_OFF' diff --git a/nova/api/openstack/compute/schemas/servers.py b/nova/api/openstack/compute/schemas/servers.py index 0ebba08a79..a6f7216271 100644 --- a/nova/api/openstack/compute/schemas/servers.py +++ b/nova/api/openstack/compute/schemas/servers.py @@ -731,6 +731,72 @@ show_query = { 'additionalProperties': True, } +_server_status = { + 'type': 'string', + 'enum': [ + 'ACTIVE', + 'BUILD', + 'DELETED', + 'ERROR', + 'HARD_REBOOT', + 'MIGRATING', + 'PASSWORD', + 'PAUSED', + 'REBOOT', + 'REBUILD', + 'RESCUE', + 'RESIZE', + 'REVERT_RESIZE', + 'SHELVED', + 'SHELVED_OFFLOADED', + 'SHUTOFF', + 'SOFT_DELETED', + 'SUSPENDED', + 'VERIFY_RESIZE', + ], +} + +index_response = { + 'type': 'object', + 'properties': { + 'servers': { + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'id': {'type': 'string', 'format': 'uuid'}, + 'links': response_types.links, + 'name': {'type': 'string'}, + }, + 'required': ['id', 'links', 'name'], + 'additionalProperties': False, + }, + }, + 'servers_links': response_types.collection_links, + }, + 'required': ['servers'], + 'additionalProperties': False, +} + +# v2.69 add an alternative representation for instances from down cells. name +# is gone, status is in. +index_response_v269 = copy.deepcopy(index_response) +index_response_v269['properties']['servers']['items'] = { + 'oneOf': [ + index_response_v269['properties']['servers']['items'], + { + 'type': 'object', + 'properties': { + 'id': {'type': 'string', 'format': 'uuid'}, + 'links': response_types.links, + 'status': {'type': 'string', 'const': 'UNKNOWN'}, + }, + 'required': ['id', 'links', 'status'], + 'additionalProperties': False, + }, + ], +} + _server_cell_down_response = { 'type': 'object', 'properties': { @@ -929,7 +995,7 @@ _server_response = { 'additionalProperties': False, }, }, - 'status': {'type': 'string'}, + 'status': _server_status, 'tenant_id': parameter_types.project_id, 'updated': {'type': 'string', 'format': 'date-time'}, 'user_id': parameter_types.user_id, @@ -1296,7 +1362,7 @@ rebuild_response = { }, 'name': {'type': ['string', 'null']}, 'progress': {'type': ['null', 'number']}, - 'status': {'type': 'string'}, + 'status': _server_status, 'tenant_id': parameter_types.project_id, 'updated': {'type': 'string', 'format': 'date-time'}, 'user_id': parameter_types.user_id, diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index d3fb689efb..60562165b7 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -113,11 +113,13 @@ class ServersController(wsgi.Controller): self.compute_api = compute.API() @wsgi.expected_errors((400, 403)) - @validation.query_schema(schema.query_params_v275, '2.75') - @validation.query_schema(schema.query_params_v273, '2.73', '2.74') - @validation.query_schema(schema.query_params_v266, '2.66', '2.72') - @validation.query_schema(schema.query_params_v226, '2.26', '2.65') @validation.query_schema(schema.query_params_v21, '2.1', '2.25') + @validation.query_schema(schema.query_params_v226, '2.26', '2.65') + @validation.query_schema(schema.query_params_v266, '2.66', '2.72') + @validation.query_schema(schema.query_params_v273, '2.73', '2.74') + @validation.query_schema(schema.query_params_v275, '2.75') + @validation.response_body_schema(schema.index_response, '2.1', '2.68') + @validation.response_body_schema(schema.index_response_v269, '2.69') def index(self, req): """Returns a list of server names and ids for a given user.""" context = req.environ['nova.context'] diff --git a/nova/tests/unit/api/openstack/compute/test_servers.py b/nova/tests/unit/api/openstack/compute/test_servers.py index 3a721bbfee..bd2951c875 100644 --- a/nova/tests/unit/api/openstack/compute/test_servers.py +++ b/nova/tests/unit/api/openstack/compute/test_servers.py @@ -454,7 +454,10 @@ class ServersControllerTest(_ServersControllerTest): ctxt = context.RequestContext('fake', fakes.FAKE_PROJECT_ID) return fake_instance.fake_instance_obj( ctxt, expected_attrs=expected_attrs, - project_id=self.request.environ['nova.context'].project_id) + project_id=self.request.environ['nova.context'].project_id, + task_state=None, + vm_state=vm_states.ACTIVE, + ) self.mock_get.side_effect = fake_get self.controller.show(self.request, FAKE_UUID)