Address PR feedback

This commit is contained in:
Jeremy Stretch 2024-10-31 09:50:00 -04:00
parent cf72b7cb63
commit 0d3016f287
3 changed files with 28 additions and 1 deletions

View File

@ -567,7 +567,7 @@ class BaseInterface(models.Model):
related_name='%(class)ss_svlan',
null=True,
blank=True,
verbose_name=_('Q-inQ SVLAN')
verbose_name=_('Q-in-Q SVLAN')
)
class Meta:

View File

@ -282,6 +282,12 @@ class VLAN(PrimaryModel):
'qinq_svlan': _("Only Q-in-Q customer VLANs maybe assigned to a service VLAN.")
})
# A Q-in-Q customer VLAN must be assigned to a service VLAN
if self.qinq_role == VLANQinQRoleChoices.ROLE_CUSTOMER and not self.qinq_svlan:
raise ValidationError({
'qinq_role': _("A Q-in-Q customer VLAN must be assigned to a service VLAN.")
})
def get_status_color(self):
return VLANStatusChoices.colors.get(self.status)

View File

@ -586,3 +586,24 @@ class TestVLANGroup(TestCase):
vlangroup.vid_ranges = string_to_ranges('2-2')
vlangroup.full_clean()
vlangroup.save()
class TestVLAN(TestCase):
@classmethod
def setUpTestData(cls):
VLAN.objects.bulk_create((
VLAN(name='VLAN 1', vid=1, qinq_role=VLANQinQRoleChoices.ROLE_SERVICE),
))
def test_qinq_role(self):
svlan = VLAN.objects.filter(qinq_role=VLANQinQRoleChoices.ROLE_SERVICE).first()
vlan = VLAN(
name='VLAN X',
vid=999,
qinq_role=VLANQinQRoleChoices.ROLE_SERVICE,
qinq_svlan=svlan
)
with self.assertRaises(ValidationError):
vlan.full_clean()