diff --git a/service-mgmt-api/sm-api/sm_api/api/middleware/auth_token.py b/service-mgmt-api/sm-api/sm_api/api/middleware/auth_token.py index edc4fdb8..c4994253 100644 --- a/service-mgmt-api/sm-api/sm_api/api/middleware/auth_token.py +++ b/service-mgmt-api/sm-api/sm_api/api/middleware/auth_token.py @@ -21,8 +21,10 @@ class AuthTokenMiddleware(auth_token.AuthProtocol): """ - def __init__(self, app, conf, public_api_routes=[]): + def __init__(self, app, conf, public_api_routes=None): self.smapi_app = app + if public_api_routes is None: + public_api_routes = [] self.public_api_routes = set(public_api_routes) super(AuthTokenMiddleware, self).__init__(app, conf) diff --git a/service-mgmt-api/sm-api/sm_api/common/service.py b/service-mgmt-api/sm-api/sm_api/common/service.py index 0e1bd10c..bb37aa12 100644 --- a/service-mgmt-api/sm-api/sm_api/common/service.py +++ b/service-mgmt-api/sm-api/sm_api/common/service.py @@ -56,7 +56,9 @@ class PeriodicService(rpc_service.Service, periodic_task.PeriodicTasks): context=admin_context) -def prepare_service(argv=[]): +def prepare_service(argv=None): + if argv is None: + argv = [] rpc.set_defaults(control_exchange='sm_api') cfg.set_defaults(log.log_opts, default_log_levels=['amqplib=WARN', diff --git a/service-mgmt-api/sm-api/sm_api/openstack/common/db/exception.py b/service-mgmt-api/sm-api/sm_api/openstack/common/db/exception.py index f465dd27..1120a172 100644 --- a/service-mgmt-api/sm-api/sm_api/openstack/common/db/exception.py +++ b/service-mgmt-api/sm-api/sm_api/openstack/common/db/exception.py @@ -34,8 +34,8 @@ class DBError(Exception): class DBDuplicateEntry(DBError): """Wraps an implementation specific exception.""" - def __init__(self, columns=[], inner_exception=None): - self.columns = columns + def __init__(self, columns=None, inner_exception=None): + self.columns = columns if columns is not None else [] super(DBDuplicateEntry, self).__init__(inner_exception) diff --git a/service-mgmt-api/sm-api/sm_api/openstack/common/rootwrap/filters.py b/service-mgmt-api/sm-api/sm_api/openstack/common/rootwrap/filters.py index 30f08b2f..35781584 100644 --- a/service-mgmt-api/sm-api/sm_api/openstack/common/rootwrap/filters.py +++ b/service-mgmt-api/sm-api/sm_api/openstack/common/rootwrap/filters.py @@ -33,10 +33,12 @@ class CommandFilter(object): self.args = args self.real_exec = None - def get_exec(self, exec_dirs=[]): + def get_exec(self, exec_dirs=None): """Returns existing executable, or empty string if none found.""" if self.real_exec is not None: return self.real_exec + if exec_dirs is None: + exec_dirs = [] self.real_exec = "" if self.exec_path.startswith('/'): if os.access(self.exec_path, os.X_OK): @@ -53,8 +55,10 @@ class CommandFilter(object): """Only check that the first argument (command) matches exec_path.""" return os.path.basename(self.exec_path) == userargs[0] - def get_command(self, userargs, exec_dirs=[]): + def get_command(self, userargs, exec_dirs=None): """Returns command to execute (with sudo -u if run_as != root).""" + if exec_dirs is None: + exec_dirs = [] to_exec = self.get_exec(exec_dirs=exec_dirs) or self.exec_path if (self.run_as != 'root'): # Used to run commands at lesser privileges @@ -125,7 +129,7 @@ class PathFilter(CommandFilter): args_equal_or_pass and paths_are_within_base_dirs) - def get_command(self, userargs, exec_dirs=[]): + def get_command(self, userargs, exec_dirs=None): command, arguments = userargs[0], userargs[1:] # convert path values to canonical ones; copy other args as is @@ -149,7 +153,7 @@ class DnsmasqFilter(CommandFilter): return True return False - def get_command(self, userargs, exec_dirs=[]): + def get_command(self, userargs, exec_dirs=None): to_exec = self.get_exec(exec_dirs=exec_dirs) or self.exec_path dnsmasq_pos = userargs.index('dnsmasq') return [to_exec] + userargs[dnsmasq_pos + 1:] diff --git a/service-mgmt-api/sm-api/sm_api/openstack/common/rootwrap/wrapper.py b/service-mgmt-api/sm-api/sm_api/openstack/common/rootwrap/wrapper.py index 842bbdcc..eee5a822 100644 --- a/service-mgmt-api/sm-api/sm_api/openstack/common/rootwrap/wrapper.py +++ b/service-mgmt-api/sm-api/sm_api/openstack/common/rootwrap/wrapper.py @@ -125,7 +125,7 @@ def load_filters(filters_path): return filterlist -def match_filter(filter_list, userargs, exec_dirs=[]): +def match_filter(filter_list, userargs, exec_dirs=None): """ Checks user command and arguments through command filters and returns the first matching filter. @@ -134,6 +134,8 @@ def match_filter(filter_list, userargs, exec_dirs=[]): best filter match. """ first_not_executable_filter = None + if exec_dirs is None: + exec_dirs = [] for f in filter_list: if f.match(userargs): diff --git a/service-mgmt-api/sm-api/sm_api/openstack/common/setup.py b/service-mgmt-api/sm-api/sm_api/openstack/common/setup.py index 7eda561e..bf628e3c 100644 --- a/service-mgmt-api/sm-api/sm_api/openstack/common/setup.py +++ b/service-mgmt-api/sm-api/sm_api/openstack/common/setup.py @@ -72,9 +72,10 @@ def get_reqs_from_files(requirements_files): return [] -def parse_requirements(requirements_files=['requirements.txt', - 'tools/pip-requires']): +def parse_requirements(requirements_files=None): requirements = [] + if requirements_files is None: + requirements_files = ['requirements.txt', 'tools/pip-requires'] for line in get_reqs_from_files(requirements_files): # For the requirements list, we need to inject only the portion # after egg= so that distutils knows the package it's looking for @@ -101,8 +102,9 @@ def parse_requirements(requirements_files=['requirements.txt', return requirements -def parse_dependency_links(requirements_files=['requirements.txt', - 'tools/pip-requires']): +def parse_dependency_links(requirements_files=None): + if requirements_files is None: + requirements_files = ['requirements.txt', 'tools/pip-requires'] dependency_links = [] # dependency_links inject alternate locations to find packages listed # in requirements diff --git a/service-mgmt-client/sm-client/sm_client/common/utils.py b/service-mgmt-client/sm-client/sm_client/common/utils.py index 81dfccaf..4bb75b95 100644 --- a/service-mgmt-client/sm-client/sm_client/common/utils.py +++ b/service-mgmt-client/sm-client/sm_client/common/utils.py @@ -85,7 +85,7 @@ def pretty_choice_list(l): return ', '.join("'%s'" % i for i in l) -def print_list(objs, fields, field_labels, formatters={}, sortby=0): +def print_list(objs, fields, field_labels, formatters=None, sortby=0): pt = prettytable.PrettyTable([f for f in field_labels], caching=False, print_empty=False) pt.align = 'l' @@ -93,7 +93,7 @@ def print_list(objs, fields, field_labels, formatters={}, sortby=0): for o in objs: row = [] for field in fields: - if field in formatters: + if formatters and field in formatters: row.append(formatters[field](o)) else: data = getattr(o, field, '') @@ -102,7 +102,7 @@ def print_list(objs, fields, field_labels, formatters={}, sortby=0): print(pt.get_string(sortby=field_labels[sortby])) -def print_tuple_list(tuples, tuple_labels=[]): +def print_tuple_list(tuples, tuple_labels=None): pt = prettytable.PrettyTable(['Property', 'Value'], caching=False, print_empty=False) pt.align = 'l' diff --git a/service-mgmt-client/sm-client/sm_client/openstack/common/rootwrap/filters.py b/service-mgmt-client/sm-client/sm_client/openstack/common/rootwrap/filters.py index 30f08b2f..490338b4 100644 --- a/service-mgmt-client/sm-client/sm_client/openstack/common/rootwrap/filters.py +++ b/service-mgmt-client/sm-client/sm_client/openstack/common/rootwrap/filters.py @@ -33,7 +33,7 @@ class CommandFilter(object): self.args = args self.real_exec = None - def get_exec(self, exec_dirs=[]): + def get_exec(self, exec_dirs=None): """Returns existing executable, or empty string if none found.""" if self.real_exec is not None: return self.real_exec @@ -41,7 +41,7 @@ class CommandFilter(object): if self.exec_path.startswith('/'): if os.access(self.exec_path, os.X_OK): self.real_exec = self.exec_path - else: + elif exec_dirs is not None: for binary_path in exec_dirs: expanded_path = os.path.join(binary_path, self.exec_path) if os.access(expanded_path, os.X_OK): @@ -53,7 +53,7 @@ class CommandFilter(object): """Only check that the first argument (command) matches exec_path.""" return os.path.basename(self.exec_path) == userargs[0] - def get_command(self, userargs, exec_dirs=[]): + def get_command(self, userargs, exec_dirs=None): """Returns command to execute (with sudo -u if run_as != root).""" to_exec = self.get_exec(exec_dirs=exec_dirs) or self.exec_path if (self.run_as != 'root'): @@ -125,7 +125,7 @@ class PathFilter(CommandFilter): args_equal_or_pass and paths_are_within_base_dirs) - def get_command(self, userargs, exec_dirs=[]): + def get_command(self, userargs, exec_dirs=None): command, arguments = userargs[0], userargs[1:] # convert path values to canonical ones; copy other args as is @@ -149,7 +149,7 @@ class DnsmasqFilter(CommandFilter): return True return False - def get_command(self, userargs, exec_dirs=[]): + def get_command(self, userargs, exec_dirs=None): to_exec = self.get_exec(exec_dirs=exec_dirs) or self.exec_path dnsmasq_pos = userargs.index('dnsmasq') return [to_exec] + userargs[dnsmasq_pos + 1:] diff --git a/service-mgmt-client/sm-client/sm_client/openstack/common/rootwrap/wrapper.py b/service-mgmt-client/sm-client/sm_client/openstack/common/rootwrap/wrapper.py index 31b84ddb..542394cf 100644 --- a/service-mgmt-client/sm-client/sm_client/openstack/common/rootwrap/wrapper.py +++ b/service-mgmt-client/sm-client/sm_client/openstack/common/rootwrap/wrapper.py @@ -126,7 +126,7 @@ def load_filters(filters_path): return filterlist -def match_filter(filter_list, userargs, exec_dirs=[]): +def match_filter(filter_list, userargs, exec_dirs=None): """check user command and args Checks user command and arguments through command filters and @@ -136,6 +136,8 @@ def match_filter(filter_list, userargs, exec_dirs=[]): best filter match. """ first_not_executable_filter = None + if exec_dirs is None: + exec_dirs = [] for f in filter_list: if f.match(userargs): diff --git a/tox.ini b/tox.ini index 6492f871..a1c8139f 100644 --- a/tox.ini +++ b/tox.ini @@ -70,14 +70,13 @@ commands = # F811 redefinition of unused '' from line # F821 undefined name 'e' # - bugbear - -# B006 Do not use mutable data structures for argument defaults. (python3) # B008 Do not perform calls in argument defaults. The call is performed only once at function definition time. # B009: Do not call getattr with a constant attribute value # B010: Do not call setattr with a constant attribute value ignore= E402, H102,H104,H105,H106,H306,H401,H403,H404,H405,H501, F811,F821, - B006,B008,B009,B010 + B008,B009,B010 # Enable checks which are off by default # H106 Don’t put vim configuration in source files (off by default). SHOULD BE ENABLED. # H203 Use assertIs(Not)None to check for None (off by default).