···
pkgs ? import ../.. { inherit system config; }
6
-
with import ../lib/testing.nix { inherit system pkgs; };
6
+
with import ../lib/testing-python.nix { inherit system pkgs; };
with import common/ec2.nix { inherit makeTest pkgs; };
13
-
(import ../lib/eval-config.nix {
16
-
../maintainers/scripts/ec2/amazon-image.nix
17
-
../modules/testing/test-instrumentation.nix
18
-
../modules/profiles/qemu-guest.nix
12
+
imageCfg = (import ../lib/eval-config.nix {
15
+
../maintainers/scripts/ec2/amazon-image.nix
16
+
../modules/testing/test-instrumentation.nix
17
+
../modules/profiles/qemu-guest.nix
21
-
# Hack to make the partition resizing work in QEMU.
22
-
boot.initrd.postDeviceCommands = mkBefore
25
-
ln -s vda1 /dev/xvda1
21
+
# Hack to make the partition resizing work in QEMU.
22
+
boot.initrd.postDeviceCommands = mkBefore ''
24
+
ln -s vda1 /dev/xvda1
28
-
# Needed by nixos-rebuild due to the lack of network
29
-
# access. Determined by trial and error.
30
-
system.extraDependencies =
33
-
# Needed for a nixos-rebuild.
37
-
mkinitcpio-nfs-utils
27
+
# Needed by nixos-rebuild due to the lack of network
28
+
# access. Determined by trial and error.
29
+
system.extraDependencies = with pkgs; ( [
30
+
# Needed for a nixos-rebuild.
35
+
mkinitcpio-nfs-utils
45
-
# These are used in the configure-from-userdata tests
46
-
# for EC2. Httpd and valgrind are requested by the
48
-
apacheHttpd apacheHttpd.doc apacheHttpd.man valgrind.doc
42
+
# These are used in the configure-from-userdata tests
43
+
# for EC2. Httpd and valgrind are requested by the
image = "${imageCfg.system.build.amazonImage}/${imageCfg.amazonImage.name}.vhd";
sshKeys = import ./ssh-keys.nix pkgs;
snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text;
57
+
snakeOilPrivateKeyFile = pkgs.writeText "private-key" snakeOilPrivateKey;
snakeOilPublicKey = sshKeys.snakeOilPublicKey;
···
SSH_HOST_ED25519_KEY:${replaceStrings ["\n"] ["|"] snakeOilPrivateKey}
72
-
$machine->waitForFile("/etc/ec2-metadata/user-data");
73
-
$machine->waitForUnit("sshd.service");
72
+
machine.wait_for_file("/etc/ec2-metadata/user-data")
73
+
machine.wait_for_unit("sshd.service")
75
-
$machine->succeed("grep unknown /etc/ec2-metadata/ami-manifest-path");
75
+
machine.succeed("grep unknown /etc/ec2-metadata/ami-manifest-path")
# We have no keys configured on the client side yet, so this should fail
78
-
$machine->fail("ssh -o BatchMode=yes localhost exit");
78
+
machine.fail("ssh -o BatchMode=yes localhost exit")
# Let's install our client private key
81
-
$machine->succeed("mkdir -p ~/.ssh");
81
+
machine.succeed("mkdir -p ~/.ssh")
83
-
$machine->succeed("echo '${snakeOilPrivateKey}' > ~/.ssh/id_ed25519");
84
-
$machine->succeed("chmod 600 ~/.ssh/id_ed25519");
83
+
machine.copy_from_host_via_shell(
84
+
"${snakeOilPrivateKeyFile}", "~/.ssh/id_ed25519"
86
+
machine.succeed("chmod 600 ~/.ssh/id_ed25519")
# We haven't configured the host key yet, so this should still fail
87
-
$machine->fail("ssh -o BatchMode=yes localhost exit");
89
+
machine.fail("ssh -o BatchMode=yes localhost exit")
# Add the host key; ssh should finally succeed
90
-
$machine->succeed("echo localhost,127.0.0.1 ${snakeOilPublicKey} > ~/.ssh/known_hosts");
91
-
$machine->succeed("ssh -o BatchMode=yes localhost exit");
93
+
"echo localhost,127.0.0.1 ${snakeOilPublicKey} > ~/.ssh/known_hosts"
95
+
machine.succeed("ssh -o BatchMode=yes localhost exit")
# Test whether the root disk was resized.
94
-
my $blocks = $machine->succeed("stat -c %b -f /");
95
-
my $bsize = $machine->succeed("stat -c %S -f /");
96
-
my $size = $blocks * $bsize;
97
-
die "wrong free space $size" if $size < 9.7 * 1024 * 1024 * 1024 || $size > 10 * 1024 * 1024 * 1024;
98
+
blocks, block_size = map(int, machine.succeed("stat -c %b:%S -f /").split(":"))
100
+
assert 9.7 * GB <= blocks * block_size <= 10 * GB
# Just to make sure resizing is idempotent.
100
-
$machine->shutdown;
102
-
$machine->waitForFile("/etc/ec2-metadata/user-data");
105
+
machine.wait_for_file("/etc/ec2-metadata/user-data")
boot-ec2-config = makeEc2Test {
name = "config-userdata";
111
+
meta.broken = true; # amazon-init wants to download from the internet while building the system
sshPublicKey = snakeOilPublicKey;
···
# amazon-init must succeed. if it fails, make the test fail
139
-
# immediately instead of timing out in waitForFile.
140
-
$machine->waitForUnit('amazon-init.service');
143
+
# immediately instead of timing out in wait_for_file.
144
+
machine.wait_for_unit("amazon-init.service")
142
-
$machine->waitForFile("/etc/testFile");
143
-
$machine->succeed("cat /etc/testFile | grep -q 'whoa'");
146
+
machine.wait_for_file("/etc/testFile")
147
+
assert "whoa" in machine.succeed("cat /etc/testFile")
145
-
$machine->waitForUnit("httpd.service");
146
-
$machine->succeed("curl http://localhost | grep Valgrind");
149
+
machine.wait_for_unit("httpd.service")
150
+
assert "Valgrind" in machine.succeed("curl http://localhost")