From 7fd26bf8031041a0e6df261c71101e29e8bf9610 Mon Sep 17 00:00:00 2001 From: Vladyslav Drok Date: Mon, 27 Feb 2017 13:37:37 +0200 Subject: [PATCH] Fix usage of various deprecated methods Our unittest output complains about some of the codebase, described in more detail in the referred bug. This change fixes all of those places. static_root is now set only if debug=True is set in pecan configuration. Logging is now setup as part of the conf module import, so that unittests can use it. Closes-Bug: #1668240 Change-Id: I2536bd2b174e0d224ddf6806f1be37bd29017669 --- ironic/api/app.py | 4 ++-- ironic/api/controllers/root.py | 4 ++-- ironic/api/controllers/v1/__init__.py | 4 ++-- ironic/api/controllers/v1/portgroup.py | 8 +++++--- ironic/common/service.py | 19 ------------------- ironic/conf/__init__.py | 21 +++++++++++++++++++++ ironic/tests/unit/api/base.py | 1 + ironic/tests/unit/conductor/test_manager.py | 7 +++---- 8 files changed, 36 insertions(+), 32 deletions(-) diff --git a/ironic/api/app.py b/ironic/api/app.py index 5af2187051..4ba6f3bc4b 100644 --- a/ironic/api/app.py +++ b/ironic/api/app.py @@ -52,8 +52,8 @@ def setup_app(pecan_config=None, extra_hooks=None): app = pecan.make_app( pecan_config.app.root, - static_root=pecan_config.app.static_root, debug=CONF.pecan_debug, + static_root=pecan_config.app.static_root if CONF.pecan_debug else None, force_canonical=getattr(pecan_config.app, 'force_canonical', True), hooks=app_hooks, wrap_app=middleware.ParsableErrorMiddleware, @@ -81,7 +81,7 @@ def setup_app(pecan_config=None, extra_hooks=None): # Create a CORS wrapper, and attach ironic-specific defaults that must be # included in all CORS responses. app = cors_middleware.CORS(app, CONF) - app.set_latent( + cors_middleware.set_defaults( allow_headers=[base.Version.max_string, base.Version.min_string, base.Version.string], allow_methods=['GET', 'PUT', 'POST', 'DELETE', 'PATCH'], diff --git a/ironic/api/controllers/root.py b/ironic/api/controllers/root.py index 534d4bdc35..1a359b5056 100644 --- a/ironic/api/controllers/root.py +++ b/ironic/api/controllers/root.py @@ -109,7 +109,7 @@ class RootController(rest.RestController): return Root.convert() @pecan.expose() - def _route(self, args): + def _route(self, args, request=None): """Overrides the default routing behavior. It redirects the request to the default version of the ironic API @@ -118,4 +118,4 @@ class RootController(rest.RestController): if args[0] and args[0] not in self._versions: args = [self._default_version] + args - return super(RootController, self)._route(args) + return super(RootController, self)._route(args, request) diff --git a/ironic/api/controllers/v1/__init__.py b/ironic/api/controllers/v1/__init__.py index e6c23a1c7a..c1f1b6a5b4 100644 --- a/ironic/api/controllers/v1/__init__.py +++ b/ironic/api/controllers/v1/__init__.py @@ -199,7 +199,7 @@ class Controller(rest.RestController): headers=headers) @pecan.expose() - def _route(self, args): + def _route(self, args, request=None): v = base.Version(pecan.request.headers, versions.MIN_VERSION_STRING, versions.MAX_VERSION_STRING) @@ -214,7 +214,7 @@ class Controller(rest.RestController): pecan.response.headers[base.Version.string] = str(v) pecan.request.version = v - return super(Controller, self)._route(args) + return super(Controller, self)._route(args, request) __all__ = ('Controller',) diff --git a/ironic/api/controllers/v1/portgroup.py b/ironic/api/controllers/v1/portgroup.py index 2ac6baabe0..d93346b90d 100644 --- a/ironic/api/controllers/v1/portgroup.py +++ b/ironic/api/controllers/v1/portgroup.py @@ -237,19 +237,21 @@ class PortgroupsController(pecan.rest.RestController): } @pecan.expose() - def _lookup(self, ident, subres, *remainder): + def _lookup(self, ident, *remainder): if not api_utils.allow_portgroups(): pecan.abort(http_client.NOT_FOUND) try: ident = types.uuid_or_name.validate(ident) except exception.InvalidUuidOrName as e: pecan.abort(http_client.BAD_REQUEST, e.args[0]) - subcontroller = self._subcontroller_map.get(subres) + if not remainder: + return + subcontroller = self._subcontroller_map.get(remainder[0]) if subcontroller: if api_utils.allow_portgroups_subcontrollers(): return subcontroller( portgroup_ident=ident, - node_ident=self.parent_node_ident), remainder + node_ident=self.parent_node_ident), remainder[1:] pecan.abort(http_client.NOT_FOUND) def __init__(self, node_ident=None): diff --git a/ironic/common/service.py b/ironic/common/service.py index b5db7d8f62..91ae7765c6 100644 --- a/ironic/common/service.py +++ b/ironic/common/service.py @@ -14,7 +14,6 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_log import log from oslo_service import service from ironic.common import config @@ -24,25 +23,7 @@ from ironic import objects def prepare_service(argv=None): argv = [] if argv is None else argv - log.register_options(CONF) - log.set_defaults(default_log_levels=['amqp=WARNING', - 'amqplib=WARNING', - 'qpid.messaging=INFO', - 'oslo_messaging=INFO', - 'sqlalchemy=WARNING', - 'stevedore=INFO', - 'eventlet.wsgi.server=INFO', - 'iso8601=WARNING', - 'paramiko=WARNING', - 'requests=WARNING', - 'neutronclient=WARNING', - 'glanceclient=WARNING', - 'urllib3.connectionpool=WARNING', - 'keystonemiddleware.auth_token=INFO', - 'keystoneauth.session=INFO', - ]) config.parse_args(argv) - log.setup(CONF, 'ironic') objects.register_all() diff --git a/ironic/conf/__init__.py b/ironic/conf/__init__.py index 9c2097c24e..96fb7f2621 100644 --- a/ironic/conf/__init__.py +++ b/ironic/conf/__init__.py @@ -14,6 +14,7 @@ # under the License. from oslo_config import cfg +from oslo_log import log from ironic.conf import agent from ironic.conf import api @@ -45,6 +46,26 @@ from ironic.conf import swift CONF = cfg.CONF +log.register_options(CONF) +log.set_defaults(default_log_levels=[ + 'amqp=WARNING', + 'amqplib=WARNING', + 'qpid.messaging=INFO', + 'oslo_messaging=INFO', + 'sqlalchemy=WARNING', + 'stevedore=INFO', + 'eventlet.wsgi.server=INFO', + 'iso8601=WARNING', + 'paramiko=WARNING', + 'requests=WARNING', + 'neutronclient=WARNING', + 'glanceclient=WARNING', + 'urllib3.connectionpool=WARNING', + 'keystonemiddleware.auth_token=INFO', + 'keystoneauth.session=INFO', +]) +log.setup(CONF, 'ironic') + agent.register_opts(CONF) api.register_opts(CONF) audit.register_opts(CONF) diff --git a/ironic/tests/unit/api/base.py b/ironic/tests/unit/api/base.py index e2e2ebbbbe..7c9aef74b5 100644 --- a/ironic/tests/unit/api/base.py +++ b/ironic/tests/unit/api/base.py @@ -70,6 +70,7 @@ class BaseApiTest(base.DbTestCase): 'root': 'ironic.api.controllers.root.RootController', 'modules': ['ironic.api'], 'static_root': '%s/public' % root_dir, + 'debug': True, 'template_path': '%s/api/templates' % root_dir, 'acl_public_routes': ['/', '/v1'], }, diff --git a/ironic/tests/unit/conductor/test_manager.py b/ironic/tests/unit/conductor/test_manager.py index 49d3de9414..82e0c163d3 100644 --- a/ironic/tests/unit/conductor/test_manager.py +++ b/ironic/tests/unit/conductor/test_manager.py @@ -3230,10 +3230,9 @@ class UpdatePortTestCase(mgr_utils.ServiceSetUpMixin, @mock.patch.object(n_flat.FlatNetwork, 'port_changed', autospec=True) @mock.patch.object(n_flat.FlatNetwork, 'validate', autospec=True) def test_update_port_address_maintenance(self, mock_val, mock_pc): - node = obj_utils.create_test_node(self.context, driver='fake', - instance_uuid='uuid', - provision_state='active', - maintenance=True) + node = obj_utils.create_test_node( + self.context, driver='fake', maintenance=True, + instance_uuid=uuidutils.generate_uuid(), provision_state='active') port = obj_utils.create_test_port(self.context, node_id=node.id, extra={'vif_port_id': 'fake-id'})