summary refs log tree commit diff
path: root/nixos/tests/common/ec2.nix
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2020-08-23 10:35:28 +0200
committerGitHub <noreply@github.com>2020-08-23 10:35:28 +0200
commit4460cda6b5807ea19b97e34c1dfcbba57b137118 (patch)
treec3ed6613a418d8d0763c1621393b2915abe3c2f9 /nixos/tests/common/ec2.nix
parent36f7483da23aa3005e56d9a8e3b53d2437c0598a (diff)
parent97a32bcd082a32f8a4de68121f86f878b9b4bc9e (diff)
downloadnixpkgs-4460cda6b5807ea19b97e34c1dfcbba57b137118.tar
nixpkgs-4460cda6b5807ea19b97e34c1dfcbba57b137118.tar.gz
nixpkgs-4460cda6b5807ea19b97e34c1dfcbba57b137118.tar.bz2
nixpkgs-4460cda6b5807ea19b97e34c1dfcbba57b137118.tar.lz
nixpkgs-4460cda6b5807ea19b97e34c1dfcbba57b137118.tar.xz
nixpkgs-4460cda6b5807ea19b97e34c1dfcbba57b137118.tar.zst
nixpkgs-4460cda6b5807ea19b97e34c1dfcbba57b137118.zip
Merge pull request #79696 from tfc/port-ec2-test
nixosTests.ec2: Port tests that depend on common/ec2.nix
Diffstat (limited to 'nixos/tests/common/ec2.nix')
-rw-r--r--nixos/tests/common/ec2.nix58
1 files changed, 36 insertions, 22 deletions
diff --git a/nixos/tests/common/ec2.nix b/nixos/tests/common/ec2.nix
index ba087bb6009..502fe96231f 100644
--- a/nixos/tests/common/ec2.nix
+++ b/nixos/tests/common/ec2.nix
@@ -20,30 +20,44 @@ with pkgs.lib;
     in makeTest {
       name = "ec2-" + name;
       nodes = {};
-      testScript =
-        ''
-          my $imageDir = ($ENV{'TMPDIR'} // "/tmp") . "/vm-state-machine";
-          mkdir $imageDir, 0700;
-          my $diskImage = "$imageDir/machine.qcow2";
-          system("qemu-img create -f qcow2 -o backing_file=${image} $diskImage") == 0 or die;
-          system("qemu-img resize $diskImage 10G") == 0 or die;
+      testScript = ''
+        import os
+        import subprocess
 
-          # Note: we use net=169.0.0.0/8 rather than
-          # net=169.254.0.0/16 to prevent dhcpcd from getting horribly
-          # confused. (It would get a DHCP lease in the 169.254.*
-          # range, which it would then configure and prompty delete
-          # again when it deletes link-local addresses.) Ideally we'd
-          # turn off the DHCP server, but qemu does not have an option
-          # to do that.
-          my $startCommand = "qemu-kvm -m 1024";
-          $startCommand .= " -device virtio-net-pci,netdev=vlan0";
-          $startCommand .= " -netdev 'user,id=vlan0,net=169.0.0.0/8,guestfwd=tcp:169.254.169.254:80-cmd:${pkgs.micro-httpd}/bin/micro_httpd ${metaData}'";
-          $startCommand .= " -drive file=$diskImage,if=virtio,werror=report";
-          $startCommand .= " \$QEMU_OPTS";
+        image_dir = os.path.join(
+            os.environ.get("TMPDIR", tempfile.gettempdir()), "tmp", "vm-state-machine"
+        )
+        os.makedirs(image_dir, mode=0o700, exist_ok=True)
+        disk_image = os.path.join(image_dir, "machine.qcow2")
+        subprocess.check_call(
+            [
+                "qemu-img",
+                "create",
+                "-f",
+                "qcow2",
+                "-o",
+                "backing_file=${image}",
+                disk_image,
+            ]
+        )
+        subprocess.check_call(["qemu-img", "resize", disk_image, "10G"])
 
-          my $machine = createMachine({ startCommand => $startCommand });
+        # Note: we use net=169.0.0.0/8 rather than
+        # net=169.254.0.0/16 to prevent dhcpcd from getting horribly
+        # confused. (It would get a DHCP lease in the 169.254.*
+        # range, which it would then configure and prompty delete
+        # again when it deletes link-local addresses.) Ideally we'd
+        # turn off the DHCP server, but qemu does not have an option
+        # to do that.
+        start_command = (
+            "qemu-kvm -m 1024"
+            + " -device virtio-net-pci,netdev=vlan0"
+            + " -netdev 'user,id=vlan0,net=169.0.0.0/8,guestfwd=tcp:169.254.169.254:80-cmd:${pkgs.micro-httpd}/bin/micro_httpd ${metaData}'"
+            + f" -drive file={disk_image},if=virtio,werror=report"
+            + " $QEMU_OPTS"
+        )
 
-          ${script}
-        '';
+        machine = create_machine({"startCommand": start_command})
+      '' + script;
     };
 }