mirror of
https://github.com/ansible/awx.git
synced 2026-06-22 23:27:46 -02:30
Merge pull request #2664 from anoek/todo-cleanup
API todo/fixme addressing and cleanup
This commit is contained in:
@@ -78,7 +78,7 @@ class MemObject(object):
|
||||
v = yaml.safe_load(file(path, 'r').read())
|
||||
if hasattr(v, 'items'): # is a dict
|
||||
all_vars.update(v)
|
||||
except yaml.YAMLError, e:
|
||||
except yaml.YAMLError as e:
|
||||
if hasattr(e, 'problem_mark'):
|
||||
logger.error('Invalid YAML in %s:%s col %s', path,
|
||||
e.problem_mark.line + 1,
|
||||
@@ -1329,7 +1329,7 @@ class Command(NoArgsCommand):
|
||||
self.logger.warning('Inventory import required %d queries '
|
||||
'taking %0.3fs', len(queries_this_import),
|
||||
sqltime)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
if isinstance(e, KeyboardInterrupt):
|
||||
status = 'canceled'
|
||||
exc = e
|
||||
|
||||
@@ -173,7 +173,7 @@ class CallbackReceiver(object):
|
||||
# If for any reason there's a problem, just use 0.
|
||||
try:
|
||||
verbose = Job.objects.get(id=data['job_id']).verbosity
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
verbose = 0
|
||||
|
||||
# Convert the datetime for the job event's creation appropriately,
|
||||
@@ -191,7 +191,7 @@ class CallbackReceiver(object):
|
||||
|
||||
# Print the data to stdout if we're in DEBUG mode.
|
||||
if settings.DEBUG:
|
||||
print data
|
||||
print(data)
|
||||
|
||||
# Sanity check: Don't honor keys that we don't recognize.
|
||||
for key in data.keys():
|
||||
@@ -234,7 +234,7 @@ class CallbackReceiver(object):
|
||||
# If for any reason there's a problem, just use 0.
|
||||
try:
|
||||
verbose = AdHocCommand.objects.get(id=data['ad_hoc_command_id']).verbosity
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
verbose = 0
|
||||
|
||||
# Convert the datetime for the job event's creation appropriately,
|
||||
@@ -252,7 +252,7 @@ class CallbackReceiver(object):
|
||||
|
||||
# Print the data to stdout if we're in DEBUG mode.
|
||||
if settings.DEBUG:
|
||||
print data
|
||||
print(data)
|
||||
|
||||
# Sanity check: Don't honor keys that we don't recognize.
|
||||
for key in data.keys():
|
||||
@@ -288,7 +288,7 @@ class CallbackReceiver(object):
|
||||
message = queue_actual.get(block=True, timeout=1)
|
||||
except QueueEmpty:
|
||||
continue
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.error("Exception on listen socket, restarting: " + str(e))
|
||||
break
|
||||
self.process_job_event(message)
|
||||
|
||||
@@ -59,7 +59,7 @@ class FactCacheReceiver(object):
|
||||
except Fact.MultipleObjectsReturned:
|
||||
logger.warn('Database inconsistent. Multiple Hosts found for <hostname, inventory_id> <%s, %s>.' % (hostname, inventory_id))
|
||||
return None
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.error("Exception communicating with Fact Cache Database: %s" % str(e))
|
||||
return None
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ class SocketController(object):
|
||||
if socket_session and socket_session.is_valid():
|
||||
try:
|
||||
socket.send_packet(packet)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.error("Error sending client packet to %s: %s" % (str(session_id), str(packet)))
|
||||
logger.error("Error was: " + str(e))
|
||||
|
||||
@@ -116,7 +116,7 @@ class SocketController(object):
|
||||
if socket:
|
||||
try:
|
||||
socket.send_packet(packet)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.error("Error sending client packet to %s: %s" % (str(socket_session.session_id), str(packet)))
|
||||
logger.error("Error was: " + str(e))
|
||||
|
||||
@@ -129,18 +129,18 @@ socketController = SocketController(SocketSessionManager())
|
||||
#
|
||||
# Socket session is attached to self.session['socket_session']
|
||||
# self.session and self.socket.session point to the same dict
|
||||
#
|
||||
#
|
||||
class TowerBaseNamespace(BaseNamespace):
|
||||
|
||||
def get_allowed_methods(self):
|
||||
return ['recv_disconnect']
|
||||
|
||||
|
||||
def get_initial_acl(self):
|
||||
request_token = self._get_request_token()
|
||||
if request_token:
|
||||
# (1) This is the first time the socket has been seen (first
|
||||
# (1) This is the first time the socket has been seen (first
|
||||
# namespace joined).
|
||||
# (2) This socket has already been seen (already joined and maybe
|
||||
# (2) This socket has already been seen (already joined and maybe
|
||||
# left a namespace)
|
||||
#
|
||||
# Note: Assume that the user token is valid if the session is found
|
||||
@@ -168,7 +168,7 @@ class TowerBaseNamespace(BaseNamespace):
|
||||
if k == "Token":
|
||||
token_actual = urllib.unquote_plus(v).decode().replace("\"","")
|
||||
return token_actual
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.error("Exception validating user: " + str(e))
|
||||
return False
|
||||
return False
|
||||
|
||||
@@ -880,7 +880,6 @@ class JobTemplateAccess(BaseAccess):
|
||||
|
||||
team_ids = Team.objects.filter(deprecated_users__in=[self.user])
|
||||
|
||||
# TODO: I think the below queries can be combined
|
||||
deploy_permissions_ids = Permission.objects.filter(
|
||||
Q(user=self.user) | Q(team_id__in=team_ids),
|
||||
permission_type__in=allowed_deploy,
|
||||
@@ -1094,7 +1093,6 @@ class JobAccess(BaseAccess):
|
||||
allowed_check = [PERM_JOBTEMPLATE_CREATE, PERM_INVENTORY_DEPLOY, PERM_INVENTORY_CHECK]
|
||||
team_ids = Team.objects.filter(deprecated_users__in=[self.user])
|
||||
|
||||
# TODO: I think the below queries can be combined
|
||||
deploy_permissions_ids = Permission.objects.filter(
|
||||
Q(user=self.user) | Q(team__in=team_ids),
|
||||
permission_type__in=allowed_deploy,
|
||||
|
||||
@@ -137,7 +137,7 @@ class BaseModel(models.Model):
|
||||
errors = {}
|
||||
try:
|
||||
super(BaseModel, self).clean_fields(exclude)
|
||||
except ValidationError, e:
|
||||
except ValidationError as e:
|
||||
errors = e.update_error_dict(errors)
|
||||
for f in self._meta.fields:
|
||||
if f.name in exclude:
|
||||
@@ -145,7 +145,7 @@ class BaseModel(models.Model):
|
||||
if hasattr(self, 'clean_%s' % f.name):
|
||||
try:
|
||||
setattr(self, f.name, getattr(self, 'clean_%s' % f.name)())
|
||||
except ValidationError, e:
|
||||
except ValidationError as e:
|
||||
errors[f.name] = e.messages
|
||||
if errors:
|
||||
raise ValidationError(errors)
|
||||
|
||||
@@ -701,7 +701,7 @@ class Job(UnifiedJob, JobOptions):
|
||||
return
|
||||
try:
|
||||
extra_vars = json.loads(extra_data)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.warn("Exception deserializing extra vars: " + str(e))
|
||||
evars = self.extra_vars_dict
|
||||
evars.update(extra_vars)
|
||||
@@ -1316,7 +1316,7 @@ class SystemJob(UnifiedJob, SystemJobOptions):
|
||||
return
|
||||
try:
|
||||
extra_vars = json.loads(extra_data)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.warn("Exception deserializing extra vars: " + str(e))
|
||||
evars = self.extra_vars_dict
|
||||
evars.update(extra_vars)
|
||||
|
||||
@@ -115,7 +115,7 @@ class ProjectOptions(models.Model):
|
||||
try:
|
||||
scm_url = update_scm_url(self.scm_type, scm_url,
|
||||
check_special_cases=False)
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
raise ValidationError((e.args or ('Invalid SCM URL.',))[0])
|
||||
scm_url_parts = urlparse.urlsplit(scm_url)
|
||||
if self.scm_type and not any(scm_url_parts):
|
||||
@@ -142,7 +142,7 @@ class ProjectOptions(models.Model):
|
||||
try:
|
||||
update_scm_url(self.scm_type, self.scm_url, scm_username,
|
||||
scm_password)
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
raise ValidationError((e.args or ('Invalid credential.',))[0])
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
@@ -29,12 +29,10 @@ class UriCleaner(object):
|
||||
username = o.username
|
||||
password = o.password
|
||||
|
||||
# Given a python MatchObject, with respect to redactedtext, find and
|
||||
# Given a python MatchObject, with respect to redactedtext, find and
|
||||
# replace the first occurance of username and the first and second
|
||||
# occurance of password
|
||||
|
||||
# TODO: Ideally, we would replace username and password using the index
|
||||
# that they were found at.
|
||||
uri_str = redactedtext[match.start():match.end()]
|
||||
if username:
|
||||
uri_str = uri_str.replace(username, UriCleaner.REPLACE_STR, 1)
|
||||
|
||||
@@ -339,7 +339,6 @@ def activity_stream_create(sender, instance, created, **kwargs):
|
||||
# Skip recording any inventory source directly associated with a group.
|
||||
if isinstance(instance, InventorySource) and instance.group:
|
||||
return
|
||||
# TODO: Rethink details of the new instance
|
||||
object1 = camelcase_to_underscore(instance.__class__.__name__)
|
||||
changes = model_to_dict(instance, model_serializer_mapping)
|
||||
# Special case where Job survey password variables need to be hidden
|
||||
|
||||
@@ -77,7 +77,7 @@ def celery_startup(conf=None, **kwargs):
|
||||
try:
|
||||
sch.update_computed_fields()
|
||||
sch.save()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.error("Failed to rebuild schedule {}: {}".format(sch, e))
|
||||
|
||||
@task()
|
||||
@@ -142,8 +142,8 @@ def tower_periodic_scheduler(self):
|
||||
try:
|
||||
last_run = dateutil.parser.parse(fd.read())
|
||||
return last_run
|
||||
except Exception:
|
||||
#TODO: LOG
|
||||
except Exception as exc:
|
||||
logger.error("get_last_run failed: {}".format(exc))
|
||||
return None
|
||||
|
||||
def write_last_run(last_run):
|
||||
@@ -1722,7 +1722,7 @@ class RunSystemJob(BaseTask):
|
||||
args.extend(['--older_than', str(json_vars['older_than'])])
|
||||
if 'granularity' in json_vars:
|
||||
args.extend(['--granularity', str(json_vars['granularity'])])
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.error("Failed to parse system job: " + str(e))
|
||||
return args
|
||||
|
||||
|
||||
@@ -1058,7 +1058,7 @@ class JobTransactionTest(BaseJobTestMixin, django.test.LiveServerTestCase):
|
||||
data = json.loads(response.content)
|
||||
if data.get('status', '') not in ('new', 'pending', 'running'):
|
||||
break
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
errors.append(e)
|
||||
break
|
||||
|
||||
|
||||
@@ -44,9 +44,9 @@ def get_object_or_400(klass, *args, **kwargs):
|
||||
queryset = _get_queryset(klass)
|
||||
try:
|
||||
return queryset.get(*args, **kwargs)
|
||||
except queryset.model.DoesNotExist, e:
|
||||
except queryset.model.DoesNotExist as e:
|
||||
raise ParseError(*e.args)
|
||||
except queryset.model.MultipleObjectsReturned, e:
|
||||
except queryset.model.MultipleObjectsReturned as e:
|
||||
raise ParseError(*e.args)
|
||||
|
||||
|
||||
@@ -59,9 +59,9 @@ def get_object_or_403(klass, *args, **kwargs):
|
||||
queryset = _get_queryset(klass)
|
||||
try:
|
||||
return queryset.get(*args, **kwargs)
|
||||
except queryset.model.DoesNotExist, e:
|
||||
except queryset.model.DoesNotExist as e:
|
||||
raise PermissionDenied(*e.args)
|
||||
except queryset.model.MultipleObjectsReturned, e:
|
||||
except queryset.model.MultipleObjectsReturned as e:
|
||||
raise PermissionDenied(*e.args)
|
||||
|
||||
def to_python_boolean(value, allow_none=False):
|
||||
|
||||
Reference in New Issue
Block a user