Skip to content

Commit 011a936

Browse files
authored
Fixes #10686 - Import cables using VC master device (#12551)
* Allow importing cables against master device for subordinate device interfaces * Add tests
1 parent 556beee commit 011a936

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

netbox/dcim/forms/bulk_import.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,11 @@ def _clean_side(self, side):
10781078

10791079
model = content_type.model_class()
10801080
try:
1081-
termination_object = model.objects.get(device=device, name=name)
1081+
if device.virtual_chassis and device.virtual_chassis.master == device and \
1082+
model.objects.filter(device=device, name=name).count() == 0:
1083+
termination_object = model.objects.get(device__in=device.virtual_chassis.members.all(), name=name)
1084+
else:
1085+
termination_object = model.objects.get(device=device, name=name)
10821086
if termination_object.cable is not None:
10831087
raise forms.ValidationError(f"Side {side.upper()}: {device} {termination_object} is already connected")
10841088
except ObjectDoesNotExist:

netbox/dcim/tests/test_views.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,6 +2907,7 @@ def setUpTestData(cls):
29072907
manufacturer = Manufacturer.objects.create(name='Manufacturer 1', slug='manufacturer-1')
29082908
devicetype = DeviceType.objects.create(model='Device Type 1', manufacturer=manufacturer)
29092909
devicerole = DeviceRole.objects.create(name='Device Role 1', slug='device-role-1')
2910+
vc = VirtualChassis.objects.create(name='Virtual Chassis')
29102911

29112912
devices = (
29122913
Device(name='Device 1', site=site, device_type=devicetype, device_role=devicerole),
@@ -2916,6 +2917,10 @@ def setUpTestData(cls):
29162917
)
29172918
Device.objects.bulk_create(devices)
29182919

2920+
vc.members.set((devices[0], devices[1], devices[2]))
2921+
vc.master = devices[0]
2922+
vc.save()
2923+
29192924
interfaces = (
29202925
Interface(device=devices[0], name='Interface 1', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
29212926
Interface(device=devices[0], name='Interface 2', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
@@ -2929,6 +2934,10 @@ def setUpTestData(cls):
29292934
Interface(device=devices[3], name='Interface 1', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
29302935
Interface(device=devices[3], name='Interface 2', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
29312936
Interface(device=devices[3], name='Interface 3', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
2937+
Interface(device=devices[1], name='Device 2 Interface', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
2938+
Interface(device=devices[2], name='Device 3 Interface', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
2939+
Interface(device=devices[3], name='Interface 4', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
2940+
Interface(device=devices[3], name='Interface 5', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
29322941
)
29332942
Interface.objects.bulk_create(interfaces)
29342943

@@ -2961,6 +2970,8 @@ def setUpTestData(cls):
29612970
"Device 3,dcim.interface,Interface 1,Device 4,dcim.interface,Interface 1",
29622971
"Device 3,dcim.interface,Interface 2,Device 4,dcim.interface,Interface 2",
29632972
"Device 3,dcim.interface,Interface 3,Device 4,dcim.interface,Interface 3",
2973+
"Device 1,dcim.interface,Device 2 Interface,Device 4,dcim.interface,Interface 4",
2974+
"Device 1,dcim.interface,Device 3 Interface,Device 4,dcim.interface,Interface 5",
29642975
)
29652976

29662977
cls.csv_update_data = (

0 commit comments

Comments
 (0)