2020-10-11 20:45:25 +02:00
|
|
|
{ system ? builtins.currentSystem
|
|
|
|
, config ? {}
|
|
|
|
, pkgs ? import ../.. { inherit system config; }
|
|
|
|
# bool: whether to use networkd in the tests
|
2020-10-20 17:33:45 +02:00
|
|
|
, networkd ? false
|
|
|
|
} @ args:
|
2020-10-11 20:45:25 +02:00
|
|
|
|
2014-04-14 14:02:44 +02:00
|
|
|
# Test whether `avahi-daemon' and `libnss-mdns' work as expected.
|
2020-10-20 17:33:45 +02:00
|
|
|
import ./make-test-python.nix {
|
2014-06-28 16:04:49 +02:00
|
|
|
name = "avahi";
|
2021-01-10 20:08:30 +01:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
2019-02-22 16:14:13 +01:00
|
|
|
maintainers = [ eelco ];
|
2015-07-12 12:09:40 +02:00
|
|
|
};
|
2010-10-07 18:58:07 +02:00
|
|
|
|
2016-02-28 16:03:47 +01:00
|
|
|
nodes = let
|
2018-07-20 22:56:59 +02:00
|
|
|
cfg = { ... }: {
|
2016-02-28 16:03:47 +01:00
|
|
|
services.avahi = {
|
|
|
|
enable = true;
|
2023-12-11 08:33:11 +01:00
|
|
|
nssmdns4 = true;
|
2016-02-28 16:03:47 +01:00
|
|
|
publish.addresses = true;
|
|
|
|
publish.domain = true;
|
|
|
|
publish.enable = true;
|
|
|
|
publish.userServices = true;
|
|
|
|
publish.workstation = true;
|
2019-06-04 00:21:51 +02:00
|
|
|
extraServiceFiles.ssh = "${pkgs.avahi}/etc/avahi/services/ssh.service";
|
2010-10-07 18:58:07 +02:00
|
|
|
};
|
2020-10-11 20:45:25 +02:00
|
|
|
} // pkgs.lib.optionalAttrs (networkd) {
|
|
|
|
networking = {
|
|
|
|
useNetworkd = true;
|
|
|
|
useDHCP = false;
|
|
|
|
};
|
2016-02-28 16:03:47 +01:00
|
|
|
};
|
|
|
|
in {
|
|
|
|
one = cfg;
|
|
|
|
two = cfg;
|
2010-10-07 18:58:07 +02:00
|
|
|
};
|
|
|
|
|
2019-11-05 12:20:20 +01:00
|
|
|
testScript = ''
|
|
|
|
start_all()
|
2010-10-07 18:58:07 +02:00
|
|
|
|
2019-11-05 12:20:20 +01:00
|
|
|
# mDNS.
|
|
|
|
one.wait_for_unit("network.target")
|
|
|
|
two.wait_for_unit("network.target")
|
2014-04-08 18:43:58 +02:00
|
|
|
|
2019-11-05 12:20:20 +01:00
|
|
|
one.succeed("avahi-resolve-host-name one.local | tee out >&2")
|
|
|
|
one.succeed('test "`cut -f1 < out`" = one.local')
|
|
|
|
one.succeed("avahi-resolve-host-name two.local | tee out >&2")
|
|
|
|
one.succeed('test "`cut -f1 < out`" = two.local')
|
2012-10-24 18:22:53 +02:00
|
|
|
|
2019-11-05 12:20:20 +01:00
|
|
|
two.succeed("avahi-resolve-host-name one.local | tee out >&2")
|
|
|
|
two.succeed('test "`cut -f1 < out`" = one.local')
|
|
|
|
two.succeed("avahi-resolve-host-name two.local | tee out >&2")
|
|
|
|
two.succeed('test "`cut -f1 < out`" = two.local')
|
2010-10-07 18:58:07 +02:00
|
|
|
|
2019-11-05 12:20:20 +01:00
|
|
|
# Basic DNS-SD.
|
|
|
|
one.succeed("avahi-browse -r -t _workstation._tcp | tee out >&2")
|
|
|
|
one.succeed("test `wc -l < out` -gt 0")
|
|
|
|
two.succeed("avahi-browse -r -t _workstation._tcp | tee out >&2")
|
|
|
|
two.succeed("test `wc -l < out` -gt 0")
|
2010-10-07 18:58:07 +02:00
|
|
|
|
2019-11-05 12:20:20 +01:00
|
|
|
# More DNS-SD.
|
2022-03-21 19:18:18 +01:00
|
|
|
one.execute('avahi-publish -s "This is a test" _test._tcp 123 one=1 >&2 &')
|
2019-11-05 12:20:20 +01:00
|
|
|
one.sleep(5)
|
|
|
|
two.succeed("avahi-browse -r -t _test._tcp | tee out >&2")
|
|
|
|
two.succeed("test `wc -l < out` -gt 0")
|
2010-10-07 18:58:07 +02:00
|
|
|
|
2019-11-05 12:20:20 +01:00
|
|
|
# NSS-mDNS.
|
|
|
|
one.succeed("getent hosts one.local >&2")
|
|
|
|
one.succeed("getent hosts two.local >&2")
|
|
|
|
two.succeed("getent hosts one.local >&2")
|
|
|
|
two.succeed("getent hosts two.local >&2")
|
2019-06-04 00:21:51 +02:00
|
|
|
|
2019-11-05 12:20:20 +01:00
|
|
|
# extra service definitions
|
|
|
|
one.succeed("avahi-browse -r -t _ssh._tcp | tee out >&2")
|
|
|
|
one.succeed("test `wc -l < out` -gt 0")
|
|
|
|
two.succeed("avahi-browse -r -t _ssh._tcp | tee out >&2")
|
|
|
|
two.succeed("test `wc -l < out` -gt 0")
|
|
|
|
'';
|
2020-10-20 17:33:45 +02:00
|
|
|
} args
|