about summary refs log tree commit diff
path: root/nixpkgs/nixos/tests/containers-ephemeral.nix
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2019-08-31 11:57:05 +0000
committerAlyssa Ross <hi@alyssa.is>2019-09-16 22:04:28 +0000
commita0842e8b20cbe1ed717b72775428d1f8fc047fa4 (patch)
treeb86d0614a477f7e092d626d59b888d085aaca400 /nixpkgs/nixos/tests/containers-ephemeral.nix
parentc36b32d476b520ed0d2a37cd0973f98583d6dc7c (diff)
parent8d1510abfb592339e13ce8f6db6f29c1f8b72924 (diff)
downloadnixlib-a0842e8b20cbe1ed717b72775428d1f8fc047fa4.tar
nixlib-a0842e8b20cbe1ed717b72775428d1f8fc047fa4.tar.gz
nixlib-a0842e8b20cbe1ed717b72775428d1f8fc047fa4.tar.bz2
nixlib-a0842e8b20cbe1ed717b72775428d1f8fc047fa4.tar.lz
nixlib-a0842e8b20cbe1ed717b72775428d1f8fc047fa4.tar.xz
nixlib-a0842e8b20cbe1ed717b72775428d1f8fc047fa4.tar.zst
nixlib-a0842e8b20cbe1ed717b72775428d1f8fc047fa4.zip
Merge commit '8d1510abfb592339e13ce8f6db6f29c1f8b72924'
Diffstat (limited to 'nixpkgs/nixos/tests/containers-ephemeral.nix')
-rw-r--r--nixpkgs/nixos/tests/containers-ephemeral.nix56
1 files changed, 56 insertions, 0 deletions
diff --git a/nixpkgs/nixos/tests/containers-ephemeral.nix b/nixpkgs/nixos/tests/containers-ephemeral.nix
new file mode 100644
index 000000000000..1ef8717d9a0e
--- /dev/null
+++ b/nixpkgs/nixos/tests/containers-ephemeral.nix
@@ -0,0 +1,56 @@
+# Test for NixOS' container support.
+
+import ./make-test.nix ({ pkgs, ...} : {
+  name = "containers-ephemeral";
+
+  machine = { pkgs, ... }: {
+    virtualisation.memorySize = 768;
+    virtualisation.writableStore = true;
+
+    containers.webserver = {
+      ephemeral = true;
+      privateNetwork = true;
+      hostAddress = "10.231.136.1";
+      localAddress = "10.231.136.2";
+      config = {
+        services.nginx = {
+          enable = true;
+          virtualHosts.localhost = {
+            root = (pkgs.runCommand "localhost" {} ''
+              mkdir "$out"
+              echo hello world > "$out/index.html"
+            '');
+          };
+        };
+        networking.firewall.allowedTCPPorts = [ 80 ];
+      };
+    };
+  };
+
+  testScript = ''
+    $machine->succeed("nixos-container list") =~ /webserver/ or die;
+
+    # Start the webserver container.
+    $machine->succeed("nixos-container start webserver");
+
+    # Check that container got its own root folder
+    $machine->succeed("ls /run/containers/webserver");
+
+    # Check that container persistent directory is not created
+    $machine->fail("ls /var/lib/containers/webserver");
+
+    # Since "start" returns after the container has reached
+    # multi-user.target, we should now be able to access it.
+    my $ip = $machine->succeed("nixos-container show-ip webserver");
+    chomp $ip;
+    $machine->succeed("ping -n -c1 $ip");
+    $machine->succeed("curl --fail http://$ip/ > /dev/null");
+
+    # Stop the container.
+    $machine->succeed("nixos-container stop webserver");
+    $machine->fail("curl --fail --connect-timeout 2 http://$ip/ > /dev/null");
+
+    # Check that container's root folder was removed
+    $machine->fail("ls /run/containers/webserver");
+  '';
+})