Просмотр исходного кода

Fixes #6822: Use consistent maximum value for interface MTU

jeremystretch 4 лет назад
Родитель
Сommit
8355270a1a

+ 1 - 0
docs/release-notes/version-2.11.md

@@ -12,6 +12,7 @@
 * [#6778](https://github.com/netbox-community/netbox/issues/6778) - Rack reservation should display rack's location
 * [#6780](https://github.com/netbox-community/netbox/issues/6780) - Include rack location in navigation breadcrumbs
 * [#6794](https://github.com/netbox-community/netbox/issues/6794) - Fix device name display on device status view
+* [#6822](https://github.com/netbox-community/netbox/issues/6822) - Use consistent maximum value for interface MTU
 
 ### Other Changes
 

+ 1 - 1
netbox/dcim/constants.py

@@ -29,7 +29,7 @@ REARPORT_POSITIONS_MAX = 1024
 #
 
 INTERFACE_MTU_MIN = 1
-INTERFACE_MTU_MAX = 32767  # Max value of a signed 16-bit integer
+INTERFACE_MTU_MAX = 65536
 
 VIRTUAL_IFACE_TYPES = [
     InterfaceTypeChoices.TYPE_VIRTUAL,

+ 6 - 6
netbox/dcim/forms.py

@@ -102,6 +102,12 @@ class InterfaceCommonForm(forms.Form):
         required=False,
         label='MAC address'
     )
+    mtu = forms.IntegerField(
+        required=False,
+        min_value=INTERFACE_MTU_MIN,
+        max_value=INTERFACE_MTU_MAX,
+        label='MTU'
+    )
 
     def clean(self):
         super().clean()
@@ -3173,12 +3179,6 @@ class InterfaceCreateForm(ComponentCreateForm, InterfaceCommonForm):
             'type': 'lag',
         }
     )
-    mtu = forms.IntegerField(
-        required=False,
-        min_value=INTERFACE_MTU_MIN,
-        max_value=INTERFACE_MTU_MAX,
-        label='MTU'
-    )
     mac_address = forms.CharField(
         required=False,
         label='MAC Address'

+ 4 - 1
netbox/dcim/models/device_components.py

@@ -483,7 +483,10 @@ class BaseInterface(models.Model):
     mtu = models.PositiveIntegerField(
         blank=True,
         null=True,
-        validators=[MinValueValidator(1), MaxValueValidator(65536)],
+        validators=[
+            MinValueValidator(INTERFACE_MTU_MIN),
+            MaxValueValidator(INTERFACE_MTU_MAX)
+        ],
         verbose_name='MTU'
     )
     mode = models.CharField(

+ 1 - 1
netbox/dcim/tests/test_views.py

@@ -1464,7 +1464,7 @@ class InterfaceTestCase(ViewTestCases.DeviceComponentViewTestCase):
             'enabled': False,
             'lag': interfaces[3].pk,
             'mac_address': EUI('01:02:03:04:05:06'),
-            'mtu': 2000,
+            'mtu': 65000,
             'mgmt_only': True,
             'description': 'A front port',
             'mode': InterfaceModeChoices.MODE_TAGGED,

+ 4 - 10
netbox/virtualization/forms.py

@@ -16,10 +16,10 @@ from ipam.models import IPAddress, VLAN
 from tenancy.forms import TenancyFilterForm, TenancyForm
 from tenancy.models import Tenant
 from utilities.forms import (
-    add_blank_choice, BootstrapMixin, BulkEditForm, BulkEditNullBooleanSelect, BulkRenameForm, CommentField,
-    ConfirmationForm, CSVChoiceField, CSVModelChoiceField, CSVModelForm, DynamicModelChoiceField,
-    DynamicModelMultipleChoiceField, ExpandableNameField, form_from_model, JSONField, SlugField, SmallTextarea,
-    StaticSelect2, StaticSelect2Multiple, TagFilterField, BOOLEAN_WITH_BLANK_CHOICES,
+    add_blank_choice, BootstrapMixin, BulkEditNullBooleanSelect, BulkRenameForm, CommentField, ConfirmationForm,
+    CSVChoiceField, CSVModelChoiceField, DynamicModelChoiceField, DynamicModelMultipleChoiceField, ExpandableNameField,
+    form_from_model, JSONField, SlugField, SmallTextarea, StaticSelect2, StaticSelect2Multiple, TagFilterField,
+    BOOLEAN_WITH_BLANK_CHOICES,
 )
 from .choices import *
 from .models import Cluster, ClusterGroup, ClusterType, VirtualMachine, VMInterface
@@ -680,12 +680,6 @@ class VMInterfaceCreateForm(BootstrapMixin, CustomFieldForm, InterfaceCommonForm
             'virtual_machine_id': '$virtual_machine',
         }
     )
-    mtu = forms.IntegerField(
-        required=False,
-        min_value=INTERFACE_MTU_MIN,
-        max_value=INTERFACE_MTU_MAX,
-        label='MTU'
-    )
     mac_address = forms.CharField(
         required=False,
         label='MAC Address'

+ 1 - 1
netbox/virtualization/tests/test_views.py

@@ -263,7 +263,7 @@ class VMInterfaceTestCase(ViewTestCases.DeviceComponentViewTestCase):
             'name': 'Interface X',
             'enabled': False,
             'mac_address': EUI('01-02-03-04-05-06'),
-            'mtu': 2000,
+            'mtu': 65000,
             'description': 'New description',
             'mode': InterfaceModeChoices.MODE_TAGGED,
             'untagged_vlan': vlans[0].pk,