From 377cbbdc3001d85242b21bb89823c69abf1765ba Mon Sep 17 00:00:00 2001 From: Yarny0 <41838844+Yarny0@users.noreply.github.com> Date: Thu, 29 Aug 2024 15:12:43 +0200 Subject: [PATCH 1/4] cups: add 'cups-pdf' vm test to passthru.tests While aimed at the cups-pdf printing package, this vm tests also serves as a test for the cups printing module in general. --- pkgs/misc/cups/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/misc/cups/default.nix b/pkgs/misc/cups/default.nix index 4c9d2de10873..566632d74d78 100644 --- a/pkgs/misc/cups/default.nix +++ b/pkgs/misc/cups/default.nix @@ -138,6 +138,7 @@ stdenv.mkDerivation rec { passthru.tests = { inherit (nixosTests) + cups-pdf printing-service printing-socket ; From 1693e1acc0cde969c70b93acc4a92534eb83194b Mon Sep 17 00:00:00 2001 From: Yarny0 <41838844+Yarny0@users.noreply.github.com> Date: Thu, 29 Aug 2024 15:12:49 +0200 Subject: [PATCH 2/4] nixos/tests/printing: fix race of lpstat and ensure-printers There is a nasty race condition in the cups tests. To understand what is going on, one must first note that printers are installed in the vms with ensure-printers.service, which is started as part of multi-user.target. ensure-printers.service in turn triggers a start of cups.service as it needs to connect to the local cups daemon. This is what happens when the test runs: 1 the test waits for cups.socket or cups.service to start up (subtest "Make sure that cups is up on both sides...") 2 after cups.service started (it starts even in the "socket" case, triggered by ensure-printers.service), ensure-printers.service is started 3 the test tries to connect to the cups daemons via curl (subtest "HTTP server is available too") 4 the test verifies the required printers are installed ("lpstat -a" called by subtest "LP status checks") Usually, 3 needs some time, so ensure-printers.service already installed all printers that are required by 4. But if 3 is too fast, or if ensure-printers.service is too slow, 4 fails to find the printers it is looking for. One can provoke the problem by adding > systemd.services.ensure-printers.serviceConfig.ExecStartPre = "/run/current-system/sw/bin/sleep 10"; to the `nodes.client` configuration. The commit at hand fixes the problem by changing 1: Instead of waiting for cups, it now waits for ensure-printers.service (which in turn waits for cups.service and cups.socket). This is also in accordance with the subtest description in the code that promises to "Make sure that cups is up [...] and printers are set up". --- nixos/tests/printing.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nixos/tests/printing.nix b/nixos/tests/printing.nix index b413996c67db..f8bad5e8638f 100644 --- a/nixos/tests/printing.nix +++ b/nixos/tests/printing.nix @@ -54,8 +54,8 @@ import ./make-test-python.nix ( start_all() with subtest("Make sure that cups is up on both sides and printers are set up"): - server.wait_for_unit("cups.${if socket then "socket" else "service"}") - client.wait_for_unit("cups.${if socket then "socket" else "service"}") + server.wait_for_unit("ensure-printers.service") + client.wait_for_unit("ensure-printers.service") assert "scheduler is running" in client.succeed("lpstat -r") From 2e48883fc47b43ecdc035d1142c263febcfce61c Mon Sep 17 00:00:00 2001 From: Yarny0 <41838844+Yarny0@users.noreply.github.com> Date: Sun, 27 Oct 2024 10:47:31 +0100 Subject: [PATCH 3/4] nixos/tests/printing: inherit lib --- nixos/tests/printing.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nixos/tests/printing.nix b/nixos/tests/printing.nix index f8bad5e8638f..c612345e9583 100644 --- a/nixos/tests/printing.nix +++ b/nixos/tests/printing.nix @@ -6,9 +6,13 @@ import ./make-test-python.nix ( , ... }: +let + inherit (pkgs) lib; +in + { name = "printing"; - meta = with pkgs.lib.maintainers; { + meta = with lib.maintainers; { maintainers = [ domenkozar matthewbauer ]; }; From 9bca42857a280d8c4fc83efd1884ceaf96b6e3d0 Mon Sep 17 00:00:00 2001 From: Yarny0 <41838844+Yarny0@users.noreply.github.com> Date: Thu, 29 Aug 2024 15:12:56 +0200 Subject: [PATCH 4/4] nixos/tests/printing: test cases for domain socket only config Add two new vm tests for the printing configuration that test `listenAddresses = []`, i.e., the situation where cups only listens on the unix domain socket `/run/cups/cups.sock`. This helps catching bugs like this: https://github.com/OpenPrinting/cups/issues/985 https://github.com/NixOS/nixpkgs/pull/337748 --- nixos/tests/all-tests.nix | 6 ++++-- nixos/tests/printing.nix | 6 ++++-- pkgs/misc/cups/default.nix | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index dd6519ff9361..78915a8c1db3 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -827,8 +827,10 @@ in { predictable-interface-names = handleTest ./predictable-interface-names.nix {}; pretalx = runTest ./web-apps/pretalx.nix; pretix = runTest ./web-apps/pretix.nix; - printing-socket = handleTest ./printing.nix { socket = true; }; - printing-service = handleTest ./printing.nix { socket = false; }; + printing-socket = handleTest ./printing.nix { socket = true; listenTcp = true; }; + printing-service = handleTest ./printing.nix { socket = false; listenTcp = true; }; + printing-socket-notcp = handleTest ./printing.nix { socket = true; listenTcp = false; }; + printing-service-notcp = handleTest ./printing.nix { socket = false; listenTcp = false; }; private-gpt = handleTest ./private-gpt.nix {}; privatebin = runTest ./privatebin.nix; privoxy = handleTest ./privoxy.nix {}; diff --git a/nixos/tests/printing.nix b/nixos/tests/printing.nix index c612345e9583..5f719a5d97c1 100644 --- a/nixos/tests/printing.nix +++ b/nixos/tests/printing.nix @@ -3,6 +3,7 @@ import ./make-test-python.nix ( { pkgs , socket ? true # whether to use socket activation +, listenTcp ? true # whether to open port 631 on client , ... }: @@ -39,9 +40,10 @@ in }]; }; - nodes.client = { ... }: { + nodes.client = { lib, ... }: { services.printing.enable = true; services.printing.startWhenNeeded = socket; + services.printing.listenAddresses = lib.mkIf (!listenTcp) []; # Add printer to the client as well, via IPP. hardware.printers.ensurePrinters = [{ name = "DeskjetRemote"; @@ -67,7 +69,7 @@ in assert "/var/run/cups/cups.sock" in client.succeed("lpstat -H") with subtest("HTTP server is available too"): - client.succeed("curl --fail http://localhost:631/") + ${lib.optionalString listenTcp ''client.succeed("curl --fail http://localhost:631/")''} client.succeed(f"curl --fail http://{server.name}:631/") server.fail(f"curl --fail --connect-timeout 2 http://{client.name}:631/") diff --git a/pkgs/misc/cups/default.nix b/pkgs/misc/cups/default.nix index 566632d74d78..085ecdbed827 100644 --- a/pkgs/misc/cups/default.nix +++ b/pkgs/misc/cups/default.nix @@ -141,6 +141,8 @@ stdenv.mkDerivation rec { cups-pdf printing-service printing-socket + printing-service-notcp + printing-socket-notcp ; };