mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-04 19:45:54 +00:00
fd78ff23f7
reason: after the upgrade of iputils from 20151218 to 20161105 functionality of ping6 and tracepath6 was merged into ping and tracepath. Ping is now mostly a drop-in replacment for ping6, except that selecting a specific interface is done by encoding it into the address (ex.: fe80::1%eth0) rather then specifing it with the `-I` flag.
82 lines
2.3 KiB
Nix
82 lines
2.3 KiB
Nix
# Test for NixOS' container support.
|
|
|
|
let
|
|
hostIp = "192.168.0.1";
|
|
containerIp = "192.168.0.100/24";
|
|
hostIp6 = "fc00::1";
|
|
containerIp6 = "fc00::2/7";
|
|
in
|
|
|
|
import ./make-test.nix ({ pkgs, ...} : {
|
|
name = "containers-bridge";
|
|
meta = with pkgs.stdenv.lib.maintainers; {
|
|
maintainers = [ aristid aszlig eelco chaoflow kampfschlaefer ];
|
|
};
|
|
|
|
machine =
|
|
{ config, pkgs, ... }:
|
|
{ imports = [ ../modules/installer/cd-dvd/channel.nix ];
|
|
virtualisation.writableStore = true;
|
|
virtualisation.memorySize = 768;
|
|
|
|
networking.bridges = {
|
|
br0 = {
|
|
interfaces = [];
|
|
};
|
|
};
|
|
networking.interfaces = {
|
|
br0 = {
|
|
ip4 = [{ address = hostIp; prefixLength = 24; }];
|
|
ip6 = [{ address = hostIp6; prefixLength = 7; }];
|
|
};
|
|
};
|
|
|
|
containers.webserver =
|
|
{
|
|
autoStart = true;
|
|
privateNetwork = true;
|
|
hostBridge = "br0";
|
|
localAddress = containerIp;
|
|
localAddress6 = containerIp6;
|
|
config =
|
|
{ services.httpd.enable = true;
|
|
services.httpd.adminAddr = "foo@example.org";
|
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
|
networking.firewall.allowPing = true;
|
|
};
|
|
};
|
|
|
|
virtualisation.pathsInNixDB = [ pkgs.stdenv ];
|
|
};
|
|
|
|
testScript =
|
|
''
|
|
$machine->waitForUnit("default.target");
|
|
$machine->succeed("nixos-container list") =~ /webserver/ or die;
|
|
|
|
# Start the webserver container.
|
|
$machine->succeed("nixos-container status webserver") =~ /up/ or die;
|
|
|
|
"${containerIp}" =~ /([^\/]+)\/([0-9+])/;
|
|
my $ip = $1;
|
|
chomp $ip;
|
|
$machine->succeed("ping -n -c 1 $ip");
|
|
$machine->succeed("curl --fail http://$ip/ > /dev/null");
|
|
|
|
"${containerIp6}" =~ /([^\/]+)\/([0-9+])/;
|
|
my $ip6 = $1;
|
|
chomp $ip6;
|
|
$machine->succeed("ping -n -c 1 $ip6");
|
|
$machine->succeed("curl --fail http://[$ip6]/ > /dev/null");
|
|
|
|
# Stop the container.
|
|
$machine->succeed("nixos-container stop webserver");
|
|
$machine->fail("curl --fail --connect-timeout 2 http://$ip/ > /dev/null");
|
|
$machine->fail("curl --fail --connect-timeout 2 http://[$ip6]/ > /dev/null");
|
|
|
|
# Destroying a declarative container should fail.
|
|
$machine->fail("nixos-container destroy webserver");
|
|
'';
|
|
|
|
})
|