Skip to content

Fixes #19134: Interfaces TX power allows negative value #19226

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion netbox/dcim/forms/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ class InterfaceFilterForm(PathEndpointFilterForm, DeviceComponentFilterForm):
tx_power = forms.IntegerField(
required=False,
label=_('Transmit power (dBm)'),
min_value=0,
min_value=-127,
max_value=127
)
vrf_id = DynamicModelMultipleChoiceField(
Expand Down
21 changes: 21 additions & 0 deletions netbox/dcim/migrations/0201_alter_interface_tx_power.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.1.8 on 2025-04-17 03:36

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


class Migration(migrations.Migration):

dependencies = [
('dcim', '0200_populate_mac_addresses'),
]

operations = [
migrations.AlterField(
model_name='interface',
name='tx_power',
field=models.SmallIntegerField(blank=True, null=True, validators=[
django.core.validators.MinValueValidator(-127), django.core.validators.MaxValueValidator(127)
]),
),
]
7 changes: 5 additions & 2 deletions netbox/dcim/models/device_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,10 +710,13 @@ class Interface(ModularComponentModel, BaseInterface, CabledObjectModel, PathEnd
verbose_name=('channel width (MHz)'),
help_text=_("Populated by selected channel (if set)")
)
tx_power = models.PositiveSmallIntegerField(
tx_power = models.SmallIntegerField(
blank=True,
null=True,
validators=(MaxValueValidator(127),),
validators=[
MinValueValidator(-127),
MaxValueValidator(127)
],
verbose_name=_('transmit power (dBm)')
)
poe_mode = models.CharField(
Expand Down
2 changes: 1 addition & 1 deletion netbox/dcim/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@ def setUpTestData(cls):
'name': 'Interface 8',
'type': InterfaceTypeChoices.TYPE_80211A,
'mode': InterfaceModeChoices.MODE_Q_IN_Q,
'tx_power': 10,
'tx_power': -10,
'wireless_lans': [wireless_lans[0].pk, wireless_lans[1].pk],
'rf_channel': "",
'qinq_svlan': vlans[3].pk,
Expand Down
7 changes: 5 additions & 2 deletions netbox/dcim/tests/test_filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4072,7 +4072,7 @@ def setUpTestData(cls):
type=InterfaceTypeChoices.TYPE_OTHER,
enabled=False,
mgmt_only=False,
tx_power=40,
tx_power=-40,
mode=InterfaceModeChoices.MODE_Q_IN_Q,
qinq_svlan=vlans[2]
),
Expand Down Expand Up @@ -4340,7 +4340,10 @@ def test_rf_channel_width(self):

def test_tx_power(self):
params = {'tx_power': [40]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)

params = {'tx_power': [-40]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)

def test_vrf(self):
vrfs = VRF.objects.all()[:2]
Expand Down
2 changes: 1 addition & 1 deletion netbox/dcim/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2660,7 +2660,7 @@ def setUpTestData(cls):
'poe_mode': InterfacePoEModeChoices.MODE_PD,
'poe_type': InterfacePoETypeChoices.TYPE_2_8023AT,
'mode': InterfaceModeChoices.MODE_TAGGED,
'tx_power': 10,
'tx_power': -10,
'untagged_vlan': vlans[0].pk,
'tagged_vlans': [v.pk for v in vlans[1:4]],
'vrf': vrfs[1].pk,
Expand Down