| 
									
										
										
										
											2021-02-26 16:03:49 +01:00
										 |  |  | import ./make-test-python.nix ({ pkgs, lib, ... }: | 
					
						
							| 
									
										
										
										
											2017-08-23 12:43:07 +03:00
										 |  |  | let | 
					
						
							| 
									
										
										
										
											2019-08-13 21:52:01 +00:00
										 |  |  |   client_base = { | 
					
						
							| 
									
										
										
										
											2017-08-23 12:43:07 +03:00
										 |  |  |     containers.test1 = { | 
					
						
							|  |  |  |       autoStart = true; | 
					
						
							|  |  |  |       config = { | 
					
						
							| 
									
										
										
										
											2019-08-13 21:52:01 +00:00
										 |  |  |         environment.etc.check.text = "client_base"; | 
					
						
							| 
									
										
										
										
											2017-08-23 12:43:07 +03:00
										 |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-23 11:00:35 +02:00
										 |  |  |     # prevent make-test-python.nix to change IP | 
					
						
							| 
									
										
										
										
											2017-08-23 12:43:07 +03:00
										 |  |  |     networking.interfaces = { | 
					
						
							| 
									
										
										
										
											2017-12-03 05:14:54 +01:00
										 |  |  |       eth1.ipv4.addresses = lib.mkOverride 0 [ ]; | 
					
						
							| 
									
										
										
										
											2017-08-23 12:43:07 +03:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | in { | 
					
						
							| 
									
										
										
										
											2020-08-23 11:00:54 +02:00
										 |  |  |   name = "containers-reloadable"; | 
					
						
							| 
									
										
										
										
											2021-02-26 16:03:49 +01:00
										 |  |  |   meta = { | 
					
						
							|  |  |  |     maintainers = with lib.maintainers; [ danbst ]; | 
					
						
							| 
									
										
										
										
											2017-08-23 12:43:07 +03:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   nodes = { | 
					
						
							| 
									
										
										
										
											2018-07-20 20:56:59 +00:00
										 |  |  |     client = { ... }: { | 
					
						
							| 
									
										
										
										
											2017-08-23 12:43:07 +03:00
										 |  |  |       imports = [ client_base ]; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-20 20:56:59 +00:00
										 |  |  |     client_c1 = { lib, ... }: { | 
					
						
							| 
									
										
										
										
											2017-08-23 12:43:07 +03:00
										 |  |  |       imports = [ client_base ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       containers.test1.config = { | 
					
						
							| 
									
										
										
										
											2019-08-13 21:52:01 +00:00
										 |  |  |         environment.etc.check.text = lib.mkForce "client_c1"; | 
					
						
							| 
									
										
										
										
											2017-08-23 12:43:07 +03:00
										 |  |  |         services.httpd.enable = true; | 
					
						
							|  |  |  |         services.httpd.adminAddr = "nixos@example.com"; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2018-07-20 20:56:59 +00:00
										 |  |  |     client_c2 = { lib, ... }: { | 
					
						
							| 
									
										
										
										
											2017-08-23 12:43:07 +03:00
										 |  |  |       imports = [ client_base ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       containers.test1.config = { | 
					
						
							| 
									
										
										
										
											2019-08-13 21:52:01 +00:00
										 |  |  |         environment.etc.check.text = lib.mkForce "client_c2"; | 
					
						
							| 
									
										
										
										
											2017-08-23 12:43:07 +03:00
										 |  |  |         services.nginx.enable = true; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   testScript = {nodes, ...}: let | 
					
						
							|  |  |  |     c1System = nodes.client_c1.config.system.build.toplevel; | 
					
						
							|  |  |  |     c2System = nodes.client_c2.config.system.build.toplevel; | 
					
						
							|  |  |  |   in ''
 | 
					
						
							| 
									
										
										
										
											2019-11-25 21:58:02 +01:00
										 |  |  |     client.start() | 
					
						
							|  |  |  |     client.wait_for_unit("default.target") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert "client_base" in client.succeed("nixos-container run test1 cat /etc/check") | 
					
						
							| 
									
										
										
										
											2017-08-23 12:43:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-25 21:58:02 +01:00
										 |  |  |     with subtest("httpd is available after activating config1"): | 
					
						
							|  |  |  |         client.succeed( | 
					
						
							|  |  |  |             "${c1System}/bin/switch-to-configuration test >&2", | 
					
						
							|  |  |  |             "[[ $(nixos-container run test1 cat /etc/check) == client_c1 ]] >&2", | 
					
						
							|  |  |  |             "systemctl status httpd -M test1 >&2", | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2017-08-23 12:43:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-25 21:58:02 +01:00
										 |  |  |     with subtest("httpd is not available any longer after switching to config2"): | 
					
						
							|  |  |  |         client.succeed( | 
					
						
							|  |  |  |             "${c2System}/bin/switch-to-configuration test >&2", | 
					
						
							|  |  |  |             "[[ $(nixos-container run test1 cat /etc/check) == client_c2 ]] >&2", | 
					
						
							|  |  |  |             "systemctl status nginx -M test1 >&2", | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         client.fail("systemctl status httpd -M test1 >&2") | 
					
						
							| 
									
										
										
										
											2017-08-23 12:43:07 +03:00
										 |  |  |   '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }) |