From f20d16f188bce3f43bcce616166ebc9dc138e20a Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Fri, 10 Jan 2020 16:42:02 +0000 Subject: [PATCH 1/8] Fixes #3491: include content of webhook error response --- docs/release-notes/version-2.6.md | 1 + netbox/extras/webhooks_worker.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 025994856..325ac2234 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -11,6 +11,7 @@ * [#3187](https://github.com/netbox-community/netbox/issues/3187) - Add rack selection field to rack elevations * [#3393](https://github.com/netbox-community/netbox/issues/3393) - Paginate the circuits at the provider details view * [#3440](https://github.com/netbox-community/netbox/issues/3440) - Add total length to cable trace +* [#3491](https://github.com/netbox-community/netbox/issues/3491) - Include content of response on webhook error * [#3623](https://github.com/netbox-community/netbox/issues/3623) - Add word expansion during interface creation * [#3668](https://github.com/netbox-community/netbox/issues/3668) - Search by DNS name when assigning IP address * [#3851](https://github.com/netbox-community/netbox/issues/3851) - Allow passing initial data to custom script forms diff --git a/netbox/extras/webhooks_worker.py b/netbox/extras/webhooks_worker.py index 9a637e852..d41d795c6 100644 --- a/netbox/extras/webhooks_worker.py +++ b/netbox/extras/webhooks_worker.py @@ -60,5 +60,5 @@ def process_webhook(webhook, data, model_name, event, timestamp, username, reque return 'Status {} returned, webhook successfully processed.'.format(response.status_code) else: raise requests.exceptions.RequestException( - "Status {} returned, webhook FAILED to process.".format(response.status_code) + "Status {} returned with content '{}', webhook FAILED to process.".format(response.status_code, response.content) ) From 422c6bad5bc6b1f465e3d86195afc8bc5a5f3125 Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Sat, 11 Jan 2020 15:36:58 +0000 Subject: [PATCH 2/8] Fixes #3895: Elevations filter regression --- netbox/dcim/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index f0b91c2f5..e85468445 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -739,7 +739,7 @@ class RackElevationFilterForm(RackFilterForm): # Filter the rack field based on the site and group self.fields['site'].widget.add_filter_for('id', 'site') - self.fields['rack_group_id'].widget.add_filter_for('id', 'group_id') + self.fields['group_id'].widget.add_filter_for('id', 'group_id') # From a2308b9c9949de742142f3a40600b5178b7216a9 Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Sun, 12 Jan 2020 11:08:13 +0000 Subject: [PATCH 3/8] Fixes #3898: Call str of cable on delete to save PK in id_string --- docs/release-notes/version-2.6.md | 1 + netbox/dcim/models.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 88cd9c120..c4d8f1414 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -28,6 +28,7 @@ * [#3872](https://github.com/netbox-community/netbox/issues/3872) - Paginate related IPs of an address * [#3876](https://github.com/netbox-community/netbox/issues/3876) - Fixed min/max to ASN input field at the site creation page * [#3882](https://github.com/netbox-community/netbox/issues/3882) - Fix filtering of devices by rack group +* [#3898](https://github.com/netbox-community/netbox/issues/3898) - Fix deleted message being set to None for cable --- diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 69c3c3475..89ff8bc15 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -3040,6 +3040,11 @@ class Cable(ChangeLoggedModel): def get_absolute_url(self): return reverse('dcim:cable', args=[self.pk]) + def delete(self, *args, **kwargs): + # Trigger the __str__ method to save the pk into `self.id_string` + str(self) + super().delete(*args, **kwargs) + def clean(self): # Validate that termination A exists From 49fa243b4f9779d05e2e6e697b685b46484a265c Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Sun, 12 Jan 2020 11:21:02 +0000 Subject: [PATCH 4/8] Added post-delete cable ID test --- netbox/dcim/tests/test_models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/netbox/dcim/tests/test_models.py b/netbox/dcim/tests/test_models.py index 2b5bed283..eba81b136 100644 --- a/netbox/dcim/tests/test_models.py +++ b/netbox/dcim/tests/test_models.py @@ -325,9 +325,12 @@ class CableTestCase(TestCase): def test_cable_deletion(self): """ - When a Cable is deleted, the `cable` field on its termination points must be nullified. + When a Cable is deleted, the `cable` field on its termination points must be nullified. The str() method + should still return the PK of the string even after being nullified. """ self.cable.delete() + self.assertIsNone(self.cable.pk) + self.assertNotEqual(str(self.cable), '#None') interface1 = Interface.objects.get(pk=self.interface1.pk) self.assertIsNone(interface1.cable) interface2 = Interface.objects.get(pk=self.interface2.pk) From fe0fbeab49ed345f838a74bd61eef4d265a15d90 Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Mon, 13 Jan 2020 12:05:06 +0000 Subject: [PATCH 5/8] Fixes #3902: relax non-essential required fields --- docs/release-notes/version-2.6.md | 1 + netbox/dcim/forms.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 88cd9c120..c83fc8173 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -15,6 +15,7 @@ * [#3668](https://github.com/netbox-community/netbox/issues/3668) - Search by DNS name when assigning IP address * [#3851](https://github.com/netbox-community/netbox/issues/3851) - Allow passing initial data to custom script forms * [#3891](https://github.com/netbox-community/netbox/issues/3891) - Add `local_context_data` filter for virtual machines +* [#3902](https://github.com/netbox-community/netbox/issues/3902) - Relax the non-essential required fields when connecting cable to circuit or power feed ## Bug Fixes diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index f0b91c2f5..14c997b30 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -2804,6 +2804,7 @@ class ConnectCableToCircuitTerminationForm(BootstrapMixin, ChainedFieldsMixin, f termination_b_provider = forms.ModelChoiceField( queryset=Provider.objects.all(), label='Provider', + required=False, widget=APISelect( api_url='/api/circuits/providers/', filter_for={ @@ -2857,6 +2858,7 @@ class ConnectCableToPowerFeedForm(BootstrapMixin, ChainedFieldsMixin, forms.Mode termination_b_site = forms.ModelChoiceField( queryset=Site.objects.all(), label='Site', + required=False, widget=APISelect( api_url='/api/dcim/sites/', display_field='cid', @@ -2888,6 +2890,7 @@ class ConnectCableToPowerFeedForm(BootstrapMixin, ChainedFieldsMixin, forms.Mode ('rack_group', 'termination_b_rackgroup'), ), label='Power Panel', + required=False, widget=APISelect( api_url='/api/dcim/power-panels/', filter_for={ From 3d78a673431bfe370e95a4f82a90a11e0041932d Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Mon, 13 Jan 2020 14:57:21 +0000 Subject: [PATCH 6/8] Store a private copy of the pk during init and use that with __str__ --- netbox/dcim/models.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 89ff8bc15..d7c85ff00 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -3027,24 +3027,18 @@ class Cable(ChangeLoggedModel): ('termination_b_type', 'termination_b_id'), ) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + # A copy of the PK to be used by __str__ in case the object is deleted + self._pk = self.pk + def __str__(self): - if self.label: - return self.label - - # Save a copy of the PK on the instance since it's nullified if .delete() is called - if not hasattr(self, 'id_string'): - self.id_string = '#{}'.format(self.pk) - - return self.id_string + return self.label or '#{}'.format(self._pk) def get_absolute_url(self): return reverse('dcim:cable', args=[self.pk]) - def delete(self, *args, **kwargs): - # Trigger the __str__ method to save the pk into `self.id_string` - str(self) - super().delete(*args, **kwargs) - def clean(self): # Validate that termination A exists From 608006ee776a2f6fe8e7174f196e9eb51757f19e Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Mon, 13 Jan 2020 15:21:37 +0000 Subject: [PATCH 7/8] Set the private pk after super save --- netbox/dcim/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index d7c85ff00..833fb483b 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -3141,6 +3141,9 @@ class Cable(ChangeLoggedModel): super().save(*args, **kwargs) + # Update the private pk used in __str__ in case this is a new object (i.e. just got its pk) + self._pk = self.pk + def to_csv(self): return ( '{}.{}'.format(self.termination_a_type.app_label, self.termination_a_type.model), From 32ffc1b54b128260e627659a7816dfd13ca80e1c Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Mon, 13 Jan 2020 15:31:35 +0000 Subject: [PATCH 8/8] Fixes #3905: divide by zero on power feeds with low values --- docs/release-notes/version-2.6.md | 1 + netbox/templates/dcim/powerfeed.html | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 88cd9c120..cffaa1a41 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -28,6 +28,7 @@ * [#3872](https://github.com/netbox-community/netbox/issues/3872) - Paginate related IPs of an address * [#3876](https://github.com/netbox-community/netbox/issues/3876) - Fixed min/max to ASN input field at the site creation page * [#3882](https://github.com/netbox-community/netbox/issues/3882) - Fix filtering of devices by rack group +* [#3905](https://github.com/netbox-community/netbox/issues/3905) - Fix divide-by-zero on power feeds with low power values --- diff --git a/netbox/templates/dcim/powerfeed.html b/netbox/templates/dcim/powerfeed.html index a8ab302eb..4e88f09c9 100644 --- a/netbox/templates/dcim/powerfeed.html +++ b/netbox/templates/dcim/powerfeed.html @@ -112,7 +112,9 @@ {% if utilization %} {{ utilization.allocated }}VA / {{ powerfeed.available_power }}VA - {% utilization_graph utilization.allocated|percentage:powerfeed.available_power %} + {% if powerfeed.available_power > 0 %} + {% utilization_graph utilization.allocated|percentage:powerfeed.available_power %} + {% endif %} {% else %} N/A