3
0
Fork 0
forked from mirrors/nixpkgs

nixos/containers-bridge: Port test to python

This commit is contained in:
Jacek Galowicz 2019-11-26 00:43:52 +01:00
parent 6127bf9837
commit 4e89f75ca6

View file

@ -7,7 +7,7 @@ let
containerIp6 = "fc00::2/7"; containerIp6 = "fc00::2/7";
in in
import ./make-test.nix ({ pkgs, ...} : { import ./make-test-python.nix ({ pkgs, ...} : {
name = "containers-bridge"; name = "containers-bridge";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ aristid aszlig eelco kampfschlaefer ]; maintainers = [ aristid aszlig eelco kampfschlaefer ];
@ -61,43 +61,42 @@ import ./make-test.nix ({ pkgs, ...} : {
virtualisation.pathsInNixDB = [ pkgs.stdenv ]; virtualisation.pathsInNixDB = [ pkgs.stdenv ];
}; };
testScript = testScript = ''
'' machine.wait_for_unit("default.target")
$machine->waitForUnit("default.target"); assert "webserver" in machine.succeed("nixos-container list")
$machine->succeed("nixos-container list") =~ /webserver/ or die;
# Start the webserver container. with subtest("Start the webserver container"):
$machine->succeed("nixos-container status webserver") =~ /up/ or die; assert "up" in machine.succeed("nixos-container status webserver")
# Check if bridges exist inside containers with subtest("Bridges exist inside containers"):
$machine->succeed("nixos-container run webserver -- ip link show eth0"); machine.succeed(
$machine->succeed("nixos-container run web-noip -- ip link show eth0"); "nixos-container run webserver -- ip link show eth0",
"nixos-container run web-noip -- ip link show eth0",
)
"${containerIp}" =~ /([^\/]+)\/([0-9+])/; ip = "${containerIp}".split("/")[0]
my $ip = $1; machine.succeed(f"ping -n -c 1 {ip}")
chomp $ip; machine.succeed(f"curl --fail http://{ip}/ > /dev/null")
$machine->succeed("ping -n -c 1 $ip");
$machine->succeed("curl --fail http://$ip/ > /dev/null");
"${containerIp6}" =~ /([^\/]+)\/([0-9+])/; ip6 = "${containerIp6}".split("/")[0]
my $ip6 = $1; machine.succeed(f"ping -n -c 1 {ip6}")
chomp $ip6; machine.succeed(f"curl --fail http://[{ip6}]/ > /dev/null")
$machine->succeed("ping -n -c 1 $ip6");
$machine->succeed("curl --fail http://[$ip6]/ > /dev/null");
# Check that nixos-container show-ip works in case of an ipv4 address with with subtest(
# subnetmask in CIDR notation. "nixos-container show-ip works in case of an ipv4 address "
my $result = $machine->succeed("nixos-container show-ip webserver"); + "with subnetmask in CIDR notation."
chomp $result; ):
$result eq $ip or die; result = machine.succeed("nixos-container show-ip webserver").rstrip()
assert result == ip
# Stop the container. with subtest("Stop the container"):
$machine->succeed("nixos-container stop webserver"); machine.succeed("nixos-container stop webserver")
$machine->fail("curl --fail --connect-timeout 2 http://$ip/ > /dev/null"); machine.fail(
$machine->fail("curl --fail --connect-timeout 2 http://[$ip6]/ > /dev/null"); f"curl --fail --connect-timeout 2 http://{ip}/ > /dev/null",
f"curl --fail --connect-timeout 2 http://[{ip6}]/ > /dev/null",
)
# Destroying a declarative container should fail. # Destroying a declarative container should fail.
$machine->fail("nixos-container destroy webserver"); machine.fail("nixos-container destroy webserver")
''; '';
}) })