Skip to content

Commit

Permalink
netbox: 3.7.8 -> 4.1.3 (#331750)
Browse files Browse the repository at this point in the history
  • Loading branch information
minijackson authored Oct 25, 2024
2 parents 31eafae + 5bf6575 commit 0433962
Show file tree
Hide file tree
Showing 20 changed files with 617 additions and 63 deletions.
8 changes: 8 additions & 0 deletions nixos/doc/manual/release-notes/rl-2411.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@
- The method to safely handle secrets in the `networking.wireless` module has been changed to benefit from a [new feature](https://w1.fi/cgit/hostap/commit/?id=e680a51e94a33591f61edb210926bcb71217a21a) of wpa_supplicant.
The syntax to refer to secrets has changed slightly and the option `networking.wireless.environmentFile` has been replaced by `networking.wireless.secretsFile`; see the description of the latter for how to upgrade.

- NetBox was updated to `>= 4.1.0`.
Have a look at the breaking changes
of the [4.0 release](https://github.com/netbox-community/netbox/releases/tag/v4.0.0)
and the [4.1 release](https://github.com/netbox-community/netbox/releases/tag/v4.1.0),
make the required changes to your database, if needed,
then upgrade by setting `services.netbox.package = pkgs.netbox_4_1;`
in your configuration.

- `services.cgit` now runs as the cgit user by default instead of root.
This change requires granting access to the repositories to this user or
setting the appropriate one through `services.cgit.some-instance.user`.
Expand Down
21 changes: 9 additions & 12 deletions nixos/modules/services/web-apps/netbox.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,17 @@ in {
package = lib.mkOption {
type = lib.types.package;
default =
if lib.versionAtLeast config.system.stateVersion "24.05"
if lib.versionAtLeast config.system.stateVersion "24.11"
then pkgs.netbox_4_1
else if lib.versionAtLeast config.system.stateVersion "24.05"
then pkgs.netbox_3_7
else if lib.versionAtLeast config.system.stateVersion "23.11"
then pkgs.netbox_3_6
else if lib.versionAtLeast config.system.stateVersion "23.05"
then pkgs.netbox_3_5
else pkgs.netbox_3_3;
else pkgs.netbox_3_6;
defaultText = lib.literalExpression ''
if lib.versionAtLeast config.system.stateVersion "24.05"
if lib.versionAtLeast config.system.stateVersion "24.11"
then pkgs.netbox_4_1
else if lib.versionAtLeast config.system.stateVersion "24.05"
then pkgs.netbox_3_7
else if lib.versionAtLeast config.system.stateVersion "23.11"
then pkgs.netbox_3_6
else if lib.versionAtLeast config.system.stateVersion "23.05"
then pkgs.netbox_3_5
else pkgs.netbox_3_3;
else pkgs.netbox_3_6;
'';
description = ''
NetBox package to use.
Expand Down Expand Up @@ -328,6 +324,7 @@ in {
--pythonpath ${pkg}/opt/netbox/netbox
'';
PrivateTmp = true;
TimeoutStartSec = lib.mkDefault "5min";
};
};

Expand Down
2 changes: 2 additions & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,8 @@ in {
networking.networkmanager = handleTest ./networking/networkmanager.nix {};
netbox_3_6 = handleTest ./web-apps/netbox.nix { netbox = pkgs.netbox_3_6; };
netbox_3_7 = handleTest ./web-apps/netbox.nix { netbox = pkgs.netbox_3_7; };
netbox_4_0 = handleTest ./web-apps/netbox.nix { netbox = pkgs.netbox_4_0; };
netbox_4_1 = handleTest ./web-apps/netbox.nix { netbox = pkgs.netbox_4_1; };
netbox-upgrade = handleTest ./web-apps/netbox-upgrade.nix {};
# TODO: put in networking.nix after the test becomes more complete
networkingProxy = handleTest ./networking-proxy.nix {};
Expand Down
8 changes: 5 additions & 3 deletions nixos/tests/web-apps/netbox-upgrade.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ../make-test-python.nix ({ lib, pkgs, ... }: let
oldNetbox = pkgs.netbox_3_6;
newNetbox = pkgs.netbox_3_7;
oldNetbox = pkgs.netbox_3_7;
newNetbox = pkgs.netbox_4_1;
in {
name = "netbox-upgrade";

Expand Down Expand Up @@ -58,8 +58,10 @@ in {
return header.split()[1]
def check_api_version(version):
# Returns 403 with NetBox >= 4.0,
# but we still get the API version in the headers
headers = machine.succeed(
"curl -sSfL http://localhost/api/ --head -H 'Content-Type: application/json'"
"curl -sSL http://localhost/api/ --head -H 'Content-Type: application/json'"
)
assert api_version(headers) == version
Expand Down
7 changes: 1 addition & 6 deletions nixos/tests/web-apps/netbox.nix
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ in import ../make-test-python.nix ({ lib, pkgs, netbox, ... }: {

testScript = let
changePassword = pkgs.writeText "change-password.py" ''
from django.contrib.auth.models import User
from users.models import User
u = User.objects.get(username='netbox')
u.set_password('netbox')
u.save()
Expand Down Expand Up @@ -171,11 +171,6 @@ in import ../make-test-python.nix ({ lib, pkgs, netbox, ... }: {
machine.succeed("curl -sSfL http://localhost/static/netbox.js")
machine.succeed("curl -sSfL http://localhost/static/docs/")
with subtest("Can interact with API"):
json.loads(
machine.succeed("curl -sSfL -H 'Accept: application/json' 'http://localhost/api/'")
)
def login(username: str, password: str):
encoded_data = json.dumps({"username": username, "password": password})
uri = "/users/tokens/provision/"
Expand Down
13 changes: 13 additions & 0 deletions pkgs/by-name/ne/netbox_4_0/custom-static-root.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py
index 2de06dd10..00406af48 100644
--- a/netbox/netbox/settings.py
+++ b/netbox/netbox/settings.py
@@ -410,7 +412,7 @@ USE_X_FORWARDED_HOST = True
X_FRAME_OPTIONS = 'SAMEORIGIN'

# Static files (CSS, JavaScript, Images)
-STATIC_ROOT = BASE_DIR + '/static'
+STATIC_ROOT = getattr(configuration, 'STATIC_ROOT', os.path.join(BASE_DIR, 'static')).rstrip('/')
STATIC_URL = f'/{BASE_PATH}static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'project-static', 'dist'),
81 changes: 81 additions & 0 deletions pkgs/by-name/ne/netbox_4_0/django-5.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
diff --git a/netbox/extras/forms/bulk_import.py b/netbox/extras/forms/bulk_import.py
index f2cf0b721..a17b6712d 100644
--- a/netbox/extras/forms/bulk_import.py
+++ b/netbox/extras/forms/bulk_import.py
@@ -194,7 +194,7 @@ class Meta:
model = EventRule
fields = (
'name', 'description', 'enabled', 'conditions', 'object_types', 'type_create', 'type_update',
- 'type_delete', 'type_job_start', 'type_job_end', 'action_type', 'action_object', 'comments', 'tags'
+ 'type_delete', 'type_job_start', 'type_job_end', 'action_type', 'comments', 'tags'
)

def clean(self):
diff --git a/netbox/extras/migrations/0002_squashed_0059.py b/netbox/extras/migrations/0002_squashed_0059.py
index 98bed255a..a403a0e19 100644
--- a/netbox/extras/migrations/0002_squashed_0059.py
+++ b/netbox/extras/migrations/0002_squashed_0059.py
@@ -131,10 +131,6 @@ class Migration(migrations.Migration):
name='webhook',
unique_together={('payload_url', 'type_create', 'type_update', 'type_delete')},
),
- migrations.AlterIndexTogether(
- name='taggeditem',
- index_together={('content_type', 'object_id')},
- ),
migrations.AlterUniqueTogether(
name='exporttemplate',
unique_together={('content_type', 'name')},
diff --git a/netbox/extras/migrations/0087_squashed_0098.py b/netbox/extras/migrations/0087_squashed_0098.py
index 55f276ecd..bbe7f79f5 100644
--- a/netbox/extras/migrations/0087_squashed_0098.py
+++ b/netbox/extras/migrations/0087_squashed_0098.py
@@ -98,10 +98,9 @@ class Migration(migrations.Migration):
name='object_types',
field=models.ManyToManyField(blank=True, related_name='+', to='contenttypes.contenttype'),
),
- migrations.RenameIndex(
+ migrations.AddIndex(
model_name='taggeditem',
- new_name='extras_tagg_content_717743_idx',
- old_fields=('content_type', 'object_id'),
+ index=models.Index(fields=['content_type', 'object_id'], name='extras_tagg_content_717743_idx'),
),
migrations.CreateModel(
name='Bookmark',
diff --git a/netbox/ipam/forms/model_forms.py b/netbox/ipam/forms/model_forms.py
index f5e3bca30..4f96bac71 100644
--- a/netbox/ipam/forms/model_forms.py
+++ b/netbox/ipam/forms/model_forms.py
@@ -588,7 +588,7 @@ class VLANGroupForm(NetBoxModelForm):
class Meta:
model = VLANGroup
fields = [
- 'name', 'slug', 'description', 'min_vid', 'max_vid', 'scope_type', 'scope', 'tags',
+ 'name', 'slug', 'description', 'min_vid', 'max_vid', 'scope_type', 'tags',
]

def __init__(self, *args, **kwargs):
diff --git a/netbox/vpn/forms/model_forms.py b/netbox/vpn/forms/model_forms.py
index a17ca9a5e..dee98afd3 100644
--- a/netbox/vpn/forms/model_forms.py
+++ b/netbox/vpn/forms/model_forms.py
@@ -258,7 +258,7 @@ class TunnelTerminationForm(NetBoxModelForm):
class Meta:
model = TunnelTermination
fields = [
- 'tunnel', 'role', 'termination', 'outside_ip', 'tags',
+ 'tunnel', 'role', 'outside_ip', 'tags',
]

def __init__(self, *args, initial=None, **kwargs):
diff --git a/requirements.txt b/requirements.txt
index 09f23871c..57f167dae 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,4 @@
-Django==5.0.9
+Django==5.1.2
django-cors-headers==4.4.0
django-debug-toolbar==4.4.6
django-filter==24.2
132 changes: 132 additions & 0 deletions pkgs/by-name/ne/netbox_4_0/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
lib,
fetchFromGitHub,
python3,
plugins ? _ps: [ ],
nixosTests,
}:
let
py = python3.override {
packageOverrides = _final: prev: { django = prev.django_5; };
};

extraBuildInputs = plugins py.pkgs;
in
py.pkgs.buildPythonApplication rec {
pname = "netbox";
version = "4.0.11";

format = "other";

src = fetchFromGitHub {
owner = "netbox-community";
repo = "netbox";
rev = "refs/tags/v${version}";
hash = "sha256-0yEz7v5RL1+cqbGDyuyEsywFonJQfPdVIQdL0qLyc04=";
};

patches = [
./custom-static-root.patch
# From https://github.com/netbox-community/netbox/pull/17620
./django-5.1.patch
];

propagatedBuildInputs =
(
with py.pkgs;
[
django
django-cors-headers
django-debug-toolbar
django-filter
django-graphiql-debug-toolbar
django-htmx
django-mptt
django-pglocks
django-prometheus
django-redis
django-rq
django-tables2
django-taggit
django-timezone-field
djangorestframework
drf-spectacular
drf-spectacular-sidecar
feedparser
jinja2
markdown
netaddr
nh3
pillow
psycopg
psycopg.optional-dependencies.c
psycopg.optional-dependencies.pool
pyyaml
requests
social-auth-core
social-auth-app-django
strawberry-graphql
strawberry-django
svgwrite
tablib

# Optional dependencies, kept here for backward compatibility

# for the S3 data source backend
boto3
# for Git data source backend
dulwich
# for error reporting
sentry-sdk
]
++ social-auth-core.passthru.optional-dependencies.openidconnect
)
++ extraBuildInputs;

buildInputs = with py.pkgs; [
mkdocs-material
mkdocs-material-extensions
mkdocstrings
mkdocstrings-python
];

nativeBuildInputs = [ py.pkgs.mkdocs ];

postBuild = ''
PYTHONPATH=$PYTHONPATH:netbox/
python -m mkdocs build
'';

installPhase = ''
mkdir -p $out/opt/netbox
cp -r . $out/opt/netbox
chmod +x $out/opt/netbox/netbox/manage.py
makeWrapper $out/opt/netbox/netbox/manage.py $out/bin/netbox \
--prefix PYTHONPATH : "$PYTHONPATH"
'';

passthru = {
python = python3;
# PYTHONPATH of all dependencies used by the package
pythonPath = py.pkgs.makePythonPath propagatedBuildInputs;
inherit (py.pkgs) gunicorn;
tests = {
netbox = nixosTests.netbox_4_0;
};
};

meta = {
homepage = "https://github.com/netbox-community/netbox";
description = "IP address management (IPAM) and data center infrastructure management (DCIM) tool";
mainProgram = "netbox";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [
minijackson
n0emis
raitobezarius
];
knownVulnerabilities = [
"Netbox version ${version} is EOL; please upgrade by following the current release notes instructions."
];
};
}
13 changes: 13 additions & 0 deletions pkgs/by-name/ne/netbox_4_1/custom-static-root.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py
index 2de06dd10..00406af48 100644
--- a/netbox/netbox/settings.py
+++ b/netbox/netbox/settings.py
@@ -410,7 +412,7 @@ USE_X_FORWARDED_HOST = True
X_FRAME_OPTIONS = 'SAMEORIGIN'

# Static files (CSS, JavaScript, Images)
-STATIC_ROOT = BASE_DIR + '/static'
+STATIC_ROOT = getattr(configuration, 'STATIC_ROOT', os.path.join(BASE_DIR, 'static')).rstrip('/')
STATIC_URL = f'/{BASE_PATH}static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'project-static', 'dist'),
Loading

0 comments on commit 0433962

Please sign in to comment.