Skip to content

Commit

Permalink
Support 202409 (#106)
Browse files Browse the repository at this point in the history
* Support 202409

- IX media type field deprecated peeringdb/#1555
- Add location of Physical IX-Port & Router Port peeringdb/#607

---------

Co-authored-by: 20C <[email protected]>
  • Loading branch information
vegu and 20c-ed authored Oct 18, 2024
1 parent 5ffb835 commit dc89d80
Show file tree
Hide file tree
Showing 17 changed files with 855 additions and 596 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
uses: 20c/workflows/poetry@v1
- name: Run linters
run: |
poetry run isort src/
poetry run black --check src/
poetry run pre-commit run --all-files
test:
Expand Down
25 changes: 2 additions & 23 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,14 @@ repos:
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
args: ["--select", "I", "--fix"]
# Run the formatter.
- id: ruff-format
- repo: local
hooks:
- id: system
name: isort
entry: poetry run isort .
language: system
pass_filenames: false
- repo: local
hooks:
- id: pyupgrade
name: pyupgrade
entry: poetry run pyupgrade --py38-plus
language: python
types: [python]
pass_filenames: true
- repo: local
hooks:
- id: system
name: Black
entry: poetry run black .
language: system
pass_filenames: false
- repo: local
hooks:
- id: system
name: flake8
entry: poetry run flake8 .
language: system
pass_filenames: false
pass_filenames: true
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
### Added
- help text for info_traffic
- ORM configuration options exposed
- NetworkIXLan.ix_side field added
- NetworkIXLan.net_side field added
### Fixed
- missing migrations
- facility voltage value migration to fix peeringdb-py#86 on old databases
### Changed
- Facility.property label for Lessee changed to "Leased or Rented"
- Facility.property help text clarified
- social media service `twitter` renamed to `x`
### Deprecated
- InternetExchange.media field has been deprecated and will default to `Ethernet` until it will be removed in v3 of the PeeringDB API.


## 3.4.0
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ Unreleased:
added:
- help text for info_traffic
- ORM configuration options exposed
- NetworkIXLan.ix_side field added
- NetworkIXLan.net_side field added
fixed:
- missing migrations
- facility voltage value migration to fix peeringdb-py#86 on old databases
changed:
- Facility.property label for Lessee changed to "Leased or Rented"
- Facility.property help text clarified
- social media service `twitter` renamed to `x`
deprecated: []
deprecated:
- InternetExchange.media field has been deprecated and will default to `Ethernet` until it will be removed in v3 of the PeeringDB API.
removed: []
security: []
3.4.0:
Expand Down
1,252 changes: 695 additions & 557 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Internet",
]
Expand Down Expand Up @@ -63,11 +64,11 @@ twine = ">=3.3"
[tool.poetry.plugins."markdown.extensions"]
pymdgen = "pymdgen.md:Extension"


[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.isort]
profile = "black"
multi_line_output = 3

1 change: 0 additions & 1 deletion src/django_peeringdb/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class MultipleChoiceField(models.CharField):

"""
Field that can take a set of string values
and store them in a charfield using a delimiter
Expand Down
61 changes: 61 additions & 0 deletions src/django_peeringdb/migrations/0034_fix_voltage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Generated by Django 4.2.7 on 2024-08-07 19:37

from django.db import migrations


def _from_db_value(value, expression, connection):
# for bypass clean_choices validation
if value is None:
return None
if not value or value == "[]":
return []
return value.split(",")


def forward(apps, schema_editor):
Facility = apps.get_model("django_peeringdb", "Facility")
updated_field = Facility._meta.get_field("updated")
updated_field_auto_now = updated_field.auto_now
from_db_value = Facility._meta.get_field("available_voltage_services").from_db_value
invalid_voltage_values = ["120 VAC", "208 VAC", "240 VAC"]

try:
# overide from_db_value method
# because this method calls "clean_choices" resulting in a validation error when retrieving all facilites.
Facility._meta.get_field(
"available_voltage_services"
).from_db_value = _from_db_value
facilities = Facility.handleref.all()
for facility in facilities:
voltage = facility.available_voltage_services
removed = []

for invalid_voltage_value in invalid_voltage_values:
try:
voltage.remove(invalid_voltage_value)
removed.append(invalid_voltage_value)
except ValueError:
pass

if removed:
facility.available_voltage_services = voltage
print(f"Removed {removed} from {facility}")
facility.save()
finally:
Facility._meta.get_field(
"available_voltage_services"
).from_db_value = from_db_value
updated_field.auto_now = updated_field_auto_now


class Migration(migrations.Migration):
dependencies = [
(
"django_peeringdb",
"0033_alter_facility_property_alter_ixlan_rs_asn_and_more",
),
]

operations = [
migrations.RunPython(forward, migrations.RunPython.noop),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.16 on 2024-09-29 14:10

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("django_peeringdb", "0034_fix_voltage"),
]

operations = [
migrations.AlterField(
model_name="internetexchange",
name="media",
field=models.CharField(
choices=[
("Ethernet", "Ethernet"),
("ATM", "ATM"),
("Multiple", "Multiple"),
],
default="Ethernet",
max_length=128,
verbose_name="Media Type",
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 4.2.16 on 2024-09-19 12:23

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("django_peeringdb", "0035_alter_ix_media_field_add_default_value"),
]

operations = [
migrations.AddField(
model_name="networkixlan",
name="net_side",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="net_side_set",
to="django_peeringdb.facility",
),
),
migrations.AddField(
model_name="networkixlan",
name="ix_side",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="ix_side_set",
to="django_peeringdb.facility",
),
),
]
4 changes: 3 additions & 1 deletion src/django_peeringdb/models/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ class InternetExchangeBase(HandleRefModel):
region_continent = models.CharField(
_("Continental Region"), max_length=255, choices=const.REGIONS
)
media = models.CharField(_("Media Type"), max_length=128, choices=const.MEDIA)
media = models.CharField(
_("Media Type"), max_length=128, choices=const.MEDIA, default="Ethernet"
)
proto_unicast = models.BooleanField(_("Unicast IPv4"), default=False)
proto_multicast = models.BooleanField(_("Multicast"), default=False)
proto_ipv6 = models.BooleanField(_("Unicast IPv6"), default=False)
Expand Down
15 changes: 15 additions & 0 deletions src/django_peeringdb/models/concrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,21 @@ class NetworkIXLan(NetworkIXLanBase):
on_delete=models.CASCADE,
)

net_side = models.ForeignKey(
Facility,
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="net_side_set",
)
ix_side = models.ForeignKey(
Facility,
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="ix_side_set",
)

def __str__(self):
return f"{self.net} @ {self.ixlan}"

Expand Down
1 change: 0 additions & 1 deletion tests/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import models

from django_peeringdb.models import LG_URLField, MultipleChoiceField, URLField


Expand Down
5 changes: 2 additions & 3 deletions tests/test_client_adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
from decimal import Decimal

import django.core.exceptions
import django_peeringdb.models as models
import pytest
from django.db import IntegrityError
from django.db.transaction import atomic as atomic_transaction

import django_peeringdb.models as models
from django_peeringdb.client_adaptor.load import database_settings

# import order is important here, linters will complain
# about the backend import not being on top of the file
# TODO: find better way to handle this
import tests.peeringdb_mock # noqa
from django_peeringdb.client_adaptor.load import database_settings

sys.modules["peeringdb"] = sys.modules["tests.peeringdb_mock"] # noqa
from django_peeringdb.client_adaptor.backend import Backend # noqa
Expand Down
1 change: 0 additions & 1 deletion tests/test_concrete_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from django_peeringdb.models import Carrier, CarrierFacility, Facility, Organization


Expand Down
3 changes: 1 addition & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.test import TestCase

import django_peeringdb.models
from django.test import TestCase


class CoreTests(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest
from django.core.exceptions import ValidationError
from django.test import TestCase

from django_peeringdb.models import LG_URLField, URLField

from tests.models import FieldModel, LG_FieldModel


Expand Down

0 comments on commit dc89d80

Please sign in to comment.