mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
12510 legacy jobs
This commit is contained in:
parent
52689616e9
commit
e61b960cd7
@ -272,18 +272,17 @@ class BaseScript(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._logs = {}
|
self._logs = {}
|
||||||
self._failed = False
|
self._failed = False
|
||||||
self._current_method = 'totals'
|
self._current_method = 'unassigned'
|
||||||
self._output = ''
|
self._output = ''
|
||||||
|
|
||||||
# Initiate the log
|
# Initiate the log
|
||||||
self.logger = logging.getLogger(f"netbox.scripts.{self.__module__}.{self.__class__.__name__}")
|
self.logger = logging.getLogger(f"netbox.scripts.{self.__module__}.{self.__class__.__name__}")
|
||||||
self.log = []
|
|
||||||
|
|
||||||
# Declare the placeholder for the current request
|
# Declare the placeholder for the current request
|
||||||
self.request = None
|
self.request = None
|
||||||
|
|
||||||
# Compile test methods and initialize results skeleton
|
# Compile test methods and initialize results skeleton
|
||||||
self._logs['totals'] = {
|
self._logs['unassigned'] = {
|
||||||
'success': 0,
|
'success': 0,
|
||||||
'info': 0,
|
'info': 0,
|
||||||
'warning': 0,
|
'warning': 0,
|
||||||
@ -454,8 +453,8 @@ class BaseScript(object):
|
|||||||
if log_level != LogLevelChoices.LOG_DEFAULT:
|
if log_level != LogLevelChoices.LOG_DEFAULT:
|
||||||
self._logs[self._current_method][log_level] += 1
|
self._logs[self._current_method][log_level] += 1
|
||||||
|
|
||||||
if self._current_method != 'totals':
|
if self._current_method != 'unassigned':
|
||||||
self._logs['totals'][log_level] += 1
|
self._logs['unassigned'][log_level] += 1
|
||||||
|
|
||||||
if obj:
|
if obj:
|
||||||
self.logger.log(level, f"{log_level.capitalize()} | {obj}: {message}")
|
self.logger.log(level, f"{log_level.capitalize()} | {obj}: {message}")
|
||||||
@ -527,12 +526,12 @@ class BaseScript(object):
|
|||||||
test_method()
|
test_method()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.post_run()
|
self.post_run()
|
||||||
self._current_method = 'totals'
|
self._current_method = 'unassigned'
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
# Perform any post-run tasks
|
# Perform any post-run tasks
|
||||||
self.post_run()
|
self.post_run()
|
||||||
self._current_method = 'totals'
|
self._current_method = 'unassigned'
|
||||||
|
|
||||||
def run(self, data, commit):
|
def run(self, data, commit):
|
||||||
self.run_test_scripts()
|
self.run_test_scripts()
|
||||||
@ -650,12 +649,10 @@ def run_script(data, job, request=None, commit=True, **kwargs):
|
|||||||
|
|
||||||
return fn(**kwargs)
|
return fn(**kwargs)
|
||||||
|
|
||||||
def set_job_data(job, script):
|
def set_job_data(script):
|
||||||
logs = script._logs
|
logs = script._logs
|
||||||
totals = logs.pop('totals')
|
|
||||||
job.data = {
|
job.data = {
|
||||||
'logs': logs,
|
'logs': logs,
|
||||||
'totals': totals,
|
|
||||||
'output': script._output,
|
'output': script._output,
|
||||||
}
|
}
|
||||||
return job
|
return job
|
||||||
@ -675,7 +672,7 @@ def run_script(data, job, request=None, commit=True, **kwargs):
|
|||||||
call_with_appropriate(script.log_info, kwargs={'message': "Database changes have been reverted automatically."})
|
call_with_appropriate(script.log_info, kwargs={'message': "Database changes have been reverted automatically."})
|
||||||
if request:
|
if request:
|
||||||
clear_events.send(request)
|
clear_events.send(request)
|
||||||
job = set_job_data(job, script)
|
job = set_job_data(script)
|
||||||
if script._failed:
|
if script._failed:
|
||||||
logger.warning(f"Script failed")
|
logger.warning(f"Script failed")
|
||||||
job.terminate(status=JobStatusChoices.STATUS_FAILED)
|
job.terminate(status=JobStatusChoices.STATUS_FAILED)
|
||||||
|
@ -1163,15 +1163,18 @@ class ScriptResultView(ContentTypePermissionRequiredMixin, View):
|
|||||||
module = job.object
|
module = job.object
|
||||||
script = module.scripts[job.name]()
|
script = module.scripts[job.name]()
|
||||||
|
|
||||||
if 'logs' in job.data:
|
legacy_script = False
|
||||||
legacy_script = False
|
legacy_report = False
|
||||||
legacy_report = False
|
if job.data:
|
||||||
elif 'log' in job.data:
|
if 'logs' in job.data:
|
||||||
legacy_script = True
|
legacy_script = False
|
||||||
legacy_report = False
|
legacy_report = False
|
||||||
else:
|
elif 'log' in job.data:
|
||||||
legacy_script = False
|
legacy_script = True
|
||||||
legacy_report = True
|
legacy_report = False
|
||||||
|
else:
|
||||||
|
legacy_script = False
|
||||||
|
legacy_report = True
|
||||||
|
|
||||||
# If this is an HTMX request, return only the result HTML
|
# If this is an HTMX request, return only the result HTML
|
||||||
if request.htmx:
|
if request.htmx:
|
||||||
|
@ -89,19 +89,36 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% for method, stats in last_job.data.logs.items %}
|
{% if last_job.data.logs %}
|
||||||
<tr>
|
{% for method, stats in last_job.data.logs.items %}
|
||||||
<td colspan="4" class="method">
|
<tr>
|
||||||
<span class="ps-3">{{ method }}</span>
|
<td colspan="4" class="method">
|
||||||
</td>
|
<span class="ps-3">{{ method }}</span>
|
||||||
<td class="text-end text-nowrap script-stats">
|
</td>
|
||||||
<span class="badge text-bg-success">{{ stats.success }}</span>
|
<td class="text-end text-nowrap script-stats">
|
||||||
<span class="badge text-bg-info">{{ stats.info }}</span>
|
<span class="badge text-bg-success">{{ stats.success }}</span>
|
||||||
<span class="badge text-bg-warning">{{ stats.warning }}</span>
|
<span class="badge text-bg-info">{{ stats.info }}</span>
|
||||||
<span class="badge text-bg-danger">{{ stats.failure }}</span>
|
<span class="badge text-bg-warning">{{ stats.warning }}</span>
|
||||||
</td>
|
<span class="badge text-bg-danger">{{ stats.failure }}</span>
|
||||||
</tr>
|
</td>
|
||||||
{% endfor %}
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% elif not last_job.data.log %}
|
||||||
|
{# legacy #}
|
||||||
|
{% for method, stats in last_job.data.items %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="4" class="method">
|
||||||
|
<span class="ps-3">{{ method }}</span>
|
||||||
|
</td>
|
||||||
|
<td class="text-end text-nowrap report-stats">
|
||||||
|
<span class="badge bg-success">{{ stats.success }}</span>
|
||||||
|
<span class="badge bg-info">{{ stats.info }}</span>
|
||||||
|
<span class="badge bg-warning">{{ stats.warning }}</span>
|
||||||
|
<span class="badge bg-danger">{{ stats.failure }}</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
Loading…
Reference in New Issue
Block a user