Add a pre-populate subcommand. (#11)
This commit is contained in:
parent
9254ace18f
commit
cead991210
5 changed files with 237 additions and 60 deletions
|
|
@ -3,13 +3,14 @@
|
|||
, system
|
||||
}:
|
||||
|
||||
lib.flip lib.mapAttrs' system-manager.lib.images.ubuntu.${system} (imgName: image:
|
||||
let
|
||||
forEachUbuntuImage = lib.flip lib.mapAttrs' system-manager.lib.images.ubuntu.${system};
|
||||
|
||||
newConfig = system-manager.lib.makeSystemConfig {
|
||||
modules = [
|
||||
({ lib, pkgs, ... }: {
|
||||
config = {
|
||||
nixpkgs.hostPlatform = "x86_64-linux";
|
||||
nixpkgs.hostPlatform = system;
|
||||
|
||||
services.nginx.enable = true;
|
||||
|
||||
|
|
@ -20,6 +21,7 @@ let
|
|||
'';
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services.new-service = {
|
||||
enable = true;
|
||||
description = "new-service";
|
||||
|
|
@ -28,7 +30,7 @@ let
|
|||
RemainAfterExit = true;
|
||||
ExecReload = "${lib.getBin pkgs.coreutils}/bin/true";
|
||||
};
|
||||
wantedBy = [ "system-manager.target" ];
|
||||
wantedBy = [ "system-manager.target" "default.target" ];
|
||||
script = ''
|
||||
sleep 2
|
||||
'';
|
||||
|
|
@ -38,57 +40,136 @@ let
|
|||
];
|
||||
};
|
||||
in
|
||||
lib.nameValuePair
|
||||
"example-${imgName}"
|
||||
(system-manager.lib.make-vm-test {
|
||||
inherit system;
|
||||
modules = [
|
||||
({ config, ... }:
|
||||
let
|
||||
inherit (config) hostPkgs;
|
||||
in
|
||||
{
|
||||
nodes = {
|
||||
node1 = { config, ... }: {
|
||||
modules = [
|
||||
../../../examples/example.nix
|
||||
];
|
||||
|
||||
virtualisation.rootImage = system-manager.lib.prepareUbuntuImage {
|
||||
inherit hostPkgs image;
|
||||
nodeConfig = config;
|
||||
forEachUbuntuImage
|
||||
(imgName: image: lib.nameValuePair
|
||||
"example-${imgName}"
|
||||
(system-manager.lib.make-vm-test {
|
||||
inherit system;
|
||||
modules = [
|
||||
({ config, ... }:
|
||||
let
|
||||
inherit (config) hostPkgs;
|
||||
in
|
||||
{
|
||||
nodes = {
|
||||
node1 = { config, ... }: {
|
||||
modules = [
|
||||
../../../examples/example.nix
|
||||
];
|
||||
|
||||
virtualisation.rootImage = system-manager.lib.prepareUbuntuImage {
|
||||
inherit hostPkgs image;
|
||||
nodeConfig = config;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
# Start all machines in parallel
|
||||
start_all()
|
||||
testScript = ''
|
||||
# Start all machines in parallel
|
||||
start_all()
|
||||
|
||||
node1.wait_for_unit("default.target")
|
||||
node1.wait_for_unit("default.target")
|
||||
|
||||
node1.execute("/system-manager-profile/bin/activate")
|
||||
node1.wait_for_unit("system-manager.target")
|
||||
node1.execute("/system-manager-profile/bin/activate")
|
||||
node1.wait_for_unit("system-manager.target")
|
||||
|
||||
node1.wait_for_unit("service-9.service")
|
||||
node1.wait_for_file("/etc/baz/bar/foo2")
|
||||
node1.wait_for_file("/etc/a/nested/example/foo3")
|
||||
node1.wait_for_file("/etc/foo.conf")
|
||||
node1.succeed("grep -F 'launch_the_rockets = true' /etc/foo.conf")
|
||||
node1.fail("grep -F 'launch_the_rockets = false' /etc/foo.conf")
|
||||
node1.wait_for_unit("service-9.service")
|
||||
node1.wait_for_file("/etc/baz/bar/foo2")
|
||||
node1.wait_for_file("/etc/a/nested/example/foo3")
|
||||
node1.wait_for_file("/etc/foo.conf")
|
||||
node1.succeed("grep -F 'launch_the_rockets = true' /etc/foo.conf")
|
||||
node1.fail("grep -F 'launch_the_rockets = false' /etc/foo.conf")
|
||||
|
||||
node1.execute("${newConfig}/bin/activate")
|
||||
node1.wait_for_unit("new-service.service")
|
||||
node1.wait_until_fails("systemctl status service-9.service")
|
||||
node1.wait_until_fails("cat /etc/a/nested/example/foo3")
|
||||
node1.wait_until_fails("cat /etc/baz/bar/foo2")
|
||||
node1.wait_for_file("/etc/foo_new")
|
||||
node1.execute("${newConfig}/bin/activate")
|
||||
node1.wait_for_unit("new-service.service")
|
||||
node1.wait_until_fails("systemctl status service-9.service")
|
||||
node1.wait_until_fails("cat /etc/a/nested/example/foo3")
|
||||
node1.wait_until_fails("cat /etc/baz/bar/foo2")
|
||||
node1.wait_for_file("/etc/foo_new")
|
||||
|
||||
node1.execute("${newConfig}/bin/deactivate")
|
||||
node1.wait_until_fails("systemctl status new-service.service")
|
||||
node1.wait_until_fails("cat /etc/foo_new")
|
||||
'';
|
||||
})
|
||||
];
|
||||
})
|
||||
)
|
||||
# Simulate a reboot, to check that the services defined with
|
||||
# system-manager start correctly after a reboot.
|
||||
# TODO: can we find an easy way to really reboot the VM and not
|
||||
# loose the root FS state?
|
||||
node1.systemctl("isolate rescue.target")
|
||||
# We need to send a return character to dismiss the rescue-mode prompt
|
||||
node1.send_key("ret")
|
||||
node1.systemctl("isolate default.target")
|
||||
node1.wait_for_unit("default.target")
|
||||
|
||||
node1.wait_for_unit("new-service.service")
|
||||
node1.wait_until_fails("systemctl status service-9.service")
|
||||
node1.wait_until_fails("cat /etc/a/nested/example/foo3")
|
||||
node1.wait_until_fails("cat /etc/baz/bar/foo2")
|
||||
node1.wait_for_file("/etc/foo_new")
|
||||
|
||||
node1.execute("${newConfig}/bin/deactivate")
|
||||
node1.wait_until_fails("systemctl status new-service.service")
|
||||
node1.wait_until_fails("cat /etc/foo_new")
|
||||
'';
|
||||
})
|
||||
];
|
||||
})
|
||||
)
|
||||
|
||||
//
|
||||
|
||||
forEachUbuntuImage
|
||||
(imgName: image: lib.nameValuePair
|
||||
"prepopulate-${imgName}"
|
||||
(system-manager.lib.make-vm-test {
|
||||
inherit system;
|
||||
modules = [
|
||||
({ config, ... }:
|
||||
let
|
||||
inherit (config) hostPkgs;
|
||||
in
|
||||
{
|
||||
nodes = {
|
||||
node1 = { config, ... }: {
|
||||
modules = [
|
||||
../../../examples/example.nix
|
||||
];
|
||||
|
||||
virtualisation.rootImage = system-manager.lib.prepareUbuntuImage {
|
||||
inherit hostPkgs image;
|
||||
nodeConfig = config;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
# Start all machines in parallel
|
||||
start_all()
|
||||
|
||||
node1.wait_for_unit("default.target")
|
||||
|
||||
node1.execute("/system-manager-profile/bin/prepopulate")
|
||||
node1.systemctl("daemon-reload")
|
||||
node1.systemctl("start default.target")
|
||||
node1.wait_for_unit("system-manager.target")
|
||||
|
||||
node1.wait_for_unit("service-9.service")
|
||||
node1.wait_for_file("/etc/baz/bar/foo2")
|
||||
node1.wait_for_file("/etc/a/nested/example/foo3")
|
||||
node1.wait_for_file("/etc/foo.conf")
|
||||
node1.succeed("grep -F 'launch_the_rockets = true' /etc/foo.conf")
|
||||
node1.fail("grep -F 'launch_the_rockets = false' /etc/foo.conf")
|
||||
|
||||
node1.execute("${newConfig}/bin/activate")
|
||||
node1.wait_for_unit("new-service.service")
|
||||
node1.wait_until_fails("systemctl status service-9.service")
|
||||
node1.wait_until_fails("cat /etc/a/nested/example/foo3")
|
||||
node1.wait_until_fails("cat /etc/baz/bar/foo2")
|
||||
node1.wait_for_file("/etc/foo_new")
|
||||
|
||||
node1.execute("${newConfig}/bin/deactivate")
|
||||
node1.wait_until_fails("systemctl status new-service.service")
|
||||
node1.wait_until_fails("cat /etc/foo_new")
|
||||
'';
|
||||
}
|
||||
)
|
||||
];
|
||||
})
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue