mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-28 03:16:25 -06:00
18296 add tenant to vlan groups
This commit is contained in:
parent
689ce73272
commit
99bf1cba5a
@ -411,12 +411,13 @@ class FHRPGroupFilterForm(NetBoxModelFilterSetForm):
|
|||||||
tag = TagFilterField(model)
|
tag = TagFilterField(model)
|
||||||
|
|
||||||
|
|
||||||
class VLANGroupFilterForm(NetBoxModelFilterSetForm):
|
class VLANGroupFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('q', 'filter_id', 'tag'),
|
FieldSet('q', 'filter_id', 'tag'),
|
||||||
FieldSet('region', 'sitegroup', 'site', 'location', 'rack', name=_('Location')),
|
FieldSet('region', 'sitegroup', 'site', 'location', 'rack', name=_('Location')),
|
||||||
FieldSet('cluster_group', 'cluster', name=_('Cluster')),
|
FieldSet('cluster_group', 'cluster', name=_('Cluster')),
|
||||||
FieldSet('contains_vid', name=_('VLANs')),
|
FieldSet('contains_vid', name=_('VLANs')),
|
||||||
|
FieldSet('tenant_group_id', 'tenant_id', name=_('Tenant')),
|
||||||
)
|
)
|
||||||
model = VLANGroup
|
model = VLANGroup
|
||||||
region = DynamicModelMultipleChoiceField(
|
region = DynamicModelMultipleChoiceField(
|
||||||
|
@ -1568,27 +1568,45 @@ class VLANGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
|||||||
cluster = Cluster(name='Cluster 1', type=clustertype)
|
cluster = Cluster(name='Cluster 1', type=clustertype)
|
||||||
cluster.save()
|
cluster.save()
|
||||||
|
|
||||||
|
tenant_groups = (
|
||||||
|
TenantGroup(name='Tenant group 1', slug='tenant-group-1'),
|
||||||
|
TenantGroup(name='Tenant group 2', slug='tenant-group-2'),
|
||||||
|
TenantGroup(name='Tenant group 3', slug='tenant-group-3'),
|
||||||
|
)
|
||||||
|
for tenantgroup in tenant_groups:
|
||||||
|
tenantgroup.save()
|
||||||
|
|
||||||
|
tenants = (
|
||||||
|
Tenant(name='Tenant 1', slug='tenant-1', group=tenant_groups[0]),
|
||||||
|
Tenant(name='Tenant 2', slug='tenant-2', group=tenant_groups[1]),
|
||||||
|
Tenant(name='Tenant 3', slug='tenant-3', group=tenant_groups[2]),
|
||||||
|
)
|
||||||
|
Tenant.objects.bulk_create(tenants)
|
||||||
|
|
||||||
vlan_groups = (
|
vlan_groups = (
|
||||||
VLANGroup(
|
VLANGroup(
|
||||||
name='VLAN Group 1',
|
name='VLAN Group 1',
|
||||||
slug='vlan-group-1',
|
slug='vlan-group-1',
|
||||||
vid_ranges=[NumericRange(1, 11), NumericRange(100, 200)],
|
vid_ranges=[NumericRange(1, 11), NumericRange(100, 200)],
|
||||||
scope=region,
|
scope=region,
|
||||||
description='foobar1'
|
description='foobar1',
|
||||||
|
tenant=tenants[0]
|
||||||
),
|
),
|
||||||
VLANGroup(
|
VLANGroup(
|
||||||
name='VLAN Group 2',
|
name='VLAN Group 2',
|
||||||
slug='vlan-group-2',
|
slug='vlan-group-2',
|
||||||
vid_ranges=[NumericRange(1, 11), NumericRange(200, 300)],
|
vid_ranges=[NumericRange(1, 11), NumericRange(200, 300)],
|
||||||
scope=sitegroup,
|
scope=sitegroup,
|
||||||
description='foobar2'
|
description='foobar2',
|
||||||
|
tenant=tenants[1]
|
||||||
),
|
),
|
||||||
VLANGroup(
|
VLANGroup(
|
||||||
name='VLAN Group 3',
|
name='VLAN Group 3',
|
||||||
slug='vlan-group-3',
|
slug='vlan-group-3',
|
||||||
vid_ranges=[NumericRange(1, 11), NumericRange(300, 400)],
|
vid_ranges=[NumericRange(1, 11), NumericRange(300, 400)],
|
||||||
scope=site,
|
scope=site,
|
||||||
description='foobar3'
|
description='foobar3',
|
||||||
|
tenant=tenants[1]
|
||||||
),
|
),
|
||||||
VLANGroup(
|
VLANGroup(
|
||||||
name='VLAN Group 4',
|
name='VLAN Group 4',
|
||||||
@ -1671,6 +1689,20 @@ class VLANGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
|||||||
params = {'cluster': Cluster.objects.first().pk}
|
params = {'cluster': Cluster.objects.first().pk}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||||
|
|
||||||
|
def test_tenant(self):
|
||||||
|
tenants = Tenant.objects.all()[:2]
|
||||||
|
params = {'tenant_id': [tenants[0].pk, tenants[1].pk]}
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
|
||||||
|
params = {'tenant': [tenants[0].slug, tenants[1].slug]}
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
|
||||||
|
|
||||||
|
def test_tenant_group(self):
|
||||||
|
tenant_groups = TenantGroup.objects.all()[:2]
|
||||||
|
params = {'tenant_group_id': [tenant_groups[0].pk, tenant_groups[1].pk]}
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
|
||||||
|
params = {'tenant_group': [tenant_groups[0].slug, tenant_groups[1].slug]}
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
|
||||||
|
|
||||||
|
|
||||||
class VLANTestCase(TestCase, ChangeLoggedFilterSetTests):
|
class VLANTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||||
queryset = VLAN.objects.all()
|
queryset = VLAN.objects.all()
|
||||||
|
Loading…
Reference in New Issue
Block a user