git.iko.soy/typeable/nixpkgs
on master help sign in
nixosTests.containers*: port rest to python
commit6fbb76cf7664aa12170ba77b17687c759a860506 authorMartin Milata <martin@martinmilata.cz> dateSun 1 Dec 2019, 02:29 (7 years ago) parentcf5ec7a
5 files changed+151−151
nixos/tests/containers-extra_veth.nix+31−40 nixos/tests/containers-macvlans.nix+16−12 nixos/tests/containers-physical_interfaces.nix+47−44 nixos/tests/containers-portforward.nix+11−11 nixos/tests/containers-restart_networking.nix+46−44
nixos/tests/containers-extra_veth.nix+31−40
@@ -1,7 +1,7 @@
11# Test for NixOS' container support.
22
3−import ./make-test.nix ({ pkgs, ...} : {
4− name = "containers-bridge";
3+import ./make-test-python.nix ({ pkgs, ...} : {
4+ name = "containers-extra_veth";
55 meta = with pkgs.stdenv.lib.maintainers; {
66 maintainers = [ kampfschlaefer ];
77 };
@@ -52,52 +52,43 @@ import ./make-test.nix ({ pkgs, ...} : {
5252
5353 testScript =
5454 ''
55− $machine->waitForUnit("default.target");
56− $machine->succeed("nixos-container list") =~ /webserver/ or die;
55+ machine.wait_for_unit("default.target")
56+ assert "webserver" in machine.succeed("nixos-container list")
5757
58− # Status of the webserver container.
59− $machine->succeed("nixos-container status webserver") =~ /up/ or die;
58+ with subtest("Status of the webserver container is up"):
59+ assert "up" in machine.succeed("nixos-container status webserver")
6060
61− # Debug
62− #$machine->succeed("nixos-container run webserver -- ip link >&2");
61+ with subtest("Ensure that the veths are inside the container"):
62+ assert "state UP" in machine.succeed(
63+ "nixos-container run webserver -- ip link show veth1"
64+ )
65+ assert "state UP" in machine.succeed(
66+ "nixos-container run webserver -- ip link show veth2"
67+ )
6368
64− # Ensure that the veths are inside the container
65− $machine->succeed("nixos-container run webserver -- ip link show veth1") =~ /state UP/ or die;
66− $machine->succeed("nixos-container run webserver -- ip link show veth2") =~ /state UP/ or die;
69+ with subtest("Ensure the presence of the extra veths"):
70+ assert "state UP" in machine.succeed("ip link show veth1")
71+ assert "state UP" in machine.succeed("ip link show veth2")
6772
68− # Debug
69− #$machine->succeed("ip link >&2");
73+ with subtest("Ensure the veth1 is part of br1 on the host"):
74+ assert "master br1" in machine.succeed("ip link show veth1")
7075
71− # Ensure the presence of the extra veths
72− $machine->succeed("ip link show veth1") =~ /state UP/ or die;
73− $machine->succeed("ip link show veth2") =~ /state UP/ or die;
76+ with subtest("Ping on main veth"):
77+ machine.succeed("ping -n -c 1 192.168.0.100")
78+ machine.succeed("ping -n -c 1 fc00::2")
7479
75− # Ensure the veth1 is part of br1 on the host
76− $machine->succeed("ip link show veth1") =~ /master br1/ or die;
80+ with subtest("Ping on the first extra veth"):
81+ machine.succeed("ping -n -c 1 192.168.1.100 >&2")
7782
78− # Debug
79− #$machine->succeed("ip -4 a >&2");
80− #$machine->succeed("ip -4 r >&2");
81− #$machine->succeed("nixos-container run webserver -- ip link >&2");
82− #$machine->succeed("nixos-container run webserver -- ip -4 a >&2");
83− #$machine->succeed("nixos-container run webserver -- ip -4 r >&2");
83+ with subtest("Ping on the second extra veth"):
84+ machine.succeed("ping -n -c 1 192.168.2.100 >&2")
8485
85− # Ping on main veth
86− $machine->succeed("ping -n -c 1 192.168.0.100");
87− $machine->succeed("ping -n -c 1 fc00::2");
86+ with subtest("Container can be stopped"):
87+ machine.succeed("nixos-container stop webserver")
88+ machine.fail("ping -n -c 1 192.168.1.100 >&2")
89+ machine.fail("ping -n -c 1 192.168.2.100 >&2")
8890
89− # Ping on the first extra veth
90− $machine->succeed("ping -n -c 1 192.168.1.100 >&2");
91−
92− # Ping on the second extra veth
93− $machine->succeed("ping -n -c 1 192.168.2.100 >&2");
94−
95− # Stop the container.
96− $machine->succeed("nixos-container stop webserver");
97− $machine->fail("ping -n -c 1 192.168.1.100 >&2");
98− $machine->fail("ping -n -c 1 192.168.2.100 >&2");
99−
100− # Destroying a declarative container should fail.
101− $machine->fail("nixos-container destroy webserver");
91+ with subtest("Destroying a declarative container should fail"):
92+ machine.fail("nixos-container destroy webserver")
10293 '';
10394})
nixos/tests/containers-macvlans.nix+16−12
@@ -6,7 +6,7 @@ let
66 containerIp2 = "192.168.1.254";
77in
88
9−import ./make-test.nix ({ pkgs, ...} : {
9+import ./make-test-python.nix ({ pkgs, ...} : {
1010 name = "containers-macvlans";
1111 meta = with pkgs.stdenv.lib.maintainers; {
1212 maintainers = [ montag451 ];
@@ -64,19 +64,23 @@ import ./make-test.nix ({ pkgs, ...} : {
6464 };
6565
6666 testScript = ''
67− startAll;
68− $machine1->waitForUnit("default.target");
69− $machine2->waitForUnit("default.target");
67+ start_all()
68+ machine1.wait_for_unit("default.target")
69+ machine2.wait_for_unit("default.target")
7070
71− # Ping between containers to check that macvlans are created in bridge mode
72− $machine1->succeed("nixos-container run test1 -- ping -n -c 1 ${containerIp2}");
71+ with subtest(
72+ "Ping between containers to check that macvlans are created in bridge mode"
73+ ):
74+ machine1.succeed("nixos-container run test1 -- ping -n -c 1 ${containerIp2}")
7375
74− # Ping containers from the host (machine1)
75− $machine1->succeed("ping -n -c 1 ${containerIp1}");
76− $machine1->succeed("ping -n -c 1 ${containerIp2}");
76+ with subtest("Ping containers from the host (machine1)"):
77+ machine1.succeed("ping -n -c 1 ${containerIp1}")
78+ machine1.succeed("ping -n -c 1 ${containerIp2}")
7779
78− # Ping containers from the second machine to check that containers are reachable from the outside
79− $machine2->succeed("ping -n -c 1 ${containerIp1}");
80− $machine2->succeed("ping -n -c 1 ${containerIp2}");
80+ with subtest(
81+ "Ping containers from the second machine to check that containers are reachable from the outside"
82+ ):
83+ machine2.succeed("ping -n -c 1 ${containerIp1}")
84+ machine2.succeed("ping -n -c 1 ${containerIp2}")
8185 '';
8286})
nixos/tests/containers-physical_interfaces.nix+47−44
@@ -1,5 +1,5 @@
11
2−import ./make-test.nix ({ pkgs, ...} : {
2+import ./make-test-python.nix ({ pkgs, ...} : {
33 name = "containers-physical_interfaces";
44 meta = with pkgs.stdenv.lib.maintainers; {
55 maintainers = [ kampfschlaefer ];
@@ -86,48 +86,51 @@ import ./make-test.nix ({ pkgs, ...} : {
8686 };
8787
8888 testScript = ''
89− startAll;
90−
91− subtest "prepare server", sub {
92− $server->waitForUnit("default.target");
93− $server->succeed("ip link show dev eth1 >&2");
94− };
95−
96− subtest "simple physical interface", sub {
97− $server->succeed("nixos-container start server");
98− $server->waitForUnit("container\@server");
99− $server->succeed("systemctl -M server list-dependencies network-addresses-eth1.service >&2");
100−
101− # The other tests will ping this container on its ip. Here we just check
102− # that the device is present in the container.
103− $server->succeed("nixos-container run server -- ip a show dev eth1 >&2");
104− };
105−
106− subtest "physical device in bridge in container", sub {
107− $bridged->waitForUnit("default.target");
108− $bridged->succeed("nixos-container start bridged");
109− $bridged->waitForUnit("container\@bridged");
110− $bridged->succeed("systemctl -M bridged list-dependencies network-addresses-br0.service >&2");
111− $bridged->succeed("systemctl -M bridged status -n 30 -l network-addresses-br0.service");
112− $bridged->succeed("nixos-container run bridged -- ping -w 10 -c 1 -n 10.10.0.1");
113− };
114−
115− subtest "physical device in bond in container", sub {
116− $bonded->waitForUnit("default.target");
117− $bonded->succeed("nixos-container start bonded");
118− $bonded->waitForUnit("container\@bonded");
119− $bonded->succeed("systemctl -M bonded list-dependencies network-addresses-bond0 >&2");
120− $bonded->succeed("systemctl -M bonded status -n 30 -l network-addresses-bond0 >&2");
121− $bonded->succeed("nixos-container run bonded -- ping -w 10 -c 1 -n 10.10.0.1");
122− };
123−
124− subtest "physical device in bond in bridge in container", sub {
125− $bridgedbond->waitForUnit("default.target");
126− $bridgedbond->succeed("nixos-container start bridgedbond");
127− $bridgedbond->waitForUnit("container\@bridgedbond");
128− $bridgedbond->succeed("systemctl -M bridgedbond list-dependencies network-addresses-br0.service >&2");
129− $bridgedbond->succeed("systemctl -M bridgedbond status -n 30 -l network-addresses-br0.service");
130− $bridgedbond->succeed("nixos-container run bridgedbond -- ping -w 10 -c 1 -n 10.10.0.1");
131− };
89+ start_all()
90+
91+ with subtest("Prepare server"):
92+ server.wait_for_unit("default.target")
93+ server.succeed("ip link show dev eth1 >&2")
94+
95+ with subtest("Simple physical interface is up"):
96+ server.succeed("nixos-container start server")
97+ server.wait_for_unit("container@server")
98+ server.succeed(
99+ "systemctl -M server list-dependencies network-addresses-eth1.service >&2"
100+ )
101+
102+ # The other tests will ping this container on its ip. Here we just check
103+ # that the device is present in the container.
104+ server.succeed("nixos-container run server -- ip a show dev eth1 >&2")
105+
106+ with subtest("Physical device in bridge in container can ping server"):
107+ bridged.wait_for_unit("default.target")
108+ bridged.succeed("nixos-container start bridged")
109+ bridged.wait_for_unit("container@bridged")
110+ bridged.succeed(
111+ "systemctl -M bridged list-dependencies network-addresses-br0.service >&2",
112+ "systemctl -M bridged status -n 30 -l network-addresses-br0.service",
113+ "nixos-container run bridged -- ping -w 10 -c 1 -n 10.10.0.1",
114+ )
115+
116+ with subtest("Physical device in bond in container can ping server"):
117+ bonded.wait_for_unit("default.target")
118+ bonded.succeed("nixos-container start bonded")
119+ bonded.wait_for_unit("container@bonded")
120+ bonded.succeed(
121+ "systemctl -M bonded list-dependencies network-addresses-bond0 >&2",
122+ "systemctl -M bonded status -n 30 -l network-addresses-bond0 >&2",
123+ "nixos-container run bonded -- ping -w 10 -c 1 -n 10.10.0.1",
124+ )
125+
126+ with subtest("Physical device in bond in bridge in container can ping server"):
127+ bridgedbond.wait_for_unit("default.target")
128+ bridgedbond.succeed("nixos-container start bridgedbond")
129+ bridgedbond.wait_for_unit("container@bridgedbond")
130+ bridgedbond.succeed(
131+ "systemctl -M bridgedbond list-dependencies network-addresses-br0.service >&2",
132+ "systemctl -M bridgedbond status -n 30 -l network-addresses-br0.service",
133+ "nixos-container run bridgedbond -- ping -w 10 -c 1 -n 10.10.0.1",
134+ )
132135 '';
133136})
nixos/tests/containers-portforward.nix+11−11
@@ -7,7 +7,7 @@ let
77 containerPort = 80;
88in
99
10−import ./make-test.nix ({ pkgs, ...} : {
10+import ./make-test-python.nix ({ pkgs, ...} : {
1111 name = "containers-portforward";
1212 meta = with pkgs.stdenv.lib.maintainers; {
1313 maintainers = [ aristid aszlig eelco kampfschlaefer ianwookim ];
@@ -36,27 +36,27 @@ import ./make-test.nix ({ pkgs, ...} : {
3636
3737 testScript =
3838 ''
39− $machine->succeed("nixos-container list") =~ /webserver/ or die;
39+ container_list = machine.succeed("nixos-container list")
40+ assert "webserver" in container_list
4041
4142 # Start the webserver container.
42− $machine->succeed("nixos-container start webserver");
43+ machine.succeed("nixos-container start webserver")
4344
4445 # wait two seconds for the container to start and the network to be up
45− sleep 2;
46+ machine.sleep(2)
4647
4748 # Since "start" returns after the container has reached
4849 # multi-user.target, we should now be able to access it.
49− #my $ip = $machine->succeed("nixos-container show-ip webserver");
50− #chomp $ip;
51− $machine->succeed("ping -n -c1 ${hostIp}");
52− $machine->succeed("curl --fail http://${hostIp}:${toString hostPort}/ > /dev/null");
50+ # ip = machine.succeed("nixos-container show-ip webserver").strip()
51+ machine.succeed("ping -n -c1 ${hostIp}")
52+ machine.succeed("curl --fail http://${hostIp}:${toString hostPort}/ > /dev/null")
5353
5454 # Stop the container.
55− $machine->succeed("nixos-container stop webserver");
56− $machine->fail("curl --fail --connect-timeout 2 http://${hostIp}:${toString hostPort}/ > /dev/null");
55+ machine.succeed("nixos-container stop webserver")
56+ machine.fail("curl --fail --connect-timeout 2 http://${hostIp}:${toString hostPort}/ > /dev/null")
5757
5858 # Destroying a declarative container should fail.
59− $machine->fail("nixos-container destroy webserver");
59+ machine.fail("nixos-container destroy webserver")
6060 '';
6161
6262})
nixos/tests/containers-restart_networking.nix+46−44
@@ -16,7 +16,7 @@ let
1616 };
1717 };
1818 };
19−in import ./make-test.nix ({ pkgs, ...} :
19+in import ./make-test-python.nix ({ pkgs, ...} :
2020{
2121 name = "containers-restart_networking";
2222 meta = with pkgs.stdenv.lib.maintainers; {
@@ -64,50 +64,52 @@ in import ./make-test.nix ({ pkgs, ...} :
6464 eth1_bridged = nodes.client_eth1.config.system.build.toplevel;
6565 eth1_rstp = nodes.client_eth1_rstp.config.system.build.toplevel;
6666 in ''
67− $client->start();
68−
69− $client->waitForUnit("default.target");
70−
71− subtest "initial state", sub {
72− $client->succeed("ping 192.168.1.122 -c 1 -n >&2");
73− $client->succeed("nixos-container run webserver -- ping -c 1 -n 192.168.1.1 >&2");
74−
75− $client->fail("ip l show eth1 |grep \"master br0\" >&2");
76− $client->fail("grep eth1 /run/br0.interfaces >&2");
77− };
78−
79− subtest "interfaces without stp", sub {
80− $client->succeed("${eth1_bridged}/bin/switch-to-configuration test >&2");
81−
82− $client->succeed("ping 192.168.1.122 -c 1 -n >&2");
83− $client->succeed("nixos-container run webserver -- ping -c 1 -n 192.168.1.2 >&2");
84−
85− $client->succeed("ip l show eth1 |grep \"master br0\" >&2");
86− $client->succeed("grep eth1 /run/br0.interfaces >&2");
87− };
88−
89− # activating rstp needs another service, therefor the bridge will restart and the container will loose its connectivity
90− #subtest "interfaces with rstp", sub {
91− # $client->succeed("${eth1_rstp}/bin/switch-to-configuration test >&2");
92− # $client->execute("ip -4 a >&2");
93− # $client->execute("ip l >&2");
67+ client.start()
68+
69+ client.wait_for_unit("default.target")
70+
71+ with subtest("Initial configuration connectivity check"):
72+ client.succeed("ping 192.168.1.122 -c 1 -n >&2")
73+ client.succeed("nixos-container run webserver -- ping -c 1 -n 192.168.1.1 >&2")
74+
75+ client.fail("ip l show eth1 |grep 'master br0' >&2")
76+ client.fail("grep eth1 /run/br0.interfaces >&2")
77+
78+ with subtest("Bridged configuration without STP preserves connectivity"):
79+ client.succeed(
80+ "${eth1_bridged}/bin/switch-to-configuration test >&2"
81+ )
82+
83+ client.succeed(
84+ "ping 192.168.1.122 -c 1 -n >&2",
85+ "nixos-container run webserver -- ping -c 1 -n 192.168.1.2 >&2",
86+ "ip l show eth1 |grep 'master br0' >&2",
87+ "grep eth1 /run/br0.interfaces >&2",
88+ )
89+
90+ # activating rstp needs another service, therefore the bridge will restart and the container will lose its connectivity
91+ # with subtest("Bridged configuration with STP"):
92+ # client.succeed("${eth1_rstp}/bin/switch-to-configuration test >&2")
93+ # client.execute("ip -4 a >&2")
94+ # client.execute("ip l >&2")
9495 #
95− # $client->succeed("ping 192.168.1.122 -c 1 -n >&2");
96− # $client->succeed("nixos-container run webserver -- ping -c 1 -n 192.168.1.2 >&2");
97− #
98− # $client->succeed("ip l show eth1 |grep \"master br0\" >&2");
99− # $client->succeed("grep eth1 /run/br0.interfaces >&2");
100− #};
101−
102− subtest "back to no interfaces and no stp", sub {
103− $client->succeed("${originalSystem}/bin/switch-to-configuration test >&2");
104−
105− $client->succeed("ping 192.168.1.122 -c 1 -n >&2");
106− $client->succeed("nixos-container run webserver -- ping -c 1 -n 192.168.1.1 >&2");
107−
108− $client->fail("ip l show eth1 |grep \"master br0\" >&2");
109− $client->fail("grep eth1 /run/br0.interfaces >&2");
110− };
96+ # client.succeed(
97+ # "ping 192.168.1.122 -c 1 -n >&2",
98+ # "nixos-container run webserver -- ping -c 1 -n 192.168.1.2 >&2",
99+ # "ip l show eth1 |grep 'master br0' >&2",
100+ # "grep eth1 /run/br0.interfaces >&2",
101+ # )
102+
103+ with subtest("Reverting to initial configuration preserves connectivity"):
104+ client.succeed(
105+ "${originalSystem}/bin/switch-to-configuration test >&2"
106+ )
107+
108+ client.succeed("ping 192.168.1.122 -c 1 -n >&2")
109+ client.succeed("nixos-container run webserver -- ping -c 1 -n 192.168.1.1 >&2")
110+
111+ client.fail("ip l show eth1 |grep 'master br0' >&2")
112+ client.fail("grep eth1 /run/br0.interfaces >&2")
111113 '';
112114
113115})