1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #4272: Interface type should be required by API serializer

This commit is contained in:
Jeremy Stretch
2020-02-25 11:20:43 -05:00
parent 161f03217e
commit 62efe0621f
3 changed files with 23 additions and 8 deletions

View File

@ -21,6 +21,7 @@
* [#4241](https://github.com/netbox-community/netbox/issues/4241) - Correct IP address hyperlinks on interface view * [#4241](https://github.com/netbox-community/netbox/issues/4241) - Correct IP address hyperlinks on interface view
* [#4246](https://github.com/netbox-community/netbox/issues/4246) - Fix duplication of field attributes when multiple IPNetworkVars are present in a script * [#4246](https://github.com/netbox-community/netbox/issues/4246) - Fix duplication of field attributes when multiple IPNetworkVars are present in a script
* [#4252](https://github.com/netbox-community/netbox/issues/4252) - Fix power port assignment for power outlet templates created via REST API * [#4252](https://github.com/netbox-community/netbox/issues/4252) - Fix power port assignment for power outlet templates created via REST API
* [#4272](https://github.com/netbox-community/netbox/issues/4272) - Interface type should be required by API serializer
--- ---

View File

@ -298,7 +298,7 @@ class PowerOutletTemplateSerializer(ValidatedModelSerializer):
class InterfaceTemplateSerializer(ValidatedModelSerializer): class InterfaceTemplateSerializer(ValidatedModelSerializer):
device_type = NestedDeviceTypeSerializer() device_type = NestedDeviceTypeSerializer()
type = ChoiceField(choices=InterfaceTypeChoices, required=False) type = ChoiceField(choices=InterfaceTypeChoices)
class Meta: class Meta:
model = InterfaceTemplate model = InterfaceTemplate
@ -518,7 +518,7 @@ class PowerPortSerializer(TaggitSerializer, ConnectedEndpointSerializer):
class InterfaceSerializer(TaggitSerializer, ConnectedEndpointSerializer): class InterfaceSerializer(TaggitSerializer, ConnectedEndpointSerializer):
device = NestedDeviceSerializer() device = NestedDeviceSerializer()
type = ChoiceField(choices=InterfaceTypeChoices, required=False) type = ChoiceField(choices=InterfaceTypeChoices)
lag = NestedInterfaceSerializer(required=False, allow_null=True) lag = NestedInterfaceSerializer(required=False, allow_null=True)
mode = ChoiceField(choices=InterfaceModeChoices, allow_blank=True, required=False) mode = ChoiceField(choices=InterfaceModeChoices, allow_blank=True, required=False)
untagged_vlan = NestedVLANSerializer(required=False, allow_null=True) untagged_vlan = NestedVLANSerializer(required=False, allow_null=True)

View File

@ -1470,13 +1470,13 @@ class InterfaceTemplateTest(APITestCase):
manufacturer=self.manufacturer, model='Test Device Type 1', slug='test-device-type-1' manufacturer=self.manufacturer, model='Test Device Type 1', slug='test-device-type-1'
) )
self.interfacetemplate1 = InterfaceTemplate.objects.create( self.interfacetemplate1 = InterfaceTemplate.objects.create(
device_type=self.devicetype, name='Test Interface Template 1' device_type=self.devicetype, name='Test Interface Template 1', type='1000base-t'
) )
self.interfacetemplate2 = InterfaceTemplate.objects.create( self.interfacetemplate2 = InterfaceTemplate.objects.create(
device_type=self.devicetype, name='Test Interface Template 2' device_type=self.devicetype, name='Test Interface Template 2', type='1000base-t'
) )
self.interfacetemplate3 = InterfaceTemplate.objects.create( self.interfacetemplate3 = InterfaceTemplate.objects.create(
device_type=self.devicetype, name='Test Interface Template 3' device_type=self.devicetype, name='Test Interface Template 3', type='1000base-t'
) )
def test_get_interfacetemplate(self): def test_get_interfacetemplate(self):
@ -1498,6 +1498,7 @@ class InterfaceTemplateTest(APITestCase):
data = { data = {
'device_type': self.devicetype.pk, 'device_type': self.devicetype.pk,
'name': 'Test Interface Template 4', 'name': 'Test Interface Template 4',
'type': '1000base-t',
} }
url = reverse('dcim-api:interfacetemplate-list') url = reverse('dcim-api:interfacetemplate-list')
@ -1515,14 +1516,17 @@ class InterfaceTemplateTest(APITestCase):
{ {
'device_type': self.devicetype.pk, 'device_type': self.devicetype.pk,
'name': 'Test Interface Template 4', 'name': 'Test Interface Template 4',
'type': '1000base-t',
}, },
{ {
'device_type': self.devicetype.pk, 'device_type': self.devicetype.pk,
'name': 'Test Interface Template 5', 'name': 'Test Interface Template 5',
'type': '1000base-t',
}, },
{ {
'device_type': self.devicetype.pk, 'device_type': self.devicetype.pk,
'name': 'Test Interface Template 6', 'name': 'Test Interface Template 6',
'type': '1000base-t',
}, },
] ]
@ -1540,6 +1544,7 @@ class InterfaceTemplateTest(APITestCase):
data = { data = {
'device_type': self.devicetype.pk, 'device_type': self.devicetype.pk,
'name': 'Test Interface Template X', 'name': 'Test Interface Template X',
'type': '1000base-x-gbic',
} }
url = reverse('dcim-api:interfacetemplate-detail', kwargs={'pk': self.interfacetemplate1.pk}) url = reverse('dcim-api:interfacetemplate-detail', kwargs={'pk': self.interfacetemplate1.pk})
@ -2650,9 +2655,9 @@ class InterfaceTest(APITestCase):
self.device = Device.objects.create( self.device = Device.objects.create(
device_type=devicetype, device_role=devicerole, name='Test Device 1', site=site device_type=devicetype, device_role=devicerole, name='Test Device 1', site=site
) )
self.interface1 = Interface.objects.create(device=self.device, name='Test Interface 1') self.interface1 = Interface.objects.create(device=self.device, name='Test Interface 1', type='1000base-t')
self.interface2 = Interface.objects.create(device=self.device, name='Test Interface 2') self.interface2 = Interface.objects.create(device=self.device, name='Test Interface 2', type='1000base-t')
self.interface3 = Interface.objects.create(device=self.device, name='Test Interface 3') self.interface3 = Interface.objects.create(device=self.device, name='Test Interface 3', type='1000base-t')
self.vlan1 = VLAN.objects.create(name="Test VLAN 1", vid=1) self.vlan1 = VLAN.objects.create(name="Test VLAN 1", vid=1)
self.vlan2 = VLAN.objects.create(name="Test VLAN 2", vid=2) self.vlan2 = VLAN.objects.create(name="Test VLAN 2", vid=2)
@ -2713,6 +2718,7 @@ class InterfaceTest(APITestCase):
data = { data = {
'device': self.device.pk, 'device': self.device.pk,
'name': 'Test Interface 4', 'name': 'Test Interface 4',
'type': '1000base-t',
} }
url = reverse('dcim-api:interface-list') url = reverse('dcim-api:interface-list')
@ -2729,6 +2735,7 @@ class InterfaceTest(APITestCase):
data = { data = {
'device': self.device.pk, 'device': self.device.pk,
'name': 'Test Interface 4', 'name': 'Test Interface 4',
'type': '1000base-t',
'mode': InterfaceModeChoices.MODE_TAGGED, 'mode': InterfaceModeChoices.MODE_TAGGED,
'untagged_vlan': self.vlan3.id, 'untagged_vlan': self.vlan3.id,
'tagged_vlans': [self.vlan1.id, self.vlan2.id], 'tagged_vlans': [self.vlan1.id, self.vlan2.id],
@ -2750,14 +2757,17 @@ class InterfaceTest(APITestCase):
{ {
'device': self.device.pk, 'device': self.device.pk,
'name': 'Test Interface 4', 'name': 'Test Interface 4',
'type': '1000base-t',
}, },
{ {
'device': self.device.pk, 'device': self.device.pk,
'name': 'Test Interface 5', 'name': 'Test Interface 5',
'type': '1000base-t',
}, },
{ {
'device': self.device.pk, 'device': self.device.pk,
'name': 'Test Interface 6', 'name': 'Test Interface 6',
'type': '1000base-t',
}, },
] ]
@ -2776,6 +2786,7 @@ class InterfaceTest(APITestCase):
{ {
'device': self.device.pk, 'device': self.device.pk,
'name': 'Test Interface 4', 'name': 'Test Interface 4',
'type': '1000base-t',
'mode': InterfaceModeChoices.MODE_TAGGED, 'mode': InterfaceModeChoices.MODE_TAGGED,
'untagged_vlan': self.vlan2.id, 'untagged_vlan': self.vlan2.id,
'tagged_vlans': [self.vlan1.id], 'tagged_vlans': [self.vlan1.id],
@ -2783,6 +2794,7 @@ class InterfaceTest(APITestCase):
{ {
'device': self.device.pk, 'device': self.device.pk,
'name': 'Test Interface 5', 'name': 'Test Interface 5',
'type': '1000base-t',
'mode': InterfaceModeChoices.MODE_TAGGED, 'mode': InterfaceModeChoices.MODE_TAGGED,
'untagged_vlan': self.vlan2.id, 'untagged_vlan': self.vlan2.id,
'tagged_vlans': [self.vlan1.id], 'tagged_vlans': [self.vlan1.id],
@ -2790,6 +2802,7 @@ class InterfaceTest(APITestCase):
{ {
'device': self.device.pk, 'device': self.device.pk,
'name': 'Test Interface 6', 'name': 'Test Interface 6',
'type': '1000base-t',
'mode': InterfaceModeChoices.MODE_TAGGED, 'mode': InterfaceModeChoices.MODE_TAGGED,
'untagged_vlan': self.vlan2.id, 'untagged_vlan': self.vlan2.id,
'tagged_vlans': [self.vlan1.id], 'tagged_vlans': [self.vlan1.id],
@ -2815,6 +2828,7 @@ class InterfaceTest(APITestCase):
data = { data = {
'device': self.device.pk, 'device': self.device.pk,
'name': 'Test Interface X', 'name': 'Test Interface X',
'type': '1000base-x-gbic',
'lag': lag_interface.pk, 'lag': lag_interface.pk,
} }