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

Merge branch 'develop' into 2921-tags-select2

This commit is contained in:
Jeremy Stretch
2020-02-04 09:37:31 -05:00
committed by GitHub
49 changed files with 2290 additions and 1546 deletions

View File

@@ -6,7 +6,9 @@ from dcim.choices import InterfaceModeChoices
from dcim.constants import INTERFACE_MTU_MAX, INTERFACE_MTU_MIN
from dcim.forms import INTERFACE_MODE_HELP_TEXT
from dcim.models import Device, DeviceRole, Interface, Platform, Rack, Region, Site
from extras.forms import AddRemoveTagsForm, CustomFieldBulkEditForm, CustomFieldForm, CustomFieldFilterForm
from extras.forms import (
AddRemoveTagsForm, CustomFieldBulkEditForm, CustomFieldModelCSVForm, CustomFieldModelForm, CustomFieldFilterForm,
)
from ipam.models import IPAddress, VLANGroup, VLAN
from tenancy.forms import TenancyFilterForm, TenancyForm
from tenancy.models import Tenant
@@ -74,7 +76,7 @@ class ClusterGroupCSVForm(forms.ModelForm):
# Clusters
#
class ClusterForm(BootstrapMixin, TenancyForm, CustomFieldForm):
class ClusterForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
comments = CommentField()
tags = TagField(
required=False
@@ -98,7 +100,7 @@ class ClusterForm(BootstrapMixin, TenancyForm, CustomFieldForm):
}
class ClusterCSVForm(forms.ModelForm):
class ClusterCSVForm(CustomFieldModelCSVForm):
type = forms.ModelChoiceField(
queryset=ClusterType.objects.all(),
to_field_name='name',
@@ -328,7 +330,7 @@ class ClusterRemoveDevicesForm(ConfirmationForm):
# Virtual Machines
#
class VirtualMachineForm(BootstrapMixin, TenancyForm, CustomFieldForm):
class VirtualMachineForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
cluster_group = forms.ModelChoiceField(
queryset=ClusterGroup.objects.all(),
required=False,
@@ -431,7 +433,7 @@ class VirtualMachineForm(BootstrapMixin, TenancyForm, CustomFieldForm):
self.fields['primary_ip6'].widget.attrs['readonly'] = True
class VirtualMachineCSVForm(forms.ModelForm):
class VirtualMachineCSVForm(CustomFieldModelCSVForm):
status = CSVChoiceField(
choices=VirtualMachineStatusChoices,
required=False,

View File

@@ -1,23 +1,19 @@
import urllib.parse
from django.test import Client, TestCase
from django.urls import reverse
from utilities.testing import create_test_user
from dcim.models import DeviceRole, Platform, Site
from utilities.testing import StandardTestCases
from virtualization.choices import *
from virtualization.models import Cluster, ClusterGroup, ClusterType, VirtualMachine
class ClusterGroupTestCase(TestCase):
class ClusterGroupTestCase(StandardTestCases.Views):
model = ClusterGroup
def setUp(self):
user = create_test_user(
permissions=[
'virtualization.view_clustergroup',
'virtualization.add_clustergroup',
]
)
self.client = Client()
self.client.force_login(user)
# Disable inapplicable tests
test_get_object = None
test_delete_object = None
test_bulk_edit_objects = None
@classmethod
def setUpTestData(cls):
ClusterGroup.objects.bulk_create([
ClusterGroup(name='Cluster Group 1', slug='cluster-group-1'),
@@ -25,39 +21,29 @@ class ClusterGroupTestCase(TestCase):
ClusterGroup(name='Cluster Group 3', slug='cluster-group-3'),
])
def test_clustergroup_list(self):
cls.form_data = {
'name': 'Cluster Group X',
'slug': 'cluster-group-x',
}
url = reverse('virtualization:clustergroup_list')
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
def test_clustergroup_import(self):
csv_data = (
cls.csv_data = (
"name,slug",
"Cluster Group 4,cluster-group-4",
"Cluster Group 5,cluster-group-5",
"Cluster Group 6,cluster-group-6",
)
response = self.client.post(reverse('virtualization:clustergroup_import'), {'csv': '\n'.join(csv_data)})
self.assertEqual(response.status_code, 200)
self.assertEqual(ClusterGroup.objects.count(), 6)
class ClusterTypeTestCase(StandardTestCases.Views):
model = ClusterType
# Disable inapplicable tests
test_get_object = None
test_delete_object = None
test_bulk_edit_objects = None
class ClusterTypeTestCase(TestCase):
def setUp(self):
user = create_test_user(
permissions=[
'virtualization.view_clustertype',
'virtualization.add_clustertype',
]
)
self.client = Client()
self.client.force_login(user)
@classmethod
def setUpTestData(cls):
ClusterType.objects.bulk_create([
ClusterType(name='Cluster Type 1', slug='cluster-type-1'),
@@ -65,134 +51,139 @@ class ClusterTypeTestCase(TestCase):
ClusterType(name='Cluster Type 3', slug='cluster-type-3'),
])
def test_clustertype_list(self):
cls.form_data = {
'name': 'Cluster Type X',
'slug': 'cluster-type-x',
}
url = reverse('virtualization:clustertype_list')
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
def test_clustertype_import(self):
csv_data = (
cls.csv_data = (
"name,slug",
"Cluster Type 4,cluster-type-4",
"Cluster Type 5,cluster-type-5",
"Cluster Type 6,cluster-type-6",
)
response = self.client.post(reverse('virtualization:clustertype_import'), {'csv': '\n'.join(csv_data)})
self.assertEqual(response.status_code, 200)
self.assertEqual(ClusterType.objects.count(), 6)
class ClusterTestCase(StandardTestCases.Views):
model = Cluster
@classmethod
def setUpTestData(cls):
class ClusterTestCase(TestCase):
def setUp(self):
user = create_test_user(
permissions=[
'virtualization.view_cluster',
'virtualization.add_cluster',
]
sites = (
Site(name='Site 1', slug='site-1'),
Site(name='Site 2', slug='site-2'),
)
self.client = Client()
self.client.force_login(user)
Site.objects.bulk_create(sites)
clustergroup = ClusterGroup(name='Cluster Group 1', slug='cluster-group-1')
clustergroup.save()
clustergroups = (
ClusterGroup(name='Cluster Group 1', slug='cluster-group-1'),
ClusterGroup(name='Cluster Group 2', slug='cluster-group-2'),
)
ClusterGroup.objects.bulk_create(clustergroups)
clustertype = ClusterType(name='Cluster Type 1', slug='cluster-type-1')
clustertype.save()
clustertypes = (
ClusterType(name='Cluster Type 1', slug='cluster-type-1'),
ClusterType(name='Cluster Type 2', slug='cluster-type-2'),
)
ClusterType.objects.bulk_create(clustertypes)
Cluster.objects.bulk_create([
Cluster(name='Cluster 1', group=clustergroup, type=clustertype),
Cluster(name='Cluster 2', group=clustergroup, type=clustertype),
Cluster(name='Cluster 3', group=clustergroup, type=clustertype),
Cluster(name='Cluster 1', group=clustergroups[0], type=clustertypes[0], site=sites[0]),
Cluster(name='Cluster 2', group=clustergroups[0], type=clustertypes[0], site=sites[0]),
Cluster(name='Cluster 3', group=clustergroups[0], type=clustertypes[0], site=sites[0]),
])
def test_cluster_list(self):
url = reverse('virtualization:cluster_list')
params = {
"group": ClusterGroup.objects.first().slug,
"type": ClusterType.objects.first().slug,
cls.form_data = {
'name': 'Cluster X',
'group': clustergroups[1].pk,
'type': clustertypes[1].pk,
'tenant': None,
'site': sites[1].pk,
'comments': 'Some comments',
'tags': 'Alpha,Bravo,Charlie',
}
response = self.client.get('{}?{}'.format(url, urllib.parse.urlencode(params)))
self.assertEqual(response.status_code, 200)
def test_cluster(self):
cluster = Cluster.objects.first()
response = self.client.get(cluster.get_absolute_url())
self.assertEqual(response.status_code, 200)
def test_cluster_import(self):
csv_data = (
cls.csv_data = (
"name,type",
"Cluster 4,Cluster Type 1",
"Cluster 5,Cluster Type 1",
"Cluster 6,Cluster Type 1",
)
response = self.client.post(reverse('virtualization:cluster_import'), {'csv': '\n'.join(csv_data)})
self.assertEqual(response.status_code, 200)
self.assertEqual(Cluster.objects.count(), 6)
class VirtualMachineTestCase(TestCase):
def setUp(self):
user = create_test_user(
permissions=[
'virtualization.view_virtualmachine',
'virtualization.add_virtualmachine',
]
)
self.client = Client()
self.client.force_login(user)
clustertype = ClusterType(name='Cluster Type 1', slug='cluster-type-1')
clustertype.save()
cluster = Cluster(name='Cluster 1', type=clustertype)
cluster.save()
VirtualMachine.objects.bulk_create([
VirtualMachine(name='Virtual Machine 1', cluster=cluster),
VirtualMachine(name='Virtual Machine 2', cluster=cluster),
VirtualMachine(name='Virtual Machine 3', cluster=cluster),
])
def test_virtualmachine_list(self):
url = reverse('virtualization:virtualmachine_list')
params = {
"cluster_id": Cluster.objects.first().pk,
cls.bulk_edit_data = {
'group': clustergroups[1].pk,
'type': clustertypes[1].pk,
'tenant': None,
'site': sites[1].pk,
'comments': 'New comments',
}
response = self.client.get('{}?{}'.format(url, urllib.parse.urlencode(params)))
self.assertEqual(response.status_code, 200)
def test_virtualmachine(self):
class VirtualMachineTestCase(StandardTestCases.Views):
model = VirtualMachine
virtualmachine = VirtualMachine.objects.first()
response = self.client.get(virtualmachine.get_absolute_url())
self.assertEqual(response.status_code, 200)
@classmethod
def setUpTestData(cls):
def test_virtualmachine_import(self):
deviceroles = (
DeviceRole(name='Device Role 1', slug='device-role-1'),
DeviceRole(name='Device Role 2', slug='device-role-2'),
)
DeviceRole.objects.bulk_create(deviceroles)
csv_data = (
platforms = (
Platform(name='Platform 1', slug='platform-1'),
Platform(name='Platform 2', slug='platform-2'),
)
Platform.objects.bulk_create(platforms)
clustertype = ClusterType.objects.create(name='Cluster Type 1', slug='cluster-type-1')
clusters = (
Cluster(name='Cluster 1', type=clustertype),
Cluster(name='Cluster 2', type=clustertype),
)
Cluster.objects.bulk_create(clusters)
VirtualMachine.objects.bulk_create([
VirtualMachine(name='Virtual Machine 1', cluster=clusters[0], role=deviceroles[0], platform=platforms[0]),
VirtualMachine(name='Virtual Machine 2', cluster=clusters[0], role=deviceroles[0], platform=platforms[0]),
VirtualMachine(name='Virtual Machine 3', cluster=clusters[0], role=deviceroles[0], platform=platforms[0]),
])
cls.form_data = {
'cluster': clusters[1].pk,
'tenant': None,
'platform': platforms[1].pk,
'name': 'Virtual Machine X',
'status': VirtualMachineStatusChoices.STATUS_STAGED,
'role': deviceroles[1].pk,
'primary_ip4': None,
'primary_ip6': None,
'vcpus': 4,
'memory': 32768,
'disk': 4000,
'comments': 'Some comments',
'tags': 'Alpha,Bravo,Charlie',
'local_context_data': None,
}
cls.csv_data = (
"name,cluster",
"Virtual Machine 4,Cluster 1",
"Virtual Machine 5,Cluster 1",
"Virtual Machine 6,Cluster 1",
)
response = self.client.post(reverse('virtualization:virtualmachine_import'), {'csv': '\n'.join(csv_data)})
self.assertEqual(response.status_code, 200)
self.assertEqual(VirtualMachine.objects.count(), 6)
cls.bulk_edit_data = {
'cluster': clusters[1].pk,
'tenant': None,
'platform': platforms[1].pk,
'status': VirtualMachineStatusChoices.STATUS_STAGED,
'role': deviceroles[1].pk,
'vcpus': 8,
'memory': 65535,
'disk': 8000,
'comments': 'New comments',
}