2013-09-26 20:00:30 +01:00
|
|
|
# Test printing via CUPS.
|
|
|
|
|
2014-04-14 13:02:44 +01:00
|
|
|
import ./make-test.nix ({pkgs, ... }: {
|
2014-06-28 15:04:49 +01:00
|
|
|
name = "printing";
|
2013-09-26 20:00:30 +01:00
|
|
|
|
|
|
|
nodes = {
|
|
|
|
|
|
|
|
server =
|
|
|
|
{ config, pkgs, ... }:
|
|
|
|
{ services.printing.enable = true;
|
2014-04-24 23:30:12 +01:00
|
|
|
services.printing.listenAddresses = [ "*:631" ];
|
2014-11-27 19:00:56 +00:00
|
|
|
services.printing.extraConf =
|
2013-09-26 20:00:30 +01:00
|
|
|
''
|
|
|
|
<Location />
|
|
|
|
Order allow,deny
|
|
|
|
Allow from all
|
|
|
|
</Location>
|
|
|
|
'';
|
2014-04-11 16:15:56 +01:00
|
|
|
networking.firewall.allowedTCPPorts = [ 631 ];
|
2013-09-26 20:00:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
client =
|
|
|
|
{ config, pkgs, nodes, ... }:
|
|
|
|
{ services.printing.enable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
''
|
|
|
|
startAll;
|
|
|
|
|
|
|
|
# Make sure that cups is up on both sides.
|
|
|
|
$server->waitForUnit("cupsd.service");
|
|
|
|
$client->waitForUnit("cupsd.service");
|
|
|
|
$client->succeed("lpstat -r") =~ /scheduler is running/ or die;
|
|
|
|
$client->succeed("lpstat -H") =~ "/var/run/cups/cups.sock" or die;
|
|
|
|
$client->succeed("curl --fail http://localhost:631/");
|
|
|
|
$client->succeed("curl --fail http://server:631/");
|
2014-04-11 16:15:56 +01:00
|
|
|
$server->fail("curl --fail --connect-timeout 2 http://client:631/");
|
2013-09-26 20:00:30 +01:00
|
|
|
|
|
|
|
# Add a HP Deskjet printer connected via USB to the server.
|
2014-11-27 19:00:56 +00:00
|
|
|
$server->succeed("lpadmin -p DeskjetLocal -E -v usb://foobar/printers/foobar");
|
2013-09-26 20:00:30 +01:00
|
|
|
|
|
|
|
# Add it to the client as well via IPP.
|
2014-11-27 19:00:56 +00:00
|
|
|
$client->succeed("lpadmin -p DeskjetRemote -E -v ipp://server/printers/DeskjetLocal");
|
2013-09-26 20:00:30 +01:00
|
|
|
$client->succeed("lpadmin -d DeskjetRemote");
|
|
|
|
|
|
|
|
# Do some status checks.
|
|
|
|
$client->succeed("lpstat -a") =~ /DeskjetRemote accepting requests/ or die;
|
|
|
|
$client->succeed("lpstat -h server -a") =~ /DeskjetLocal accepting requests/ or die;
|
|
|
|
$client->succeed("cupsdisable DeskjetRemote");
|
|
|
|
$client->succeed("lpq") =~ /DeskjetRemote is not ready.*no entries/s or die;
|
|
|
|
$client->succeed("cupsenable DeskjetRemote");
|
|
|
|
$client->succeed("lpq") =~ /DeskjetRemote is ready.*no entries/s or die;
|
|
|
|
|
|
|
|
# Test printing various file types.
|
2014-11-27 19:00:56 +00:00
|
|
|
foreach my $file ("${pkgs.groff}/share/doc/*/examples/mom/penguin.pdf",
|
2013-09-26 20:00:30 +01:00
|
|
|
"${pkgs.groff}/share/doc/*/meref.ps",
|
|
|
|
"${pkgs.cups}/share/doc/cups/images/cups.png",
|
2015-02-05 09:48:36 +00:00
|
|
|
"${pkgs.pcre}/share/doc/pcre/pcre.txt")
|
2013-09-26 20:00:30 +01:00
|
|
|
{
|
|
|
|
$file =~ /([^\/]*)$/; my $fn = $1;
|
|
|
|
|
|
|
|
subtest "print $fn", sub {
|
|
|
|
|
|
|
|
# Print the file on the client.
|
|
|
|
$client->succeed("lp $file");
|
|
|
|
$client->succeed("lpq") =~ /active.*root.*$fn/ or die;
|
|
|
|
|
|
|
|
# Ensure that a raw PCL file appeared in the server's queue
|
|
|
|
# (showing that the right filters have been applied). Of
|
|
|
|
# course, since there is no actual USB printer attached, the
|
|
|
|
# file will stay in the queue forever.
|
2014-11-27 19:00:56 +00:00
|
|
|
$server->waitForFile("/var/spool/cups/d00001-001");
|
|
|
|
$server->succeed("lpq -a") =~ /$fn/ or die;
|
2013-09-26 20:00:30 +01:00
|
|
|
|
|
|
|
# Delete the job on the client. It should disappear on the
|
|
|
|
# server as well.
|
|
|
|
$client->succeed("lprm");
|
|
|
|
$client->succeed("lpq -a") =~ /no entries/;
|
|
|
|
Machine::retry sub {
|
|
|
|
return 1 if $server->succeed("lpq -a") =~ /no entries/;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
2014-04-14 13:02:44 +01:00
|
|
|
})
|