summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Kotton <gkotton@vmware.com>2016-06-19 00:18:13 -0700
committerGary Kotton <gkotton@vmware.com>2016-06-19 10:27:48 -0700
commitbc895486babf221444d0f36c935fb11f7a3eaec8 (patch)
treeebe03eb8d73084a9fc289699039ca206e9e5155b
parent5c659ed3080412ed929c5821375593c375df6db8 (diff)
downloadironic-bc895486babf221444d0f36c935fb11f7a3eaec8.tar.gz
Removes the use of mutables as default args
Passing mutable objects as default args is a known Python pitfall. We'd better avoid this. This commit changes mutable default args with None, 'arg = [] if arg is None else arg'. TrivialFix Change-Id: I2909b111266c696bcdcd26db167d3ad5e0603e45
-rw-r--r--ironic/api/middleware/auth_token.py5
-rw-r--r--ironic/common/service.py3
-rw-r--r--ironic/tests/unit/api/test_acl.py4
3 files changed, 8 insertions, 4 deletions
diff --git a/ironic/api/middleware/auth_token.py b/ironic/api/middleware/auth_token.py
index 64e6d9dc8..c2aba19fa 100644
--- a/ironic/api/middleware/auth_token.py
+++ b/ironic/api/middleware/auth_token.py
@@ -31,7 +31,8 @@ class AuthTokenMiddleware(auth_token.AuthProtocol):
for public routes in the API.
"""
- def __init__(self, app, conf, public_api_routes=[]):
+ def __init__(self, app, conf, public_api_routes=None):
+ api_routes = [] if public_api_routes is None else public_api_routes
self._ironic_app = app
# TODO(mrda): Remove .xml and ensure that doesn't result in a
# 401 Authentication Required instead of 404 Not Found
@@ -39,7 +40,7 @@ class AuthTokenMiddleware(auth_token.AuthProtocol):
try:
self.public_api_routes = [re.compile(route_pattern_tpl % route_tpl)
- for route_tpl in public_api_routes]
+ for route_tpl in api_routes]
except re.error as e:
msg = _('Cannot compile public API routes: %s') % e
diff --git a/ironic/common/service.py b/ironic/common/service.py
index 18fabccc7..fa79f8cbd 100644
--- a/ironic/common/service.py
+++ b/ironic/common/service.py
@@ -116,7 +116,8 @@ class RPCService(service.Service):
signal.signal(signal.SIGUSR1, self._handle_signal)
-def prepare_service(argv=[]):
+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',
diff --git a/ironic/tests/unit/api/test_acl.py b/ironic/tests/unit/api/test_acl.py
index bce7041dc..65479c1b0 100644
--- a/ironic/tests/unit/api/test_acl.py
+++ b/ironic/tests/unit/api/test_acl.py
@@ -37,7 +37,9 @@ class TestACL(base.BaseApiTest):
self.fake_db_node = db_utils.get_test_node(chassis_id=None)
self.node_path = '/nodes/%s' % self.fake_db_node['uuid']
- def get_json(self, path, expect_errors=False, headers=None, q=[], **param):
+ def get_json(self, path, expect_errors=False, headers=None, q=None,
+ **param):
+ q = [] if q is None else q
return super(TestACL, self).get_json(path,
expect_errors=expect_errors,
headers=headers,