at 18.03-beta 2.1 kB view raw
1# Test for NixOS' container support. 2 3let 4 hostIp = "192.168.0.1"; 5 hostPort = 10080; 6 containerIp = "192.168.0.100"; 7 containerPort = 80; 8in 9 10import ./make-test.nix ({ pkgs, ...} : { 11 name = "containers-portforward"; 12 meta = with pkgs.stdenv.lib.maintainers; { 13 maintainers = [ aristid aszlig eelco chaoflow kampfschlaefer ianwookim ]; 14 }; 15 16 machine = 17 { config, pkgs, ... }: 18 { imports = [ ../modules/installer/cd-dvd/channel.nix ]; 19 virtualisation.writableStore = true; 20 virtualisation.memorySize = 768; 21 22 containers.webserver = 23 { privateNetwork = true; 24 hostAddress = hostIp; 25 localAddress = containerIp; 26 forwardPorts = [ { protocol = "tcp"; hostPort = hostPort; containerPort = containerPort; } ]; 27 config = 28 { services.httpd.enable = true; 29 services.httpd.adminAddr = "foo@example.org"; 30 networking.firewall.allowedTCPPorts = [ 80 ]; 31 networking.firewall.allowPing = true; 32 }; 33 }; 34 35 virtualisation.pathsInNixDB = [ pkgs.stdenv ]; 36 }; 37 38 testScript = 39 '' 40 $machine->succeed("nixos-container list") =~ /webserver/ or die; 41 42 # Start the webserver container. 43 $machine->succeed("nixos-container start webserver"); 44 45 # wait two seconds for the container to start and the network to be up 46 sleep 2; 47 48 # Since "start" returns after the container has reached 49 # multi-user.target, we should now be able to access it. 50 #my $ip = $machine->succeed("nixos-container show-ip webserver"); 51 #chomp $ip; 52 $machine->succeed("ping -n -c1 ${hostIp}"); 53 $machine->succeed("curl --fail http://${hostIp}:${toString hostPort}/ > /dev/null"); 54 55 # Stop the container. 56 $machine->succeed("nixos-container stop webserver"); 57 $machine->fail("curl --fail --connect-timeout 2 http://${hostIp}:${toString hostPort}/ > /dev/null"); 58 59 # Destroying a declarative container should fail. 60 $machine->fail("nixos-container destroy webserver"); 61 ''; 62 63})