blob: 152a6590bbaae70c2b5ad16a272d8a808ed59ae4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
{ pkgs, lib, ... }:
{
name = "containers-extra_veth";
meta = {
};
nodes.machine =
{ pkgs, ... }:
{
imports = [ ../modules/installer/cd-dvd/channel.nix ];
virtualisation.writableStore = true;
virtualisation.vlans = [ ];
networking.useDHCP = false;
networking.bridges = {
br0 = {
interfaces = [ ];
};
br1 = {
interfaces = [ ];
};
};
networking.interfaces = {
br0 = {
ipv4.addresses = [
{
address = "192.168.0.1";
prefixLength = 24;
}
];
ipv6.addresses = [
{
address = "fc00::1";
prefixLength = 7;
}
];
};
br1 = {
ipv4.addresses = [
{
address = "192.168.1.1";
prefixLength = 24;
}
];
};
};
containers.webserver = {
autoStart = true;
privateNetwork = true;
hostBridge = "br0";
localAddress = "192.168.0.100/24";
localAddress6 = "fc00::2/7";
extraVeths = {
veth1 = {
hostBridge = "br1";
localAddress = "192.168.1.100/24";
};
veth2 = {
hostAddress = "192.168.2.1";
localAddress = "192.168.2.100";
};
};
config = {
networking.firewall.allowedTCPPorts = [ 80 ];
nix.enable = false; # disabled by default on the test's host. See all-tests.nix / tag(no-nix-by-default)
};
};
virtualisation.additionalPaths = [ pkgs.stdenv ];
};
testScript = ''
machine.wait_for_unit("default.target")
assert "webserver" in machine.succeed("nixos-container list")
with subtest("Status of the webserver container is up"):
assert "up" in machine.succeed("nixos-container status webserver")
with subtest("Ensure that the veths are inside the container"):
assert "state UP" in machine.succeed(
"nixos-container run webserver -- ip link show veth1"
)
assert "state UP" in machine.succeed(
"nixos-container run webserver -- ip link show veth2"
)
with subtest("Ensure the presence of the extra veths"):
assert "state UP" in machine.succeed("ip link show veth1")
assert "state UP" in machine.succeed("ip link show veth2")
with subtest("Ensure the veth1 is part of br1 on the host"):
assert "master br1" in machine.succeed("ip link show veth1")
with subtest("Ping on main veth"):
machine.succeed("ping -n -c 1 192.168.0.100")
machine.succeed("ping -n -c 1 fc00::2")
with subtest("Ping on the first extra veth"):
machine.succeed("ping -n -c 1 192.168.1.100 >&2")
with subtest("Ping on the second extra veth"):
machine.succeed("ping -n -c 1 192.168.2.100 >&2")
with subtest("Container can be stopped"):
machine.succeed("nixos-container stop webserver")
machine.fail("ping -n -c 1 192.168.1.100 >&2")
machine.fail("ping -n -c 1 192.168.2.100 >&2")
with subtest("Destroying a declarative container should fail"):
machine.fail("nixos-container destroy webserver")
'';
}
|