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

Config Deployment and Remediation #533

Closed
wants to merge 42 commits into from
Closed

Conversation

jeffkala
Copy link
Contributor

The origin branch has two new models etc. to support these features, this PR will be used to make sure all integrations of both new features work in conjunction before merging into Next.

joewesch and others added 3 commits July 19, 2023 13:32
* Adds ConfigPlan model and initial generation utils

* Updates logic to not create empty config_set

* Changes functions to return config_set instead

* Format via black

* Adds signal to create default ConfigPlan statuses

* Adds ConfigPlan initial UI/API elements

* Fixes Status filter

* Removes unused imports

* Changes variable to function

* Adds ConfigPlan nested serializer

* Update help text per feedback

* Adds CLI rule generation

* Adds ConfigPlan model tests

* Adds ConfigPlan filter tests

* Adds ConfigPlan api tests

* Adds ConfigPlan utility tests

* Adds ConfigPlan view tests

* Changes the test to only run on certain versions

* Hides generate button until a plan type is chosen

* Adds line break to help text

* Changes serializer to disable POST method

* Updates wording

* Changes default statuses to Approved/Not Approved

* Changes field to singular

* Adds plan type to str method

* Adds initial Config Plan documentation

* Reorders migration file after rebase

* Fixes imported class after rebase

* Updates from PR feedback

* Fixes absolute url test

* Fixes typo

* Enables and fixes Edit View tests

---------

Co-authored-by: Jeff Kala <48843785+jeffkala@users.noreply.github.com>
* initial commit for remediation

* initial commit for remediation

* typo fix

* typo fix

* initial commit for remediation

* initial commit for remediation

* typo fix

* typo fix

* modified:   nautobot_golden_config/models.py
	modified:   pyproject.toml

* temporary fixes and changes

* modified:   nautobot_golden_config/nornir_plays/config_compliance.py

* modified:   nautobot_golden_config/models.py

* modified:   nautobot_golden_config/forms.py
	modified:   nautobot_golden_config/templates/nautobot_golden_config/compliance_device_report.html
	modified:   nautobot_golden_config/templates/nautobot_golden_config/compliancerule_retrieve.html
	modified:   nautobot_golden_config/templates/nautobot_golden_config/configcompliance.html

* Remediation options updates

* modified:   nautobot_golden_config/choices.py
	modified:   nautobot_golden_config/models.py
	modified:   nautobot_golden_config/navigation.py
	modified:   nautobot_golden_config/tables.py

* modified:   nautobot_golden_config/models.py
	modified:   nautobot_golden_config/navigation.py
	modified:   nautobot_golden_config/tables.py
	modified:   nautobot_golden_config/templates/nautobot_golden_config/remediationsetting_retrieve.html

* modified:   nautobot_golden_config/models.py
	modified:   nautobot_golden_config/templates/nautobot_golden_config/compliancerule_retrieve.html
	modified:   nautobot_golden_config/templates/nautobot_golden_config/remediationsetting_retrieve.html
	modified:   nautobot_golden_config/views.py

* modified:   nautobot_golden_config/models.py
	modified:   nautobot_golden_config/templates/nautobot_golden_config/compliancerule_retrieve.html
	modified:   nautobot_golden_config/templates/nautobot_golden_config/configcompliance.html

* lint:   nautobot_golden_config/api/serializers.py
	lint:   nautobot_golden_config/forms.py
	lint:   nautobot_golden_config/models.py
	lint:   nautobot_golden_config/tables.py
	lint:   nautobot_golden_config/views.py

* lint:   nautobot_golden_config/models.py

* lint:   nautobot_golden_config/models.py

* lint:   nautobot_golden_config/models.py

* lint:   nautobot_golden_config/models.py

* lint:   nautobot_golden_config/models.py

* Update pyproject.toml

* Update pyproject.toml

* Update pyproject.toml

* remove python 3.7 from ci.yml

* Update ci.yml

* Update ci.yml

* modified:   .github/workflows/ci.yml
	new file:   nautobot_golden_config/migrations/0025_auto_20230707_0921.py
	modified:   poetry.lock

* black:   nautobot_golden_config/migrations/0025_auto_20230707_0921.py

* black:   nautobot_golden_config/migrations/0025_auto_20230707_0921.py

* modified:   nautobot_golden_config/migrations/0005_json_compliance_rule.py
	modified:   nautobot_golden_config/migrations/0025_auto_20230707_0921.py

* modified:   nautobot_golden_config/tests/test_models.py

* tests:   nautobot_golden_config/tests/test_models.py

* modified:   nautobot_golden_config/tests/test_models.py

* peer-review:   .github/workflows/ci.yml
	peer-review:   nautobot_golden_config/models.py

* new file:   docs/images/remediation_custom_function_setup.png
	new file:   docs/images/remediation_enable_compliance_rule_feature.png
	new file:   docs/images/remediation_hier_edit_options.png
	new file:   docs/images/remediation_settings_per_platform.png
	new file:   docs/images/remediation_validate_feature.png
	new file:   docs/user/app_feature_remediation.md
	modified:   nautobot_golden_config/api/serializers.py
	modified:   nautobot_golden_config/filters.py
	modified:   nautobot_golden_config/models.py
	modified:   nautobot_golden_config/tests/conftest.py
	modified:   nautobot_golden_config/tests/test_api.py
	modified:   nautobot_golden_config/tests/test_models.py
	modified:   pyproject.toml

* modified:   nautobot_golden_config/filters.py

* lint:   nautobot_golden_config/filters.py

* new file:   nautobot_golden_config/migrations/0025_remediation_settings_part1.py

* deleted:    nautobot_golden_config/migrations/0025_auto_20230707_0921.py

* lint:   nautobot_golden_config/tests/test_models.py

* modified:   nautobot_golden_config/migrations/0005_json_compliance_rule.py
	modified:   nautobot_golden_config/migrations/0025_remediation_settings_part1.py

* modified:   nautobot_golden_config/migrations/0025_remediation_settings_part1.py

---------

Co-authored-by: pato23arg <patricior_villar@hotmail.com>
Co-authored-by: pvillar_netdev <pato23arg@users.noreply.github.com>
Co-authored-by: Ken Celenza <ken@celenza.org>
@jeffkala jeffkala marked this pull request as draft July 19, 2023 20:14
itdependsnetworks and others added 3 commits July 20, 2023 09:47
* Split Migrations

* Bump min to 1.5.14
#536)

* Add Config Set modal to list view, copy button on modal/detail view, and update bulk edit.

* Update nautobot_golden_config/tables.py

Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com>

* update navigation

---------

Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com>
@itdependsnetworks
Copy link
Contributor

Just adding some screenshots

Config Plans
image

Config Plans Config Set Modal

image

Generate Config Plans from manual jinja template

image

Updated Navbar

image

Remediation in line with compliance

image

Custom Remdiation
image

* Move config create to a javascript process that waits for job to complete and report details into modal. Modal provides
    * Provide progress spinner
    * Provide job status,
    * Job results link
    * Redirect link
    * Error message.
* Separated edit and create templates as they serve different purposes.
* Converted hidden form to uses standard NautobotUIViewSet create method with small amount of JS
* Updated model to link job_result and cm URL
* Updated job to aggregate config to one per job run

Made the JS pieces composable for near future use to kick off job to push configurations.
try:
remediation_setting = RemediationSetting.objects.get(platform=self.platform)
except RemediationSetting.DoesNotExist as err:
raise ValidationError(f"Platform {self.platform.slug} has no Remediation Settings defined.") from err
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 this should rather return None here

self.remediation = None
return

if not self.rule.config_remediation:
Copy link
Contributor

Choose a reason for hiding this comment

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

This will have no effect , but technically this should be the first rule in order

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mzbroch Can you expand on why you're saying here?

rule2 = create_feature_rule_json(device2, feature="Test Feature 2")
rule3 = create_feature_rule_json(device3, feature="Test Feature 3")

not_approved_status = Status.objects.get(slug="not-approved")
Copy link
Contributor

Choose a reason for hiding this comment

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

With planned slug removal, would it make sense to change this to simpler form "unapproved" ?


# TODO: Make the default Status configurable
def config_plan_default_status():
"""Return the default status for config plan."""
Copy link
Contributor

Choose a reason for hiding this comment

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

This one should come from the plugin's settings.

Copy link
Contributor

@mzbroch mzbroch left a comment

Choose a reason for hiding this comment

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

reviewing..

@jeffkala jeffkala added the status: internal review Internal discussion is required to move forward with issue label Aug 9, 2023
joewesch and others added 7 commits August 21, 2023 14:13
* Removes deprecated pylint options

* Updates CI to run on 1.5.14

* Updates CI to run on 1.5.14
* Adds config deployment job and UI elements

* Adds logic to fail if any plans are not approved

* Skips plan deletion if the job failed
needed for now, can remove late but some other dependencies
@jeffkala jeffkala requested a review from joewesch August 31, 2023 19:44
mkdocs.yml Show resolved Hide resolved
Co-authored-by: Jeff Kala <48843785+jeffkala@users.noreply.github.com>
@jeffkala
Copy link
Contributor Author

jeffkala commented Sep 1, 2023

Last few todos:

  • Do additional testing and validation of all features before merging into next.
  • WARN - Last commit before merging to next should be a migration file cleanup.

@jeffkala
Copy link
Contributor Author

jeffkala commented Sep 1, 2023

Last few todos:

  • Do additional testing and validation of all features before merging into next.
  • WARN - Last commit before merging to next should be a migration file cleanup.

#559 needs to be merged into this PR before we finalize this.

@mzbroch
Copy link
Contributor

mzbroch commented Sep 4, 2023

*** I don't think any of the following is really blocking the merge, however I believe we should implement them in nearest future / next-next release ***

  • In a fresh installation , "Generate Config Plan" job is disabled by default and I can not generate any plans. Is this expected behaviour / documented already ?
Screenshot 2023-09-04 at 11 08 27
  • Limiting unexpected behaviours. I would like to discuss "match all devices" behaviour while generating config plans. By default, config plans will be generated for all of the devices if no filter options are selected. Majority of users will not want to generate config plan for all of the devices. (ie. manual), and I'm afraid for first-time users this can cause unexpected behaviour.

  • Pre-viewing device in scope. In general , adding a modal that would allow to pre-view list of impacted would be awesome!

filter: role, platform, site

-----------------------------------
| name | role | platform | site |
-----------------------------------
| dev1 | switch | cisco_ios | waw |
| dev2 | router | cisco_ios | nyc |
| dev3 | router | cisco_ios | jcy |
  • Describing changes. I would like to discuss naming or describing configuration changes. As of now there is no native place to store description. CR field is intended to store change identifiers , that are internal standard and naming could not be meaningful for network engineers.

If there are multiple config plans, this would be the view I could receive for hundreds of the devices that would allow me to easier and quicker understand change context and scope. (second column)

Screenshot 2023-09-04 at 11 52 15

I think viewing the change description / name would be really helpful in such a view to understand a set of changes that is other than a CR identifier.

  • Limiting negative user experience. From the user perspective , it would look better if we gracefully ignore and skip the config plan that is unapproved . We could print the log "config plan was skipped as it was not approved" As of now , a hard error message is displayed
Screenshot 2023-09-04 at 11 29 16
  • Approving plans. From the user perspective , having a new button to "approve" changes instead of relying on the status change would be awesome! See below
Screenshot 2023-09-04 at 11 33 59
  • Persisting config plans. Please consider that once a config plan is implemented , instead of deleting the object we should change the status to the "Implemented".

This would allow to answer following questions :

  • when a change happened ?
  • how many changes were implemented from nautobot ?
  • can I script for rollback ?
  • what were the devices included in change CR xx ?

could be also useful for Grafana Dashboards.

Screenshot 2023-09-04 at 11 45 25

@joewesch
Copy link
Contributor

joewesch commented Sep 5, 2023

In a fresh installation , "Generate Config Plan" job is disabled by default and I can not generate any plans. Is this expected behaviour / documented already ?

Yes, all Jobs are disabled by default. We can, however, add a simple check to the view to create a warning message if the Job is disabled.

Copy link
Contributor

@joewesch joewesch left a comment

Choose a reason for hiding this comment

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

There are a lack of View and Filter tests for RemediationSetting

docs/user/app_feature_config_plans.md Outdated Show resolved Hide resolved
docs/user/app_feature_config_plans.md Show resolved Hide resolved
docs/user/app_feature_config_plans.md Outdated Show resolved Hide resolved
docs/user/app_feature_config_plans.md Outdated Show resolved Hide resolved
docs/user/app_feature_remediation.md Outdated Show resolved Hide resolved
nautobot_golden_config/forms.py Show resolved Hide resolved
nautobot_golden_config/models.py Show resolved Hide resolved
nautobot_golden_config/models.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
jeffkala and others added 2 commits September 5, 2023 14:10
Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com>
@mzbroch
Copy link
Contributor

mzbroch commented Sep 6, 2023

Yes, all Jobs are disabled by default. We can, however, add a simple check to the view to create a warning message if the Job is disabled.

Overall, plugins should be able to provide jobs that are installed and enabled without any additional user interactions.

Ideal workflow is to install and enable the golden config plugin, without any extra steps to enable / migrate jobs etc. Do You mind creating an issue within Nautobot core to track this ? The overall user experience should be simple and allow to user plugin immediately.

@joewesch
Copy link
Contributor

joewesch commented Sep 6, 2023

Do You mind creating an issue within Nautobot core to track this ?

Do I mind? Yes. I agree with the stance that all Jobs should be disabled by default for security reasons.

* additional pr review updates

* fix dunder string method

* fix docstrings and fix filters

* fix api testing for remediation settings
@jeffkala
Copy link
Contributor Author

jeffkala commented Sep 6, 2023

*** I don't think any of the following is really blocking the merge, however I believe we should implement them in nearest future / next-next release ***

  • In a fresh installation , "Generate Config Plan" job is disabled by default and I can not generate any plans. Is this expected behaviour / documented already ?
Screenshot 2023-09-04 at 11 08 27 * **Limiting unexpected behaviours**. I would like to discuss "match all devices" behaviour while generating config plans. By default, config plans will be generated for all of the devices if no filter options are selected. Majority of users will not want to generate config plan for all of the devices. (ie. manual), and I'm afraid for first-time users this can cause unexpected behaviour. * **Pre-viewing device in scope**. In general , adding a modal that would allow to pre-view list of impacted would be awesome!
filter: role, platform, site

-----------------------------------
| name | role | platform | site |
-----------------------------------
| dev1 | switch | cisco_ios | waw |
| dev2 | router | cisco_ios | nyc |
| dev3 | router | cisco_ios | jcy |
  • Describing changes. I would like to discuss naming or describing configuration changes. As of now there is no native place to store description. CR field is intended to store change identifiers , that are internal standard and naming could not be meaningful for network engineers.

If there are multiple config plans, this would be the view I could receive for hundreds of the devices that would allow me to easier and quicker understand change context and scope. (second column)

Screenshot 2023-09-04 at 11 52 15 I think viewing the change description / name would be really helpful in such a view to understand a set of changes that is other than a CR **identifier**.
  • Limiting negative user experience. From the user perspective , it would look better if we gracefully ignore and skip the config plan that is unapproved . We could print the log "config plan was skipped as it was not approved" As of now , a hard error message is displayed
Screenshot 2023-09-04 at 11 29 16 * **Approving plans.** From the user perspective , having a new button to "approve" changes instead of relying on the status change would be awesome! See below Screenshot 2023-09-04 at 11 33 59 * **Persisting config plans.** Please consider that once a config plan is implemented , instead of deleting the object we should change the status to the "Implemented".

This would allow to answer following questions :

  • when a change happened ?
  • how many changes were implemented from nautobot ?
  • can I script for rollback ?
  • what were the devices included in change CR xx ?

could be also useful for Grafana Dashboards.

Screenshot 2023-09-04 at 11 45 25

Anything else form this comment that we want to scope now? I agree that much of these would be well suited for individual feature request that can come in the near future. But don't want to neglect the solid work @mzbroch put into this review.

@jeffkala
Copy link
Contributor Author

jeffkala commented Sep 7, 2023

closing this as the simplified commit history was done in #573 . This has all the history along with all commits, conversation etc. for these features.

@jeffkala
Copy link
Contributor Author

jeffkala commented Sep 7, 2023

closing per completed in #573

@jeffkala jeffkala closed this Sep 7, 2023
@itdependsnetworks itdependsnetworks deleted the config-working-group-temp branch January 24, 2024 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: internal review Internal discussion is required to move forward with issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants