-
Notifications
You must be signed in to change notification settings - Fork 48
Expose onboarding details in device view #83
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
Merged
mzbroch
merged 2 commits into
mzb-netbox-keeper-disaggregation
from
mzb-develop-2.0-worker-status
Sep 14, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 2.2.10 on 2020-08-21 11:05 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("netbox_onboarding", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="OnboardingDevice", | ||
fields=[ | ||
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False)), | ||
("enabled", models.BooleanField(default=True)), | ||
("device", models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to="dcim.Device")), | ||
], | ||
), | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""Onboarding template content. | ||
|
||
(c) 2020 Network To Code | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
from extras.plugins import PluginTemplateExtension | ||
from .models import OnboardingDevice | ||
|
||
|
||
class DeviceContent(PluginTemplateExtension): # pylint: disable=abstract-method | ||
"""Table to show onboarding details on Device objects.""" | ||
|
||
model = "dcim.device" | ||
|
||
def right_page(self): | ||
"""Show table on right side of view.""" | ||
onboarding = OnboardingDevice.objects.filter(device=self.context["object"]).first() | ||
|
||
if not onboarding.enabled: | ||
return None | ||
|
||
status = onboarding.status | ||
last_check_attempt_date = onboarding.last_check_attempt_date | ||
last_check_successful_date = onboarding.last_check_successful_date | ||
last_ot = onboarding.last_ot | ||
|
||
return self.render( | ||
"netbox_onboarding/device_onboarding_table.html", | ||
extra_context={ | ||
"status": status, | ||
"last_check_attempt_date": last_check_attempt_date, | ||
"last_check_successful_date": last_check_successful_date, | ||
"last_ot": last_ot, | ||
}, | ||
) | ||
|
||
|
||
template_extensions = [DeviceContent] |
31 changes: 31 additions & 0 deletions
31
netbox_onboarding/templates/netbox_onboarding/device_onboarding_table.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{% block content %} | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
<strong>Device Onboarding</strong> | ||
</div> | ||
<table class="table table-hover panel-body"> | ||
<tbody> | ||
<tr> | ||
<th>Date</th> | ||
<th>Status</th> | ||
<th>Date of last success</th> | ||
<th>Latest Task</th> | ||
</tr> | ||
<tr> | ||
<td> | ||
{{ last_check_attempt_date }} | ||
</td> | ||
<td> | ||
{{ status }} | ||
</td> | ||
<td> | ||
{{ last_check_successful_date }} | ||
</td> | ||
<td> | ||
{{ last_ot.pk }} | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
"""Unit tests for netbox_onboarding OnboardingDevice model. | ||
|
||
(c) 2020 Network To Code | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
from django.test import TestCase | ||
|
||
from dcim.models import Site, DeviceRole, DeviceType, Manufacturer, Device | ||
|
||
from netbox_onboarding.models import OnboardingTask | ||
from netbox_onboarding.models import OnboardingDevice | ||
from netbox_onboarding.choices import OnboardingStatusChoices | ||
|
||
|
||
class OnboardingDeviceModelTestCase(TestCase): | ||
"""Test the Onboarding models.""" | ||
|
||
def setUp(self): | ||
"""Setup objects for Onboarding Model tests.""" | ||
self.site = Site.objects.create(name="USWEST", slug="uswest") | ||
manufacturer = Manufacturer.objects.create(name="Juniper", slug="juniper") | ||
device_role = DeviceRole.objects.create(name="Firewall", slug="firewall") | ||
device_type = DeviceType.objects.create(slug="srx3600", model="SRX3600", manufacturer=manufacturer) | ||
|
||
self.device = Device.objects.create( | ||
device_type=device_type, name="device1", device_role=device_role, site=self.site | ||
) | ||
|
||
self.succeeded_task1 = OnboardingTask.objects.create( | ||
ip_address="10.10.10.10", | ||
site=self.site, | ||
status=OnboardingStatusChoices.STATUS_SUCCEEDED, | ||
created_device=self.device, | ||
) | ||
|
||
self.succeeded_task2 = OnboardingTask.objects.create( | ||
ip_address="10.10.10.10", | ||
site=self.site, | ||
status=OnboardingStatusChoices.STATUS_SUCCEEDED, | ||
created_device=self.device, | ||
) | ||
|
||
self.failed_task1 = OnboardingTask.objects.create( | ||
ip_address="10.10.10.10", | ||
site=self.site, | ||
status=OnboardingStatusChoices.STATUS_FAILED, | ||
created_device=self.device, | ||
) | ||
|
||
self.failed_task2 = OnboardingTask.objects.create( | ||
ip_address="10.10.10.10", | ||
site=self.site, | ||
status=OnboardingStatusChoices.STATUS_FAILED, | ||
created_device=self.device, | ||
) | ||
|
||
def test_onboardingdevice_autocreated(self): | ||
"""Verify that OnboardingDevice is auto-created.""" | ||
onboarding_device = OnboardingDevice.objects.get(device=self.device) | ||
self.assertEqual(self.device, onboarding_device.device) | ||
|
||
def test_last_check_attempt_date(self): | ||
"""Verify OnboardingDevice last attempt.""" | ||
onboarding_device = OnboardingDevice.objects.get(device=self.device) | ||
self.assertEqual(onboarding_device.last_check_attempt_date, self.failed_task2.created_on) | ||
|
||
def test_last_check_successful_date(self): | ||
"""Verify OnboardingDevice last success.""" | ||
onboarding_device = OnboardingDevice.objects.get(device=self.device) | ||
self.assertEqual(onboarding_device.last_check_successful_date, self.succeeded_task2.created_on) | ||
|
||
def test_status(self): | ||
"""Verify OnboardingDevice status.""" | ||
onboarding_device = OnboardingDevice.objects.get(device=self.device) | ||
self.assertEqual(onboarding_device.status, self.failed_task2.status) | ||
|
||
def test_last_ot(self): | ||
"""Verify OnboardingDevice last ot.""" | ||
onboarding_device = OnboardingDevice.objects.get(device=self.device) | ||
self.assertEqual(onboarding_device.last_ot, self.failed_task2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.