mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 03:23:29 +03:00
nixosTests.binary-cache{no-compression,xz}: migrate to runTest
Part of #386873
This commit is contained in:
parent
a6a9f5f195
commit
fab4accced
2 changed files with 83 additions and 79 deletions
|
@ -231,9 +231,18 @@ in
|
||||||
beanstalkd = handleTest ./beanstalkd.nix { };
|
beanstalkd = handleTest ./beanstalkd.nix { };
|
||||||
bees = handleTest ./bees.nix { };
|
bees = handleTest ./bees.nix { };
|
||||||
benchexec = handleTest ./benchexec.nix { };
|
benchexec = handleTest ./benchexec.nix { };
|
||||||
binary-cache = handleTest ./binary-cache.nix { compression = "zstd"; };
|
binary-cache = runTest {
|
||||||
binary-cache-no-compression = handleTest ./binary-cache.nix { compression = "none"; };
|
imports = [ ./binary-cache.nix ];
|
||||||
binary-cache-xz = handleTest ./binary-cache.nix { compression = "xz"; };
|
_module.args.compression = "zstd";
|
||||||
|
};
|
||||||
|
binary-cache-no-compression = runTest {
|
||||||
|
imports = [ ./binary-cache.nix ];
|
||||||
|
_module.args.compression = "none";
|
||||||
|
};
|
||||||
|
binary-cache-xz = runTest {
|
||||||
|
imports = [ ./binary-cache.nix ];
|
||||||
|
_module.args.compression = "xz";
|
||||||
|
};
|
||||||
bind = handleTest ./bind.nix { };
|
bind = handleTest ./bind.nix { };
|
||||||
bird = handleTest ./bird.nix { };
|
bird = handleTest ./bird.nix { };
|
||||||
birdwatcher = handleTest ./birdwatcher.nix { };
|
birdwatcher = handleTest ./birdwatcher.nix { };
|
||||||
|
|
|
@ -1,88 +1,83 @@
|
||||||
{ compression, ... }@args:
|
{ lib, compression, ... }:
|
||||||
|
{
|
||||||
|
name = "binary-cache-" + compression;
|
||||||
|
meta.maintainers = with lib.maintainers; [ thomasjm ];
|
||||||
|
|
||||||
import ./make-test-python.nix (
|
nodes.machine =
|
||||||
{ lib, pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
imports = [ ../modules/installer/cd-dvd/channel.nix ];
|
||||||
|
environment.systemPackages = with pkgs; [
|
||||||
|
openssl
|
||||||
|
python3
|
||||||
|
];
|
||||||
|
|
||||||
{
|
# We encrypt the binary cache before putting it on the machine so Nix
|
||||||
name = "binary-cache-" + compression;
|
# doesn't bring any references along.
|
||||||
meta.maintainers = with lib.maintainers; [ thomasjm ];
|
environment.etc."binary-cache.tar.gz.encrypted".source =
|
||||||
|
with pkgs;
|
||||||
|
runCommand "binary-cache.tar.gz.encrypted"
|
||||||
|
{
|
||||||
|
allowReferences = [ ];
|
||||||
|
nativeBuildInputs = [ openssl ];
|
||||||
|
}
|
||||||
|
''
|
||||||
|
tar -czf tmp.tar.gz -C "${
|
||||||
|
mkBinaryCache {
|
||||||
|
rootPaths = [ hello ];
|
||||||
|
inherit compression;
|
||||||
|
}
|
||||||
|
}" .
|
||||||
|
openssl enc -aes-256-cbc -salt -in tmp.tar.gz -out $out -k mysecretpassword
|
||||||
|
'';
|
||||||
|
|
||||||
nodes.machine =
|
nix.extraOptions = ''
|
||||||
{ pkgs, ... }:
|
experimental-features = nix-command
|
||||||
{
|
'';
|
||||||
imports = [ ../modules/installer/cd-dvd/channel.nix ];
|
};
|
||||||
environment.systemPackages = with pkgs; [
|
|
||||||
openssl
|
|
||||||
python3
|
|
||||||
];
|
|
||||||
|
|
||||||
# We encrypt the binary cache before putting it on the machine so Nix
|
testScript = ''
|
||||||
# doesn't bring any references along.
|
# Decrypt the cache into /tmp/binary-cache.tar.gz
|
||||||
environment.etc."binary-cache.tar.gz.encrypted".source =
|
machine.succeed("openssl enc -d -aes-256-cbc -in /etc/binary-cache.tar.gz.encrypted -out /tmp/binary-cache.tar.gz -k mysecretpassword")
|
||||||
with pkgs;
|
|
||||||
runCommand "binary-cache.tar.gz.encrypted"
|
|
||||||
{
|
|
||||||
allowReferences = [ ];
|
|
||||||
nativeBuildInputs = [ openssl ];
|
|
||||||
}
|
|
||||||
''
|
|
||||||
tar -czf tmp.tar.gz -C "${
|
|
||||||
mkBinaryCache {
|
|
||||||
rootPaths = [ hello ];
|
|
||||||
inherit compression;
|
|
||||||
}
|
|
||||||
}" .
|
|
||||||
openssl enc -aes-256-cbc -salt -in tmp.tar.gz -out $out -k mysecretpassword
|
|
||||||
'';
|
|
||||||
|
|
||||||
nix.extraOptions = ''
|
# Untar the cache into /tmp/cache
|
||||||
experimental-features = nix-command
|
machine.succeed("mkdir /tmp/cache")
|
||||||
'';
|
machine.succeed("tar -C /tmp/cache -xf /tmp/binary-cache.tar.gz")
|
||||||
};
|
|
||||||
|
|
||||||
testScript = ''
|
# Sanity test of cache structure
|
||||||
# Decrypt the cache into /tmp/binary-cache.tar.gz
|
status, stdout = machine.execute("ls /tmp/cache")
|
||||||
machine.succeed("openssl enc -d -aes-256-cbc -in /etc/binary-cache.tar.gz.encrypted -out /tmp/binary-cache.tar.gz -k mysecretpassword")
|
cache_files = stdout.split()
|
||||||
|
assert ("nix-cache-info" in cache_files)
|
||||||
|
assert ("nar" in cache_files)
|
||||||
|
|
||||||
# Untar the cache into /tmp/cache
|
# Nix store ping should work
|
||||||
machine.succeed("mkdir /tmp/cache")
|
machine.succeed("nix store ping --store file:///tmp/cache")
|
||||||
machine.succeed("tar -C /tmp/cache -xf /tmp/binary-cache.tar.gz")
|
|
||||||
|
|
||||||
# Sanity test of cache structure
|
# Cache should contain a .narinfo referring to "hello"
|
||||||
status, stdout = machine.execute("ls /tmp/cache")
|
grepLogs = machine.succeed("grep -l 'StorePath: /nix/store/[[:alnum:]]*-hello-.*' /tmp/cache/*.narinfo")
|
||||||
cache_files = stdout.split()
|
|
||||||
assert ("nix-cache-info" in cache_files)
|
|
||||||
assert ("nar" in cache_files)
|
|
||||||
|
|
||||||
# Nix store ping should work
|
# Get the store path referenced by the .narinfo
|
||||||
machine.succeed("nix store ping --store file:///tmp/cache")
|
narInfoFile = grepLogs.strip()
|
||||||
|
narInfoContents = machine.succeed("cat " + narInfoFile)
|
||||||
|
import re
|
||||||
|
match = re.match(r"^StorePath: (/nix/store/[a-z0-9]*-hello-.*)$", narInfoContents, re.MULTILINE)
|
||||||
|
if not match: raise Exception("Couldn't find hello store path in cache")
|
||||||
|
storePath = match[1]
|
||||||
|
|
||||||
# Cache should contain a .narinfo referring to "hello"
|
# Make sure the store path doesn't exist yet
|
||||||
grepLogs = machine.succeed("grep -l 'StorePath: /nix/store/[[:alnum:]]*-hello-.*' /tmp/cache/*.narinfo")
|
machine.succeed("[ ! -d %s ] || exit 1" % storePath)
|
||||||
|
|
||||||
# Get the store path referenced by the .narinfo
|
# Should be able to build hello using the cache
|
||||||
narInfoFile = grepLogs.strip()
|
logs = machine.succeed("nix-build -A hello '<nixpkgs>' --option require-sigs false --option trusted-substituters file:///tmp/cache --option substituters file:///tmp/cache 2>&1")
|
||||||
narInfoContents = machine.succeed("cat " + narInfoFile)
|
logLines = logs.split("\n")
|
||||||
import re
|
if not "this path will be fetched" in logLines[0]: raise Exception("Unexpected first log line")
|
||||||
match = re.match(r"^StorePath: (/nix/store/[a-z0-9]*-hello-.*)$", narInfoContents, re.MULTILINE)
|
def shouldBe(got, desired):
|
||||||
if not match: raise Exception("Couldn't find hello store path in cache")
|
if got != desired: raise Exception("Expected '%s' but got '%s'" % (desired, got))
|
||||||
storePath = match[1]
|
shouldBe(logLines[1], " " + storePath)
|
||||||
|
shouldBe(logLines[2], "copying path '%s' from 'file:///tmp/cache'..." % storePath)
|
||||||
|
shouldBe(logLines[3], storePath)
|
||||||
|
|
||||||
# Make sure the store path doesn't exist yet
|
# Store path should exist in the store now
|
||||||
machine.succeed("[ ! -d %s ] || exit 1" % storePath)
|
machine.succeed("[ -d %s ] || exit 1" % storePath)
|
||||||
|
'';
|
||||||
# Should be able to build hello using the cache
|
}
|
||||||
logs = machine.succeed("nix-build -A hello '<nixpkgs>' --option require-sigs false --option trusted-substituters file:///tmp/cache --option substituters file:///tmp/cache 2>&1")
|
|
||||||
logLines = logs.split("\n")
|
|
||||||
if not "this path will be fetched" in logLines[0]: raise Exception("Unexpected first log line")
|
|
||||||
def shouldBe(got, desired):
|
|
||||||
if got != desired: raise Exception("Expected '%s' but got '%s'" % (desired, got))
|
|
||||||
shouldBe(logLines[1], " " + storePath)
|
|
||||||
shouldBe(logLines[2], "copying path '%s' from 'file:///tmp/cache'..." % storePath)
|
|
||||||
shouldBe(logLines[3], storePath)
|
|
||||||
|
|
||||||
# Store path should exist in the store now
|
|
||||||
machine.succeed("[ -d %s ] || exit 1" % storePath)
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
) args
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue