diff --git a/netbox/extras/models/scripts.py b/netbox/extras/models/scripts.py index 55576421f..ff620f60f 100644 --- a/netbox/extras/models/scripts.py +++ b/netbox/extras/models/scripts.py @@ -9,7 +9,7 @@ from django.utils.translation import gettext_lazy as _ from core.choices import ManagedFileRootPathChoices from core.models import ManagedFile -from extras.utils import is_script_or_report +from extras.utils import is_script from netbox.models.features import JobsMixin, EventRulesMixin from utilities.querysets import RestrictedQuerySet from .mixins import PythonModuleMixin @@ -72,7 +72,7 @@ class ScriptModule(PythonModuleMixin, JobsMixin, ManagedFile): for cls in ordered: scripts[_get_name(cls)] = cls - for name, cls in inspect.getmembers(module, is_script_or_report): + for name, cls in inspect.getmembers(module, is_script): if cls not in ordered: scripts[_get_name(cls)] = cls diff --git a/netbox/extras/scripts.py b/netbox/extras/scripts.py index 8792e08fa..49a02a1bd 100644 --- a/netbox/extras/scripts.py +++ b/netbox/extras/scripts.py @@ -257,7 +257,7 @@ class IPNetworkVar(ScriptVariable): # Scripts # -class BaseScript(object): +class BaseScript: """ Base model for custom scripts. User classes should inherit from this model if they want to extend Script functionality for use in other subclasses. @@ -510,15 +510,12 @@ class BaseScript(object): return data - def run_test_scripts(self, job): + def run_tests(self, job): """ Run the report and save its results. Each test method will be executed in order. """ self.logger.info(f"Running report") - # Perform any post-run tasks - self.pre_run() - try: for method_name in self.test_methods: self._current_method = method_name @@ -529,12 +526,12 @@ class BaseScript(object): self._current_method = 'unassigned' raise e - # Perform any post-run tasks - self.post_run() self._current_method = 'unassigned' def run(self, data, commit): - self.run_test_scripts() + self.pre_run() + self.run_tests() + self.post_run() def pre_run(self): """ diff --git a/netbox/extras/utils.py b/netbox/extras/utils.py index 563770f73..db06b07f8 100644 --- a/netbox/extras/utils.py +++ b/netbox/extras/utils.py @@ -51,28 +51,8 @@ def is_script(obj): """ Returns True if the object is a Script. """ - from .scripts import Script - try: - return issubclass(obj, Script) and obj != Script - except TypeError: - return False - -def is_report(obj): - """ - Returns True if the given object is a Report. - """ - from .reports import Report - try: - return issubclass(obj, Report) and obj != Report - except TypeError: - return False - - -def is_script_or_report(obj): - """ - Returns True if the given object is a Report. - """ + # TODO: Deprecated legacy reports support from .reports import Report from .scripts import Script try: