Merge pull request 'wireguard/test: move test to service directory' (#5507) from dave into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/5507
This commit is contained in:
@@ -92,7 +92,6 @@ in
|
|||||||
nixos-test-extra-python-packages = self.clanLib.test.containerTest ./test-extra-python-packages nixosTestArgs;
|
nixos-test-extra-python-packages = self.clanLib.test.containerTest ./test-extra-python-packages nixosTestArgs;
|
||||||
|
|
||||||
service-dummy-test = import ./service-dummy-test nixosTestArgs;
|
service-dummy-test = import ./service-dummy-test nixosTestArgs;
|
||||||
wireguard = import ./wireguard nixosTestArgs;
|
|
||||||
service-dummy-test-from-flake = import ./service-dummy-test-from-flake nixosTestArgs;
|
service-dummy-test-from-flake = import ./service-dummy-test-from-flake nixosTestArgs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,115 +0,0 @@
|
|||||||
{
|
|
||||||
pkgs,
|
|
||||||
nixosLib,
|
|
||||||
clan-core,
|
|
||||||
lib,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
nixosLib.runTest (
|
|
||||||
{ ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
machines = [
|
|
||||||
"controller1"
|
|
||||||
"controller2"
|
|
||||||
"peer1"
|
|
||||||
"peer2"
|
|
||||||
"peer3"
|
|
||||||
];
|
|
||||||
in
|
|
||||||
{
|
|
||||||
imports = [
|
|
||||||
clan-core.modules.nixosTest.clanTest
|
|
||||||
];
|
|
||||||
|
|
||||||
hostPkgs = pkgs;
|
|
||||||
|
|
||||||
name = "wireguard";
|
|
||||||
|
|
||||||
clan = {
|
|
||||||
directory = ./.;
|
|
||||||
modules."@clan/wireguard" = import ../../clanServices/wireguard/default.nix;
|
|
||||||
inventory = {
|
|
||||||
|
|
||||||
machines = lib.genAttrs machines (_: { });
|
|
||||||
|
|
||||||
instances = {
|
|
||||||
|
|
||||||
/*
|
|
||||||
wg-test-one
|
|
||||||
┌───────────────────────────────┐
|
|
||||||
│ ◄───────────── │
|
|
||||||
│ controller2 controller1
|
|
||||||
│ ▲ ─────────────► ▲ ▲
|
|
||||||
│ │ │ │ │ │ │ │ │
|
|
||||||
│ │ │ │ │ │ │ │ │
|
|
||||||
│ │ │ │ │ │ │ │ │
|
|
||||||
│ │ │ │ └───────────────┐ │ │ │ │
|
|
||||||
│ │ │ └──────────────┐ │ │ │ │ │
|
|
||||||
│ ▼ │ ▼ ▼ ▼
|
|
||||||
└─► peer2 │ peer1 peer3
|
|
||||||
│ ▲
|
|
||||||
└──────────┘
|
|
||||||
*/
|
|
||||||
|
|
||||||
wg-test-one = {
|
|
||||||
|
|
||||||
module.name = "@clan/wireguard";
|
|
||||||
module.input = "self";
|
|
||||||
|
|
||||||
roles.controller.machines."controller1".settings = {
|
|
||||||
endpoint = "192.168.1.1";
|
|
||||||
};
|
|
||||||
|
|
||||||
roles.controller.machines."controller2".settings = {
|
|
||||||
endpoint = "192.168.1.2";
|
|
||||||
};
|
|
||||||
|
|
||||||
roles.peer.machines = {
|
|
||||||
peer1.settings.controller = "controller1";
|
|
||||||
peer2.settings.controller = "controller2";
|
|
||||||
peer3.settings.controller = "controller1";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
# TODO: Will this actually work with conflicting ports? Can we re-use interfaces?
|
|
||||||
#wg-test-two = {
|
|
||||||
# module.name = "@clan/wireguard";
|
|
||||||
|
|
||||||
# roles.controller.machines."controller1".settings = {
|
|
||||||
# endpoint = "192.168.1.1";
|
|
||||||
# port = 51922;
|
|
||||||
# };
|
|
||||||
|
|
||||||
# roles.peer.machines = {
|
|
||||||
# peer1 = { };
|
|
||||||
# };
|
|
||||||
#};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
testScript = ''
|
|
||||||
start_all()
|
|
||||||
|
|
||||||
# Show all addresses
|
|
||||||
machines = [peer1, peer2, peer3, controller1, controller2]
|
|
||||||
for m in machines:
|
|
||||||
m.systemctl("start network-online.target")
|
|
||||||
|
|
||||||
for m in machines:
|
|
||||||
m.wait_for_unit("network-online.target")
|
|
||||||
m.wait_for_unit("systemd-networkd.service")
|
|
||||||
|
|
||||||
print("\n\n" + "="*60)
|
|
||||||
print("STARTING PING TESTS")
|
|
||||||
print("="*60)
|
|
||||||
|
|
||||||
for m1 in machines:
|
|
||||||
for m2 in machines:
|
|
||||||
if m1 != m2:
|
|
||||||
print(f"\n--- Pinging from {m1.name} to {m2.name}.wg-test-one ---")
|
|
||||||
m1.wait_until_succeeds(f"ping -c1 {m2.name}.wg-test-one >&2")
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@@ -4,4 +4,12 @@ let
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
clan.modules.wireguard = module;
|
clan.modules.wireguard = module;
|
||||||
|
perSystem =
|
||||||
|
{ ... }:
|
||||||
|
{
|
||||||
|
clan.nixosTests.service-wireguard = {
|
||||||
|
imports = [ ./tests/vm/default.nix ];
|
||||||
|
clan.modules."@clan/wireguard" = module;
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
102
clanServices/wireguard/tests/vm/default.nix
Normal file
102
clanServices/wireguard/tests/vm/default.nix
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
|
let
|
||||||
|
machines = [
|
||||||
|
"controller1"
|
||||||
|
"controller2"
|
||||||
|
"peer1"
|
||||||
|
"peer2"
|
||||||
|
"peer3"
|
||||||
|
];
|
||||||
|
in
|
||||||
|
{
|
||||||
|
name = "service-wireguard";
|
||||||
|
|
||||||
|
clan = {
|
||||||
|
directory = ./.;
|
||||||
|
inventory = {
|
||||||
|
|
||||||
|
machines = lib.genAttrs machines (_: { });
|
||||||
|
|
||||||
|
instances = {
|
||||||
|
|
||||||
|
/*
|
||||||
|
wg-test-one
|
||||||
|
┌───────────────────────────────┐
|
||||||
|
│ ◄───────────── │
|
||||||
|
│ controller2 controller1
|
||||||
|
│ ▲ ─────────────► ▲ ▲
|
||||||
|
│ │ │ │ │ │ │ │ │
|
||||||
|
│ │ │ │ │ │ │ │ │
|
||||||
|
│ │ │ │ │ │ │ │ │
|
||||||
|
│ │ │ │ └───────────────┐ │ │ │ │
|
||||||
|
│ │ │ └──────────────┐ │ │ │ │ │
|
||||||
|
│ ▼ │ ▼ ▼ ▼
|
||||||
|
└─► peer2 │ peer1 peer3
|
||||||
|
│ ▲
|
||||||
|
└──────────┘
|
||||||
|
*/
|
||||||
|
|
||||||
|
wg-test-one = {
|
||||||
|
|
||||||
|
module.name = "@clan/wireguard";
|
||||||
|
module.input = "self";
|
||||||
|
|
||||||
|
roles.controller.machines."controller1".settings = {
|
||||||
|
endpoint = "192.168.1.1";
|
||||||
|
};
|
||||||
|
|
||||||
|
roles.controller.machines."controller2".settings = {
|
||||||
|
endpoint = "192.168.1.2";
|
||||||
|
};
|
||||||
|
|
||||||
|
roles.peer.machines = {
|
||||||
|
peer1.settings.controller = "controller1";
|
||||||
|
peer2.settings.controller = "controller2";
|
||||||
|
peer3.settings.controller = "controller1";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# TODO: Will this actually work with conflicting ports? Can we re-use interfaces?
|
||||||
|
#wg-test-two = {
|
||||||
|
# module.name = "@clan/wireguard";
|
||||||
|
|
||||||
|
# roles.controller.machines."controller1".settings = {
|
||||||
|
# endpoint = "192.168.1.1";
|
||||||
|
# port = 51922;
|
||||||
|
# };
|
||||||
|
|
||||||
|
# roles.peer.machines = {
|
||||||
|
# peer1 = { };
|
||||||
|
# };
|
||||||
|
#};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
testScript = ''
|
||||||
|
start_all()
|
||||||
|
|
||||||
|
# Show all addresses
|
||||||
|
machines = [peer1, peer2, peer3, controller1, controller2]
|
||||||
|
for m in machines:
|
||||||
|
m.systemctl("start network-online.target")
|
||||||
|
|
||||||
|
for m in machines:
|
||||||
|
m.wait_for_unit("network-online.target")
|
||||||
|
m.wait_for_unit("systemd-networkd.service")
|
||||||
|
|
||||||
|
print("\n\n" + "="*60)
|
||||||
|
print("STARTING PING TESTS")
|
||||||
|
print("="*60)
|
||||||
|
|
||||||
|
for m1 in machines:
|
||||||
|
for m2 in machines:
|
||||||
|
if m1 != m2:
|
||||||
|
print(f"\n--- Pinging from {m1.name} to {m2.name}.wg-test-one ---")
|
||||||
|
m1.wait_until_succeeds(f"ping -c1 {m2.name}.wg-test-one >&2")
|
||||||
|
'';
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user