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
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,31 @@ jobs:
name: wobcom-public
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix build --log-format bar-with-logs -v
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Install project
run: poetry install --no-interaction
- name: Run tests
run: |
source .venv/bin/activate
pytest -m unit
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__pycache__

venv*

.pytest_cache
.idea
8 changes: 4 additions & 4 deletions flake.lock

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

16 changes: 13 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "wanda - WAN Data Aggregator";

inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/22.11";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/release-22.11";
inputs.poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
Expand All @@ -16,8 +16,18 @@
(final: prev: {
# The application
wanda = prev.poetry2nix.mkPoetryApplication {
projectDir = ./.;
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);
})
];
} // (flake-utils.lib.eachDefaultSystem (system:
Expand All @@ -29,7 +39,7 @@
in
{
packages = {
wanda = pkgs.wanda;
inherit (pkgs) wanda wandaNixosTest;
default = pkgs.wanda;
};

Expand Down
34 changes: 34 additions & 0 deletions nixos-test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{ lib, pkgs, ... }: {
name = "peering-manager";

meta = with lib.maintainers; {
maintainers = [ yuka ];
};

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

testScript = { nodes }: let
peeringmanagerUrl = "http://localhost:${toString nodes.machine.config.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)\""
).strip()

machine.succeed("PEERINGMANAGER_API_TOKEN=%s PEERINGMANAGER_URL=${peeringmanagerUrl} pytest ${pkgs.wanda.src}" % (api_token))
machine.shutdown()
'';
}
141 changes: 140 additions & 1 deletion poetry.lock

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

7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ requests = "~2.26.0"
PyYAML = ">5.1"

[tool.poetry.dev-dependencies]
pytest = "^7.2.0"

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

[tool.pytest.ini_options]
markers = [
"integration",
"unit",
]
2 changes: 1 addition & 1 deletion wanda/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from wanda.irrd_client import IRRDClient
from wanda.peeringmanager_client import PeeringManagerClient

from .logger import Logger
from wanda.logger import Logger

l = Logger("main.py")

Expand Down
Empty file added wanda/as_filter/__init__.py
Empty file.
Loading