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

Models #59

Closed
wants to merge 37 commits into from
Closed

Models #59

wants to merge 37 commits into from

Conversation

chadell
Copy link
Contributor

@chadell chadell commented Jul 31, 2023

No description provided.

@chadell chadell linked an issue Jul 31, 2023 that may be closed by this pull request
@chadell chadell changed the title Feature delices Models Jul 31, 2023
design_builder/models.py Outdated Show resolved Hide resolved
design_builder/models.py Outdated Show resolved Hide resolved
design_builder/models.py Outdated Show resolved Hide resolved
"""Guarantee that the design field cannot be changed."""
super().clean()
if not self._state.adding:
enforce_managed_fields(self, ["job"], message="is a field that cannot be changed")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thoutght this validation should be done in the other models (e.g. Device) not here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to better understand your comment. Once a design job has been loaded by Nautobot, we should create a design model in the database. The foreign key should never change. This clean method is just a way to be careful to prevent some future runtime/semantic error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the way I read the enforce_managed_fields was that is the method that we would use in the custom_validators of others models to make sure that there are no changes to models/attributes referenced by a Journal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that enforce_managed_fields can be used in both places. This was my motivation for extracting it to a utility method in the first place.

design_builder/models.py Outdated Show resolved Hide resolved
design_builder/models.py Outdated Show resolved Hide resolved
design_builder/models.py Outdated Show resolved Hide resolved
design_builder/models.py Outdated Show resolved Hide resolved


@receiver(nautobot_database_ready, sender=apps.get_app_config("design_builder"))
def create_design_statuses(**kwargs):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if the design instance status should be Statuses or simply Choices. what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have an opinion, really, I used choices since the HLD had some clearly defined statuses. I'm okay with alternate approaches pending further discussion.



@receiver(post_save, sender=Job)
def create_design_model(sender, instance: Job, **kwargs):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the Design would be manually created, so you could have many DesignJobs, but only some of them would be added.
However, doing it automatically it's easier...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I actually never considered that designs would be manually created on an as-needed basis. I guess I was thinking that once we go down this path of versions and journaling/idempotence then it is likely that we'll want to do it for everything.

Again, I'm open to further discussion.

design_builder/models.py Outdated Show resolved Hide resolved
This was referenced Aug 7, 2023
abates and others added 2 commits August 17, 2023 07:18
Implements views for:
- design
- design instance
- journal
- journal entry
A similar tag is provided out of the box with the Jinja2 framework so we aren't going to carry forward the `indent` support in Design Builder.
This provides some unit tests for the commit and roll back functionality provided by `ext.Extension`. This commit also introduces a small fix for the `commit` behavior.

old_model = model_class.objects.get(pk=new_model.pk)
changed = {}
for field_name in field_names:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of field comparison , can we use an "accessor key" to actually allow for changes to be done only through design builder ?

if instance.designbuilder_permitted:
  del instance.designbuilder_permitted
  instance.validated_save()

abates and others added 13 commits September 5, 2023 11:14
* feat: Connected design.Builder's journal to the new models

* style: Black formatting

* docs: Updated pydocs
* feat: ✨ Change status from Design to Design Instance

Remove Status from Design, Add Status to Design Instance, and also Live State.  Allow delete of a Design Instance (under certain conditions), and add a button to trigger a Design execution

* feat: ✨ Add a Tag for a full control object

* Fix pylint

* fix: Fixed cyclic import

There was a cyclic import in util.py for nautobot_design_builder. There
was actually no need for this import at all so it was removed.

Also removed the try/except block for `importlib.metadata` since
design_builder now only supports Python >= 3.8 and `metadata` was added
in 3.8

* Update tests

* bump version

* Replace rollebacked by rolled back

* Add a comment to provide context

---------

Co-authored-by: Andrew Bates <[email protected]>
* Updates pyproject.toml for 3.11

* fix: Updates for OSRB documentation review

fixes #78

* docs: The custom `indent` filter was removed in favor of using the builtin `indent` filter

* docs: Documentation updates

* docs: Removed unneeded doc template

* feat: ✨ Decommissioning Job

* Apply suggestions from code review

Co-authored-by: Leo Kirchner <[email protected]>

* Decouple pre decommission job

* use callable

* generalize hook

* wip

* wip

* fix: Fixed test failures.

The `TransactionTestCase` actually has less test isolation than `TestCase` which caused the test designs to not actually get reverted between tests.

* refactor: JournalEntry can now be reverted.

Moved the revertting code from the decommissioning job and into the JournalEntry model. Also added some tests to validate the code.

* fix tests

* fix dict logic

* docs: Documented why refreshing `design_object` is necessary

* refactor: Refactored revert code into `Journal` model

* docs: Updated branding from `plugin` to `app`

* refactor: Refactored decom code to model and hooks to signals

Moved the design instance decommissioning code into the `DesignInstance` model. Also implemented the pre/post decom hooks as signals.

* style: Autoformatting

* Add l3vpn design example

* fix old dict value null

* refactor: Minor refactoring of `JournalEntry` revert and the model itself.

* fix tests

* update the l3vppn example and add a hook to validate input data

* bump version

* avoid overwrite of  method

* clean up some leftovers

* Missing part of previous commit

* Rename variables for consistency

* fix: Fixed extra `{% endmacro %}` that got added at some point.

* fix: Now logging the design instance and journal objects.

* Adjust test with warning, improve logging plus journalentry retrieve view

* adjust logging

* mre info

* fix exception chain

---------

Co-authored-by: Josh VanDeraa <[email protected]>
Co-authored-by: Andrew Bates <[email protected]>
Co-authored-by: Leo Kirchner <[email protected]>
@chadell chadell closed this Jan 4, 2024
@abates abates mentioned this pull request Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add concrete Django models
5 participants