Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre_run for Reports #8572

Closed
hagbarddenstore opened this issue Feb 7, 2022 · 3 comments
Closed

pre_run for Reports #8572

hagbarddenstore opened this issue Feb 7, 2022 · 3 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Milestone

Comments

@hagbarddenstore
Copy link
Contributor

NetBox version

v3.1.7

Feature type

New functionality

Proposed functionality

Add a new function stub to the Reports class to be executed before any tests are executed.

Use case

If you're running multiple tests against the same dataset, it would be beneficial to be able to load the dataset once instead of loading it per test.

Example:

For each virtual machine, validate that vCPUs is set, validate that memory is set, validate that platform is set, validate that a primary IP is set, etc.

All of them are executed against the same dataset, which is loaded multiple times.

Database changes

None

External dependencies

None

@hagbarddenstore hagbarddenstore added the type: feature Introduction of new functionality to the application label Feb 7, 2022
@bistraque
Copy link

You can simply override the run method. Something like:

def run(self, job_result):
    # retrieve your data
    data = ...
    # store it in report object, test_xxx() methods can access it when called
    self.data = data
    super().run(job_result)

@jeremystretch
Copy link
Member

@bistraque is correct in that this can be accomplished by overriding the run() method, although I think there's a valid argument to introduce pre_run() as a convenience method given that we already have post_run() for a similar purpose.

@jeremystretch jeremystretch added the status: under review Further discussion is needed to determine this issue's scope and/or implementation label Feb 7, 2022
@jeremystretch
Copy link
Member

I'm going to tag this for v3.2. I'm not comfortable implementing it in a v3.1.x release as it has the potential to be a breaking change (i.e. for any script which already defines a pre_run() method).

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Feb 7, 2022
@jeremystretch jeremystretch self-assigned this Feb 7, 2022
@jeremystretch jeremystretch added this to the v3.2 milestone Feb 7, 2022
This was referenced Apr 5, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

3 participants