| 
									
										
										
										
											2013-09-26 21:00:30 +02:00
										 |  |  | # Test printing via CUPS. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-14 14:02:44 +02:00
										 |  |  | import ./make-test.nix ({pkgs, ... }: { | 
					
						
							| 
									
										
										
										
											2014-06-28 16:04:49 +02:00
										 |  |  |   name = "printing"; | 
					
						
							| 
									
										
										
										
											2015-07-12 12:09:40 +02:00
										 |  |  |   meta = with pkgs.stdenv.lib.maintainers; { | 
					
						
							| 
									
										
										
										
											2016-05-17 12:57:28 +01:00
										 |  |  |     maintainers = [ domenkozar eelco chaoflow jgeerds ]; | 
					
						
							| 
									
										
										
										
											2015-07-12 12:09:40 +02:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2013-09-26 21:00:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   nodes = { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     server = | 
					
						
							|  |  |  |       { config, pkgs, ... }: | 
					
						
							|  |  |  |       { services.printing.enable = true; | 
					
						
							| 
									
										
										
										
											2014-04-25 00:30:12 +02:00
										 |  |  |         services.printing.listenAddresses = [ "*:631" ]; | 
					
						
							| 
									
										
										
										
											2015-05-04 22:32:35 +02:00
										 |  |  |         services.printing.defaultShared = true; | 
					
						
							| 
									
										
										
										
											2014-11-27 20:00:56 +01:00
										 |  |  |         services.printing.extraConf = | 
					
						
							| 
									
										
										
										
											2013-09-26 21:00:30 +02:00
										 |  |  |           ''
 | 
					
						
							|  |  |  |             <Location /> | 
					
						
							|  |  |  |               Order allow,deny | 
					
						
							|  |  |  |               Allow from all | 
					
						
							|  |  |  |             </Location> | 
					
						
							|  |  |  |           '';
 | 
					
						
							| 
									
										
										
										
											2014-04-11 17:15:56 +02:00
										 |  |  |         networking.firewall.allowedTCPPorts = [ 631 ]; | 
					
						
							| 
									
										
										
										
											2013-09-26 21:00:30 +02:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client = | 
					
						
							|  |  |  |       { config, pkgs, nodes, ... }: | 
					
						
							|  |  |  |       { services.printing.enable = true; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   testScript = | 
					
						
							|  |  |  |     ''
 | 
					
						
							|  |  |  |       startAll; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Make sure that cups is up on both sides. | 
					
						
							| 
									
										
										
										
											2015-03-25 13:26:37 +01:00
										 |  |  |       $server->waitForUnit("cups.service"); | 
					
						
							|  |  |  |       $client->waitForUnit("cups.service"); | 
					
						
							| 
									
										
										
										
											2015-05-13 14:22:06 +02:00
										 |  |  |       $client->sleep(10); # wait until cups is fully initialized | 
					
						
							| 
									
										
										
										
											2013-09-26 21:00:30 +02:00
										 |  |  |       $client->succeed("lpstat -r") =~ /scheduler is running/ or die; | 
					
						
							| 
									
										
										
										
											2018-02-23 18:47:43 +03:00
										 |  |  |       $client->succeed("lpstat -H") =~ "localhost:631" or die; | 
					
						
							| 
									
										
										
										
											2016-04-18 13:40:35 +02:00
										 |  |  |       $client->succeed("curl --fail http://localhost:631/"); | 
					
						
							|  |  |  |       $client->succeed("curl --fail http://server:631/"); | 
					
						
							|  |  |  |       $server->fail("curl --fail --connect-timeout 2  http://client:631/"); | 
					
						
							| 
									
										
										
										
											2013-09-26 21:00:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # Add a HP Deskjet printer connected via USB to the server. | 
					
						
							| 
									
										
										
										
											2014-11-27 20:00:56 +01:00
										 |  |  |       $server->succeed("lpadmin -p DeskjetLocal -E -v usb://foobar/printers/foobar"); | 
					
						
							| 
									
										
										
										
											2013-09-26 21:00:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # Add it to the client as well via IPP. | 
					
						
							| 
									
										
										
										
											2014-11-27 20:00:56 +01:00
										 |  |  |       $client->succeed("lpadmin -p DeskjetRemote -E -v ipp://server/printers/DeskjetLocal"); | 
					
						
							| 
									
										
										
										
											2013-09-26 21:00:30 +02:00
										 |  |  |       $client->succeed("lpadmin -d DeskjetRemote"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Do some status checks. | 
					
						
							|  |  |  |       $client->succeed("lpstat -a") =~ /DeskjetRemote accepting requests/ or die; | 
					
						
							| 
									
										
										
										
											2015-05-02 15:33:22 +02:00
										 |  |  |       $client->succeed("lpstat -h server:631 -a") =~ /DeskjetLocal accepting requests/ or die; | 
					
						
							| 
									
										
										
										
											2013-09-26 21:00:30 +02:00
										 |  |  |       $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. | 
					
						
							| 
									
										
										
										
											2016-04-18 13:40:35 +02:00
										 |  |  |       foreach my $file ("${pkgs.groff.doc}/share/doc/*/examples/mom/penguin.pdf", | 
					
						
							|  |  |  |                         "${pkgs.groff.doc}/share/doc/*/meref.ps", | 
					
						
							| 
									
										
										
										
											2016-04-23 16:16:22 +02:00
										 |  |  |                         "${pkgs.cups.out}/share/doc/cups/images/cups.png", | 
					
						
							| 
									
										
										
										
											2016-04-18 13:40:35 +02:00
										 |  |  |                         "${pkgs.pcre.doc}/share/doc/pcre/pcre.txt") | 
					
						
							| 
									
										
										
										
											2013-09-26 21:00:30 +02:00
										 |  |  |       { | 
					
						
							|  |  |  |           $file =~ /([^\/]*)$/; my $fn = $1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           subtest "print $fn", sub { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               # Print the file on the client. | 
					
						
							|  |  |  |               $client->succeed("lp $file"); | 
					
						
							| 
									
										
										
										
											2015-05-14 17:45:59 +02:00
										 |  |  |               $client->sleep(10); | 
					
						
							| 
									
										
										
										
											2013-09-26 21:00:30 +02:00
										 |  |  |               $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. | 
					
						
							| 
									
										
										
										
											2016-02-22 12:22:29 +03:00
										 |  |  |               $server->waitForFile("/var/spool/cups/d*-001"); | 
					
						
							| 
									
										
										
										
											2015-05-14 17:45:59 +02:00
										 |  |  |               $server->sleep(10); | 
					
						
							| 
									
										
										
										
											2014-11-27 20:00:56 +01:00
										 |  |  |               $server->succeed("lpq -a") =~ /$fn/ or die; | 
					
						
							| 
									
										
										
										
											2013-09-26 21:00:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |               # Delete the job on the client.  It should disappear on the | 
					
						
							|  |  |  |               # server as well. | 
					
						
							|  |  |  |               $client->succeed("lprm"); | 
					
						
							| 
									
										
										
										
											2015-05-14 17:45:59 +02:00
										 |  |  |               $client->sleep(10); | 
					
						
							| 
									
										
										
										
											2013-09-26 21:00:30 +02:00
										 |  |  |               $client->succeed("lpq -a") =~ /no entries/; | 
					
						
							|  |  |  |               Machine::retry sub { | 
					
						
							|  |  |  |                 return 1 if $server->succeed("lpq -a") =~ /no entries/; | 
					
						
							|  |  |  |               }; | 
					
						
							| 
									
										
										
										
											2016-02-22 12:22:29 +03:00
										 |  |  |               # The queue is empty already, so this should be safe. | 
					
						
							|  |  |  |               # Otherwise, pairs of "c*"-"d*-001" files might persist. | 
					
						
							|  |  |  |               $server->execute("rm /var/spool/cups/*"); | 
					
						
							| 
									
										
										
										
											2013-09-26 21:00:30 +02:00
										 |  |  |           }; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     '';
 | 
					
						
							| 
									
										
										
										
											2014-04-14 14:02:44 +02:00
										 |  |  | }) |