diff --git a/ironic/api/__init__.py b/ironic/api/__init__.py index e69de29bb2..87044ae67e 100644 --- a/ironic/api/__init__.py +++ b/ironic/api/__init__.py @@ -0,0 +1,18 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import pecan + + +request = pecan.request +response = pecan.response +del pecan diff --git a/ironic/api/controllers/link.py b/ironic/api/controllers/link.py index 9d3a9096e7..007e292733 100644 --- a/ironic/api/controllers/link.py +++ b/ironic/api/controllers/link.py @@ -13,15 +13,15 @@ # License for the specific language governing permissions and limitations # under the License. -import pecan from wsme import types as wtypes +from ironic import api from ironic.api.controllers import base def build_url(resource, resource_args, bookmark=False, base_url=None): if base_url is None: - base_url = pecan.request.public_url + base_url = api.request.public_url template = '%(url)s/%(res)s' if bookmark else '%(url)s/v1/%(res)s' # FIXME(lucasagomes): I'm getting a 404 when doing a GET on diff --git a/ironic/api/controllers/v1/__init__.py b/ironic/api/controllers/v1/__init__.py index 322337e925..262de44174 100644 --- a/ironic/api/controllers/v1/__init__.py +++ b/ironic/api/controllers/v1/__init__.py @@ -23,6 +23,7 @@ from pecan import rest from webob import exc from wsme import types as wtypes +from ironic import api from ironic.api.controllers import base from ironic.api.controllers import link from ironic.api.controllers.v1 import allocation @@ -123,7 +124,7 @@ class V1(base.APIBase): def convert(): v1 = V1() v1.id = "v1" - v1.links = [link.Link.make_link('self', pecan.request.public_url, + v1.links = [link.Link.make_link('self', api.request.public_url, 'v1', '', bookmark=True), link.Link.make_link('describedby', 'https://docs.openstack.org', @@ -133,100 +134,100 @@ class V1(base.APIBase): ] v1.media_types = [MediaType('application/json', 'application/vnd.openstack.ironic.v1+json')] - v1.chassis = [link.Link.make_link('self', pecan.request.public_url, + v1.chassis = [link.Link.make_link('self', api.request.public_url, 'chassis', ''), link.Link.make_link('bookmark', - pecan.request.public_url, + api.request.public_url, 'chassis', '', bookmark=True) ] - v1.nodes = [link.Link.make_link('self', pecan.request.public_url, + v1.nodes = [link.Link.make_link('self', api.request.public_url, 'nodes', ''), link.Link.make_link('bookmark', - pecan.request.public_url, + api.request.public_url, 'nodes', '', bookmark=True) ] - v1.ports = [link.Link.make_link('self', pecan.request.public_url, + v1.ports = [link.Link.make_link('self', api.request.public_url, 'ports', ''), link.Link.make_link('bookmark', - pecan.request.public_url, + api.request.public_url, 'ports', '', bookmark=True) ] if utils.allow_portgroups(): v1.portgroups = [ - link.Link.make_link('self', pecan.request.public_url, + link.Link.make_link('self', api.request.public_url, 'portgroups', ''), - link.Link.make_link('bookmark', pecan.request.public_url, + link.Link.make_link('bookmark', api.request.public_url, 'portgroups', '', bookmark=True) ] - v1.drivers = [link.Link.make_link('self', pecan.request.public_url, + v1.drivers = [link.Link.make_link('self', api.request.public_url, 'drivers', ''), link.Link.make_link('bookmark', - pecan.request.public_url, + api.request.public_url, 'drivers', '', bookmark=True) ] if utils.allow_volume(): v1.volume = [ link.Link.make_link('self', - pecan.request.public_url, + api.request.public_url, 'volume', ''), link.Link.make_link('bookmark', - pecan.request.public_url, + api.request.public_url, 'volume', '', bookmark=True) ] if utils.allow_ramdisk_endpoints(): - v1.lookup = [link.Link.make_link('self', pecan.request.public_url, + v1.lookup = [link.Link.make_link('self', api.request.public_url, 'lookup', ''), link.Link.make_link('bookmark', - pecan.request.public_url, + api.request.public_url, 'lookup', '', bookmark=True) ] v1.heartbeat = [link.Link.make_link('self', - pecan.request.public_url, + api.request.public_url, 'heartbeat', ''), link.Link.make_link('bookmark', - pecan.request.public_url, + api.request.public_url, 'heartbeat', '', bookmark=True) ] if utils.allow_expose_conductors(): v1.conductors = [link.Link.make_link('self', - pecan.request.public_url, + api.request.public_url, 'conductors', ''), link.Link.make_link('bookmark', - pecan.request.public_url, + api.request.public_url, 'conductors', '', bookmark=True) ] if utils.allow_allocations(): v1.allocations = [link.Link.make_link('self', - pecan.request.public_url, + api.request.public_url, 'allocations', ''), link.Link.make_link('bookmark', - pecan.request.public_url, + api.request.public_url, 'allocations', '', bookmark=True) ] if utils.allow_expose_events(): - v1.events = [link.Link.make_link('self', pecan.request.public_url, + v1.events = [link.Link.make_link('self', api.request.public_url, 'events', ''), link.Link.make_link('bookmark', - pecan.request.public_url, + api.request.public_url, 'events', '', bookmark=True) ] if utils.allow_deploy_templates(): v1.deploy_templates = [ link.Link.make_link('self', - pecan.request.public_url, + api.request.public_url, 'deploy_templates', ''), link.Link.make_link('bookmark', - pecan.request.public_url, + api.request.public_url, 'deploy_templates', '', bookmark=True) ] @@ -281,19 +282,19 @@ class Controller(rest.RestController): @pecan.expose() def _route(self, args, request=None): - v = base.Version(pecan.request.headers, versions.min_version_string(), + v = base.Version(api.request.headers, versions.min_version_string(), versions.max_version_string()) # Always set the min and max headers - pecan.response.headers[base.Version.min_string] = ( + api.response.headers[base.Version.min_string] = ( versions.min_version_string()) - pecan.response.headers[base.Version.max_string] = ( + api.response.headers[base.Version.max_string] = ( versions.max_version_string()) # assert that requested version is supported - self._check_version(v, pecan.response.headers) - pecan.response.headers[base.Version.string] = str(v) - pecan.request.version = v + self._check_version(v, api.response.headers) + api.response.headers[base.Version.string] = str(v) + api.request.version = v return super(Controller, self)._route(args, request) diff --git a/ironic/api/controllers/v1/allocation.py b/ironic/api/controllers/v1/allocation.py index bcf70127e7..22c20947de 100644 --- a/ironic/api/controllers/v1/allocation.py +++ b/ironic/api/controllers/v1/allocation.py @@ -20,6 +20,7 @@ from webob import exc as webob_exc import wsme from wsme import types as wtypes +from ironic import api from ironic.api.controllers import base from ironic.api.controllers import link from ironic.api.controllers.v1 import collection @@ -112,7 +113,7 @@ class Allocation(base.APIBase): if rpc_allocation.node_id: try: allocation.node_uuid = objects.Node.get_by_id( - pecan.request.context, + api.request.context, rpc_allocation.node_id).uuid except exception.NodeNotFound: allocation.node_uuid = None @@ -129,7 +130,7 @@ class Allocation(base.APIBase): allocation.traits = [] allocation = cls._convert_with_links(allocation, - pecan.request.host_url) + api.request.host_url) if not sanitize: return allocation @@ -214,7 +215,7 @@ class AllocationsController(pecan.rest.RestController): def _route(self, args, request=None): if not api_utils.allow_allocations(): msg = _("The API version does not allow allocations") - if pecan.request.method == "GET": + if api.request.method == "GET": raise webob_exc.HTTPNotFound(msg) else: raise webob_exc.HTTPMethodNotAllowed(msg) @@ -245,7 +246,7 @@ class AllocationsController(pecan.rest.RestController): marker_obj = None if marker: - marker_obj = objects.Allocation.get_by_uuid(pecan.request.context, + marker_obj = objects.Allocation.get_by_uuid(api.request.context, marker) if node_ident: @@ -268,7 +269,7 @@ class AllocationsController(pecan.rest.RestController): if value is not None: filters[key] = value - allocations = objects.Allocation.list(pecan.request.context, + allocations = objects.Allocation.list(api.request.context, limit=limit, marker=marker_obj, sort_key=sort_key, @@ -302,7 +303,7 @@ class AllocationsController(pecan.rest.RestController): :param fields: Optional, a list with a specified set of fields of the resource to be returned. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:allocation:get', cdict, cdict) return self._get_allocations_collection(node, resource_class, state, @@ -319,7 +320,7 @@ class AllocationsController(pecan.rest.RestController): :param fields: Optional, a list with a specified set of fields of the resource to be returned. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:allocation:get', cdict, cdict) rpc_allocation = api_utils.get_rpc_allocation_with_suffix( @@ -334,7 +335,7 @@ class AllocationsController(pecan.rest.RestController): :param allocation: an allocation within the request body. """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:allocation:create', cdict, cdict) @@ -372,7 +373,7 @@ class AllocationsController(pecan.rest.RestController): if allocation.candidate_nodes: # Convert nodes from names to UUIDs and check their validity try: - converted = pecan.request.dbapi.check_node_list( + converted = api.request.dbapi.check_node_list( allocation.candidate_nodes) except exception.NodeNotFound as exc: exc.code = http_client.BAD_REQUEST @@ -396,20 +397,20 @@ class AllocationsController(pecan.rest.RestController): new_allocation = objects.Allocation(context, **all_dict) if node: new_allocation.node_id = node.id - topic = pecan.request.rpcapi.get_topic_for(node) + topic = api.request.rpcapi.get_topic_for(node) else: - topic = pecan.request.rpcapi.get_random_topic() + topic = api.request.rpcapi.get_random_topic() notify.emit_start_notification(context, new_allocation, 'create') with notify.handle_error_notification(context, new_allocation, 'create'): - new_allocation = pecan.request.rpcapi.create_allocation( + new_allocation = api.request.rpcapi.create_allocation( context, new_allocation, topic) notify.emit_end_notification(context, new_allocation, 'create') # Set the HTTP Location Header - pecan.response.location = link.build_url('allocations', - new_allocation.uuid) + api.response.location = link.build_url('allocations', + new_allocation.uuid) return Allocation.convert_with_links(new_allocation) def _validate_patch(self, patch): @@ -433,7 +434,7 @@ class AllocationsController(pecan.rest.RestController): if not api_utils.allow_allocation_update(): raise webob_exc.HTTPMethodNotAllowed(_( "The API version does not allow updating allocations")) - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:allocation:update', cdict, cdict) self._validate_patch(patch) @@ -475,14 +476,14 @@ class AllocationsController(pecan.rest.RestController): :param allocation_ident: UUID or logical name of an allocation. """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:allocation:delete', cdict, cdict) rpc_allocation = api_utils.get_rpc_allocation_with_suffix( allocation_ident) if rpc_allocation.node_id: - node_uuid = objects.Node.get_by_id(pecan.request.context, + node_uuid = objects.Node.get_by_id(api.request.context, rpc_allocation.node_id).uuid else: node_uuid = None @@ -491,9 +492,9 @@ class AllocationsController(pecan.rest.RestController): node_uuid=node_uuid) with notify.handle_error_notification(context, rpc_allocation, 'delete', node_uuid=node_uuid): - topic = pecan.request.rpcapi.get_random_topic() - pecan.request.rpcapi.destroy_allocation(context, rpc_allocation, - topic) + topic = api.request.rpcapi.get_random_topic() + api.request.rpcapi.destroy_allocation(context, rpc_allocation, + topic) notify.emit_end_notification(context, rpc_allocation, 'delete', node_uuid=node_uuid) @@ -518,7 +519,7 @@ class NodeAllocationController(pecan.rest.RestController): @METRICS.timer('NodeAllocationController.get_all') @expose.expose(Allocation, types.listtype) def get_all(self, fields=None): - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:allocation:get', cdict, cdict) result = self.inner._get_allocations_collection(self.parent_node_ident, @@ -533,13 +534,13 @@ class NodeAllocationController(pecan.rest.RestController): @METRICS.timer('NodeAllocationController.delete') @expose.expose(None, status_code=http_client.NO_CONTENT) def delete(self): - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:allocation:delete', cdict, cdict) rpc_node = api_utils.get_rpc_node_with_suffix(self.parent_node_ident) allocations = objects.Allocation.list( - pecan.request.context, + api.request.context, filters={'node_uuid': rpc_node.uuid}) try: @@ -554,8 +555,8 @@ class NodeAllocationController(pecan.rest.RestController): with notify.handle_error_notification(context, rpc_allocation, 'delete', node_uuid=rpc_node.uuid): - topic = pecan.request.rpcapi.get_random_topic() - pecan.request.rpcapi.destroy_allocation(context, rpc_allocation, - topic) + topic = api.request.rpcapi.get_random_topic() + api.request.rpcapi.destroy_allocation(context, rpc_allocation, + topic) notify.emit_end_notification(context, rpc_allocation, 'delete', node_uuid=rpc_node.uuid) diff --git a/ironic/api/controllers/v1/bios.py b/ironic/api/controllers/v1/bios.py index a9587b39d5..dc150cbba0 100644 --- a/ironic/api/controllers/v1/bios.py +++ b/ironic/api/controllers/v1/bios.py @@ -14,11 +14,11 @@ # under the License. from ironic_lib import metrics_utils -import pecan from pecan import rest import wsme from wsme import types as wtypes +from ironic import api from ironic.api.controllers import base from ironic.api.controllers import link from ironic.api.controllers.v1 import types @@ -64,7 +64,7 @@ class BIOSSetting(base.APIBase): def convert_with_links(cls, rpc_bios, node_uuid): """Add links to the bios setting.""" bios = BIOSSetting(**rpc_bios.as_dict()) - return cls._convert_with_links(bios, node_uuid, pecan.request.host_url) + return cls._convert_with_links(bios, node_uuid, api.request.host_url) class BIOSSettingsCollection(wtypes.Base): @@ -96,12 +96,12 @@ class NodeBiosController(rest.RestController): @expose.expose(BIOSSettingsCollection) def get_all(self): """List node bios settings.""" - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:bios:get', cdict, cdict) node = api_utils.get_rpc_node(self.node_ident) settings = objects.BIOSSettingList.get_by_node_id( - pecan.request.context, node.id) + api.request.context, node.id) return BIOSSettingsCollection.collection_from_list(self.node_ident, settings) @@ -112,12 +112,12 @@ class NodeBiosController(rest.RestController): :param setting_name: Logical name of the setting to retrieve. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:bios:get', cdict, cdict) node = api_utils.get_rpc_node(self.node_ident) try: - setting = objects.BIOSSetting.get(pecan.request.context, node.id, + setting = objects.BIOSSetting.get(api.request.context, node.id, setting_name) except exception.BIOSSettingNotFound: raise exception.BIOSSettingNotFound(node=node.uuid, diff --git a/ironic/api/controllers/v1/chassis.py b/ironic/api/controllers/v1/chassis.py index 752135bd65..09b0d0f8be 100644 --- a/ironic/api/controllers/v1/chassis.py +++ b/ironic/api/controllers/v1/chassis.py @@ -17,12 +17,12 @@ import datetime from ironic_lib import metrics_utils from oslo_utils import uuidutils -import pecan from pecan import rest from six.moves import http_client import wsme from wsme import types as wtypes +from ironic import api from ironic.api.controllers import base from ironic.api.controllers import link from ironic.api.controllers.v1 import collection @@ -104,7 +104,7 @@ class Chassis(base.APIBase): if fields is not None: api_utils.check_for_invalid_fields(fields, chassis.as_dict()) - chassis = cls._convert_with_links(chassis, pecan.request.public_url, + chassis = cls._convert_with_links(chassis, api.request.public_url, fields) if not sanitize: @@ -194,7 +194,7 @@ class ChassisController(rest.RestController): sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: - marker_obj = objects.Chassis.get_by_uuid(pecan.request.context, + marker_obj = objects.Chassis.get_by_uuid(api.request.context, marker) if sort_key in self.invalid_sort_key_list: @@ -202,7 +202,7 @@ class ChassisController(rest.RestController): _("The sort_key value %(key)s is an invalid field for sorting") % {'key': sort_key}) - chassis = objects.Chassis.list(pecan.request.context, limit, + chassis = objects.Chassis.list(api.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) parameters = {} @@ -233,7 +233,7 @@ class ChassisController(rest.RestController): :param fields: Optional, a list with a specified set of fields of the resource to be returned. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:chassis:get', cdict, cdict) api_utils.check_allow_specify_fields(fields) @@ -258,11 +258,11 @@ class ChassisController(rest.RestController): :param sort_key: column to sort results by. Default: id. :param sort_dir: direction to sort. "asc" or "desc". Default: asc. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:chassis:get', cdict, cdict) # /detail should only work against collections - parent = pecan.request.path.split('/')[:-1][-1] + parent = api.request.path.split('/')[:-1][-1] if parent != "chassis": raise exception.HTTPNotFound() @@ -279,11 +279,11 @@ class ChassisController(rest.RestController): :param fields: Optional, a list with a specified set of fields of the resource to be returned. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:chassis:get', cdict, cdict) api_utils.check_allow_specify_fields(fields) - rpc_chassis = objects.Chassis.get_by_uuid(pecan.request.context, + rpc_chassis = objects.Chassis.get_by_uuid(api.request.context, chassis_uuid) return Chassis.convert_with_links(rpc_chassis, fields=fields) @@ -294,7 +294,7 @@ class ChassisController(rest.RestController): :param chassis: a chassis within the request body. """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:chassis:create', cdict, cdict) @@ -308,7 +308,7 @@ class ChassisController(rest.RestController): new_chassis.create() notify.emit_end_notification(context, new_chassis, 'create') # Set the HTTP Location Header - pecan.response.location = link.build_url('chassis', new_chassis.uuid) + api.response.location = link.build_url('chassis', new_chassis.uuid) return Chassis.convert_with_links(new_chassis) @METRICS.timer('ChassisController.patch') @@ -320,7 +320,7 @@ class ChassisController(rest.RestController): :param chassis_uuid: UUID of a chassis. :param patch: a json PATCH document to apply to this chassis. """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:chassis:update', cdict, cdict) @@ -353,7 +353,7 @@ class ChassisController(rest.RestController): :param chassis_uuid: UUID of a chassis. """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:chassis:delete', cdict, cdict) diff --git a/ironic/api/controllers/v1/collection.py b/ironic/api/controllers/v1/collection.py index 0328194415..2ff98aedb1 100644 --- a/ironic/api/controllers/v1/collection.py +++ b/ironic/api/controllers/v1/collection.py @@ -13,9 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. -import pecan from wsme import types as wtypes +from ironic import api from ironic.api.controllers import base from ironic.api.controllers import link @@ -48,5 +48,5 @@ class Collection(base.APIBase): 'args': q_args, 'limit': limit, 'marker': getattr(self.collection[-1], self.get_key_field())} - return link.Link.make_link('next', pecan.request.public_url, + return link.Link.make_link('next', api.request.public_url, resource_url, next_args).href diff --git a/ironic/api/controllers/v1/conductor.py b/ironic/api/controllers/v1/conductor.py index b405e3e106..23931cc117 100644 --- a/ironic/api/controllers/v1/conductor.py +++ b/ironic/api/controllers/v1/conductor.py @@ -15,11 +15,11 @@ import datetime from ironic_lib import metrics_utils from oslo_log import log from oslo_utils import timeutils -import pecan from pecan import rest import wsme from wsme import types as wtypes +from ironic import api from ironic.api.controllers import base from ironic.api.controllers import link from ironic.api.controllers.v1 import collection @@ -90,7 +90,7 @@ class Conductor(base.APIBase): api_utils.check_for_invalid_fields(fields, conductor.as_dict()) conductor = cls._convert_with_links(conductor, - pecan.request.public_url, + api.request.public_url, fields=fields) conductor.sanitize(fields) return conductor @@ -175,9 +175,9 @@ class ConductorsController(rest.RestController): marker_obj = None if marker: marker_obj = objects.Conductor.get_by_hostname( - pecan.request.context, marker, online=None) + api.request.context, marker, online=None) - conductors = objects.Conductor.list(pecan.request.context, limit=limit, + conductors = objects.Conductor.list(api.request.context, limit=limit, marker=marker_obj, sort_key=sort_key, sort_dir=sort_dir) @@ -211,7 +211,7 @@ class ConductorsController(rest.RestController): :param detail: Optional, boolean to indicate whether retrieve a list of conductors with detail. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:conductor:get', cdict, cdict) if not api_utils.allow_expose_conductors(): @@ -237,7 +237,7 @@ class ConductorsController(rest.RestController): :param fields: Optional, a list with a specified set of fields of the resource to be returned. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:conductor:get', cdict, cdict) if not api_utils.allow_expose_conductors(): @@ -246,6 +246,6 @@ class ConductorsController(rest.RestController): api_utils.check_allow_specify_fields(fields) api_utils.check_allowed_fields(fields) - conductor = objects.Conductor.get_by_hostname(pecan.request.context, + conductor = objects.Conductor.get_by_hostname(api.request.context, hostname, online=None) return Conductor.convert_with_links(conductor, fields=fields) diff --git a/ironic/api/controllers/v1/deploy_template.py b/ironic/api/controllers/v1/deploy_template.py index 29c1e279b5..a43e222e39 100644 --- a/ironic/api/controllers/v1/deploy_template.py +++ b/ironic/api/controllers/v1/deploy_template.py @@ -24,6 +24,7 @@ from webob import exc as webob_exc import wsme from wsme import types as wtypes +from ironic import api from ironic.api.controllers import base from ironic.api.controllers import link from ironic.api.controllers.v1 import collection @@ -165,7 +166,7 @@ class DeployTemplate(base.APIBase): api_utils.check_for_invalid_fields(fields, template.as_dict()) template = cls._convert_with_links(template, - pecan.request.public_url, + api.request.public_url, fields=fields) if sanitize: template.sanitize(fields) @@ -261,7 +262,7 @@ class DeployTemplatesController(rest.RestController): def _route(self, args, request=None): if not api_utils.allow_deploy_templates(): msg = _("The API version does not allow deploy templates") - if pecan.request.method == "GET": + if api.request.method == "GET": raise webob_exc.HTTPNotFound(msg) else: raise webob_exc.HTTPMethodNotAllowed(msg) @@ -321,10 +322,10 @@ class DeployTemplatesController(rest.RestController): marker_obj = None if marker: marker_obj = objects.DeployTemplate.get_by_uuid( - pecan.request.context, marker) + api.request.context, marker) templates = objects.DeployTemplate.list( - pecan.request.context, limit=limit, marker=marker_obj, + api.request.context, limit=limit, marker=marker_obj, sort_key=sort_key, sort_dir=sort_dir) parameters = {'sort_key': sort_key, 'sort_dir': sort_dir} @@ -363,7 +364,7 @@ class DeployTemplatesController(rest.RestController): """ api_utils.check_policy('baremetal:deploy_template:create') - context = pecan.request.context + context = api.request.context tdict = template.as_dict() # NOTE(mgoddard): UUID is mandatory for notifications payload if not tdict.get('uuid'): @@ -375,8 +376,8 @@ class DeployTemplatesController(rest.RestController): with notify.handle_error_notification(context, new_template, 'create'): new_template.create() # Set the HTTP Location Header - pecan.response.location = link.build_url('deploy_templates', - new_template.uuid) + api.response.location = link.build_url('deploy_templates', + new_template.uuid) api_template = DeployTemplate.convert_with_links(new_template) notify.emit_end_notification(context, new_template, 'create') return api_template @@ -393,7 +394,7 @@ class DeployTemplatesController(rest.RestController): """ api_utils.check_policy('baremetal:deploy_template:update') - context = pecan.request.context + context = api.request.context rpc_template = api_utils.get_rpc_deploy_template_with_suffix( template_ident) @@ -436,7 +437,7 @@ class DeployTemplatesController(rest.RestController): """ api_utils.check_policy('baremetal:deploy_template:delete') - context = pecan.request.context + context = api.request.context rpc_template = api_utils.get_rpc_deploy_template_with_suffix( template_ident) notify.emit_start_notification(context, rpc_template, 'delete') diff --git a/ironic/api/controllers/v1/driver.py b/ironic/api/controllers/v1/driver.py index ce6901d35d..9a6672cd7f 100644 --- a/ironic/api/controllers/v1/driver.py +++ b/ironic/api/controllers/v1/driver.py @@ -14,12 +14,12 @@ # under the License. from ironic_lib import metrics_utils -import pecan from pecan import rest from six.moves import http_client import wsme from wsme import types as wtypes +from ironic import api from ironic.api.controllers import base from ironic.api.controllers import link from ironic.api.controllers.v1 import types @@ -147,20 +147,20 @@ class Driver(base.APIBase): driver.hosts = hosts driver.links = [ link.Link.make_link('self', - pecan.request.public_url, + api.request.public_url, 'drivers', name), link.Link.make_link('bookmark', - pecan.request.public_url, + api.request.public_url, 'drivers', name, bookmark=True) ] if api_utils.allow_links_node_states_and_driver_properties(): driver.properties = [ link.Link.make_link('self', - pecan.request.public_url, + api.request.public_url, 'drivers', name + "/properties"), link.Link.make_link('bookmark', - pecan.request.public_url, + api.request.public_url, 'drivers', name + "/properties", bookmark=True) ] @@ -172,7 +172,7 @@ class Driver(base.APIBase): if detail: if interface_info is None: # TODO(jroll) objectify this - interface_info = (pecan.request.dbapi + interface_info = (api.request.dbapi .list_hardware_type_interfaces([name])) for iface_type in driver_base.ALL_INTERFACES: default = None @@ -233,7 +233,7 @@ class DriverList(base.APIBase): # This is checked in Driver.convert_with_links(), however also # checking here can save us a DB query. if api_utils.allow_dynamic_drivers() and detail: - iface_info = pecan.request.dbapi.list_hardware_type_interfaces( + iface_info = api.request.dbapi.list_hardware_type_interfaces( list(hardware_types)) else: iface_info = [] @@ -278,13 +278,13 @@ class DriverPassthruController(rest.RestController): :raises: DriverNotFound if the driver name is invalid or the driver cannot be loaded. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:driver:vendor_passthru', cdict, cdict) if driver_name not in _VENDOR_METHODS: - topic = pecan.request.rpcapi.get_topic_for_driver(driver_name) - ret = pecan.request.rpcapi.get_driver_vendor_passthru_methods( - pecan.request.context, driver_name, topic=topic) + topic = api.request.rpcapi.get_topic_for_driver(driver_name) + ret = api.request.rpcapi.get_driver_vendor_passthru_methods( + api.request.context, driver_name, topic=topic) _VENDOR_METHODS[driver_name] = ret return _VENDOR_METHODS[driver_name] @@ -300,10 +300,10 @@ class DriverPassthruController(rest.RestController): implementation. :param data: body of data to supply to the specified method. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:driver:vendor_passthru', cdict, cdict) - topic = pecan.request.rpcapi.get_topic_for_driver(driver_name) + topic = api.request.rpcapi.get_topic_for_driver(driver_name) return api_utils.vendor_passthru(driver_name, method, topic, data=data, driver_passthru=True) @@ -329,7 +329,7 @@ class DriverRaidController(rest.RestController): :raises: DriverNotFound, if driver is not loaded on any of the conductors. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:driver:get_raid_logical_disk_properties', cdict, cdict) @@ -337,10 +337,10 @@ class DriverRaidController(rest.RestController): raise exception.NotAcceptable() if driver_name not in _RAID_PROPERTIES: - topic = pecan.request.rpcapi.get_topic_for_driver(driver_name) + topic = api.request.rpcapi.get_topic_for_driver(driver_name) try: - info = pecan.request.rpcapi.get_raid_logical_disk_properties( - pecan.request.context, driver_name, topic=topic) + info = api.request.rpcapi.get_raid_logical_disk_properties( + api.request.context, driver_name, topic=topic) except exception.UnsupportedDriverExtension as e: # Change error code as 404 seems appropriate because RAID is a # standard interface and all drivers might not have it. @@ -371,7 +371,7 @@ class DriversController(rest.RestController): # will break from a single-line doc string. # This is a result of a bug in sphinxcontrib-pecanwsme # https://github.com/dreamhost/sphinxcontrib-pecanwsme/issues/8 - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:driver:get', cdict, cdict) api_utils.check_allow_driver_detail(detail) @@ -382,7 +382,7 @@ class DriversController(rest.RestController): 'if specified.')) if type is None or type == 'dynamic': - hw_type_dict = pecan.request.dbapi.get_active_hardware_type_dict() + hw_type_dict = api.request.dbapi.get_active_hardware_type_dict() else: # NOTE(dtantsur): we don't support classic drivers starting with # the Rocky release. @@ -397,10 +397,10 @@ class DriversController(rest.RestController): # retrieving a list of drivers using the current sqlalchemy schema, but # this path must be exposed for Pecan to route any paths we might # choose to expose below it. - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:driver:get', cdict, cdict) - hw_type_dict = pecan.request.dbapi.get_active_hardware_type_dict() + hw_type_dict = api.request.dbapi.get_active_hardware_type_dict() for name, hosts in hw_type_dict.items(): if name == driver_name: return Driver.convert_with_links(name, list(hosts), @@ -419,13 +419,13 @@ class DriversController(rest.RestController): :raises: DriverNotFound (HTTP 404) if the driver name is invalid or the driver cannot be loaded. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:driver:get_properties', cdict, cdict) if driver_name not in _DRIVER_PROPERTIES: - topic = pecan.request.rpcapi.get_topic_for_driver(driver_name) - properties = pecan.request.rpcapi.get_driver_properties( - pecan.request.context, driver_name, topic=topic) + topic = api.request.rpcapi.get_topic_for_driver(driver_name) + properties = api.request.rpcapi.get_driver_properties( + api.request.context, driver_name, topic=topic) _DRIVER_PROPERTIES[driver_name] = properties return _DRIVER_PROPERTIES[driver_name] diff --git a/ironic/api/controllers/v1/event.py b/ironic/api/controllers/v1/event.py index b791926f39..5a133f2dd2 100644 --- a/ironic/api/controllers/v1/event.py +++ b/ironic/api/controllers/v1/event.py @@ -15,6 +15,7 @@ from oslo_log import log import pecan from six.moves import http_client +from ironic import api from ironic.api.controllers.v1 import collection from ironic.api.controllers.v1 import types from ironic.api.controllers.v1 import utils as api_utils @@ -48,7 +49,7 @@ class EventsController(pecan.rest.RestController): def post(self, evts): if not api_utils.allow_expose_events(): raise exception.NotFound() - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:events:post', cdict, cdict) for e in evts.events: LOG.debug("Received external event: %s", e) diff --git a/ironic/api/controllers/v1/node.py b/ironic/api/controllers/v1/node.py index 68efff8319..82665508ce 100644 --- a/ironic/api/controllers/v1/node.py +++ b/ironic/api/controllers/v1/node.py @@ -26,6 +26,7 @@ from six.moves import http_client import wsme from wsme import types as wtypes +from ironic import api from ironic.api.controllers import base from ironic.api.controllers import link from ironic.api.controllers.v1 import allocation @@ -149,7 +150,7 @@ def reject_fields_in_newer_versions(obj): if getattr(obj, field, empty_value) != empty_value: LOG.debug('Field %(field)s is not acceptable in version %(ver)s', - {'field': field, 'ver': pecan.request.version}) + {'field': field, 'ver': api.request.version}) raise exception.NotAcceptable() @@ -158,7 +159,7 @@ def reject_patch_in_newer_versions(patch): value = api_utils.get_patch_values(patch, '/%s' % field) if value: LOG.debug('Field %(field)s is not acceptable in version %(ver)s', - {'field': field, 'ver': pecan.request.version}) + {'field': field, 'ver': api.request.version}) raise exception.NotAcceptable() @@ -169,7 +170,7 @@ def update_state_in_older_versions(obj): to be updated by this method. """ # if requested version is < 1.2, convert AVAILABLE to the old NOSTATE - if (pecan.request.version.minor < versions.MINOR_2_AVAILABLE_STATE + if (api.request.version.minor < versions.MINOR_2_AVAILABLE_STATE and obj.provision_state == ir_states.AVAILABLE): obj.provision_state = ir_states.NOSTATE # if requested version < 1.39, convert INSPECTWAIT to INSPECTING @@ -196,13 +197,13 @@ class BootDeviceController(rest.RestController): """ rpc_node = api_utils.get_rpc_node(node_ident) - topic = pecan.request.rpcapi.get_topic_for(rpc_node) + topic = api.request.rpcapi.get_topic_for(rpc_node) if supported: - return pecan.request.rpcapi.get_supported_boot_devices( - pecan.request.context, rpc_node.uuid, topic) + return api.request.rpcapi.get_supported_boot_devices( + api.request.context, rpc_node.uuid, topic) else: - return pecan.request.rpcapi.get_boot_device(pecan.request.context, - rpc_node.uuid, topic) + return api.request.rpcapi.get_boot_device(api.request.context, + rpc_node.uuid, topic) @METRICS.timer('BootDeviceController.put') @expose.expose(None, types.uuid_or_name, wtypes.text, types.boolean, @@ -220,16 +221,16 @@ class BootDeviceController(rest.RestController): Default: False. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:set_boot_device', cdict, cdict) rpc_node = api_utils.get_rpc_node(node_ident) - topic = pecan.request.rpcapi.get_topic_for(rpc_node) - pecan.request.rpcapi.set_boot_device(pecan.request.context, - rpc_node.uuid, - boot_device, - persistent=persistent, - topic=topic) + topic = api.request.rpcapi.get_topic_for(rpc_node) + api.request.rpcapi.set_boot_device(api.request.context, + rpc_node.uuid, + boot_device, + persistent=persistent, + topic=topic) @METRICS.timer('BootDeviceController.get') @expose.expose(wtypes.text, types.uuid_or_name) @@ -245,7 +246,7 @@ class BootDeviceController(rest.RestController): future boots or not, None if it is unknown. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:get_boot_device', cdict, cdict) return self._get_boot_device(node_ident) @@ -260,7 +261,7 @@ class BootDeviceController(rest.RestController): devices. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:get_boot_device', cdict, cdict) boot_devices = self._get_boot_device(node_ident, supported=True) @@ -292,14 +293,14 @@ class InjectNmiController(rest.RestController): if not api_utils.allow_inject_nmi(): raise exception.NotFound() - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:inject_nmi', cdict, cdict) rpc_node = api_utils.get_rpc_node(node_ident) - topic = pecan.request.rpcapi.get_topic_for(rpc_node) - pecan.request.rpcapi.inject_nmi(pecan.request.context, - rpc_node.uuid, - topic=topic) + topic = api.request.rpcapi.get_topic_for(rpc_node) + api.request.rpcapi.inject_nmi(api.request.context, + rpc_node.uuid, + topic=topic) class NodeManagementController(rest.RestController): @@ -336,14 +337,14 @@ class NodeConsoleController(rest.RestController): :param node_ident: UUID or logical name of a node. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:get_console', cdict, cdict) rpc_node = api_utils.get_rpc_node(node_ident) - topic = pecan.request.rpcapi.get_topic_for(rpc_node) + topic = api.request.rpcapi.get_topic_for(rpc_node) try: - console = pecan.request.rpcapi.get_console_information( - pecan.request.context, rpc_node.uuid, topic) + console = api.request.rpcapi.get_console_information( + api.request.context, rpc_node.uuid, topic) console_state = True except exception.NodeConsoleNotEnabled: console = None @@ -361,16 +362,16 @@ class NodeConsoleController(rest.RestController): :param enabled: Boolean value; whether to enable or disable the console. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:set_console_state', cdict, cdict) rpc_node = api_utils.get_rpc_node(node_ident) - topic = pecan.request.rpcapi.get_topic_for(rpc_node) - pecan.request.rpcapi.set_console_mode(pecan.request.context, - rpc_node.uuid, enabled, topic) + topic = api.request.rpcapi.get_topic_for(rpc_node) + api.request.rpcapi.set_console_mode(api.request.context, + rpc_node.uuid, enabled, topic) # Set the HTTP Location Header url_args = '/'.join([node_ident, 'states', 'console']) - pecan.response.location = link.build_url('nodes', url_args) + api.response.location = link.build_url('nodes', url_args) class NodeStates(base.APIBase): @@ -452,7 +453,7 @@ class NodeStatesController(rest.RestController): :param node_ident: the UUID or logical_name of a node. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:get_states', cdict, cdict) # NOTE(lucasagomes): All these state values come from the @@ -476,16 +477,16 @@ class NodeStatesController(rest.RestController): :raises: NotAcceptable, if requested version of the API is less than 1.12. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:set_raid_state', cdict, cdict) if not api_utils.allow_raid_config(): raise exception.NotAcceptable() rpc_node = api_utils.get_rpc_node(node_ident) - topic = pecan.request.rpcapi.get_topic_for(rpc_node) + topic = api.request.rpcapi.get_topic_for(rpc_node) try: - pecan.request.rpcapi.set_target_raid_config( - pecan.request.context, rpc_node.uuid, + api.request.rpcapi.set_target_raid_config( + api.request.context, rpc_node.uuid, target_raid_config, topic=topic) except exception.UnsupportedDriverExtension as e: # Change error code as 404 seems appropriate because RAID is a @@ -513,13 +514,13 @@ class NodeStatesController(rest.RestController): :raises: Invalid (HTTP 400) if timeout value is less than 1. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:set_power_state', cdict, cdict) # TODO(lucasagomes): Test if it's able to transition to the # target state from the current one rpc_node = api_utils.get_rpc_node(node_ident) - topic = pecan.request.rpcapi.get_topic_for(rpc_node) + topic = api.request.rpcapi.get_topic_for(rpc_node) if ((target in [ir_states.SOFT_REBOOT, ir_states.SOFT_POWER_OFF] or timeout) and not api_utils.allow_soft_power_off()): @@ -542,30 +543,30 @@ class NodeStatesController(rest.RestController): action=target, node=node_ident, state=rpc_node.provision_state) - pecan.request.rpcapi.change_node_power_state(pecan.request.context, - rpc_node.uuid, target, - timeout=timeout, - topic=topic) + api.request.rpcapi.change_node_power_state(api.request.context, + rpc_node.uuid, target, + timeout=timeout, + topic=topic) # Set the HTTP Location Header url_args = '/'.join([node_ident, 'states']) - pecan.response.location = link.build_url('nodes', url_args) + api.response.location = link.build_url('nodes', url_args) def _do_provision_action(self, rpc_node, target, configdrive=None, clean_steps=None, rescue_password=None): - topic = pecan.request.rpcapi.get_topic_for(rpc_node) + topic = api.request.rpcapi.get_topic_for(rpc_node) # Note that there is a race condition. The node state(s) could change # by the time the RPC call is made and the TaskManager manager gets a # lock. if target in (ir_states.ACTIVE, ir_states.REBUILD): rebuild = (target == ir_states.REBUILD) - pecan.request.rpcapi.do_node_deploy(context=pecan.request.context, - node_id=rpc_node.uuid, - rebuild=rebuild, - configdrive=configdrive, - topic=topic) + api.request.rpcapi.do_node_deploy(context=api.request.context, + node_id=rpc_node.uuid, + rebuild=rebuild, + configdrive=configdrive, + topic=topic) elif (target == ir_states.VERBS['unrescue']): - pecan.request.rpcapi.do_node_unrescue( - pecan.request.context, rpc_node.uuid, topic) + api.request.rpcapi.do_node_unrescue( + api.request.context, rpc_node.uuid, topic) elif (target == ir_states.VERBS['rescue']): if not (rescue_password and rescue_password.strip()): msg = (_('A non-empty "rescue_password" is required when ' @@ -573,14 +574,14 @@ class NodeStatesController(rest.RestController): ir_states.VERBS['rescue']) raise wsme.exc.ClientSideError( msg, status_code=http_client.BAD_REQUEST) - pecan.request.rpcapi.do_node_rescue( - pecan.request.context, rpc_node.uuid, rescue_password, topic) + api.request.rpcapi.do_node_rescue( + api.request.context, rpc_node.uuid, rescue_password, topic) elif target == ir_states.DELETED: - pecan.request.rpcapi.do_node_tear_down( - pecan.request.context, rpc_node.uuid, topic) + api.request.rpcapi.do_node_tear_down( + api.request.context, rpc_node.uuid, topic) elif target == ir_states.VERBS['inspect']: - pecan.request.rpcapi.inspect_hardware( - pecan.request.context, rpc_node.uuid, topic=topic) + api.request.rpcapi.inspect_hardware( + api.request.context, rpc_node.uuid, topic=topic) elif target == ir_states.VERBS['clean']: if not clean_steps: msg = (_('"clean_steps" is required when setting target ' @@ -588,11 +589,11 @@ class NodeStatesController(rest.RestController): raise wsme.exc.ClientSideError( msg, status_code=http_client.BAD_REQUEST) _check_clean_steps(clean_steps) - pecan.request.rpcapi.do_node_clean( - pecan.request.context, rpc_node.uuid, clean_steps, topic) + api.request.rpcapi.do_node_clean( + api.request.context, rpc_node.uuid, clean_steps, topic) elif target in PROVISION_ACTION_STATES: - pecan.request.rpcapi.do_provisioning_action( - pecan.request.context, rpc_node.uuid, target, topic) + api.request.rpcapi.do_provisioning_action( + api.request.context, rpc_node.uuid, target, topic) else: msg = (_('The requested action "%(action)s" could not be ' 'understood.') % {'action': target}) @@ -652,7 +653,7 @@ class NodeStatesController(rest.RestController): :raises: NotAcceptable (HTTP 406) if the API version specified does not allow the requested state transition. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:set_provision_state', cdict, cdict) api_utils.check_allow_management_verbs(target) @@ -706,7 +707,7 @@ class NodeStatesController(rest.RestController): # Set the HTTP Location Header url_args = '/'.join([node_ident, 'states']) - pecan.response.location = link.build_url('nodes', url_args) + api.response.location = link.build_url('nodes', url_args) def _check_clean_steps(clean_steps): @@ -747,7 +748,7 @@ def _get_chassis_uuid(node): """ if not node.chassis_id: return - chassis = objects.Chassis.get_by_id(pecan.request.context, node.chassis_id) + chassis = objects.Chassis.get_by_id(api.request.context, node.chassis_id) return chassis.uuid @@ -776,10 +777,10 @@ class NodeTraitsController(rest.RestController): @expose.expose(Traits) def get_all(self): """List node traits.""" - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:traits:list', cdict, cdict) node = api_utils.get_rpc_node(self.node_ident) - traits = objects.TraitList.get_by_node_id(pecan.request.context, + traits = objects.TraitList.get_by_node_id(api.request.context, node.id) return Traits(traits=traits.get_trait_names()) @@ -795,7 +796,7 @@ class NodeTraitsController(rest.RestController): Mutually exclusive with 'trait'. If not None, replaces the node's traits with this list. """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:node:traits:set', cdict, cdict) node = api_utils.get_rpc_node(self.node_ident) @@ -809,7 +810,7 @@ class NodeTraitsController(rest.RestController): raise exception.Invalid(msg) if trait: - if pecan.request.body and pecan.request.json_body: + if api.request.body and api.request.json_body: # Ensure PUT nodes/uuid1/traits/trait1 with a non-empty body # fails. msg = _("No body should be provided when adding a trait") @@ -832,8 +833,8 @@ class NodeTraitsController(rest.RestController): chassis_uuid=chassis_uuid) with notify.handle_error_notification(context, node, 'update', chassis_uuid=chassis_uuid): - topic = pecan.request.rpcapi.get_topic_for(node) - pecan.request.rpcapi.add_node_traits( + topic = api.request.rpcapi.get_topic_for(node) + api.request.rpcapi.add_node_traits( context, node.id, traits, replace=replace, topic=topic) notify.emit_end_notification(context, node, 'update', chassis_uuid=chassis_uuid) @@ -841,7 +842,7 @@ class NodeTraitsController(rest.RestController): if not replace: # For single traits, set the HTTP Location Header. url_args = '/'.join((self.node_ident, 'traits', trait)) - pecan.response.location = link.build_url('nodes', url_args) + api.response.location = link.build_url('nodes', url_args) @METRICS.timer('NodeTraitsController.delete') @expose.expose(None, wtypes.text, @@ -852,7 +853,7 @@ class NodeTraitsController(rest.RestController): :param trait: String value; trait to remove from a node, or None. If None, all traits are removed. """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:node:traits:delete', cdict, cdict) node = api_utils.get_rpc_node(self.node_ident) @@ -872,9 +873,9 @@ class NodeTraitsController(rest.RestController): chassis_uuid=chassis_uuid) with notify.handle_error_notification(context, node, 'update', chassis_uuid=chassis_uuid): - topic = pecan.request.rpcapi.get_topic_for(node) + topic = api.request.rpcapi.get_topic_for(node) try: - pecan.request.rpcapi.remove_node_traits( + api.request.rpcapi.remove_node_traits( context, node.id, traits, topic=topic) except exception.NodeTraitNotFound: # NOTE(hshiina): Internal node ID should not be exposed. @@ -901,7 +902,7 @@ class Node(base.APIBase): self._chassis_uuid = value elif self._chassis_uuid != value: try: - chassis = objects.Chassis.get(pecan.request.context, value) + chassis = objects.Chassis.get(api.request.context, value) self._chassis_uuid = chassis.uuid # NOTE(lucasagomes): Create the chassis_id attribute on-the-fly # to satisfy the api -> rpc object @@ -1170,7 +1171,7 @@ class Node(base.APIBase): # NOTE(kaifeng) It is possible a node gets orphaned in certain # circumstances, set conductor to None in such case. try: - host = pecan.request.rpcapi.get_conductor_for(rpc_node) + host = api.request.rpcapi.get_conductor_for(rpc_node) node.conductor = host except (exception.NoValidHost, exception.TemporaryFailure): LOG.debug('Currently there is no conductor servicing node ' @@ -1183,7 +1184,7 @@ class Node(base.APIBase): if rpc_node.allocation_id: try: allocation = objects.Allocation.get_by_id( - pecan.request.context, + api.request.context, rpc_node.allocation_id) node.allocation_uuid = allocation.uuid except exception.AllocationNotFound: @@ -1198,7 +1199,7 @@ class Node(base.APIBase): show_portgroups = api_utils.allow_portgroups_subcontrollers() show_volume = api_utils.allow_volume() - node = cls._convert_with_links(node, pecan.request.public_url, + node = cls._convert_with_links(node, api.request.public_url, fields=fields, show_states_links=show_states_links, show_portgroups=show_portgroups, @@ -1219,7 +1220,7 @@ class Node(base.APIBase): list of fields to preserve, or ``None`` to preserve them all :type fields: list of str """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() # NOTE(deva): the 'show_password' policy setting name exists for legacy # purposes and can not be changed. Changing it will cause # upgrade problems for any operators who have customized @@ -1383,16 +1384,16 @@ class NodeVendorPassthruController(rest.RestController): entries. :raises: NodeNotFound if the node is not found. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:vendor_passthru', cdict, cdict) # Raise an exception if node is not found rpc_node = api_utils.get_rpc_node(node_ident) if rpc_node.driver not in _VENDOR_METHODS: - topic = pecan.request.rpcapi.get_topic_for(rpc_node) - ret = pecan.request.rpcapi.get_node_vendor_passthru_methods( - pecan.request.context, rpc_node.uuid, topic=topic) + topic = api.request.rpcapi.get_topic_for(rpc_node) + ret = api.request.rpcapi.get_node_vendor_passthru_methods( + api.request.context, rpc_node.uuid, topic=topic) _VENDOR_METHODS[rpc_node.driver] = ret return _VENDOR_METHODS[rpc_node.driver] @@ -1407,12 +1408,12 @@ class NodeVendorPassthruController(rest.RestController): :param method: name of the method in vendor driver. :param data: body of data to supply to the specified method. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:vendor_passthru', cdict, cdict) # Raise an exception if node is not found rpc_node = api_utils.get_rpc_node(node_ident) - topic = pecan.request.rpcapi.get_topic_for(rpc_node) + topic = api.request.rpcapi.get_topic_for(rpc_node) return api_utils.vendor_passthru(rpc_node.uuid, method, topic, data=data) @@ -1420,7 +1421,7 @@ class NodeVendorPassthruController(rest.RestController): class NodeMaintenanceController(rest.RestController): def _set_maintenance(self, node_ident, maintenance_mode, reason=None): - context = pecan.request.context + context = api.request.context rpc_node = api_utils.get_rpc_node(node_ident) rpc_node.maintenance = maintenance_mode rpc_node.maintenance_reason = reason @@ -1428,13 +1429,13 @@ class NodeMaintenanceController(rest.RestController): with notify.handle_error_notification(context, rpc_node, 'maintenance_set'): try: - topic = pecan.request.rpcapi.get_topic_for(rpc_node) + topic = api.request.rpcapi.get_topic_for(rpc_node) except exception.NoValidHost as e: e.code = http_client.BAD_REQUEST raise - new_node = pecan.request.rpcapi.update_node(context, rpc_node, - topic=topic) + new_node = api.request.rpcapi.update_node(context, rpc_node, + topic=topic) notify.emit_end_notification(context, new_node, 'maintenance_set') @METRICS.timer('NodeMaintenanceController.put') @@ -1447,7 +1448,7 @@ class NodeMaintenanceController(rest.RestController): :param reason: Optional, the reason why it's in maintenance. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:set_maintenance', cdict, cdict) self._set_maintenance(node_ident, True, reason=reason) @@ -1460,7 +1461,7 @@ class NodeMaintenanceController(rest.RestController): :param node_ident: the UUID or logical name of a node. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:clear_maintenance', cdict, cdict) self._set_maintenance(node_ident, False) @@ -1489,7 +1490,7 @@ class NodeVIFController(rest.RestController): def _get_node_and_topic(self): rpc_node = api_utils.get_rpc_node(self.node_ident) try: - return rpc_node, pecan.request.rpcapi.get_topic_for(rpc_node) + return rpc_node, api.request.rpcapi.get_topic_for(rpc_node) except exception.NoValidHost as e: e.code = http_client.BAD_REQUEST raise @@ -1498,11 +1499,11 @@ class NodeVIFController(rest.RestController): @expose.expose(VifCollection) def get_all(self): """Get a list of attached VIFs""" - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:vif:list', cdict, cdict) rpc_node, topic = self._get_node_and_topic() - vifs = pecan.request.rpcapi.vif_list(pecan.request.context, - rpc_node.uuid, topic=topic) + vifs = api.request.rpcapi.vif_list(api.request.context, + rpc_node.uuid, topic=topic) return VifCollection.collection_from_list(vifs) @METRICS.timer('NodeVIFController.post') @@ -1515,11 +1516,11 @@ class NodeVIFController(rest.RestController): It must have an 'id' key, whose value is a unique identifier for that VIF. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:vif:attach', cdict, cdict) rpc_node, topic = self._get_node_and_topic() - pecan.request.rpcapi.vif_attach(pecan.request.context, rpc_node.uuid, - vif_info=vif, topic=topic) + api.request.rpcapi.vif_attach(api.request.context, rpc_node.uuid, + vif_info=vif, topic=topic) @METRICS.timer('NodeVIFController.delete') @expose.expose(None, types.uuid_or_name, @@ -1529,11 +1530,11 @@ class NodeVIFController(rest.RestController): :param vif_id: The ID of a VIF to detach """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:vif:detach', cdict, cdict) rpc_node, topic = self._get_node_and_topic() - pecan.request.rpcapi.vif_detach(pecan.request.context, rpc_node.uuid, - vif_id=vif_id, topic=topic) + api.request.rpcapi.vif_detach(api.request.context, rpc_node.uuid, + vif_id=vif_id, topic=topic) class NodesController(rest.RestController): @@ -1613,7 +1614,7 @@ class NodesController(rest.RestController): filtered_nodes = [] for n in nodes: try: - host = pecan.request.rpcapi.get_conductor_for(n) + host = api.request.rpcapi.get_conductor_for(n) if host == conductor: filtered_nodes.append(n) except (exception.NoValidHost, exception.TemporaryFailure): @@ -1644,7 +1645,7 @@ class NodesController(rest.RestController): marker_obj = None if marker: - marker_obj = objects.Node.get_by_uuid(pecan.request.context, + marker_obj = objects.Node.get_by_uuid(api.request.context, marker) # The query parameters for the 'next' URL @@ -1679,7 +1680,7 @@ class NodesController(rest.RestController): if value is not None: filters[key] = value - nodes = objects.Node.list(pecan.request.context, limit, marker_obj, + nodes = objects.Node.list(api.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir, filters=filters) @@ -1707,7 +1708,7 @@ class NodesController(rest.RestController): It returns a list with the node, or an empty list if no node is found. """ try: - node = objects.Node.get_by_instance_uuid(pecan.request.context, + node = objects.Node.get_by_instance_uuid(api.request.context, instance_uuid) return [node] except exception.InstanceNotFound: @@ -1840,7 +1841,7 @@ class NodesController(rest.RestController): with description field contains matching value. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:get', cdict, cdict) api_utils.check_allow_specify_fields(fields) @@ -1915,7 +1916,7 @@ class NodesController(rest.RestController): with description field contains matching value. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:get', cdict, cdict) api_utils.check_for_invalid_state_and_allow_filter(provision_state) @@ -1926,7 +1927,7 @@ class NodesController(rest.RestController): api_utils.check_allow_filter_by_owner(owner) api_utils.check_allowed_fields([sort_key]) # /detail should only work against collections - parent = pecan.request.path.split('/')[:-1][-1] + parent = api.request.path.split('/')[:-1][-1] if parent != "nodes": raise exception.HTTPNotFound() @@ -1958,7 +1959,7 @@ class NodesController(rest.RestController): :param node: UUID or name of a node. :param node_uuid: UUID of a node. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:validate', cdict, cdict) if node is not None: @@ -1970,9 +1971,9 @@ class NodesController(rest.RestController): rpc_node = api_utils.get_rpc_node(node_uuid or node) - topic = pecan.request.rpcapi.get_topic_for(rpc_node) - return pecan.request.rpcapi.validate_driver_interfaces( - pecan.request.context, rpc_node.uuid, topic) + topic = api.request.rpcapi.get_topic_for(rpc_node) + return api.request.rpcapi.validate_driver_interfaces( + api.request.context, rpc_node.uuid, topic) @METRICS.timer('NodesController.get_one') @expose.expose(Node, types.uuid_or_name, types.listtype) @@ -1983,7 +1984,7 @@ class NodesController(rest.RestController): :param fields: Optional, a list with a specified set of fields of the resource to be returned. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:get', cdict, cdict) if self.from_chassis: @@ -2002,7 +2003,7 @@ class NodesController(rest.RestController): :param node: a node within the request body. """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:node:create', cdict, cdict) @@ -2044,7 +2045,7 @@ class NodesController(rest.RestController): node.uuid = uuidutils.generate_uuid() try: - topic = pecan.request.rpcapi.get_topic_for(node) + topic = api.request.rpcapi.get_topic_for(node) except exception.NoValidHost as e: # NOTE(deva): convert from 404 to 400 because client can see # list of available drivers and shouldn't request @@ -2065,10 +2066,10 @@ class NodesController(rest.RestController): chassis_uuid=node.chassis_uuid) with notify.handle_error_notification(context, new_node, 'create', chassis_uuid=node.chassis_uuid): - new_node = pecan.request.rpcapi.create_node(context, - new_node, topic) + new_node = api.request.rpcapi.create_node(context, + new_node, topic) # Set the HTTP Location Header - pecan.response.location = link.build_url('nodes', new_node.uuid) + api.response.location = link.build_url('nodes', new_node.uuid) api_node = Node.convert_with_links(new_node) notify.emit_end_notification(context, new_node, 'create', chassis_uuid=api_node.chassis_uuid) @@ -2110,7 +2111,7 @@ class NodesController(rest.RestController): defaults. Only valid when updating the driver field. :param patch: a json PATCH document to apply to this node. """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:node:update', cdict, cdict) @@ -2163,7 +2164,7 @@ class NodesController(rest.RestController): # new conductor, not the old one which may fail to # load the new driver. try: - topic = pecan.request.rpcapi.get_topic_for(rpc_node) + topic = api.request.rpcapi.get_topic_for(rpc_node) except exception.NoValidHost as e: # NOTE(deva): convert from 404 to 400 because client can see # list of available drivers and shouldn't request @@ -2176,9 +2177,9 @@ class NodesController(rest.RestController): chassis_uuid=node.chassis_uuid) with notify.handle_error_notification(context, rpc_node, 'update', chassis_uuid=node.chassis_uuid): - new_node = pecan.request.rpcapi.update_node(context, - rpc_node, topic, - reset_interfaces) + new_node = api.request.rpcapi.update_node(context, + rpc_node, topic, + reset_interfaces) api_node = Node.convert_with_links(new_node) notify.emit_end_notification(context, new_node, 'update', @@ -2194,7 +2195,7 @@ class NodesController(rest.RestController): :param node_ident: UUID or logical name of a node. """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:node:delete', cdict, cdict) @@ -2208,11 +2209,11 @@ class NodesController(rest.RestController): with notify.handle_error_notification(context, rpc_node, 'delete', chassis_uuid=chassis_uuid): try: - topic = pecan.request.rpcapi.get_topic_for(rpc_node) + topic = api.request.rpcapi.get_topic_for(rpc_node) except exception.NoValidHost as e: e.code = http_client.BAD_REQUEST raise - pecan.request.rpcapi.destroy_node(context, rpc_node.uuid, topic) + api.request.rpcapi.destroy_node(context, rpc_node.uuid, topic) notify.emit_end_notification(context, rpc_node, 'delete', chassis_uuid=chassis_uuid) diff --git a/ironic/api/controllers/v1/port.py b/ironic/api/controllers/v1/port.py index 2f75078308..6d39e58dd9 100644 --- a/ironic/api/controllers/v1/port.py +++ b/ironic/api/controllers/v1/port.py @@ -18,12 +18,12 @@ import datetime from ironic_lib import metrics_utils from oslo_log import log from oslo_utils import uuidutils -import pecan from pecan import rest from six.moves import http_client import wsme from wsme import types as wtypes +from ironic import api from ironic.api.controllers import base from ironic.api.controllers import link from ironic.api.controllers.v1 import collection @@ -83,7 +83,7 @@ class Port(base.APIBase): # FIXME(comstud): One should only allow UUID here, but # there seems to be a bug in that tests are passing an # ID. See bug #1301046 for more details. - node = objects.Node.get(pecan.request.context, value) + node = objects.Node.get(api.request.context, value) self._node_uuid = node.uuid # NOTE(lucasagomes): Create the node_id attribute on-the-fly # to satisfy the api -> rpc object @@ -106,7 +106,7 @@ class Port(base.APIBase): self._portgroup_uuid = wtypes.Unset return try: - portgroup = objects.Portgroup.get(pecan.request.context, value) + portgroup = objects.Portgroup.get(api.request.context, value) if portgroup.node_id != self.node_id: raise exception.BadRequest(_('Port can not be added to a ' 'portgroup belonging to a ' @@ -198,7 +198,7 @@ class Port(base.APIBase): port._validate_fields(fields) - url = pecan.request.public_url + url = api.request.public_url port.links = [link.Link.make_link('self', url, 'ports', port.uuid), @@ -345,7 +345,7 @@ class PortsController(rest.RestController): marker_obj = None if marker: - marker_obj = objects.Port.get_by_uuid(pecan.request.context, + marker_obj = objects.Port.get_by_uuid(api.request.context, marker) if sort_key in self.invalid_sort_key_list: @@ -365,7 +365,7 @@ class PortsController(rest.RestController): # for that column. This will get cleaned up # as we move to the object interface. portgroup = api_utils.get_rpc_portgroup(portgroup_ident) - ports = objects.Port.list_by_portgroup_id(pecan.request.context, + ports = objects.Port.list_by_portgroup_id(api.request.context, portgroup.id, limit, marker_obj, sort_key=sort_key, @@ -376,14 +376,14 @@ class PortsController(rest.RestController): # for that column. This will get cleaned up # as we move to the object interface. node = api_utils.get_rpc_node(node_ident) - ports = objects.Port.list_by_node_id(pecan.request.context, + ports = objects.Port.list_by_node_id(api.request.context, node.id, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) elif address: ports = self._get_ports_by_address(address) else: - ports = objects.Port.list(pecan.request.context, limit, + ports = objects.Port.list(api.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) parameters = {} @@ -407,7 +407,7 @@ class PortsController(rest.RestController): """ try: - port = objects.Port.get_by_address(pecan.request.context, address) + port = objects.Port.get_by_address(api.request.context, address) return [port] except exception.PortNotFound: return [] @@ -468,7 +468,7 @@ class PortsController(rest.RestController): for that portgroup. :raises: NotAcceptable, HTTPNotFound """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:port:get', cdict, cdict) api_utils.check_allow_specify_fields(fields) @@ -522,7 +522,7 @@ class PortsController(rest.RestController): :param sort_dir: direction to sort. "asc" or "desc". Default: asc. :raises: NotAcceptable, HTTPNotFound """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:port:get', cdict, cdict) self._check_allowed_port_fields([sort_key]) @@ -538,7 +538,7 @@ class PortsController(rest.RestController): raise exception.NotAcceptable() # NOTE(lucasagomes): /detail should only work against collections - parent = pecan.request.path.split('/')[:-1][-1] + parent = api.request.path.split('/')[:-1][-1] if parent != "ports": raise exception.HTTPNotFound() @@ -557,7 +557,7 @@ class PortsController(rest.RestController): of the resource to be returned. :raises: NotAcceptable, HTTPNotFound """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:port:get', cdict, cdict) if self.parent_node_ident or self.parent_portgroup_ident: @@ -566,7 +566,7 @@ class PortsController(rest.RestController): api_utils.check_allow_specify_fields(fields) self._check_allowed_port_fields(fields) - rpc_port = objects.Port.get_by_uuid(pecan.request.context, port_uuid) + rpc_port = objects.Port.get_by_uuid(api.request.context, port_uuid) return Port.convert_with_links(rpc_port, fields=fields) @METRICS.timer('PortsController.post') @@ -577,7 +577,7 @@ class PortsController(rest.RestController): :param port: a port within the request body. :raises: NotAcceptable, HTTPNotFound, Conflict """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:port:create', cdict, cdict) @@ -593,7 +593,7 @@ class PortsController(rest.RestController): "Smart NIC port must have port_id " "and hostname in local_link_connection") - create_remotely = pecan.request.rpcapi.can_send_create_port() + create_remotely = api.request.rpcapi.can_send_create_port() if (not create_remotely and pdict.get('portgroup_uuid')): # NOTE(mgoddard): In RPC API v1.41, port creation was moved to the # conductor service to facilitate validation of the physical @@ -637,16 +637,16 @@ class PortsController(rest.RestController): # the RPCAPI will reject the create_port method, so we need to # create the port locally. if create_remotely: - topic = pecan.request.rpcapi.get_topic_for(rpc_node) - new_port = pecan.request.rpcapi.create_port(context, rpc_port, - topic) + topic = api.request.rpcapi.get_topic_for(rpc_node) + new_port = api.request.rpcapi.create_port(context, rpc_port, + topic) else: rpc_port.create() new_port = rpc_port notify.emit_end_notification(context, new_port, 'create', **notify_extra) # Set the HTTP Location Header - pecan.response.location = link.build_url('ports', new_port.uuid) + api.response.location = link.build_url('ports', new_port.uuid) return Port.convert_with_links(new_port) @METRICS.timer('PortsController.patch') @@ -659,7 +659,7 @@ class PortsController(rest.RestController): :param patch: a json PATCH document to apply to this port. :raises: NotAcceptable, HTTPNotFound """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:port:update', cdict, cdict) @@ -723,9 +723,9 @@ class PortsController(rest.RestController): **notify_extra) with notify.handle_error_notification(context, rpc_port, 'update', **notify_extra): - topic = pecan.request.rpcapi.get_topic_for(rpc_node) - new_port = pecan.request.rpcapi.update_port(context, rpc_port, - topic) + topic = api.request.rpcapi.get_topic_for(rpc_node) + new_port = api.request.rpcapi.update_port(context, rpc_port, + topic) api_port = Port.convert_with_links(new_port) notify.emit_end_notification(context, new_port, 'update', @@ -741,7 +741,7 @@ class PortsController(rest.RestController): :param port_uuid: UUID of a port. :raises: OperationNotPermitted, HTTPNotFound """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:port:delete', cdict, cdict) @@ -763,7 +763,7 @@ class PortsController(rest.RestController): **notify_extra) with notify.handle_error_notification(context, rpc_port, 'delete', **notify_extra): - topic = pecan.request.rpcapi.get_topic_for(rpc_node) - pecan.request.rpcapi.destroy_port(context, rpc_port, topic) + topic = api.request.rpcapi.get_topic_for(rpc_node) + api.request.rpcapi.destroy_port(context, rpc_port, topic) notify.emit_end_notification(context, rpc_port, 'delete', **notify_extra) diff --git a/ironic/api/controllers/v1/portgroup.py b/ironic/api/controllers/v1/portgroup.py index 1e2544f83a..e2d6742446 100644 --- a/ironic/api/controllers/v1/portgroup.py +++ b/ironic/api/controllers/v1/portgroup.py @@ -19,6 +19,7 @@ from six.moves import http_client import wsme from wsme import types as wtypes +from ironic import api from ironic.api.controllers import base from ironic.api.controllers import link from ironic.api.controllers.v1 import collection @@ -57,7 +58,7 @@ class Portgroup(base.APIBase): self._node_uuid = wtypes.Unset return try: - node = objects.Node.get(pecan.request.context, value) + node = objects.Node.get(api.request.context, value) self._node_uuid = node.uuid # NOTE: Create the node_id attribute on-the-fly # to satisfy the api -> rpc object @@ -158,7 +159,7 @@ class Portgroup(base.APIBase): if fields is not None: api_utils.check_for_invalid_fields(fields, portgroup.as_dict()) - portgroup = cls._convert_with_links(portgroup, pecan.request.host_url, + portgroup = cls._convert_with_links(portgroup, api.request.host_url, fields=fields) if not sanitize: @@ -303,7 +304,7 @@ class PortgroupsController(pecan.rest.RestController): marker_obj = None if marker: - marker_obj = objects.Portgroup.get_by_uuid(pecan.request.context, + marker_obj = objects.Portgroup.get_by_uuid(api.request.context, marker) if sort_key in self.invalid_sort_key_list: @@ -320,12 +321,12 @@ class PortgroupsController(pecan.rest.RestController): # as we move to the object interface. node = api_utils.get_rpc_node(node_ident) portgroups = objects.Portgroup.list_by_node_id( - pecan.request.context, node.id, limit, + api.request.context, node.id, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) elif address: portgroups = self._get_portgroups_by_address(address) else: - portgroups = objects.Portgroup.list(pecan.request.context, limit, + portgroups = objects.Portgroup.list(api.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) parameters = {} @@ -349,7 +350,7 @@ class PortgroupsController(pecan.rest.RestController): """ try: - portgroup = objects.Portgroup.get_by_address(pecan.request.context, + portgroup = objects.Portgroup.get_by_address(api.request.context, address) return [portgroup] except exception.PortgroupNotFound: @@ -381,7 +382,7 @@ class PortgroupsController(pecan.rest.RestController): if not api_utils.allow_portgroups(): raise exception.NotFound() - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:portgroup:get', cdict, cdict) api_utils.check_allowed_portgroup_fields(fields) @@ -418,12 +419,12 @@ class PortgroupsController(pecan.rest.RestController): if not api_utils.allow_portgroups(): raise exception.NotFound() - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:portgroup:get', cdict, cdict) api_utils.check_allowed_portgroup_fields([sort_key]) # NOTE: /detail should only work against collections - parent = pecan.request.path.split('/')[:-1][-1] + parent = api.request.path.split('/')[:-1][-1] if parent != "portgroups": raise exception.HTTPNotFound() @@ -444,7 +445,7 @@ class PortgroupsController(pecan.rest.RestController): if not api_utils.allow_portgroups(): raise exception.NotFound() - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:portgroup:get', cdict, cdict) if self.parent_node_ident: @@ -466,7 +467,7 @@ class PortgroupsController(pecan.rest.RestController): if not api_utils.allow_portgroups(): raise exception.NotFound() - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:portgroup:create', cdict, cdict) @@ -504,8 +505,8 @@ class PortgroupsController(pecan.rest.RestController): node_uuid=portgroup.node_uuid) # Set the HTTP Location Header - pecan.response.location = link.build_url('portgroups', - new_portgroup.uuid) + api.response.location = link.build_url('portgroups', + new_portgroup.uuid) return Portgroup.convert_with_links(new_portgroup) @METRICS.timer('PortgroupsController.patch') @@ -520,7 +521,7 @@ class PortgroupsController(pecan.rest.RestController): if not api_utils.allow_portgroups(): raise exception.NotFound() - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:portgroup:update', cdict, cdict) @@ -583,8 +584,8 @@ class PortgroupsController(pecan.rest.RestController): node_uuid=rpc_node.uuid) with notify.handle_error_notification(context, rpc_portgroup, 'update', node_uuid=rpc_node.uuid): - topic = pecan.request.rpcapi.get_topic_for(rpc_node) - new_portgroup = pecan.request.rpcapi.update_portgroup( + topic = api.request.rpcapi.get_topic_for(rpc_node) + new_portgroup = api.request.rpcapi.update_portgroup( context, rpc_portgroup, topic) api_portgroup = Portgroup.convert_with_links(new_portgroup) @@ -604,7 +605,7 @@ class PortgroupsController(pecan.rest.RestController): if not api_utils.allow_portgroups(): raise exception.NotFound() - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:portgroup:delete', cdict, cdict) @@ -613,15 +614,15 @@ class PortgroupsController(pecan.rest.RestController): rpc_portgroup = api_utils.get_rpc_portgroup_with_suffix( portgroup_ident) - rpc_node = objects.Node.get_by_id(pecan.request.context, + rpc_node = objects.Node.get_by_id(api.request.context, rpc_portgroup.node_id) notify.emit_start_notification(context, rpc_portgroup, 'delete', node_uuid=rpc_node.uuid) with notify.handle_error_notification(context, rpc_portgroup, 'delete', node_uuid=rpc_node.uuid): - topic = pecan.request.rpcapi.get_topic_for(rpc_node) - pecan.request.rpcapi.destroy_portgroup(context, rpc_portgroup, - topic) + topic = api.request.rpcapi.get_topic_for(rpc_node) + api.request.rpcapi.destroy_portgroup(context, rpc_portgroup, + topic) notify.emit_end_notification(context, rpc_portgroup, 'delete', node_uuid=rpc_node.uuid) diff --git a/ironic/api/controllers/v1/ramdisk.py b/ironic/api/controllers/v1/ramdisk.py index 17c17ade56..d29f2ace04 100644 --- a/ironic/api/controllers/v1/ramdisk.py +++ b/ironic/api/controllers/v1/ramdisk.py @@ -14,11 +14,11 @@ from oslo_config import cfg from oslo_log import log -import pecan from pecan import rest from six.moves import http_client from wsme import types as wtypes +from ironic import api from ironic.api.controllers import base from ironic.api.controllers.v1 import node as node_ctl from ironic.api.controllers.v1 import types @@ -104,7 +104,7 @@ class LookupController(rest.RestController): if not api_utils.allow_ramdisk_endpoints(): raise exception.NotFound() - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:driver:ipa_lookup', cdict, cdict) # Validate the list of MAC addresses @@ -135,10 +135,10 @@ class LookupController(rest.RestController): try: if node_uuid: node = objects.Node.get_by_uuid( - pecan.request.context, node_uuid) + api.request.context, node_uuid) else: node = objects.Node.get_by_port_addresses( - pecan.request.context, valid_addresses) + api.request.context, valid_addresses) except exception.NotFound: # NOTE(dtantsur): we are reraising the same exception to make sure # we don't disclose the difference between nodes that are not found @@ -180,17 +180,17 @@ class HeartbeatController(rest.RestController): raise exception.InvalidParameterValue( _('Field "agent_version" not recognised')) - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:node:ipa_heartbeat', cdict, cdict) rpc_node = api_utils.get_rpc_node_with_suffix(node_ident) try: - topic = pecan.request.rpcapi.get_topic_for(rpc_node) + topic = api.request.rpcapi.get_topic_for(rpc_node) except exception.NoValidHost as e: e.code = http_client.BAD_REQUEST raise - pecan.request.rpcapi.heartbeat( - pecan.request.context, rpc_node.uuid, callback_url, + api.request.rpcapi.heartbeat( + api.request.context, rpc_node.uuid, callback_url, agent_version, topic=topic) diff --git a/ironic/api/controllers/v1/utils.py b/ironic/api/controllers/v1/utils.py index 516a906781..2949325fc0 100644 --- a/ironic/api/controllers/v1/utils.py +++ b/ironic/api/controllers/v1/utils.py @@ -22,13 +22,13 @@ from jsonschema import exceptions as json_schema_exc import os_traits from oslo_config import cfg from oslo_utils import uuidutils -import pecan from pecan import rest import six from six.moves import http_client from webob import static import wsme +from ironic import api from ironic.api.controllers.v1 import versions from ironic.common import exception from ironic.common import faults @@ -192,7 +192,7 @@ def is_path_updated(patch, path): def allow_node_logical_names(): # v1.5 added logical name aliases - return pecan.request.version.minor >= versions.MINOR_5_NODE_NAME + return api.request.version.minor >= versions.MINOR_5_NODE_NAME def _get_with_suffix(get_func, ident, exc_class): @@ -200,7 +200,7 @@ def _get_with_suffix(get_func, ident, exc_class): try: return get_func(ident) except exc_class: - if not pecan.request.environ['HAS_JSON_SUFFIX']: + if not api.request.environ['HAS_JSON_SUFFIX']: raise # NOTE(dtantsur): strip .json prefix to maintain compatibility @@ -221,12 +221,12 @@ def get_rpc_node(node_ident): # Check to see if the node_ident is a valid UUID. If it is, treat it # as a UUID. if uuidutils.is_uuid_like(node_ident): - return objects.Node.get_by_uuid(pecan.request.context, node_ident) + return objects.Node.get_by_uuid(api.request.context, node_ident) # We can refer to nodes by their name, if the client supports it if allow_node_logical_names(): if is_valid_logical_name(node_ident): - return objects.Node.get_by_name(pecan.request.context, node_ident) + return objects.Node.get_by_name(api.request.context, node_ident) raise exception.InvalidUuidOrName(name=node_ident) # Ensure we raise the same exception as we did for the Juno release @@ -260,12 +260,12 @@ def get_rpc_portgroup(portgroup_ident): # Check to see if the portgroup_ident is a valid UUID. If it is, treat it # as a UUID. if uuidutils.is_uuid_like(portgroup_ident): - return objects.Portgroup.get_by_uuid(pecan.request.context, + return objects.Portgroup.get_by_uuid(api.request.context, portgroup_ident) # We can refer to portgroups by their name if utils.is_valid_logical_name(portgroup_ident): - return objects.Portgroup.get_by_name(pecan.request.context, + return objects.Portgroup.get_by_name(api.request.context, portgroup_ident) raise exception.InvalidUuidOrName(name=portgroup_ident) @@ -299,12 +299,12 @@ def get_rpc_allocation(allocation_ident): # Check to see if the allocation_ident is a valid UUID. If it is, treat it # as a UUID. if uuidutils.is_uuid_like(allocation_ident): - return objects.Allocation.get_by_uuid(pecan.request.context, + return objects.Allocation.get_by_uuid(api.request.context, allocation_ident) # We can refer to allocations by their name if utils.is_valid_logical_name(allocation_ident): - return objects.Allocation.get_by_name(pecan.request.context, + return objects.Allocation.get_by_name(api.request.context, allocation_ident) raise exception.InvalidUuidOrName(name=allocation_ident) @@ -338,12 +338,12 @@ def get_rpc_deploy_template(template_ident): # Check to see if the template_ident is a valid UUID. If it is, treat it # as a UUID. if uuidutils.is_uuid_like(template_ident): - return objects.DeployTemplate.get_by_uuid(pecan.request.context, + return objects.DeployTemplate.get_by_uuid(api.request.context, template_ident) # We can refer to templates by their name if utils.is_valid_logical_name(template_ident): - return objects.DeployTemplate.get_by_name(pecan.request.context, + return objects.DeployTemplate.get_by_name(api.request.context, template_ident) raise exception.InvalidUuidOrName(name=template_ident) @@ -378,7 +378,7 @@ def is_valid_node_name(name): def is_valid_logical_name(name): """Determine if the provided name is a valid hostname.""" - if pecan.request.version.minor < versions.MINOR_10_UNRESTRICTED_NODE_NAME: + if api.request.version.minor < versions.MINOR_10_UNRESTRICTED_NODE_NAME: return utils.is_hostname_safe(name) else: return utils.is_valid_logical_name(name) @@ -409,12 +409,12 @@ def vendor_passthru(ident, method, topic, data=None, driver_passthru=False): if data is None: data = {} - http_method = pecan.request.method.upper() - params = (pecan.request.context, ident, method, http_method, data, topic) + http_method = api.request.method.upper() + params = (api.request.context, ident, method, http_method, data, topic) if driver_passthru: - response = pecan.request.rpcapi.driver_vendor_passthru(*params) + response = api.request.rpcapi.driver_vendor_passthru(*params) else: - response = pecan.request.rpcapi.vendor_passthru(*params) + response = api.request.rpcapi.vendor_passthru(*params) status_code = http_client.ACCEPTED if response['async'] else http_client.OK return_value = response['return'] @@ -426,7 +426,7 @@ def vendor_passthru(ident, method, topic, data=None, driver_passthru=False): # If unicode, convert to bytes return_value = return_value.encode('utf-8') file_ = wsme.types.File(content=return_value) - pecan.response.app_iter = static.FileIter(file_.file) + api.response.app_iter = static.FileIter(file_.file) # Since we've attached the return value to the response # object the response body should now be empty. return_value = None @@ -458,7 +458,7 @@ def check_allow_specify_fields(fields): attributes, this method checks if the required version is being requested. """ - if (fields is not None and pecan.request.version.minor + if (fields is not None and api.request.version.minor < versions.MINOR_8_FETCHING_SUBSET_OF_FIELDS): raise exception.NotAcceptable() @@ -496,7 +496,7 @@ for field in V31_FIELDS: def allow_field(field): """Check if a field is allowed in the current version.""" - return pecan.request.version.minor >= VERSIONED_FIELDS[field] + return api.request.version.minor >= VERSIONED_FIELDS[field] def disallowed_fields(): @@ -534,7 +534,7 @@ def check_allowed_portgroup_fields(fields): def check_allow_management_verbs(verb): min_version = MIN_VERB_VERSIONS.get(verb) - if min_version is not None and pecan.request.version.minor < min_version: + if min_version is not None and api.request.version.minor < min_version: raise exception.NotAcceptable() @@ -544,7 +544,7 @@ def check_for_invalid_state_and_allow_filter(provision_state): Version 1.9 of the API allows filter nodes by provision state. """ if provision_state is not None: - if (pecan.request.version.minor + if (api.request.version.minor < versions.MINOR_9_PROVISION_STATE_FILTER): raise exception.NotAcceptable() valid_states = states.machine.states @@ -558,7 +558,7 @@ def check_allow_specify_driver(driver): Version 1.16 of the API allows filter nodes by driver. """ - if (driver is not None and pecan.request.version.minor + if (driver is not None and api.request.version.minor < versions.MINOR_16_DRIVER_FILTER): raise exception.NotAcceptable(_( "Request not acceptable. The minimal required API version " @@ -572,7 +572,7 @@ def check_allow_specify_resource_class(resource_class): Version 1.21 of the API allows filtering nodes by resource_class. """ - if (resource_class is not None and pecan.request.version.minor + if (resource_class is not None and api.request.version.minor < versions.MINOR_21_RESOURCE_CLASS): raise exception.NotAcceptable(_( "Request not acceptable. The minimal required API version " @@ -662,7 +662,7 @@ def check_allow_filter_by_fault(fault): Version 1.42 of the API allows filtering nodes by fault. """ - if (fault is not None and pecan.request.version.minor + if (fault is not None and api.request.version.minor < versions.MINOR_42_FAULT): raise exception.NotAcceptable(_( "Request not acceptable. The minimal required API version " @@ -682,7 +682,7 @@ def check_allow_filter_by_conductor_group(conductor_group): Version 1.46 of the API allows filtering nodes by conductor_group. """ - if (conductor_group is not None and pecan.request.version.minor + if (conductor_group is not None and api.request.version.minor < versions.MINOR_46_NODE_CONDUCTOR_GROUP): raise exception.NotAcceptable(_( "Request not acceptable. The minimal required API version " @@ -696,7 +696,7 @@ def check_allow_filter_by_owner(owner): Version 1.50 of the API allows filtering nodes by owner. """ - if (owner is not None and pecan.request.version.minor + if (owner is not None and api.request.version.minor < versions.MINOR_50_NODE_OWNER): raise exception.NotAcceptable(_( "Request not acceptable. The minimal required API version " @@ -712,7 +712,7 @@ def initial_node_provision_state(): Starting with API 1.11 it is ENROLL. """ return (states.AVAILABLE - if pecan.request.version.minor < versions.MINOR_11_ENROLL_STATE + if api.request.version.minor < versions.MINOR_11_ENROLL_STATE else states.ENROLL) @@ -721,7 +721,7 @@ def allow_raid_config(): Version 1.12 of the API allows RAID configuration for the node. """ - return pecan.request.version.minor >= versions.MINOR_12_RAID_CONFIG + return api.request.version.minor >= versions.MINOR_12_RAID_CONFIG def allow_soft_power_off(): @@ -730,7 +730,7 @@ def allow_soft_power_off(): Version 1.27 of the API allows Soft Power Off, including Soft Reboot, for the node. """ - return pecan.request.version.minor >= versions.MINOR_27_SOFT_POWER_OFF + return api.request.version.minor >= versions.MINOR_27_SOFT_POWER_OFF def allow_inject_nmi(): @@ -738,7 +738,7 @@ def allow_inject_nmi(): Version 1.29 of the API allows Inject NMI for the node. """ - return pecan.request.version.minor >= versions.MINOR_29_INJECT_NMI + return api.request.version.minor >= versions.MINOR_29_INJECT_NMI def allow_links_node_states_and_driver_properties(): @@ -747,7 +747,7 @@ def allow_links_node_states_and_driver_properties(): Version 1.14 of the API allows the display of links to node states and driver properties. """ - return (pecan.request.version.minor + return (api.request.version.minor >= versions.MINOR_14_LINKS_NODESTATES_DRIVERPROPERTIES) @@ -756,7 +756,7 @@ def allow_port_internal_info(): Version 1.18 of the API exposes internal_info readonly field for the port. """ - return (pecan.request.version.minor + return (api.request.version.minor >= versions.MINOR_18_PORT_INTERNAL_INFO) @@ -765,7 +765,7 @@ def allow_port_advanced_net_fields(): Version 1.19 of the API added support for these new fields in port object. """ - return (pecan.request.version.minor + return (api.request.version.minor >= versions.MINOR_19_PORT_ADVANCED_NET_FIELDS) @@ -774,7 +774,7 @@ def allow_ramdisk_endpoints(): Version 1.22 of the API introduced them. """ - return pecan.request.version.minor >= versions.MINOR_22_LOOKUP_HEARTBEAT + return api.request.version.minor >= versions.MINOR_22_LOOKUP_HEARTBEAT def allow_portgroups(): @@ -782,7 +782,7 @@ def allow_portgroups(): Version 1.23 of the API added support for PortGroups. """ - return (pecan.request.version.minor + return (api.request.version.minor >= versions.MINOR_23_PORTGROUPS) @@ -792,7 +792,7 @@ def allow_portgroups_subcontrollers(): Version 1.24 of the API added support for Portgroups as subcontrollers """ - return (pecan.request.version.minor + return (api.request.version.minor >= versions.MINOR_24_PORTGROUPS_SUBCONTROLLERS) @@ -802,7 +802,7 @@ def allow_remove_chassis_uuid(): Version 1.25 of the API added support for chassis_uuid removal """ - return (pecan.request.version.minor + return (api.request.version.minor >= versions.MINOR_25_UNSET_CHASSIS_UUID) @@ -812,7 +812,7 @@ def allow_portgroup_mode_properties(): Version 1.26 of the API added mode and properties fields to portgroup object. """ - return (pecan.request.version.minor + return (api.request.version.minor >= versions.MINOR_26_PORTGROUP_MODE_PROPERTIES) @@ -822,7 +822,7 @@ def allow_vifs_subcontroller(): Version 1.28 of the API added support for VIFs to be attached to Nodes. """ - return (pecan.request.version.minor + return (api.request.version.minor >= versions.MINOR_28_VIFS_SUBCONTROLLER) @@ -832,7 +832,7 @@ def allow_dynamic_drivers(): Version 1.30 of the API added support for all of the driver composition related calls in the /v1/drivers API. """ - return (pecan.request.version.minor + return (api.request.version.minor >= versions.MINOR_30_DYNAMIC_DRIVERS) @@ -842,7 +842,7 @@ def allow_dynamic_interfaces(): Version 1.31 of the API added support for viewing and setting the fields in ``V31_FIELDS`` on the node object. """ - return (pecan.request.version.minor + return (api.request.version.minor >= versions.MINOR_31_DYNAMIC_INTERFACES) @@ -851,7 +851,7 @@ def allow_volume(): Version 1.32 of the API added support for volume connectors and targets """ - return pecan.request.version.minor >= versions.MINOR_32_VOLUME + return api.request.version.minor >= versions.MINOR_32_VOLUME def allow_storage_interface(): @@ -859,7 +859,7 @@ def allow_storage_interface(): Version 1.33 of the API added support for storage interfaces. """ - return (pecan.request.version.minor + return (api.request.version.minor >= versions.MINOR_33_STORAGE_INTERFACE) @@ -871,7 +871,7 @@ def allow_port_physical_network(): supports the physical_network field as this may not be the case during a rolling upgrade. """ - return ((pecan.request.version.minor + return ((api.request.version.minor >= versions.MINOR_34_PORT_PHYSICAL_NETWORK) and objects.Port.supports_physical_network()) @@ -881,7 +881,7 @@ def allow_node_rebuild_with_configdrive(): Version 1.35 of the API added support for node rebuild with configdrive. """ - return (pecan.request.version.minor + return (api.request.version.minor >= versions.MINOR_35_REBUILD_CONFIG_DRIVE) @@ -891,7 +891,7 @@ def allow_agent_version_in_heartbeat(): Version 1.36 of the API added the ability for agents to pass their version information to Ironic on heartbeat. """ - return (pecan.request.version.minor + return (api.request.version.minor >= versions.MINOR_36_AGENT_VERSION_HEARTBEAT) @@ -900,7 +900,7 @@ def allow_rescue_interface(): Version 1.38 of the API added support for rescue and unrescue. """ - return pecan.request.version.minor >= versions.MINOR_38_RESCUE_INTERFACE + return api.request.version.minor >= versions.MINOR_38_RESCUE_INTERFACE def allow_bios_interface(): @@ -908,7 +908,7 @@ def allow_bios_interface(): Version 1.40 of the API added support for bios interface. """ - return pecan.request.version.minor >= versions.MINOR_40_BIOS_INTERFACE + return api.request.version.minor >= versions.MINOR_40_BIOS_INTERFACE def get_controller_reserved_names(cls): @@ -936,7 +936,7 @@ def allow_traits(): Version 1.37 of the API allows traits for the node. """ - return pecan.request.version.minor >= versions.MINOR_37_NODE_TRAITS + return api.request.version.minor >= versions.MINOR_37_NODE_TRAITS def allow_inspect_wait_state(): @@ -945,7 +945,7 @@ def allow_inspect_wait_state(): Version 1.39 of the API adds 'inspect wait' state to substitute 'inspecting' state during asynchronous hardware inspection. """ - return pecan.request.version.minor >= versions.MINOR_39_INSPECT_WAIT + return api.request.version.minor >= versions.MINOR_39_INSPECT_WAIT def allow_inspect_abort(): @@ -953,7 +953,7 @@ def allow_inspect_abort(): Version 1.41 of the API added support for inspection abort """ - return pecan.request.version.minor >= versions.MINOR_41_INSPECTION_ABORT + return api.request.version.minor >= versions.MINOR_41_INSPECTION_ABORT def handle_post_port_like_extra_vif(p_dict): @@ -1045,13 +1045,13 @@ def allow_detail_query(): Version 1.43 allows a user to pass the detail query string to list the resource with all the fields. """ - return (pecan.request.version.minor >= + return (api.request.version.minor >= versions.MINOR_43_ENABLE_DETAIL_QUERY) def allow_reset_interfaces(): """Check if passing a reset_interfaces query string is allowed.""" - return (pecan.request.version.minor >= + return (api.request.version.minor >= versions.MINOR_45_RESET_INTERFACES) @@ -1094,7 +1094,7 @@ def allow_expose_conductors(): Version 1.49 of the API exposed conductor endpoints and conductor field for the node. """ - return pecan.request.version.minor >= versions.MINOR_49_CONDUCTORS + return api.request.version.minor >= versions.MINOR_49_CONDUCTORS def check_allow_filter_by_conductor(conductor): @@ -1116,7 +1116,7 @@ def allow_allocations(): Version 1.52 of the API exposed allocation endpoints and allocation_uuid field for the node. """ - return pecan.request.version.minor >= versions.MINOR_52_ALLOCATION + return api.request.version.minor >= versions.MINOR_52_ALLOCATION def allow_port_is_smartnic(): @@ -1124,7 +1124,7 @@ def allow_port_is_smartnic(): Version 1.53 of the API added is_smartnic field to the port object. """ - return ((pecan.request.version.minor + return ((api.request.version.minor >= versions.MINOR_53_PORT_SMARTNIC) and objects.Port.supports_is_smartnic()) @@ -1134,7 +1134,7 @@ def allow_expose_events(): Version 1.54 of the API added the events endpoint. """ - return pecan.request.version.minor >= versions.MINOR_54_EVENTS + return api.request.version.minor >= versions.MINOR_54_EVENTS def allow_deploy_templates(): @@ -1142,7 +1142,7 @@ def allow_deploy_templates(): Version 1.55 of the API exposed deploy template endpoints. """ - return pecan.request.version.minor >= versions.MINOR_55_DEPLOY_TEMPLATES + return api.request.version.minor >= versions.MINOR_55_DEPLOY_TEMPLATES def check_policy(policy_name): @@ -1151,7 +1151,7 @@ def check_policy(policy_name): :policy_name: Name of the policy to check. :raises: HTTPForbidden if the policy forbids access. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize(policy_name, cdict, cdict) @@ -1160,7 +1160,7 @@ def allow_build_configdrive(): Version 1.56 of the API added support for building configdrive. """ - return pecan.request.version.minor >= versions.MINOR_56_BUILD_CONFIGDRIVE + return api.request.version.minor >= versions.MINOR_56_BUILD_CONFIGDRIVE def allow_allocation_update(): @@ -1168,7 +1168,7 @@ def allow_allocation_update(): Version 1.57 of the API added support for updating an allocation. """ - return pecan.request.version.minor >= versions.MINOR_57_ALLOCATION_UPDATE + return api.request.version.minor >= versions.MINOR_57_ALLOCATION_UPDATE def allow_allocation_backfill(): @@ -1176,4 +1176,4 @@ def allow_allocation_backfill(): Version 1.58 of the API added support for backfilling allocations. """ - return pecan.request.version.minor >= versions.MINOR_58_ALLOCATION_BACKFILL + return api.request.version.minor >= versions.MINOR_58_ALLOCATION_BACKFILL diff --git a/ironic/api/controllers/v1/volume.py b/ironic/api/controllers/v1/volume.py index a8adcfc23d..4e9f6aef29 100644 --- a/ironic/api/controllers/v1/volume.py +++ b/ironic/api/controllers/v1/volume.py @@ -17,6 +17,7 @@ from pecan import rest from six.moves import http_client import wsme +from ironic import api from ironic.api.controllers import base from ironic.api.controllers import link from ironic.api.controllers.v1 import utils as api_utils @@ -45,7 +46,7 @@ class Volume(base.APIBase): @staticmethod def convert(node_ident=None): - url = pecan.request.public_url + url = api.request.public_url volume = Volume() if node_ident: resource = 'nodes' @@ -89,7 +90,7 @@ class VolumeController(rest.RestController): if not api_utils.allow_volume(): raise exception.NotFound() - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:volume:get', cdict, cdict) return Volume.convert(self.parent_node_ident) diff --git a/ironic/api/controllers/v1/volume_connector.py b/ironic/api/controllers/v1/volume_connector.py index d6e77f1a80..405987e790 100644 --- a/ironic/api/controllers/v1/volume_connector.py +++ b/ironic/api/controllers/v1/volume_connector.py @@ -16,13 +16,13 @@ import datetime from ironic_lib import metrics_utils from oslo_utils import uuidutils -import pecan from pecan import rest import six from six.moves import http_client import wsme from wsme import types as wtypes +from ironic import api from ironic.api.controllers import base from ironic.api.controllers import link from ironic.api.controllers.v1 import collection @@ -62,7 +62,7 @@ class VolumeConnector(base.APIBase): self._node_uuid = wtypes.Unset elif value and self._node_uuid != value: try: - node = objects.Node.get(pecan.request.context, value) + node = objects.Node.get(api.request.context, value) self._node_uuid = node.uuid # NOTE(smoriya): Create the node_id attribute on-the-fly # to satisfy the api -> rpc object conversion. @@ -137,7 +137,7 @@ class VolumeConnector(base.APIBase): api_utils.check_for_invalid_fields(fields, connector.as_dict()) connector = cls._convert_with_links(connector, - pecan.request.public_url) + api.request.public_url) if not sanitize: return connector @@ -232,7 +232,7 @@ class VolumeConnectorsController(rest.RestController): marker_obj = None if marker: marker_obj = objects.VolumeConnector.get_by_uuid( - pecan.request.context, marker) + api.request.context, marker) if sort_key in self.invalid_sort_key_list: raise exception.InvalidParameterValue( @@ -248,10 +248,10 @@ class VolumeConnectorsController(rest.RestController): # as we move to the object interface. node = api_utils.get_rpc_node(node_ident) connectors = objects.VolumeConnector.list_by_node_id( - pecan.request.context, node.id, limit, marker_obj, + api.request.context, node.id, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) else: - connectors = objects.VolumeConnector.list(pecan.request.context, + connectors = objects.VolumeConnector.list(api.request.context, limit, marker_obj, sort_key=sort_key, @@ -291,7 +291,7 @@ class VolumeConnectorsController(rest.RestController): :raises: InvalidParameterValue if sort key is invalid for sorting. :raises: InvalidParameterValue if both fields and detail are specified. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:volume:get', cdict, cdict) if fields is None and not detail: @@ -322,14 +322,14 @@ class VolumeConnectorsController(rest.RestController): :raises: VolumeConnectorNotFound if no volume connector exists with the specified UUID. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:volume:get', cdict, cdict) if self.parent_node_ident: raise exception.OperationNotPermitted() rpc_connector = objects.VolumeConnector.get_by_uuid( - pecan.request.context, connector_uuid) + api.request.context, connector_uuid) return VolumeConnector.convert_with_links(rpc_connector, fields=fields) @METRICS.timer('VolumeConnectorsController.post') @@ -349,7 +349,7 @@ class VolumeConnectorsController(rest.RestController): :raises: VolumeConnectorAlreadyExists if a volume connector with the same UUID already exists """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:volume:create', cdict, cdict) @@ -372,8 +372,8 @@ class VolumeConnectorsController(rest.RestController): notify.emit_end_notification(context, new_connector, 'create', node_uuid=connector.node_uuid) # Set the HTTP Location Header - pecan.response.location = link.build_url('volume/connectors', - new_connector.uuid) + api.response.location = link.build_url('volume/connectors', + new_connector.uuid) return VolumeConnector.convert_with_links(new_connector) @METRICS.timer('VolumeConnectorsController.patch') @@ -405,7 +405,7 @@ class VolumeConnectorsController(rest.RestController): :raises: InvalidStateRequested If a node associated with the volume connector is not powered off. """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:volume:update', cdict, cdict) @@ -448,8 +448,8 @@ class VolumeConnectorsController(rest.RestController): node_uuid=rpc_node.uuid) with notify.handle_error_notification(context, rpc_connector, 'update', node_uuid=rpc_node.uuid): - topic = pecan.request.rpcapi.get_topic_for(rpc_node) - new_connector = pecan.request.rpcapi.update_volume_connector( + topic = api.request.rpcapi.get_topic_for(rpc_node) + new_connector = api.request.rpcapi.update_volume_connector( context, rpc_connector, topic) api_connector = VolumeConnector.convert_with_links(new_connector) @@ -474,7 +474,7 @@ class VolumeConnectorsController(rest.RestController): :raises: InvalidStateRequested If a node associated with the volume connector is not powered off. """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:volume:delete', cdict, cdict) @@ -489,8 +489,8 @@ class VolumeConnectorsController(rest.RestController): with notify.handle_error_notification(context, rpc_connector, 'delete', node_uuid=rpc_node.uuid): - topic = pecan.request.rpcapi.get_topic_for(rpc_node) - pecan.request.rpcapi.destroy_volume_connector(context, - rpc_connector, topic) + topic = api.request.rpcapi.get_topic_for(rpc_node) + api.request.rpcapi.destroy_volume_connector(context, + rpc_connector, topic) notify.emit_end_notification(context, rpc_connector, 'delete', node_uuid=rpc_node.uuid) diff --git a/ironic/api/controllers/v1/volume_target.py b/ironic/api/controllers/v1/volume_target.py index 144d061464..28349670ff 100644 --- a/ironic/api/controllers/v1/volume_target.py +++ b/ironic/api/controllers/v1/volume_target.py @@ -16,13 +16,13 @@ import datetime from ironic_lib import metrics_utils from oslo_utils import uuidutils -import pecan from pecan import rest import six from six.moves import http_client import wsme from wsme import types as wtypes +from ironic import api from ironic.api.controllers import base from ironic.api.controllers import link from ironic.api.controllers.v1 import collection @@ -63,7 +63,7 @@ class VolumeTarget(base.APIBase): self._node_uuid = wtypes.Unset elif value and self._node_uuid != value: try: - node = objects.Node.get(pecan.request.context, value) + node = objects.Node.get(api.request.context, value) self._node_uuid = node.uuid # NOTE(smoriya): Create the node_id attribute on-the-fly # to satisfy the api -> rpc object conversion. @@ -143,7 +143,7 @@ class VolumeTarget(base.APIBase): if fields is not None: api_utils.check_for_invalid_fields(fields, target.as_dict()) - target = cls._convert_with_links(target, pecan.request.public_url) + target = cls._convert_with_links(target, api.request.public_url) if not sanitize: return target @@ -247,7 +247,7 @@ class VolumeTargetsController(rest.RestController): marker_obj = None if marker: marker_obj = objects.VolumeTarget.get_by_uuid( - pecan.request.context, marker) + api.request.context, marker) if sort_key in self.invalid_sort_key_list: raise exception.InvalidParameterValue( @@ -263,10 +263,10 @@ class VolumeTargetsController(rest.RestController): # as we move to the object interface. node = api_utils.get_rpc_node(node_ident) targets = objects.VolumeTarget.list_by_node_id( - pecan.request.context, node.id, limit, marker_obj, + api.request.context, node.id, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) else: - targets = objects.VolumeTarget.list(pecan.request.context, + targets = objects.VolumeTarget.list(api.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) @@ -305,7 +305,7 @@ class VolumeTargetsController(rest.RestController): :raises: InvalidParameterValue if sort key is invalid for sorting. :raises: InvalidParameterValue if both fields and detail are specified. """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:volume:get', cdict, cdict) if fields is None and not detail: @@ -337,14 +337,14 @@ class VolumeTargetsController(rest.RestController): node. :raises: VolumeTargetNotFound if no volume target with this UUID exists """ - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() policy.authorize('baremetal:volume:get', cdict, cdict) if self.parent_node_ident: raise exception.OperationNotPermitted() rpc_target = objects.VolumeTarget.get_by_uuid( - pecan.request.context, target_uuid) + api.request.context, target_uuid) return VolumeTarget.convert_with_links(rpc_target, fields=fields) @METRICS.timer('VolumeTargetsController.post') @@ -364,7 +364,7 @@ class VolumeTargetsController(rest.RestController): :raises: VolumeTargetAlreadyExists if a volume target with the same UUID exists """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:volume:create', cdict, cdict) @@ -386,8 +386,8 @@ class VolumeTargetsController(rest.RestController): notify.emit_end_notification(context, new_target, 'create', node_uuid=target.node_uuid) # Set the HTTP Location Header - pecan.response.location = link.build_url('volume/targets', - new_target.uuid) + api.response.location = link.build_url('volume/targets', + new_target.uuid) return VolumeTarget.convert_with_links(new_target) @METRICS.timer('VolumeTargetsController.patch') @@ -417,7 +417,7 @@ class VolumeTargetsController(rest.RestController): :raises: InvalidStateRequested If a node associated with the volume target is not powered off. """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:volume:update', cdict, cdict) @@ -458,8 +458,8 @@ class VolumeTargetsController(rest.RestController): node_uuid=rpc_node.uuid) with notify.handle_error_notification(context, rpc_target, 'update', node_uuid=rpc_node.uuid): - topic = pecan.request.rpcapi.get_topic_for(rpc_node) - new_target = pecan.request.rpcapi.update_volume_target( + topic = api.request.rpcapi.get_topic_for(rpc_node) + new_target = api.request.rpcapi.update_volume_target( context, rpc_target, topic) api_target = VolumeTarget.convert_with_links(new_target) @@ -483,7 +483,7 @@ class VolumeTargetsController(rest.RestController): :raises: InvalidStateRequested If a node associated with the volume target is not powered off. """ - context = pecan.request.context + context = api.request.context cdict = context.to_policy_values() policy.authorize('baremetal:volume:delete', cdict, cdict) @@ -496,8 +496,8 @@ class VolumeTargetsController(rest.RestController): node_uuid=rpc_node.uuid) with notify.handle_error_notification(context, rpc_target, 'delete', node_uuid=rpc_node.uuid): - topic = pecan.request.rpcapi.get_topic_for(rpc_node) - pecan.request.rpcapi.destroy_volume_target(context, - rpc_target, topic) + topic = api.request.rpcapi.get_topic_for(rpc_node) + api.request.rpcapi.destroy_volume_target(context, + rpc_target, topic) notify.emit_end_notification(context, rpc_target, 'delete', node_uuid=rpc_node.uuid) diff --git a/ironic/api/controllers/version.py b/ironic/api/controllers/version.py index 4516b83643..46472acd84 100644 --- a/ironic/api/controllers/version.py +++ b/ironic/api/controllers/version.py @@ -10,9 +10,9 @@ # License for the specific language governing permissions and limitations # under the License. -import pecan from wsme import types as wtypes +from ironic import api from ironic.api.controllers import base from ironic.api.controllers import link @@ -49,7 +49,7 @@ class Version(base.APIBase): def __init__(self, id, min_version, version, status='CURRENT'): self.id = id - self.links = [link.Link.make_link('self', pecan.request.public_url, + self.links = [link.Link.make_link('self', api.request.public_url, self.id, '', bookmark=True)] self.status = status self.version = version diff --git a/ironic/tests/unit/api/controllers/v1/test_node.py b/ironic/tests/unit/api/controllers/v1/test_node.py index f03b943e84..f87b98d903 100644 --- a/ironic/tests/unit/api/controllers/v1/test_node.py +++ b/ironic/tests/unit/api/controllers/v1/test_node.py @@ -2330,7 +2330,7 @@ class TestPatch(test_api_base.BaseApiTest): self.assertEqual(http_client.NOT_ACCEPTABLE, response.status_code) self.assertTrue(response.json['error_message']) - @mock.patch('pecan.request') + @mock.patch('ironic.api.request') def test__update_changed_fields_lowers_conductor_group(self, mock_pecan_req): mock_pecan_req.version.minor = versions.MINOR_MAX_VERSION @@ -2343,7 +2343,7 @@ class TestPatch(test_api_base.BaseApiTest): controller._update_changed_fields(node_obj, self.node) self.assertEqual('new-group', self.node.conductor_group) - @mock.patch("pecan.request") + @mock.patch("ironic.api.request") def test__update_changed_fields_remove_chassis_uuid(self, mock_pecan_req): mock_pecan_req.version.minor = versions.MINOR_MAX_VERSION controller = api_node.NodesController() diff --git a/ironic/tests/unit/api/controllers/v1/test_port.py b/ironic/tests/unit/api/controllers/v1/test_port.py index 302596c021..3cc53355e6 100644 --- a/ironic/tests/unit/api/controllers/v1/test_port.py +++ b/ironic/tests/unit/api/controllers/v1/test_port.py @@ -78,7 +78,7 @@ def _rpcapi_update_port(self, context, port, topic): class TestPortObject(base.TestCase): - @mock.patch("pecan.request") + @mock.patch("ironic.api.request") def test_port_init(self, mock_pecan_req): mock_pecan_req.version.minor = 1 port_dict = apiutils.port_post_data(node_id=None, diff --git a/ironic/tests/unit/api/controllers/v1/test_types.py b/ironic/tests/unit/api/controllers/v1/test_types.py index 2b18ed7f1c..9dccb2bb36 100644 --- a/ironic/tests/unit/api/controllers/v1/test_types.py +++ b/ironic/tests/unit/api/controllers/v1/test_types.py @@ -54,36 +54,33 @@ class TestUuidType(base.TestCase): types.UuidType.validate, 'invalid-uuid') +@mock.patch("ironic.api.request") class TestNameType(base.TestCase): - @mock.patch("pecan.request") def test_valid_name(self, mock_pecan_req): mock_pecan_req.version.minor = 10 test_name = 'hal-9000' self.assertEqual(test_name, types.NameType.validate(test_name)) - @mock.patch("pecan.request") def test_invalid_name(self, mock_pecan_req): mock_pecan_req.version.minor = 10 self.assertRaises(exception.InvalidName, types.NameType.validate, '-this is not valid-') +@mock.patch("ironic.api.request") class TestUuidOrNameType(base.TestCase): - @mock.patch("pecan.request") def test_valid_uuid(self, mock_pecan_req): mock_pecan_req.version.minor = 10 test_uuid = '1a1a1a1a-2b2b-3c3c-4d4d-5e5e5e5e5e5e' self.assertTrue(types.UuidOrNameType.validate(test_uuid)) - @mock.patch("pecan.request") def test_valid_name(self, mock_pecan_req): mock_pecan_req.version.minor = 10 test_name = 'dc16-database5' self.assertTrue(types.UuidOrNameType.validate(test_name)) - @mock.patch("pecan.request") def test_invalid_uuid_or_name(self, mock_pecan_req): mock_pecan_req.version.minor = 10 self.assertRaises(exception.InvalidUuidOrName, @@ -371,7 +368,7 @@ class TestLocalLinkConnectionType(base.TestCase): self.assertRaises(exception.Invalid, v.validate, value) -@mock.patch("pecan.request", mock.Mock(version=mock.Mock(minor=10))) +@mock.patch("ironic.api.request", mock.Mock(version=mock.Mock(minor=10))) class TestVifType(base.TestCase): def test_vif_type(self): diff --git a/ironic/tests/unit/api/controllers/v1/test_utils.py b/ironic/tests/unit/api/controllers/v1/test_utils.py index 8b1924257b..d18fded4a6 100644 --- a/ironic/tests/unit/api/controllers/v1/test_utils.py +++ b/ironic/tests/unit/api/controllers/v1/test_utils.py @@ -18,11 +18,11 @@ import mock import os_traits from oslo_config import cfg from oslo_utils import uuidutils -import pecan from six.moves import http_client from webob import static import wsme +from ironic import api from ironic.api.controllers.v1 import node as api_node from ironic.api.controllers.v1 import utils from ironic.common import exception @@ -197,24 +197,24 @@ class TestApiUtils(base.TestCase): utils.check_for_invalid_fields, requested, supported) - @mock.patch.object(pecan, 'request', spec_set=['version']) + +@mock.patch.object(api, 'request', spec_set=['version']) +class TestCheckAllowFields(base.TestCase): + def test_check_allow_specify_fields(self, mock_request): mock_request.version.minor = 8 self.assertIsNone(utils.check_allow_specify_fields(['foo'])) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_specify_fields_fail(self, mock_request): mock_request.version.minor = 7 self.assertRaises(exception.NotAcceptable, utils.check_allow_specify_fields, ['foo']) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allowed_fields_network_interface(self, mock_request): mock_request.version.minor = 20 self.assertIsNone( utils.check_allowed_fields(['network_interface'])) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allowed_fields_network_interface_fail(self, mock_request): mock_request.version.minor = 19 self.assertRaises( @@ -222,13 +222,11 @@ class TestApiUtils(base.TestCase): utils.check_allowed_fields, ['network_interface']) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allowed_fields_resource_class(self, mock_request): mock_request.version.minor = 21 self.assertIsNone( utils.check_allowed_fields(['resource_class'])) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allowed_fields_resource_class_fail(self, mock_request): mock_request.version.minor = 20 self.assertRaises( @@ -236,7 +234,6 @@ class TestApiUtils(base.TestCase): utils.check_allowed_fields, ['resource_class']) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allowed_fields_rescue_interface_fail(self, mock_request): mock_request.version.minor = 31 self.assertRaises( @@ -244,7 +241,6 @@ class TestApiUtils(base.TestCase): utils.check_allowed_fields, ['rescue_interface']) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allowed_portgroup_fields_mode_properties(self, mock_request): mock_request.version.minor = 26 @@ -253,7 +249,6 @@ class TestApiUtils(base.TestCase): self.assertIsNone( utils.check_allowed_portgroup_fields(['properties'])) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allowed_portgroup_fields_mode_properties_fail(self, mock_request): mock_request.version.minor = 25 @@ -266,243 +261,202 @@ class TestApiUtils(base.TestCase): utils.check_allowed_portgroup_fields, ['properties']) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_specify_driver(self, mock_request): mock_request.version.minor = 16 self.assertIsNone(utils.check_allow_specify_driver(['fake'])) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_specify_driver_fail(self, mock_request): mock_request.version.minor = 15 self.assertRaises(exception.NotAcceptable, utils.check_allow_specify_driver, ['fake']) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_specify_resource_class(self, mock_request): mock_request.version.minor = 21 self.assertIsNone(utils.check_allow_specify_resource_class(['foo'])) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_specify_resource_class_fail(self, mock_request): mock_request.version.minor = 20 self.assertRaises(exception.NotAcceptable, utils.check_allow_specify_resource_class, ['foo']) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_filter_driver_type(self, mock_request): mock_request.version.minor = 30 self.assertIsNone(utils.check_allow_filter_driver_type('classic')) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_filter_driver_type_none(self, mock_request): mock_request.version.minor = 29 self.assertIsNone(utils.check_allow_filter_driver_type(None)) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_filter_driver_type_fail(self, mock_request): mock_request.version.minor = 29 self.assertRaises(exception.NotAcceptable, utils.check_allow_filter_driver_type, 'classic') - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_filter_by_conductor_group(self, mock_request): mock_request.version.minor = 46 self.assertIsNone(utils.check_allow_filter_by_conductor_group('foo')) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_filter_by_conductor_group_none(self, mock_request): mock_request.version.minor = 46 self.assertIsNone(utils.check_allow_filter_by_conductor_group(None)) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_filter_by_conductor_group_fail(self, mock_request): mock_request.version.minor = 45 self.assertRaises(exception.NotAcceptable, utils.check_allow_filter_by_conductor_group, 'foo') - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_driver_detail(self, mock_request): mock_request.version.minor = 30 self.assertIsNone(utils.check_allow_driver_detail(True)) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_driver_detail_false(self, mock_request): mock_request.version.minor = 30 self.assertIsNone(utils.check_allow_driver_detail(False)) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_driver_detail_none(self, mock_request): mock_request.version.minor = 29 self.assertIsNone(utils.check_allow_driver_detail(None)) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_driver_detail_fail(self, mock_request): mock_request.version.minor = 29 self.assertRaises(exception.NotAcceptable, utils.check_allow_driver_detail, True) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_manage_verbs(self, mock_request): mock_request.version.minor = 4 utils.check_allow_management_verbs('manage') - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_manage_verbs_fail(self, mock_request): mock_request.version.minor = 3 self.assertRaises(exception.NotAcceptable, utils.check_allow_management_verbs, 'manage') - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_provide_verbs(self, mock_request): mock_request.version.minor = 4 utils.check_allow_management_verbs('provide') - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_provide_verbs_fail(self, mock_request): mock_request.version.minor = 3 self.assertRaises(exception.NotAcceptable, utils.check_allow_management_verbs, 'provide') - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_inspect_verbs(self, mock_request): mock_request.version.minor = 6 utils.check_allow_management_verbs('inspect') - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_inspect_verbs_fail(self, mock_request): mock_request.version.minor = 5 self.assertRaises(exception.NotAcceptable, utils.check_allow_management_verbs, 'inspect') - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_abort_verbs(self, mock_request): mock_request.version.minor = 13 utils.check_allow_management_verbs('abort') - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_abort_verbs_fail(self, mock_request): mock_request.version.minor = 12 self.assertRaises(exception.NotAcceptable, utils.check_allow_management_verbs, 'abort') - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_clean_verbs(self, mock_request): mock_request.version.minor = 15 utils.check_allow_management_verbs('clean') - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_clean_verbs_fail(self, mock_request): mock_request.version.minor = 14 self.assertRaises(exception.NotAcceptable, utils.check_allow_management_verbs, 'clean') - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_unknown_verbs(self, mock_request): utils.check_allow_management_verbs('rebuild') - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_inject_nmi(self, mock_request): mock_request.version.minor = 29 self.assertTrue(utils.allow_inject_nmi()) mock_request.version.minor = 28 self.assertFalse(utils.allow_inject_nmi()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_links_node_states_and_driver_properties(self, mock_request): mock_request.version.minor = 14 self.assertTrue(utils.allow_links_node_states_and_driver_properties()) mock_request.version.minor = 10 self.assertFalse(utils.allow_links_node_states_and_driver_properties()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_adopt_verbs_fail(self, mock_request): mock_request.version.minor = 16 self.assertRaises(exception.NotAcceptable, utils.check_allow_management_verbs, 'adopt') - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_adopt_verbs(self, mock_request): mock_request.version.minor = 17 utils.check_allow_management_verbs('adopt') - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_port_internal_info(self, mock_request): mock_request.version.minor = 18 self.assertTrue(utils.allow_port_internal_info()) mock_request.version.minor = 17 self.assertFalse(utils.allow_port_internal_info()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_port_advanced_net_fields(self, mock_request): mock_request.version.minor = 19 self.assertTrue(utils.allow_port_advanced_net_fields()) mock_request.version.minor = 18 self.assertFalse(utils.allow_port_advanced_net_fields()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_ramdisk_endpoints(self, mock_request): mock_request.version.minor = 22 self.assertTrue(utils.allow_ramdisk_endpoints()) mock_request.version.minor = 21 self.assertFalse(utils.allow_ramdisk_endpoints()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_portgroups(self, mock_request): mock_request.version.minor = 23 self.assertTrue(utils.allow_portgroups()) mock_request.version.minor = 22 self.assertFalse(utils.allow_portgroups()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_portgroups_subcontrollers(self, mock_request): mock_request.version.minor = 24 self.assertTrue(utils.allow_portgroups_subcontrollers()) mock_request.version.minor = 23 self.assertFalse(utils.allow_portgroups_subcontrollers()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_remove_chassis_uuid(self, mock_request): mock_request.version.minor = 25 self.assertTrue(utils.allow_remove_chassis_uuid()) mock_request.version.minor = 24 self.assertFalse(utils.allow_remove_chassis_uuid()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_portgroup_mode_properties(self, mock_request): mock_request.version.minor = 26 self.assertTrue(utils.allow_portgroup_mode_properties()) mock_request.version.minor = 25 self.assertFalse(utils.allow_portgroup_mode_properties()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_dynamic_drivers(self, mock_request): mock_request.version.minor = 30 self.assertTrue(utils.allow_dynamic_drivers()) mock_request.version.minor = 29 self.assertFalse(utils.allow_dynamic_drivers()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_volume(self, mock_request): mock_request.version.minor = 32 self.assertTrue(utils.allow_volume()) mock_request.version.minor = 31 self.assertFalse(utils.allow_volume()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_storage_interface(self, mock_request): mock_request.version.minor = 33 self.assertTrue(utils.allow_storage_interface()) mock_request.version.minor = 32 self.assertFalse(utils.allow_storage_interface()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_traits(self, mock_request): mock_request.version.minor = 37 self.assertTrue(utils.allow_traits()) mock_request.version.minor = 36 self.assertFalse(utils.allow_traits()) - @mock.patch.object(pecan, 'request', spec_set=['version']) @mock.patch.object(objects.Port, 'supports_physical_network') def test_allow_port_physical_network_no_pin(self, mock_spn, mock_request): mock_spn.return_value = True @@ -511,7 +465,6 @@ class TestApiUtils(base.TestCase): mock_request.version.minor = 33 self.assertFalse(utils.allow_port_physical_network()) - @mock.patch.object(pecan, 'request', spec_set=['version']) @mock.patch.object(objects.Port, 'supports_physical_network') def test_allow_port_physical_network_pin(self, mock_spn, mock_request): mock_spn.return_value = False @@ -520,14 +473,12 @@ class TestApiUtils(base.TestCase): mock_request.version.minor = 33 self.assertFalse(utils.allow_port_physical_network()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_node_rebuild_with_configdrive(self, mock_request): mock_request.version.minor = 35 self.assertTrue(utils.allow_node_rebuild_with_configdrive()) mock_request.version.minor = 34 self.assertFalse(utils.allow_node_rebuild_with_configdrive()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_configdrive_fails(self, mock_request): mock_request.version.minor = 35 self.assertRaises(wsme.exc.ClientSideError, @@ -541,7 +492,6 @@ class TestApiUtils(base.TestCase): utils.check_allow_configdrive, states.REBUILD, "abcd") - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_configdrive(self, mock_request): mock_request.version.minor = 35 utils.check_allow_configdrive(states.ACTIVE, "abcd") @@ -549,7 +499,6 @@ class TestApiUtils(base.TestCase): mock_request.version.minor = 34 utils.check_allow_configdrive(states.ACTIVE, "abcd") - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_configdrive_as_dict(self, mock_request): mock_request.version.minor = 56 utils.check_allow_configdrive(states.ACTIVE, {'meta_data': {}}) @@ -559,7 +508,6 @@ class TestApiUtils(base.TestCase): utils.check_allow_configdrive(states.ACTIVE, {'user_data': 'foo'}) utils.check_allow_configdrive(states.ACTIVE, {'user_data': ['foo']}) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_check_allow_configdrive_as_dict_invalid(self, mock_request): mock_request.version.minor = 56 self.assertRaises(wsme.exc.ClientSideError, @@ -574,28 +522,24 @@ class TestApiUtils(base.TestCase): utils.check_allow_configdrive, states.REBUILD, {key: 42}) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_rescue_interface(self, mock_request): mock_request.version.minor = 38 self.assertTrue(utils.allow_rescue_interface()) mock_request.version.minor = 37 self.assertFalse(utils.allow_rescue_interface()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_inspect_abort(self, mock_request): mock_request.version.minor = 41 self.assertTrue(utils.allow_inspect_abort()) mock_request.version.minor = 40 self.assertFalse(utils.allow_inspect_abort()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_port_is_smartnic(self, mock_request): mock_request.version.minor = 53 self.assertTrue(utils.allow_port_is_smartnic()) mock_request.version.minor = 52 self.assertFalse(utils.allow_port_is_smartnic()) - @mock.patch.object(pecan, 'request', spec_set=['version']) def test_allow_deploy_templates(self, mock_request): mock_request.version.minor = 55 self.assertTrue(utils.allow_deploy_templates()) @@ -603,6 +547,7 @@ class TestApiUtils(base.TestCase): self.assertFalse(utils.allow_deploy_templates()) +@mock.patch.object(api, 'request') class TestNodeIdent(base.TestCase): def setUp(self): @@ -612,24 +557,20 @@ class TestNodeIdent(base.TestCase): self.invalid_name = 'Mr Plow' self.node = test_api_utils.post_get_test_node() - @mock.patch.object(pecan, 'request') def test_allow_node_logical_names_pre_name(self, mock_pecan_req): mock_pecan_req.version.minor = 1 self.assertFalse(utils.allow_node_logical_names()) - @mock.patch.object(pecan, 'request') def test_allow_node_logical_names_post_name(self, mock_pecan_req): mock_pecan_req.version.minor = 5 self.assertTrue(utils.allow_node_logical_names()) - @mock.patch("pecan.request") def test_is_valid_node_name(self, mock_pecan_req): mock_pecan_req.version.minor = 10 self.assertTrue(utils.is_valid_node_name(self.valid_name)) self.assertFalse(utils.is_valid_node_name(self.invalid_name)) self.assertFalse(utils.is_valid_node_name(self.valid_uuid)) - @mock.patch.object(pecan, 'request') @mock.patch.object(utils, 'allow_node_logical_names') @mock.patch.object(objects.Node, 'get_by_uuid') @mock.patch.object(objects.Node, 'get_by_name') @@ -642,7 +583,6 @@ class TestNodeIdent(base.TestCase): self.assertEqual(1, mock_gbu.call_count) self.assertEqual(0, mock_gbn.call_count) - @mock.patch.object(pecan, 'request') @mock.patch.object(utils, 'allow_node_logical_names') @mock.patch.object(objects.Node, 'get_by_uuid') @mock.patch.object(objects.Node, 'get_by_name') @@ -656,7 +596,6 @@ class TestNodeIdent(base.TestCase): self.assertEqual(0, mock_gbu.call_count) self.assertEqual(1, mock_gbn.call_count) - @mock.patch.object(pecan, 'request') @mock.patch.object(utils, 'allow_node_logical_names') @mock.patch.object(objects.Node, 'get_by_uuid') @mock.patch.object(objects.Node, 'get_by_name') @@ -668,7 +607,6 @@ class TestNodeIdent(base.TestCase): utils.get_rpc_node, self.invalid_name) - @mock.patch.object(pecan, 'request') @mock.patch.object(utils, 'allow_node_logical_names') @mock.patch.object(objects.Node, 'get_by_uuid') @mock.patch.object(objects.Node, 'get_by_name') @@ -682,7 +620,6 @@ class TestNodeIdent(base.TestCase): self.assertEqual(1, mock_gbu.call_count) self.assertEqual(0, mock_gbn.call_count) - @mock.patch.object(pecan, 'request') @mock.patch.object(utils, 'allow_node_logical_names') @mock.patch.object(objects.Node, 'get_by_uuid') @mock.patch.object(objects.Node, 'get_by_name') @@ -703,7 +640,7 @@ class TestVendorPassthru(base.TestCase): utils.vendor_passthru, 'fake-ident', None, 'fake-topic', data='fake-data') - @mock.patch.object(pecan, 'request', + @mock.patch.object(api, 'request', spec_set=['method', 'context', 'rpcapi']) def _vendor_passthru(self, mock_request, async_call=True, driver_passthru=False): @@ -747,8 +684,8 @@ class TestVendorPassthru(base.TestCase): def test_driver_vendor_passthru_sync(self): self._vendor_passthru(async_call=False, driver_passthru=True) - @mock.patch.object(pecan, 'response', spec_set=['app_iter']) - @mock.patch.object(pecan, 'request', + @mock.patch.object(api, 'response', spec_set=['app_iter']) + @mock.patch.object(api, 'request', spec_set=['method', 'context', 'rpcapi']) def _test_vendor_passthru_attach(self, return_value, expct_return_value, mock_request, mock_response): @@ -789,14 +726,14 @@ class TestVendorPassthru(base.TestCase): sorted(utils.get_controller_reserved_names( api_node.NodesController))) - @mock.patch.object(pecan, 'request', spec_set=["context"]) + @mock.patch.object(api, 'request', spec_set=["context"]) @mock.patch.object(policy, 'authorize', spec=True) def test_check_policy(self, mock_authorize, mock_pr): utils.check_policy('fake-policy') - cdict = pecan.request.context.to_policy_values() + cdict = api.request.context.to_policy_values() mock_authorize.assert_called_once_with('fake-policy', cdict, cdict) - @mock.patch.object(pecan, 'request', spec_set=["context"]) + @mock.patch.object(api, 'request', spec_set=["context"]) @mock.patch.object(policy, 'authorize', spec=True) def test_check_policy_forbidden(self, mock_authorize, mock_pr): mock_authorize.side_effect = exception.HTTPForbidden(resource='fake') @@ -812,7 +749,7 @@ class TestPortgroupIdent(base.TestCase): self.invalid_name = 'My Portgroup' self.portgroup = test_api_utils.post_get_test_portgroup() - @mock.patch.object(pecan, 'request', spec_set=["context"]) + @mock.patch.object(api, 'request', spec_set=["context"]) @mock.patch.object(objects.Portgroup, 'get_by_name') def test_get_rpc_portgroup_name(self, mock_gbn, mock_pr): mock_gbn.return_value = self.portgroup @@ -820,7 +757,7 @@ class TestPortgroupIdent(base.TestCase): self.valid_name)) mock_gbn.assert_called_once_with(mock_pr.context, self.valid_name) - @mock.patch.object(pecan, 'request', spec_set=["context"]) + @mock.patch.object(api, 'request', spec_set=["context"]) @mock.patch.object(objects.Portgroup, 'get_by_uuid') def test_get_rpc_portgroup_uuid(self, mock_gbu, mock_pr): self.portgroup['uuid'] = self.valid_uuid