Merge branch 'feature' into 17929-prefix-scope

This commit is contained in:
Arthur Hanson 2024-11-14 11:02:08 -08:00
commit 805954eb87
17 changed files with 29 additions and 29 deletions

View File

@ -21,6 +21,7 @@ def copy_site_assignments(apps, schema_editor):
termination_id=models.F('provider_network_id') termination_id=models.F('provider_network_id')
) )
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [

View File

@ -341,7 +341,7 @@ class ProviderNetworkTestCase(ViewTestCases.PrimaryObjectViewTestCase):
} }
class TestCase(ViewTestCases.PrimaryObjectViewTestCase): class TestCase(ViewTestCases.PrimaryObjectViewTestCase):
model = CircuitTermination model = CircuitTermination
@classmethod @classmethod

View File

@ -223,7 +223,7 @@ class EventRuleImportForm(NetBoxModelImportForm):
from extras.scripts import get_module_and_script from extras.scripts import get_module_and_script
module_name, script_name = action_object.split('.', 1) module_name, script_name = action_object.split('.', 1)
try: try:
module, script = get_module_and_script(module_name, script_name) script = get_module_and_script(module_name, script_name)[1]
except ObjectDoesNotExist: except ObjectDoesNotExist:
raise forms.ValidationError(_("Script {name} not found").format(name=action_object)) raise forms.ValidationError(_("Script {name} not found").format(name=action_object))
self.instance.action_object = script self.instance.action_object = script

View File

@ -38,7 +38,7 @@ class Command(BaseCommand):
data = {} data = {}
module_name, script_name = script.split('.', 1) module_name, script_name = script.split('.', 1)
module, script_obj = get_module_and_script(module_name, script_name) script_obj = get_module_and_script(module_name, script_name)[1]
script = script_obj.python_class script = script_obj.python_class
# Take user from command line if provided and exists, other # Take user from command line if provided and exists, other

View File

@ -30,7 +30,7 @@ def get_python_name(scriptmodule):
""" """
Return the Python name of a ScriptModule's file on disk. Return the Python name of a ScriptModule's file on disk.
""" """
path, filename = os.path.split(scriptmodule.file_path) filename = os.path.split(scriptmodule.file_path)[0]
return os.path.splitext(filename)[0] return os.path.splitext(filename)[0]
@ -128,7 +128,7 @@ def update_event_rules(apps, schema_editor):
for eventrule in EventRule.objects.filter(action_object_type=scriptmodule_ct): for eventrule in EventRule.objects.filter(action_object_type=scriptmodule_ct):
name = eventrule.action_parameters.get('script_name') name = eventrule.action_parameters.get('script_name')
obj, created = Script.objects.get_or_create( obj, __ = Script.objects.get_or_create(
module_id=eventrule.action_object_id, module_id=eventrule.action_object_id,
name=name, name=name,
defaults={'is_executable': False} defaults={'is_executable': False}

View File

@ -108,8 +108,8 @@ class NetIn(Lookup):
return self.rhs return self.rhs
def as_sql(self, qn, connection): def as_sql(self, qn, connection):
lhs, lhs_params = self.process_lhs(qn, connection) lhs = self.process_lhs(qn, connection)[0]
rhs, rhs_params = self.process_rhs(qn, connection) rhs_params = self.process_rhs(qn, connection)[1]
with_mask, without_mask = [], [] with_mask, without_mask = [], []
for address in rhs_params[0]: for address in rhs_params[0]:
if '/' in address: if '/' in address:

View File

@ -42,7 +42,7 @@ class PrefixOrderingTestCase(OrderingTestBase):
""" """
This is a very basic test, which tests both prefixes without VRFs and prefixes with VRFs This is a very basic test, which tests both prefixes without VRFs and prefixes with VRFs
""" """
vrf1, vrf2, vrf3 = list(VRF.objects.all()) vrf1, vrf2 = VRF.objects.all()[:2]
prefixes = ( prefixes = (
Prefix(status=PrefixStatusChoices.STATUS_CONTAINER, vrf=None, prefix=netaddr.IPNetwork('192.168.0.0/16')), Prefix(status=PrefixStatusChoices.STATUS_CONTAINER, vrf=None, prefix=netaddr.IPNetwork('192.168.0.0/16')),
Prefix(status=PrefixStatusChoices.STATUS_ACTIVE, vrf=None, prefix=netaddr.IPNetwork('192.168.0.0/24')), Prefix(status=PrefixStatusChoices.STATUS_ACTIVE, vrf=None, prefix=netaddr.IPNetwork('192.168.0.0/24')),
@ -106,7 +106,7 @@ class PrefixOrderingTestCase(OrderingTestBase):
VRF A:10.1.1.0/24 VRF A:10.1.1.0/24
None: 192.168.0.0/16 None: 192.168.0.0/16
""" """
vrf1, vrf2, vrf3 = list(VRF.objects.all()) vrf1 = VRF.objects.first()
prefixes = [ prefixes = [
Prefix(status=PrefixStatusChoices.STATUS_CONTAINER, vrf=None, prefix=netaddr.IPNetwork('10.0.0.0/8')), Prefix(status=PrefixStatusChoices.STATUS_CONTAINER, vrf=None, prefix=netaddr.IPNetwork('10.0.0.0/8')),
Prefix(status=PrefixStatusChoices.STATUS_CONTAINER, vrf=None, prefix=netaddr.IPNetwork('10.0.0.0/16')), Prefix(status=PrefixStatusChoices.STATUS_CONTAINER, vrf=None, prefix=netaddr.IPNetwork('10.0.0.0/16')),
@ -130,7 +130,7 @@ class IPAddressOrderingTestCase(OrderingTestBase):
""" """
This function tests ordering with the inclusion of vrfs This function tests ordering with the inclusion of vrfs
""" """
vrf1, vrf2, vrf3 = list(VRF.objects.all()) vrf1, vrf2 = VRF.objects.all()[:2]
addresses = ( addresses = (
IPAddress(status=IPAddressStatusChoices.STATUS_ACTIVE, vrf=vrf1, address=netaddr.IPNetwork('10.0.0.1/24')), IPAddress(status=IPAddressStatusChoices.STATUS_ACTIVE, vrf=vrf1, address=netaddr.IPNetwork('10.0.0.1/24')),
IPAddress(status=IPAddressStatusChoices.STATUS_ACTIVE, vrf=vrf1, address=netaddr.IPNetwork('10.0.1.1/24')), IPAddress(status=IPAddressStatusChoices.STATUS_ACTIVE, vrf=vrf1, address=netaddr.IPNetwork('10.0.1.1/24')),

View File

@ -107,7 +107,7 @@ class ObjectPermissionMixin:
return perms return perms
def has_perm(self, user_obj, perm, obj=None): def has_perm(self, user_obj, perm, obj=None):
app_label, action, model_name = resolve_permission(perm) app_label, __, model_name = resolve_permission(perm)
# Superusers implicitly have all permissions # Superusers implicitly have all permissions
if user_obj.is_active and user_obj.is_superuser: if user_obj.is_active and user_obj.is_superuser:

View File

@ -213,7 +213,6 @@ class PluginTest(TestCase):
self.assertEqual(get_plugin_config(plugin, 'bar'), None) self.assertEqual(get_plugin_config(plugin, 'bar'), None)
self.assertEqual(get_plugin_config(plugin, 'bar', default=456), 456) self.assertEqual(get_plugin_config(plugin, 'bar', default=456), 456)
def test_events_pipeline(self): def test_events_pipeline(self):
""" """
Check that events pipeline is registered. Check that events pipeline is registered.

View File

@ -49,7 +49,7 @@ def handler_500(request, template_name=ERROR_500_TEMPLATE_NAME):
template = loader.get_template(template_name) template = loader.get_template(template_name)
except TemplateDoesNotExist: except TemplateDoesNotExist:
return HttpResponseServerError('<h1>Server Error (500)</h1>', content_type='text/html') return HttpResponseServerError('<h1>Server Error (500)</h1>', content_type='text/html')
type_, error, traceback = sys.exc_info() type_, error = sys.exc_info()[:2]
return HttpResponseServerError(template.render({ return HttpResponseServerError(template.render({
'error': error, 'error': error,

View File

@ -49,7 +49,7 @@ def handle_rest_api_exception(request, *args, **kwargs):
""" """
Handle exceptions and return a useful error message for REST API requests. Handle exceptions and return a useful error message for REST API requests.
""" """
type_, error, traceback = sys.exc_info() type_, error = sys.exc_info()[:2]
data = { data = {
'error': str(error), 'error': str(error),
'exception': type_.__name__, 'exception': type_.__name__,

View File

@ -83,7 +83,7 @@ class CountersTest(TestCase):
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*']) @override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
def test_mptt_child_delete(self): def test_mptt_child_delete(self):
device1, device2 = Device.objects.all() device1 = Device.objects.first()
inventory_item1 = InventoryItem.objects.create(device=device1, name='Inventory Item 1') inventory_item1 = InventoryItem.objects.create(device=device1, name='Inventory Item 1')
InventoryItem.objects.create(device=device1, name='Inventory Item 2', parent=inventory_item1) InventoryItem.objects.create(device=device1, name='Inventory Item 2', parent=inventory_item1)
device1.refresh_from_db() device1.refresh_from_db()

View File

@ -80,5 +80,3 @@ class ClusterSerializer(NetBoxModelSerializer):
serializer = get_serializer_for_model(obj.scope) serializer = get_serializer_for_model(obj.scope)
context = {'request': self.context['request']} context = {'request': self.context['request']}
return serializer(obj.scope, nested=True, context=context).data return serializer(obj.scope, nested=True, context=context).data

View File

@ -48,7 +48,7 @@ class ClusterType(VLANGroupsMixin, NetBoxObjectType):
Annotated["SiteGroupType", strawberry.lazy('dcim.graphql.types')], Annotated["SiteGroupType", strawberry.lazy('dcim.graphql.types')],
Annotated["SiteType", strawberry.lazy('dcim.graphql.types')], Annotated["SiteType", strawberry.lazy('dcim.graphql.types')],
], strawberry.union("ClusterScopeType")] | None: ], strawberry.union("ClusterScopeType")] | None:
return self.scope return self.scope
@strawberry_django.type( @strawberry_django.type(

View File

@ -3,17 +3,17 @@ from django.db import migrations, models
def copy_site_assignments(apps, schema_editor): def copy_site_assignments(apps, schema_editor):
""" """
Copy site ForeignKey values to the scope GFK. Copy site ForeignKey values to the scope GFK.
""" """
ContentType = apps.get_model('contenttypes', 'ContentType') ContentType = apps.get_model('contenttypes', 'ContentType')
Cluster = apps.get_model('virtualization', 'Cluster') Cluster = apps.get_model('virtualization', 'Cluster')
Site = apps.get_model('dcim', 'Site') Site = apps.get_model('dcim', 'Site')
Cluster.objects.filter(site__isnull=False).update( Cluster.objects.filter(site__isnull=False).update(
scope_type=ContentType.objects.get_for_model(Site), scope_type=ContentType.objects.get_for_model(Site),
scope_id=models.F('site_id') scope_id=models.F('site_id')
) )
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -7,7 +7,7 @@ from ipam.models import VLAN
from netbox.choices import * from netbox.choices import *
from netbox.forms import NetBoxModelImportForm from netbox.forms import NetBoxModelImportForm
from tenancy.models import Tenant from tenancy.models import Tenant
from utilities.forms.fields import CSVChoiceField, CSVModelChoiceField, SlugField from utilities.forms.fields import CSVChoiceField, CSVModelChoiceField, SlugField
from wireless.choices import * from wireless.choices import *
from wireless.models import * from wireless.models import *

View File

@ -1,2 +1,4 @@
[lint] [lint]
extend-select = ["E1", "E2", "E3", "W"]
ignore = ["E501", "F403", "F405"] ignore = ["E501", "F403", "F405"]
preview = true