Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ venv*

machines/*
wanda.yml
generated_vars/*
generated_vars/*
result
130 changes: 8 additions & 122 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 17 additions & 27 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,19 @@
description = "wanda - WAN Data Aggregator";

inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
inputs.poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";

outputs = { self, nixpkgs, flake-utils, poetry2nix }:
outputs = { self, nixpkgs, flake-utils }:
{
# Nixpkgs overlay providing the application
overlay = nixpkgs.lib.composeManyExtensions [
poetry2nix.overlays.default
(final: prev: {
# The application
wanda = prev.poetry2nix.mkPoetryApplication {
projectDir = with final.lib; cleanSourceWith {
src = ./.;
filter = path: type: !(hasSuffix ".nix" path) && baseNameOf path != ".nix";
};
};

# Used to run tests for wanda
wandaTestEnv = prev.poetry2nix.mkPoetryEnv {
projectDir = ./.;
};

wandaNixosTest = final.nixosTest (import ./nixos-test.nix);
})
];
overlay = (final: prev: let
pyprojectFile = builtins.fromTOML (builtins.readFile ./pyproject.toml);
# We absolutly want to ship our own deps, so we use our own python and our own python3Packages.
pkgs = nixpkgs.legacyPackages.${final.stdenv.hostPlatform.system};
in rec {
wanda = pkgs.python3.pkgs.callPackage ./package.nix { wanda-version = pyprojectFile.tool.poetry.version; };
wandaTest = final.callPackage ./nixos-test.nix { };
});
} // (flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
Expand All @@ -39,13 +24,18 @@
in
{
packages = {
inherit (pkgs) wanda wandaNixosTest;
inherit (pkgs) wanda wandaTest;
default = pkgs.wanda;
};

checks = {
inherit (pkgs) wandaTest;
};

devShell = pkgs.mkShell {
buildInputs = with pkgs; [
wanda.dependencyEnv
bgpq4
wanda.pythonEnv
];
};
}));
Expand Down
21 changes: 10 additions & 11 deletions nixos-test.nix
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
{ lib, pkgs, ... }: {
name = "peering-manager";
{ lib, testers, wanda }:

meta = with lib.maintainers; {
maintainers = [ yuka ];
};
testers.nixosTest {
name = "wanda";

nodes.machine = { ... }: {
nodes.machine = { pkgs, ... }: {
services.peering-manager = {
enable = true;
secretKeyFile = pkgs.writeText "secret" ''
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
'';
};
environment.systemPackages = with pkgs; [ wanda wandaTestEnv ];
environment.systemPackages = [ wanda wanda.pythonEnv ];
environment.etc."wanda-src".source = wanda.src;
};

testScript = { nodes }: let
peeringmanagerUrl = "http://localhost:${toString nodes.machine.config.services.peering-manager.port}";
peeringmanagerUrl = "http://localhost:${toString nodes.machine.services.peering-manager.port}";
in ''
machine.start()
machine.wait_for_unit("peering-manager.target")
machine.wait_until_succeeds("journalctl --since -1m --unit peering-manager --grep Listening")

machine.succeed("peering-manager-manage createsuperuser --no-input --username admin --email admin@example.com")

api_token=machine.succeed(
"peering-manager-manage shell -c \"from users.models import Token; from users.models import User; u=User.objects.get(email='admin@example.com'); t = Token.objects.create(user=u); print(t.key)\""
api_token = machine.succeed(
"peering-manager-manage shell -c \"from users.models import Token; from users.models import User; u=User.objects.get(email='admin@example.com'); t = Token.objects.create(user=u); print(t.key)\" | grep --only-matching \"[0-9a-f]*$\""
).strip()

machine.succeed("PEERINGMANAGER_API_TOKEN=%s PEERINGMANAGER_URL=${peeringmanagerUrl} pytest ${pkgs.wanda.src}" % (api_token))
machine.succeed("PEERINGMANAGER_API_TOKEN=%s PEERINGMANAGER_URL=${peeringmanagerUrl} pytest -m integration /etc/wanda-src" % (api_token))
machine.shutdown()
'';
}
50 changes: 50 additions & 0 deletions package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{ lib,
python,
buildPythonApplication,
poetry-core,
requests,
pyyaml,
enlighten,
pytestCheckHook,
pytest,
pytest-mock,
wanda-version,
}:

buildPythonApplication rec {
version = wanda-version;

pname = "wanda";
pyproject = true;

src = with lib; cleanSourceWith {
src = ./.;
filter = path: type: !(hasSuffix ".nix" path);
};

build-system = [
poetry-core
];

dependencies = [
requests
pyyaml
enlighten
];

nativeCheckInputs = [
pytestCheckHook
pytest-mock
];

pytestFlagsArray = [ "-m" "unit" ];

optional-dependencies = [
pytest
pytest-mock
];

passthru = {
pythonEnv = python.withPackages (_: (dependencies ++ optional-dependencies));
};
}
Loading