mirror of
https://github.com/NixOS/nix
synced 2025-06-25 14:51:16 +02:00
tests: Wait for network *online* targets
More prevalent than I thought in15073e86a
See also3588783032
which is a failed github-flakes test without "Network is Online" (cherry picked from commit6f0bdd9ae7
) # Conflicts: # tests/nixos/nix-docker.nix
This commit is contained in:
parent
df5246dd8e
commit
0284eef493
6 changed files with 64 additions and 0 deletions
|
@ -46,6 +46,7 @@
|
||||||
remote.wait_for_unit("sshd")
|
remote.wait_for_unit("sshd")
|
||||||
remote.wait_for_unit("multi-user.target")
|
remote.wait_for_unit("multi-user.target")
|
||||||
remote.wait_for_unit("network-online.target")
|
remote.wait_for_unit("network-online.target")
|
||||||
|
client.wait_for_unit("network-online.target")
|
||||||
client.succeed(f"ssh -o StrictHostKeyChecking=no {remote.name} 'echo hello world'")
|
client.succeed(f"ssh -o StrictHostKeyChecking=no {remote.name} 'echo hello world'")
|
||||||
|
|
||||||
remote.succeed("""
|
remote.succeed("""
|
||||||
|
|
|
@ -161,7 +161,9 @@ in
|
||||||
github.succeed("cat /var/log/httpd/*.log >&2")
|
github.succeed("cat /var/log/httpd/*.log >&2")
|
||||||
|
|
||||||
github.wait_for_unit("httpd.service")
|
github.wait_for_unit("httpd.service")
|
||||||
|
github.wait_for_unit("network-online.target")
|
||||||
|
|
||||||
|
client.wait_for_unit("network-online.target")
|
||||||
client.succeed("curl -v https://github.com/ >&2")
|
client.succeed("curl -v https://github.com/ >&2")
|
||||||
out = client.succeed("nix registry list")
|
out = client.succeed("nix registry list")
|
||||||
print(out)
|
print(out)
|
||||||
|
|
54
tests/nixos/nix-docker.nix
Normal file
54
tests/nixos/nix-docker.nix
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
# Test the container built by ../../docker.nix.
|
||||||
|
|
||||||
|
{ lib, config, nixpkgs, hostPkgs, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
pkgs = config.nodes.machine.nixpkgs.pkgs;
|
||||||
|
|
||||||
|
nixImage = import ../../docker.nix {
|
||||||
|
inherit (config.nodes.machine.nixpkgs) pkgs;
|
||||||
|
};
|
||||||
|
nixUserImage = import ../../docker.nix {
|
||||||
|
inherit (config.nodes.machine.nixpkgs) pkgs;
|
||||||
|
name = "nix-user";
|
||||||
|
uid = 1000;
|
||||||
|
gid = 1000;
|
||||||
|
uname = "user";
|
||||||
|
gname = "user";
|
||||||
|
};
|
||||||
|
|
||||||
|
containerTestScript = ./nix-docker-test.sh;
|
||||||
|
|
||||||
|
in {
|
||||||
|
name = "nix-docker";
|
||||||
|
|
||||||
|
nodes =
|
||||||
|
{ machine =
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
{ virtualisation.diskSize = 4096;
|
||||||
|
};
|
||||||
|
cache =
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
{ virtualisation.additionalPaths = [ pkgs.stdenv pkgs.hello ];
|
||||||
|
services.harmonia.enable = true;
|
||||||
|
networking.firewall.allowedTCPPorts = [ 5000 ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
testScript = { nodes }: ''
|
||||||
|
cache.wait_for_unit("harmonia.service")
|
||||||
|
cache.wait_for_unit("network-online.target")
|
||||||
|
|
||||||
|
machine.succeed("mkdir -p /etc/containers")
|
||||||
|
machine.succeed("""echo '{"default":[{"type":"insecureAcceptAnything"}]}' > /etc/containers/policy.json""")
|
||||||
|
|
||||||
|
machine.succeed("${pkgs.podman}/bin/podman load -i ${nixImage}")
|
||||||
|
machine.succeed("${pkgs.podman}/bin/podman run --rm nix nix --version")
|
||||||
|
machine.succeed("${pkgs.podman}/bin/podman run --rm -i nix < ${containerTestScript}")
|
||||||
|
|
||||||
|
machine.succeed("${pkgs.podman}/bin/podman load -i ${nixUserImage}")
|
||||||
|
machine.succeed("${pkgs.podman}/bin/podman run --rm nix-user nix --version")
|
||||||
|
machine.succeed("${pkgs.podman}/bin/podman run --rm -i nix-user < ${containerTestScript}")
|
||||||
|
machine.succeed("[[ $(${pkgs.podman}/bin/podman run --rm nix-user stat -c %u /nix/store) = 1000 ]]")
|
||||||
|
'';
|
||||||
|
}
|
|
@ -102,6 +102,7 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
testScript = { nodes, ... }: ''
|
testScript = { nodes, ... }: ''
|
||||||
|
http_dns.wait_for_unit("network-online.target")
|
||||||
http_dns.wait_for_unit("nginx")
|
http_dns.wait_for_unit("nginx")
|
||||||
http_dns.wait_for_open_port(80)
|
http_dns.wait_for_open_port(80)
|
||||||
http_dns.wait_for_unit("unbound")
|
http_dns.wait_for_unit("unbound")
|
||||||
|
@ -109,6 +110,7 @@ in
|
||||||
|
|
||||||
client.start()
|
client.start()
|
||||||
client.wait_for_unit('multi-user.target')
|
client.wait_for_unit('multi-user.target')
|
||||||
|
client.wait_for_unit('network-online.target')
|
||||||
|
|
||||||
with subtest("can fetch data from a remote server outside sandbox"):
|
with subtest("can fetch data from a remote server outside sandbox"):
|
||||||
client.succeed("nix --version >&2")
|
client.succeed("nix --version >&2")
|
||||||
|
|
|
@ -52,12 +52,15 @@ in {
|
||||||
|
|
||||||
# Create a binary cache.
|
# Create a binary cache.
|
||||||
server.wait_for_unit("minio")
|
server.wait_for_unit("minio")
|
||||||
|
server.wait_for_unit("network-online.target")
|
||||||
|
|
||||||
server.succeed("mc config host add minio http://localhost:9000 ${accessKey} ${secretKey} --api s3v4")
|
server.succeed("mc config host add minio http://localhost:9000 ${accessKey} ${secretKey} --api s3v4")
|
||||||
server.succeed("mc mb minio/my-cache")
|
server.succeed("mc mb minio/my-cache")
|
||||||
|
|
||||||
server.succeed("${env} nix copy --to '${storeUrl}' ${pkgA}")
|
server.succeed("${env} nix copy --to '${storeUrl}' ${pkgA}")
|
||||||
|
|
||||||
|
client.wait_for_unit("network-online.target")
|
||||||
|
|
||||||
# Test fetchurl on s3:// URLs while we're at it.
|
# Test fetchurl on s3:// URLs while we're at it.
|
||||||
client.succeed("${env} nix eval --impure --expr 'builtins.fetchurl { name = \"foo\"; url = \"s3://my-cache/nix-cache-info?endpoint=http://server:9000®ion=eu-west-1\"; }'")
|
client.succeed("${env} nix eval --impure --expr 'builtins.fetchurl { name = \"foo\"; url = \"s3://my-cache/nix-cache-info?endpoint=http://server:9000®ion=eu-west-1\"; }'")
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,8 @@ in
|
||||||
start_all()
|
start_all()
|
||||||
|
|
||||||
sourcehut.wait_for_unit("httpd.service")
|
sourcehut.wait_for_unit("httpd.service")
|
||||||
|
sourcehut.wait_for_unit("network-online.target")
|
||||||
|
client.wait_for_unit("network-online.target")
|
||||||
|
|
||||||
client.succeed("curl -v https://git.sr.ht/ >&2")
|
client.succeed("curl -v https://git.sr.ht/ >&2")
|
||||||
client.succeed("nix registry list | grep nixpkgs")
|
client.succeed("nix registry list | grep nixpkgs")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue