at 23.05-pre 2.2 kB view raw
1# This test runs PowerDNS authoritative server with the 2# generic MySQL backend (gmysql) to connect to a 3# MariaDB server using UNIX sockets authentication. 4 5import ./make-test-python.nix ({ pkgs, lib, ... }: { 6 name = "powerdns"; 7 8 nodes.server = { ... }: { 9 services.powerdns.enable = true; 10 services.powerdns.extraConfig = '' 11 launch=gmysql 12 gmysql-user=pdns 13 zone-cache-refresh-interval=0 14 ''; 15 16 services.mysql = { 17 enable = true; 18 package = pkgs.mariadb; 19 ensureDatabases = [ "powerdns" ]; 20 ensureUsers = lib.singleton 21 { name = "pdns"; 22 ensurePermissions = { "powerdns.*" = "ALL PRIVILEGES"; }; 23 }; 24 }; 25 26 environment.systemPackages = with pkgs; 27 [ dnsutils powerdns mariadb ]; 28 }; 29 30 testScript = '' 31 import re 32 33 with subtest("PowerDNS database exists"): 34 server.wait_for_unit("mysql") 35 server.succeed("echo 'SHOW DATABASES;' | sudo -u pdns mysql -u pdns >&2") 36 37 with subtest("Loading the MySQL schema works"): 38 server.succeed( 39 "sudo -u pdns mysql -u pdns -D powerdns <" 40 "${pkgs.powerdns}/share/doc/pdns/schema.mysql.sql" 41 ) 42 43 with subtest("PowerDNS server starts"): 44 server.wait_for_unit("pdns") 45 server.succeed("dig version.bind txt chaos @127.0.0.1 >&2") 46 47 with subtest("Adding an example zone works"): 48 # Extract configuration file needed by pdnsutil 49 unit = server.succeed("systemctl cat pdns") 50 match = re.search("(--config-dir=[^ ]+)", unit) 51 assert(match is not None) 52 conf = match.group(1) 53 pdnsutil = "sudo -u pdns pdnsutil " + conf 54 server.succeed(f"{pdnsutil} create-zone example.com ns1.example.com") 55 server.succeed(f"{pdnsutil} add-record example.com ns1 A 192.168.1.2") 56 57 with subtest("Querying the example zone works"): 58 reply = server.succeed("dig +noall +answer ns1.example.com @127.0.0.1") 59 assert ( 60 "192.168.1.2" in reply 61 ), f"""" 62 The reply does not contain the expected IP address: 63 Expected: 64 ns1.example.com. 3600 IN A 192.168.1.2 65 Reply: 66 {reply}""" 67 ''; 68})