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