Merge "api: Remove use of microversion constants"
This commit is contained in:
commit
3748335cf0
@ -36,8 +36,6 @@ from nova import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
UUID_FOR_ID_MIN_VERSION = '2.53'
|
||||
|
||||
|
||||
class HypervisorsController(wsgi.Controller):
|
||||
"""The Hypervisors API controller for the OpenStack API."""
|
||||
@ -56,7 +54,7 @@ class HypervisorsController(wsgi.Controller):
|
||||
alive = self.servicegroup_api.service_is_up(service)
|
||||
# The 2.53 microversion returns the compute node uuid rather than id.
|
||||
uuid_for_id = api_version_request.is_supported(
|
||||
req, min_version=UUID_FOR_ID_MIN_VERSION)
|
||||
req, min_version="2.53")
|
||||
|
||||
hyp_dict = {
|
||||
'id': hypervisor.uuid if uuid_for_id else hypervisor.id,
|
||||
@ -154,8 +152,7 @@ class HypervisorsController(wsgi.Controller):
|
||||
# The 2.53 microversion moves the search and servers routes into
|
||||
# GET /os-hypervisors and GET /os-hypervisors/detail with query
|
||||
# parameters.
|
||||
if api_version_request.is_supported(
|
||||
req, min_version=UUID_FOR_ID_MIN_VERSION):
|
||||
if api_version_request.is_supported(req, min_version="2.53"):
|
||||
hypervisor_match = req.GET.get('hypervisor_hostname_pattern')
|
||||
with_servers = strutils.bool_from_string(
|
||||
req.GET.get('with_servers', False), strict=True)
|
||||
@ -226,10 +223,9 @@ class HypervisorsController(wsgi.Controller):
|
||||
hypervisors_dict['hypervisors_links'] = hypervisors_links
|
||||
return hypervisors_dict
|
||||
|
||||
@wsgi.Controller.api_version(UUID_FOR_ID_MIN_VERSION)
|
||||
@wsgi.Controller.api_version("2.53")
|
||||
@wsgi.expected_errors((400, 404))
|
||||
@validation.query_schema(hyper_schema.index_query_v253,
|
||||
UUID_FOR_ID_MIN_VERSION)
|
||||
@validation.query_schema(hyper_schema.index_query_v253, "2.53")
|
||||
def index(self, req):
|
||||
"""Starting with the 2.53 microversion, the id field in the response
|
||||
is the compute_nodes.uuid value. Also, the search and servers routes
|
||||
@ -259,10 +255,9 @@ class HypervisorsController(wsgi.Controller):
|
||||
return self._get_hypervisors(req, detail=False, limit=limit,
|
||||
marker=marker, links=links)
|
||||
|
||||
@wsgi.Controller.api_version(UUID_FOR_ID_MIN_VERSION)
|
||||
@wsgi.Controller.api_version("2.53")
|
||||
@wsgi.expected_errors((400, 404))
|
||||
@validation.query_schema(hyper_schema.index_query_v253,
|
||||
UUID_FOR_ID_MIN_VERSION)
|
||||
@validation.query_schema(hyper_schema.index_query_v253, "2.53")
|
||||
def detail(self, req):
|
||||
"""Starting with the 2.53 microversion, the id field in the response
|
||||
is the compute_nodes.uuid value. Also, the search and servers routes
|
||||
@ -304,9 +299,7 @@ class HypervisorsController(wsgi.Controller):
|
||||
:raises: webob.exc.HTTPNotFound if the requested microversion is
|
||||
less than 2.53 and the id is not an integer.
|
||||
"""
|
||||
expect_uuid = api_version_request.is_supported(
|
||||
req, min_version=UUID_FOR_ID_MIN_VERSION)
|
||||
if expect_uuid:
|
||||
if api_version_request.is_supported(req, min_version="2.53"):
|
||||
if not uuidutils.is_uuid_like(hypervisor_id):
|
||||
msg = _('Invalid uuid %s') % hypervisor_id
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
@ -318,10 +311,9 @@ class HypervisorsController(wsgi.Controller):
|
||||
hypervisor_id)
|
||||
raise webob.exc.HTTPNotFound(explanation=msg)
|
||||
|
||||
@wsgi.Controller.api_version(UUID_FOR_ID_MIN_VERSION)
|
||||
@wsgi.Controller.api_version("2.53")
|
||||
@wsgi.expected_errors((400, 404))
|
||||
@validation.query_schema(hyper_schema.show_query_v253,
|
||||
UUID_FOR_ID_MIN_VERSION)
|
||||
@validation.query_schema(hyper_schema.show_query_v253, "2.53")
|
||||
def show(self, req, id):
|
||||
"""The 2.53 microversion requires that the id is a uuid and as a result
|
||||
it can also return a 400 response if an invalid uuid is passed.
|
||||
|
@ -40,9 +40,6 @@ LOG = logging.getLogger(__name__)
|
||||
CONF = nova.conf.CONF
|
||||
|
||||
|
||||
GROUP_POLICY_OBJ_MICROVERSION = "2.64"
|
||||
|
||||
|
||||
def _get_not_deleted(context, uuids):
|
||||
mappings = objects.InstanceMappingList.get_by_instance_uuids(
|
||||
context, uuids)
|
||||
@ -97,8 +94,7 @@ class ServerGroupController(wsgi.Controller):
|
||||
server_group = {}
|
||||
server_group['id'] = group.uuid
|
||||
server_group['name'] = group.name
|
||||
if api_version_request.is_supported(
|
||||
req, min_version=GROUP_POLICY_OBJ_MICROVERSION):
|
||||
if api_version_request.is_supported(req, min_version='2.64'):
|
||||
server_group['policy'] = group.policy
|
||||
server_group['rules'] = group.rules
|
||||
else:
|
||||
@ -183,7 +179,7 @@ class ServerGroupController(wsgi.Controller):
|
||||
@wsgi.expected_errors((400, 403, 409))
|
||||
@validation.schema(schema.create, "2.0", "2.14")
|
||||
@validation.schema(schema.create_v215, "2.15", "2.63")
|
||||
@validation.schema(schema.create_v264, GROUP_POLICY_OBJ_MICROVERSION)
|
||||
@validation.schema(schema.create_v264, "2.64")
|
||||
def create(self, req, body):
|
||||
"""Creates a new server group."""
|
||||
context = req.environ['nova.context']
|
||||
@ -203,8 +199,7 @@ class ServerGroupController(wsgi.Controller):
|
||||
|
||||
vals = body['server_group']
|
||||
|
||||
if api_version_request.is_supported(
|
||||
req, GROUP_POLICY_OBJ_MICROVERSION):
|
||||
if api_version_request.is_supported(req, "2.64"):
|
||||
policy = vals['policy']
|
||||
rules = vals.get('rules', {})
|
||||
if policy != 'anti-affinity' and rules:
|
||||
|
@ -45,7 +45,6 @@ from nova.policies import servers as server_policies
|
||||
from nova import utils
|
||||
|
||||
TAG_SEARCH_FILTERS = ('tags', 'tags-any', 'not-tags', 'not-tags-any')
|
||||
PARTIAL_CONSTRUCT_FOR_CELL_DOWN_MIN_VERSION = '2.69'
|
||||
PAGING_SORTING_PARAMS = ('sort_key', 'sort_dir', 'limit', 'marker')
|
||||
|
||||
CONF = nova.conf.CONF
|
||||
@ -148,7 +147,7 @@ class ServersController(wsgi.Controller):
|
||||
@staticmethod
|
||||
def _is_cell_down_supported(req, search_opts):
|
||||
cell_down_support = api_version_request.is_supported(
|
||||
req, min_version=PARTIAL_CONSTRUCT_FOR_CELL_DOWN_MIN_VERSION)
|
||||
req, min_version='2.69')
|
||||
|
||||
if cell_down_support:
|
||||
# NOTE(tssurya): Minimal constructs would be returned from the down
|
||||
@ -464,7 +463,7 @@ class ServersController(wsgi.Controller):
|
||||
"""Returns server details by server id."""
|
||||
context = req.environ['nova.context']
|
||||
cell_down_support = api_version_request.is_supported(
|
||||
req, min_version=PARTIAL_CONSTRUCT_FOR_CELL_DOWN_MIN_VERSION)
|
||||
req, min_version='2.69')
|
||||
show_server_groups = api_version_request.is_supported(
|
||||
req, min_version='2.71')
|
||||
|
||||
|
@ -32,9 +32,6 @@ from nova.scheduler.client import report
|
||||
from nova import servicegroup
|
||||
from nova import utils
|
||||
|
||||
UUID_FOR_ID_MIN_VERSION = '2.53'
|
||||
PARTIAL_CONSTRUCT_FOR_CELL_DOWN_MIN_VERSION = '2.69'
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -62,7 +59,7 @@ class ServiceController(wsgi.Controller):
|
||||
context = req.environ['nova.context']
|
||||
|
||||
cell_down_support = api_version_request.is_supported(
|
||||
req, min_version=PARTIAL_CONSTRUCT_FOR_CELL_DOWN_MIN_VERSION)
|
||||
req, min_version='2.69')
|
||||
|
||||
_services = [
|
||||
s
|
||||
@ -102,7 +99,7 @@ class ServiceController(wsgi.Controller):
|
||||
updated_time = self.servicegroup_api.get_updated_time(svc)
|
||||
|
||||
uuid_for_id = api_version_request.is_supported(
|
||||
req, min_version=UUID_FOR_ID_MIN_VERSION)
|
||||
req, min_version='2.53')
|
||||
|
||||
if 'availability_zone' not in svc:
|
||||
# The service wasn't loaded with the AZ so we need to do it here.
|
||||
@ -130,8 +127,8 @@ class ServiceController(wsgi.Controller):
|
||||
|
||||
def _get_services_list(self, req, additional_fields=()):
|
||||
_services = self._get_services(req)
|
||||
cell_down_support = api_version_request.is_supported(req,
|
||||
min_version=PARTIAL_CONSTRUCT_FOR_CELL_DOWN_MIN_VERSION)
|
||||
cell_down_support = api_version_request.is_supported(
|
||||
req, min_version='2.69')
|
||||
return [self._get_service_detail(svc, additional_fields, req,
|
||||
cell_down_support=cell_down_support) for svc in _services]
|
||||
|
||||
@ -251,8 +248,7 @@ class ServiceController(wsgi.Controller):
|
||||
context = req.environ['nova.context']
|
||||
context.can(services_policies.BASE_POLICY_NAME % 'delete', target={})
|
||||
|
||||
if api_version_request.is_supported(
|
||||
req, min_version=UUID_FOR_ID_MIN_VERSION):
|
||||
if api_version_request.is_supported(req, min_version='2.53'):
|
||||
if not uuidutils.is_uuid_like(id):
|
||||
msg = _('Invalid uuid %s') % id
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
@ -411,9 +407,9 @@ class ServiceController(wsgi.Controller):
|
||||
|
||||
return self._perform_action(req, id, body, actions)
|
||||
|
||||
@wsgi.Controller.api_version(UUID_FOR_ID_MIN_VERSION) # noqa F811
|
||||
@wsgi.Controller.api_version('2.53') # noqa F811
|
||||
@wsgi.expected_errors((400, 404))
|
||||
@validation.schema(services.service_update_v2_53, UUID_FOR_ID_MIN_VERSION)
|
||||
@validation.schema(services.service_update_v2_53, '2.53')
|
||||
def update(self, req, id, body): # noqa
|
||||
"""Perform service update
|
||||
|
||||
|
@ -986,7 +986,7 @@ class HypervisorsTestV252(HypervisorsTestV233):
|
||||
|
||||
|
||||
class HypervisorsTestV253(HypervisorsTestV252):
|
||||
api_version = hypervisors_v21.UUID_FOR_ID_MIN_VERSION
|
||||
api_version = '2.53'
|
||||
expect_uuid_for_id = True
|
||||
|
||||
# This is an expected response for index().
|
||||
|
@ -1154,8 +1154,7 @@ class ServicesTestV253(test.TestCase):
|
||||
super(ServicesTestV253, self).setUp()
|
||||
self.controller = services_v21.ServiceController()
|
||||
self.controller.servicegroup_api = FakeServiceGroupAPI()
|
||||
self.req = fakes.HTTPRequest.blank(
|
||||
'', version=services_v21.UUID_FOR_ID_MIN_VERSION)
|
||||
self.req = fakes.HTTPRequest.blank('', version='2.53')
|
||||
|
||||
def assert_services_equal(self, s1, s2):
|
||||
for k in ('binary', 'host'):
|
||||
@ -1253,8 +1252,7 @@ class ServicesTestV253(test.TestCase):
|
||||
self.assertDictEqual(expected_resp, resp)
|
||||
|
||||
# Now enable the service to see the response change.
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'', version=services_v21.UUID_FOR_ID_MIN_VERSION)
|
||||
req = fakes.HTTPRequest.blank('', version='2.53')
|
||||
resp = self.controller.update(req, service.uuid,
|
||||
body={'status': 'enabled'})
|
||||
expected_resp['service']['status'] = 'enabled'
|
||||
|
@ -64,8 +64,7 @@ class ServicesPolicyTest(base.BasePolicyTest):
|
||||
|
||||
def test_update_service_policy(self):
|
||||
rule_name = "os_compute_api:os-services:update"
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'', version=services_v21.UUID_FOR_ID_MIN_VERSION)
|
||||
req = fakes.HTTPRequest.blank('', version='2.53')
|
||||
service = self.start_service(
|
||||
'compute', 'fake-compute-host').service_ref
|
||||
with mock.patch('nova.compute.api.HostAPI.service_update'):
|
||||
|
Loading…
Reference in New Issue
Block a user