@@ -3,58 +3,58 @@
33 pkgs ? import ../.. { inherit system config; }
44}:
55
6−with import ../lib/testing.nix { inherit system pkgs; };
6+with import ../lib/testing-python.nix { inherit system pkgs; };
77with pkgs.lib;
88
99with import common/ec2.nix { inherit makeTest pkgs; };
1010
1111let
12− imageCfg =
13− (import ../lib/eval-config.nix {
14− inherit system;
15− modules = [
16− ../maintainers/scripts/ec2/amazon-image.nix
17− ../modules/testing/test-instrumentation.nix
18− ../modules/profiles/qemu-guest.nix
19− { ec2.hvm = true;
20−
21− # Hack to make the partition resizing work in QEMU.
22− boot.initrd.postDeviceCommands = mkBefore
23− ''
24− ln -s vda /dev/xvda
25− ln -s vda1 /dev/xvda1
26− '';
27−
28− # Needed by nixos-rebuild due to the lack of network
29− # access. Determined by trial and error.
30− system.extraDependencies =
31− with pkgs; (
32− [
33− # Needed for a nixos-rebuild.
34− busybox
35− stdenv
36− stdenvNoCC
37− mkinitcpio-nfs-utils
38− unionfs-fuse
39− cloud-utils
40− desktop-file-utils
41− texinfo
42− libxslt.bin
43− xorg.lndir
44−
45− # These are used in the configure-from-userdata tests
46− # for EC2. Httpd and valgrind are requested by the
47− # configuration.
48− apacheHttpd apacheHttpd.doc apacheHttpd.man valgrind.doc
49− ]
50− );
51− }
52− ];
53− }).config;
12+ imageCfg = (import ../lib/eval-config.nix {
13+ inherit system;
14+ modules = [
15+ ../maintainers/scripts/ec2/amazon-image.nix
16+ ../modules/testing/test-instrumentation.nix
17+ ../modules/profiles/qemu-guest.nix
18+ {
19+ ec2.hvm = true;
20+
21+ # Hack to make the partition resizing work in QEMU.
22+ boot.initrd.postDeviceCommands = mkBefore ''
23+ ln -s vda /dev/xvda
24+ ln -s vda1 /dev/xvda1
25+ '';
26+
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.
31+ busybox
32+ cloud-utils
33+ desktop-file-utils
34+ libxslt.bin
35+ mkinitcpio-nfs-utils
36+ stdenv
37+ stdenvNoCC
38+ texinfo
39+ unionfs-fuse
40+ xorg.lndir
41+
42+ # These are used in the configure-from-userdata tests
43+ # for EC2. Httpd and valgrind are requested by the
44+ # configuration.
45+ apacheHttpd
46+ apacheHttpd.doc
47+ apacheHttpd.man
48+ valgrind.doc
49+ ]);
50+ }
51+ ];
52+ }).config;
5453 image = "${imageCfg.system.build.amazonImage}/${imageCfg.amazonImage.name}.vhd";
5554
5655 sshKeys = import ./ssh-keys.nix pkgs;
5756 snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text;
57+ snakeOilPrivateKeyFile = pkgs.writeText "private-key" snakeOilPrivateKey;
5858 snakeOilPublicKey = sshKeys.snakeOilPublicKey;
5959
6060in {
@@ -68,38 +68,41 @@ in {
6868 SSH_HOST_ED25519_KEY:${replaceStrings ["\n"] ["|"] snakeOilPrivateKey}
6969 '';
7070 script = ''
71− $machine->start;
72− $machine->waitForFile("/etc/ec2-metadata/user-data");
73− $machine->waitForUnit("sshd.service");
71+ machine.start()
72+ machine.wait_for_file("/etc/ec2-metadata/user-data")
73+ machine.wait_for_unit("sshd.service")
7474
75− $machine->succeed("grep unknown /etc/ec2-metadata/ami-manifest-path");
75+ machine.succeed("grep unknown /etc/ec2-metadata/ami-manifest-path")
7676
7777 # 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")
7979
8080 # Let's install our client private key
81− $machine->succeed("mkdir -p ~/.ssh");
81+ machine.succeed("mkdir -p ~/.ssh")
8282
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"
85+ )
86+ machine.succeed("chmod 600 ~/.ssh/id_ed25519")
8587
8688 # 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")
8890
8991 # 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");
92+ machine.succeed(
93+ "echo localhost,127.0.0.1 ${snakeOilPublicKey} > ~/.ssh/known_hosts"
94+ )
95+ machine.succeed("ssh -o BatchMode=yes localhost exit")
9296
9397 # 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(":"))
99+ GB = 1024 ** 3
100+ assert 9.7 * GB <= blocks * block_size <= 10 * GB
98101
99102 # Just to make sure resizing is idempotent.
100− $machine->shutdown;
101− $machine->start;
102− $machine->waitForFile("/etc/ec2-metadata/user-data");
103+ machine.shutdown()
104+ machine.start()
105+ machine.wait_for_file("/etc/ec2-metadata/user-data")
103106 '';
104107 };
105108
@@ -133,17 +136,17 @@ in {
133136 }
134137 '';
135138 script = ''
136− $machine->start;
139+ machine.start()
137140
138141 # 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');
142+ # immediately instead of timing out in wait_for_file.
143+ machine.wait_for_unit("amazon-init.service")
141144
142− $machine->waitForFile("/etc/testFile");
143− $machine->succeed("cat /etc/testFile | grep -q 'whoa'");
145+ machine.wait_for_file("/etc/testFile")
146+ assert "whoa" in machine.succeed("cat /etc/testFile")
144147
145− $machine->waitForUnit("httpd.service");
146− $machine->succeed("curl http://localhost | grep Valgrind");
148+ machine.wait_for_unit("httpd.service")
149+ assert "Valgrind" in machine.succeed("curl http://localhost")
147150 '';
148151 };
149152}