Skip to content
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

Set VCID's range from 1 to 4294967295 #28

Merged
merged 4 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions netbox_virtual_circuit_plugin/migrations/0003_vcid_size.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.0.6 on 2020-07-21 20:06

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('netbox_virtual_circuit_plugin', '0002_metadata'),
]

operations = [
migrations.AlterField(
model_name='virtualcircuit',
name='vcid',
field=models.BigIntegerField(primary_key=True, serialize=False, validators=[django.core.validators.MaxValueValidator(4294967295), django.core.validators.MinValueValidator(1)]),
),
]
10 changes: 8 additions & 2 deletions netbox_virtual_circuit_plugin/models.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator
from ipam.models import VLAN

from .choices import VirtualCircuitStatusChoices


class VirtualCircuit(models.Model):
"""Virtual Circuit model."""

vcid = models.PositiveSmallIntegerField(
vcid = models.BigIntegerField(
primary_key=True,
verbose_name='ID',
validators=[
MaxValueValidator(4294967295),
MinValueValidator(1),
],
)
name = models.CharField(
max_length=64,
)
status = models.CharField(
max_length=30,
choices=VirtualCircuitStatusChoices,
default=VirtualCircuitStatusChoices.STATUS_PENDING_CONFIGURATION
default=VirtualCircuitStatusChoices.STATUS_PENDING_CONFIGURATION,
)
context = models.CharField(
max_length=100,
Expand Down
12 changes: 11 additions & 1 deletion netbox_virtual_circuit_plugin/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ def setUp(self):

self.vc1_vlan1 = VirtualCircuitVLAN.objects.create(virtual_circuit=self.vc1, vlan=self.vlan1)

def test_invalid_vcid(self):
negative = VirtualCircuit(vcid=-1, name='VC -1')
self.assertRaises(ValidationError, negative.full_clean)

zero = VirtualCircuit(vcid=0, name='VC 0')
self.assertRaises(ValidationError, zero.full_clean)

out_of_range = VirtualCircuit(vcid=4294967296, name='VC 4294967296')
self.assertRaises(ValidationError, out_of_range.full_clean)

def test_duplicate_vlan(self):
duplicate = VirtualCircuitVLAN(virtual_circuit=self.vc1, vlan=self.vlan1)
self.assertRaises(ValidationError, duplicate.full_clean)

def test_create_vlan(self):
def test_create_virtual_circuit(self):
vc1_vlan2 = VirtualCircuitVLAN.objects.create(virtual_circuit=self.vc1, vlan=self.vlan2)
self.assertEqual(vc1_vlan2.virtual_circuit, self.vc1)
self.assertEqual(vc1_vlan2.vlan, self.vlan2)