| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  | # Test for NixOS' container support. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-01 02:29:24 +01:00
										 |  |  | import ./make-test-python.nix ({ pkgs, ...} : { | 
					
						
							|  |  |  |   name = "containers-extra_veth"; | 
					
						
							| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  |   meta = with pkgs.stdenv.lib.maintainers; { | 
					
						
							| 
									
										
										
										
											2016-05-16 13:06:40 +02:00
										 |  |  |     maintainers = [ kampfschlaefer ]; | 
					
						
							| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   machine = | 
					
						
							| 
									
										
										
										
											2018-07-20 20:56:59 +00:00
										 |  |  |     { pkgs, ... }: | 
					
						
							| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  |     { imports = [ ../modules/installer/cd-dvd/channel.nix ]; | 
					
						
							|  |  |  |       virtualisation.writableStore = true; | 
					
						
							|  |  |  |       virtualisation.memorySize = 768; | 
					
						
							|  |  |  |       virtualisation.vlans = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-11 19:50:15 +01:00
										 |  |  |       networking.useDHCP = false; | 
					
						
							| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  |       networking.bridges = { | 
					
						
							|  |  |  |         br0 = { | 
					
						
							|  |  |  |           interfaces = []; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         br1 = { interfaces = []; }; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |       networking.interfaces = { | 
					
						
							|  |  |  |         br0 = { | 
					
						
							| 
									
										
										
										
											2017-12-03 05:14:54 +01:00
										 |  |  |           ipv4.addresses = [{ address = "192.168.0.1"; prefixLength = 24; }]; | 
					
						
							|  |  |  |           ipv6.addresses = [{ address = "fc00::1"; prefixLength = 7; }]; | 
					
						
							| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  |         }; | 
					
						
							|  |  |  |         br1 = { | 
					
						
							| 
									
										
										
										
											2017-12-03 05:14:54 +01:00
										 |  |  |           ipv4.addresses = [{ address = "192.168.1.1"; prefixLength = 24; }]; | 
					
						
							| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  |         }; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       containers.webserver = | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           autoStart = true; | 
					
						
							|  |  |  |           privateNetwork = true; | 
					
						
							|  |  |  |           hostBridge = "br0"; | 
					
						
							|  |  |  |           localAddress = "192.168.0.100/24"; | 
					
						
							|  |  |  |           localAddress6 = "fc00::2/7"; | 
					
						
							|  |  |  |           extraVeths = { | 
					
						
							|  |  |  |             veth1 = { hostBridge = "br1"; localAddress = "192.168.1.100/24"; }; | 
					
						
							|  |  |  |             veth2 = { hostAddress = "192.168.2.1"; localAddress = "192.168.2.100"; }; | 
					
						
							|  |  |  |           }; | 
					
						
							|  |  |  |           config = | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |               networking.firewall.allowedTCPPorts = [ 80 ]; | 
					
						
							|  |  |  |             }; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       virtualisation.pathsInNixDB = [ pkgs.stdenv ]; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   testScript = | 
					
						
							|  |  |  |     ''
 | 
					
						
							| 
									
										
										
										
											2019-12-01 02:29:24 +01:00
										 |  |  |       machine.wait_for_unit("default.target") | 
					
						
							|  |  |  |       assert "webserver" in machine.succeed("nixos-container list") | 
					
						
							| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-01 02:29:24 +01:00
										 |  |  |       with subtest("Status of the webserver container is up"): | 
					
						
							|  |  |  |           assert "up" in machine.succeed("nixos-container status webserver") | 
					
						
							| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-01 02:29:24 +01:00
										 |  |  |       with subtest("Ensure that the veths are inside the container"): | 
					
						
							|  |  |  |           assert "state UP" in machine.succeed( | 
					
						
							|  |  |  |               "nixos-container run webserver -- ip link show veth1" | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |           assert "state UP" in machine.succeed( | 
					
						
							|  |  |  |               "nixos-container run webserver -- ip link show veth2" | 
					
						
							|  |  |  |           ) | 
					
						
							| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-01 02:29:24 +01:00
										 |  |  |       with subtest("Ensure the presence of the extra veths"): | 
					
						
							|  |  |  |           assert "state UP" in machine.succeed("ip link show veth1") | 
					
						
							|  |  |  |           assert "state UP" in machine.succeed("ip link show veth2") | 
					
						
							| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-01 02:29:24 +01:00
										 |  |  |       with subtest("Ensure the veth1 is part of br1 on the host"): | 
					
						
							|  |  |  |           assert "master br1" in machine.succeed("ip link show veth1") | 
					
						
							| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-01 02:29:24 +01:00
										 |  |  |       with subtest("Ping on main veth"): | 
					
						
							|  |  |  |           machine.succeed("ping -n -c 1 192.168.0.100") | 
					
						
							|  |  |  |           machine.succeed("ping -n -c 1 fc00::2") | 
					
						
							| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-01 02:29:24 +01:00
										 |  |  |       with subtest("Ping on the first extra veth"): | 
					
						
							|  |  |  |           machine.succeed("ping -n -c 1 192.168.1.100 >&2") | 
					
						
							| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-01 02:29:24 +01:00
										 |  |  |       with subtest("Ping on the second extra veth"): | 
					
						
							|  |  |  |           machine.succeed("ping -n -c 1 192.168.2.100 >&2") | 
					
						
							| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-01 02:29:24 +01:00
										 |  |  |       with subtest("Container can be stopped"): | 
					
						
							|  |  |  |           machine.succeed("nixos-container stop webserver") | 
					
						
							|  |  |  |           machine.fail("ping -n -c 1 192.168.1.100 >&2") | 
					
						
							|  |  |  |           machine.fail("ping -n -c 1 192.168.2.100 >&2") | 
					
						
							| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-01 02:29:24 +01:00
										 |  |  |       with subtest("Destroying a declarative container should fail"): | 
					
						
							|  |  |  |           machine.fail("nixos-container destroy webserver") | 
					
						
							| 
									
										
										
										
											2016-05-07 00:04:28 +02:00
										 |  |  |     '';
 | 
					
						
							|  |  |  | }) |