Add --extra-params option to the tools, add systemd tests

This commit is contained in:
Sander van der Burg 2020-07-07 21:48:20 +02:00 committed by Sander van der Burg
parent 7897fc0b15
commit 7c636c9d14
21 changed files with 252 additions and 32 deletions

View File

@ -6,6 +6,7 @@
, tmpDir ? (if stateDir == "/var" then "/tmp" else "${stateDir}/tmp")
, forceDisableUserChange ? false
, exprFile
, extraParams ? {}
}@args:
let
@ -15,7 +16,7 @@ let
processesArgs = builtins.intersectAttrs processesFormalArgs (args // {
processManager = "bsdrc";
});
} // extraParams);
processes = processesFun processesArgs;
in

View File

@ -5,6 +5,7 @@
, logDir ? "${stateDir}/log"
, tmpDir ? (if stateDir == "/var" then "/tmp" else "${stateDir}/tmp")
, forceDisableUserChange ? false
, extraParams ? {}
, exprFile
}@args:
@ -15,7 +16,7 @@ let
processesArgs = builtins.intersectAttrs processesFormalArgs (args // {
processManager = "cygrunsrv";
});
} // extraParams);
processes = processesFun processesArgs;
in

View File

@ -7,6 +7,7 @@
, forceDisableUserChange ? false
, clientInterface ? (if builtins.getEnv "DISNIX_CLIENT_INTERFACE" == "" then "disnix-run-activity" else builtins.getEnv "DISNIX_CLIENT_INTERFACE")
, disnixPath ? (if builtins.getEnv "DISNIX_PATH" == "" then throw "Set DISNIX_PATH to the data directory of Disnix" else builtins.getEnv "DISNIX_PATH")
, extraParams ? {}
, exprFile
}@args:
@ -17,7 +18,7 @@ let
processesArgs = builtins.intersectAttrs processesFormalArgs (args // {
processManager = "disnix";
});
} // extraParams);
processes = processesFun processesArgs;

View File

@ -5,6 +5,7 @@
, logDir ? "${stateDir}/log"
, tmpDir ? (if stateDir == "/var" then "/tmp" else "${stateDir}/tmp")
, forceDisableUserChange ? false
, extraParams ? {}
, exprFile
}@args:
@ -15,7 +16,7 @@ let
processesArgs = builtins.intersectAttrs processesFormalArgs (args // {
processManager = "docker";
});
} // extraParams);
processes = processesFun processesArgs;
in

View File

@ -5,6 +5,7 @@
, logDir ? "${stateDir}/log"
, tmpDir ? (if stateDir == "/var" then "/tmp" else "${stateDir}/tmp")
, forceDisableUserChange ? false
, extraParams ? {}
, exprFile
}@args:
@ -15,7 +16,7 @@ let
processesArgs = builtins.intersectAttrs processesFormalArgs (args // {
processManager = "launchd";
});
} // extraParams);
processes = processesFun processesArgs;
in

View File

@ -5,6 +5,7 @@
, logDir ? "${stateDir}/log"
, tmpDir ? (if stateDir == "/var" then "/tmp" else "${stateDir}/tmp")
, forceDisableUserChange ? false
, extraParams ? {}
, exprFile
}@args:
@ -15,7 +16,7 @@ let
processesArgs = builtins.intersectAttrs processesFormalArgs (args // {
processManager = "supervisord";
});
} // extraParams);
processes = processesFun processesArgs;
in

View File

@ -5,6 +5,7 @@
, logDir ? "${stateDir}/log"
, tmpDir ? (if stateDir == "/var" then "/tmp" else "${stateDir}/tmp")
, forceDisableUserChange ? false
, extraParams ? {}
, exprFile
}@args:
@ -15,7 +16,7 @@ let
processesArgs = builtins.intersectAttrs processesFormalArgs (args // {
processManager = "systemd";
});
} // extraParams);
processes = processesFun processesArgs;
in

View File

@ -5,6 +5,7 @@
, logDir ? "${stateDir}/log"
, tmpDir ? (if stateDir == "/var" then "/tmp" else "${stateDir}/tmp")
, forceDisableUserChange ? false
, extraParams ? {}
, exprFile
}@args:
@ -15,7 +16,7 @@ let
processesArgs = builtins.intersectAttrs processesFormalArgs (args // {
processManager = "sysvinit";
});
} // extraParams);
processes = processesFun processesArgs;
in

View File

@ -0,0 +1,152 @@
{nixpkgs ? <nixpkgs>}:
with import "${nixpkgs}/nixos/lib/testing-python.nix" { system = builtins.currentSystem; };
let
processesEnvForeground = import ../nixproc/create-managed-process/systemd/build-systemd-env.nix {
exprFile = ../examples/webapps-agnostic/processes.nix;
extraParams = {
webappMode = "foreground";
};
};
processesEnvDaemon = import ../nixproc/create-managed-process/systemd/build-systemd-env.nix {
exprFile = ../examples/webapps-agnostic/processes.nix;
extraParams = {
webappMode = "daemon";
};
};
processesEnvAuto = import ../nixproc/create-managed-process/systemd/build-systemd-env.nix {
exprFile = ../examples/webapps-agnostic/processes.nix;
};
tools = import ../tools {};
nix-processmgmt = ./..;
env = "NIX_PATH=nixpkgs=${nixpkgs} SYSTEMD_TARGET_DIR=/etc/systemd-mutable/system";
in
makeTest {
machine =
{pkgs, ...}:
{
virtualisation.pathsInNixDB = [ pkgs.stdenv ] ++ pkgs.coreutils.all ++ [ processesEnvForeground processesEnvDaemon processesEnvAuto ];
virtualisation.writableStore = true;
virtualisation.memorySize = 1024;
users.extraUsers = {
unprivileged = {
uid = 1000;
group = "users";
shell = "/bin/sh";
description = "Unprivileged user";
home = "/home/unprivileged";
createHome = true;
};
};
# We can't download any substitutes in a test environment. To make tests
# faster, we disable substitutes so that Nix does not waste any time by
# attempting to download them.
nix.extraOptions = ''
substitute = false
'';
environment.systemPackages = [
pkgs.stdenv
pkgs.dysnomia
tools.build
tools.systemd
];
};
testScript = ''
def check_nginx_redirection():
machine.succeed(
"curl --fail -H 'Host: webapp.local' http://localhost:8080 | grep 'listening on port: 5000'"
)
def check_system_unavailable():
machine.fail("curl --fail http://localhost:8080")
machine.fail("pgrep -f '/bin/webapp'")
def check_nginx_multi_instance_redirection():
machine.succeed(
"curl --fail -H 'Host: webapp1.local' http://localhost:8080 | grep 'listening on port: 5000'"
)
machine.succeed(
"curl --fail -H 'Host: webapp5.local' http://localhost:8081 | grep 'listening on port: 6002'"
)
start_all()
machine.succeed("mkdir -p /etc/systemd-mutable/system")
# Deploy the system with foreground webapp processes
machine.succeed(
'${env} nixproc-systemd-switch ${nix-processmgmt}/examples/webapps-agnostic/processes.nix --extra-params \'{ "webappMode" = "foreground"; }\'${""}'
)
machine.succeed("sleep 1")
machine.succeed("pgrep -u webapp -f '/bin/webapp$'")
check_nginx_redirection()
# Deploy the system with daemon webapp processes
machine.succeed(
'${env} nixproc-systemd-switch ${nix-processmgmt}/examples/webapps-agnostic/processes.nix --extra-params \'{ "webappMode" = "daemon"; }\'${""}'
)
machine.succeed("sleep 1")
machine.succeed("pgrep -u webapp -f '/bin/webapp -D$'")
check_nginx_redirection()
# Deploy the entire system in auto mode. Should result in foreground webapp processes
machine.succeed(
"${env} nixproc-systemd-switch ${nix-processmgmt}/examples/webapps-agnostic/processes.nix"
)
machine.succeed("sleep 1")
machine.succeed("pgrep -u webapp -f '/bin/webapp$'")
check_nginx_redirection()
# Deploy the advanced example with multiple instances and see if it works
machine.succeed(
"${env} nixproc-systemd-switch ${nix-processmgmt}/examples/webapps-agnostic/processes-advanced.nix"
)
machine.succeed("sleep 1")
check_nginx_multi_instance_redirection()
# Deploy an instance without changing user privileges
machine.succeed(
"${env} nixproc-systemd-switch ${nix-processmgmt}/examples/webapps-agnostic/processes.nix --force-disable-user-change"
)
machine.succeed("sleep 1")
machine.succeed("pgrep -u root -f '/bin/webapp$'")
check_nginx_redirection()
# Undeploy the system
machine.succeed(
"${env} nixproc-systemd-switch ${nix-processmgmt}/examples/webapps-agnostic/processes-empty.nix"
)
check_system_unavailable()
'';
}

View File

@ -34,6 +34,9 @@ Options:
Forces to not create users, groups or change user
permissions
--show-trace Shows a trace of the output
--extra-params=PARAMS
A string with an attribute set in the Nix expression
language propagating extra parameters to the input models
-h, --help Shows the usage of this command
Environment:
@ -53,7 +56,7 @@ EOF
# Parse valid argument options
PARAMS=`@getopt@ -n $0 -o p:o:h -l profile:,old-profile:,enable-at-boot,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,show-trace,help -- "$@"`
PARAMS=`@getopt@ -n $0 -o p:o:h -l profile:,old-profile:,enable-at-boot,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,show-trace,extra-params:,help -- "$@"`
if [ $? != 0 ]
then
@ -95,6 +98,9 @@ do
--show-trace)
showTraceArg="--show-trace"
;;
--extra-params)
extraParamsArg=("--extra-params" "$2")
;;
-h|--help)
showUsage
exit 0

View File

@ -12,18 +12,21 @@ their start and stop symlinks.
Options:
-P, --process-manager=MANAGER
Process manager to build for
--state-dir Changes the directory in which the state of the processes
are stored
--runtime-dir Changes the directory in which the PID files are stored
--log-dir Changes the directory in which the log files are stored
--tmp-dir Changes the directory in which temp files are stored
Process manager to build for
--state-dir Changes the directory in which the state of the processes
are stored
--runtime-dir Changes the directory in which the PID files are stored
--log-dir Changes the directory in which the log files are stored
--tmp-dir Changes the directory in which temp files are stored
--force-disable-user-change
Forces to not create users, groups or change user
permissions
--no-out-link Do not create a symlink to the output path
--show-trace Shows a trace of the output
-h, --help Shows the usage of this command
Forces to not create users, groups or change user
permissions
--no-out-link Do not create a symlink to the output path
--show-trace Shows a trace of the output
--extra-params=PARAMS
A string with an attribute set in the Nix expression
language propagating extra parameters to the input models
-h, --help Shows the usage of this command
Environment:
NIXPROC_STATE_DIR Changes the directory in which the state of the
@ -39,7 +42,7 @@ EOF
# Parse valid argument options
PARAMS=`@getopt@ -n $0 -o P:h -l process-manager:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,no-out-link,show-trace,help -- "$@"`
PARAMS=`@getopt@ -n $0 -o P:h -l process-manager:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,no-out-link,show-trace,extra-params:,help -- "$@"`
if [ $? != 0 ]
then
@ -78,6 +81,9 @@ do
--show-trace)
showTraceArg="--show-trace"
;;
--extra-params)
extraParamsArg=("--arg" "extraParams" "$2")
;;
-h|--help)
showUsage
exit 0
@ -135,4 +141,4 @@ fi
NIXPROC=${NIXPROC:-@NIXPROC@}
# Build the profile
nix-build $stateDirArg $runtimeDirArg $logDirArg $tmpDirArg $forceDisableUserChangeArg $noOutLinkArg $showTraceArg $processManagerArg --argstr exprFile "$exprFile" $NIXPROC/create-managed-process/$processManager/build-$processManager-env.nix
nix-build $stateDirArg $runtimeDirArg $logDirArg $tmpDirArg $forceDisableUserChangeArg $noOutLinkArg $showTraceArg $processManagerArg "${extraParamsArg[@]}" --argstr exprFile "$exprFile" $NIXPROC/create-managed-process/$processManager/build-$processManager-env.nix

View File

@ -27,7 +27,7 @@ checkProfile()
buildProfile()
{
local processManager="$1"
profilePath=$(nixproc-build --process-manager $processManager $stateDirArg $runtimeDirArg $logDirArg $tmpDirArg $forceDisableUserChangeArg $showTraceArg --no-out-link "$path")
profilePath=$(nixproc-build --process-manager $processManager $stateDirArg $runtimeDirArg $logDirArg $tmpDirArg $forceDisableUserChangeArg $showTraceArg "${extraParamsArg[@]}" --no-out-link "$path")
}
composeProfileDir()

View File

@ -25,6 +25,9 @@ Options:
Forces to not create users, groups or change user
permissions
--show-trace Shows a trace of the output
--extra-params=PARAMS
A string with an attribute set in the Nix expression
language propagating extra parameters to the input models
-h, --help Shows the usage of this command
Environment:
@ -42,7 +45,7 @@ EOF
# Parse valid argument options
PARAMS=`@getopt@ -n $0 -o p:o:h -l profile:,old-profile:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,show-trace,help -- "$@"`
PARAMS=`@getopt@ -n $0 -o p:o:h -l profile:,old-profile:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,show-trace,extra-params:,help -- "$@"`
if [ $? != 0 ]
then
@ -81,6 +84,9 @@ do
--show-trace)
showTraceArg="--show-trace"
;;
--extra-params)
extraParamsArg=("--extra-params" "$2")
;;
-h|--help)
showUsage
exit 0

View File

@ -24,6 +24,9 @@ Options:
Forces to not create users, groups or change user
permissions
--show-trace Shows a trace of the output
--extra-params=PARAMS
A string with an attribute set in the Nix expression
language propagating extra parameters to the input models
-h, --help Shows the usage of this command
Environment:
@ -41,7 +44,7 @@ EOF
# Parse valid argument options
PARAMS=`@getopt@ -n $0 -o p:o:h -l profile:,old-profile:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,show-trace,help -- "$@"`
PARAMS=`@getopt@ -n $0 -o p:o:h -l profile:,old-profile:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,show-trace,extra-params:,help -- "$@"`
if [ $? != 0 ]
then
@ -80,6 +83,9 @@ do
--show-trace)
showTraceArg="--show-trace"
;;
--extra-params)
extraParamsArg=("--extra-params" "$2")
;;
-h|--help)
showUsage
exit 0

View File

@ -25,6 +25,9 @@ Options:
--force-disable-user-change
Forces to not create users, groups or change user
permissions
--extra-params=PARAMS
A string with an attribute set in the Nix expression
language propagating extra parameters to the input models
--show-trace Shows a trace of the output
-h, --help Shows the usage of this command
@ -45,7 +48,7 @@ EOF
# Parse valid argument options
PARAMS=`@getopt@ -n $0 -o p:o:h -l profile:,old-profile:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,show-trace,help -- "$@"`
PARAMS=`@getopt@ -n $0 -o p:o:h -l profile:,old-profile:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,show-trace,extra-params:,help -- "$@"`
if [ $? != 0 ]
then
@ -85,6 +88,9 @@ do
--show-trace)
showTraceArg="--show-trace"
;;
--extra-params)
extraParamsArg=("--extra-params" "$2")
;;
-h|--help)
showUsage
exit 0

View File

@ -26,6 +26,9 @@ Options:
Forces to not create users, groups or change user
permissions
--show-trace Shows a trace of the output
--extra-params=PARAMS
A string with an attribute set in the Nix expression
language propagating extra parameters to the input models
-h, --help Shows the usage of this command
Environment:
@ -45,7 +48,7 @@ EOF
# Parse valid argument options
PARAMS=`@getopt@ -n $0 -o p:o:h -l profile:,old-profile:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,show-trace,help -- "$@"`
PARAMS=`@getopt@ -n $0 -o p:o:h -l profile:,old-profile:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,show-trace,extra-params:,help -- "$@"`
if [ $? != 0 ]
then
@ -84,6 +87,9 @@ do
--show-trace)
showTraceArg="--show-trace"
;;
--extra-params)
extraParamsArg=("--extra-params" "$2")
;;
-h|--help)
showUsage
exit 0

View File

@ -22,6 +22,9 @@ Options:
Forces to not create users, groups or change user
permissions
--show-trace Shows a trace of the output
--extra-params=PARAMS
A string with an attribute set in the Nix expression
language propagating extra parameters to the input models
-h, --help Shows the usage of this command
Environment:
@ -38,7 +41,7 @@ EOF
# Parse valid argument options
PARAMS=`@getopt@ -n $0 -o h -l state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,show-trace,help -- "$@"`
PARAMS=`@getopt@ -n $0 -o h -l state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,show-trace,extra-params:,help -- "$@"`
if [ $? != 0 ]
then
@ -71,6 +74,9 @@ do
--show-trace)
showTraceArg="--show-trace"
;;
--extra-params)
extraParamsArg=("--extra-params" "$2")
;;
-h|--help)
showUsage
exit 0
@ -85,7 +91,7 @@ shift
path="$1"
# Build the environment with supervisord config files
profilePath=$(nixproc-build --process-manager supervisord $stateDirArg $runtimeDirArg $logDirArg $tmpDirArg $forceDisableUserChangeArg $showTraceArg --no-out-link "$path")
profilePath=$(nixproc-build --process-manager supervisord $stateDirArg $runtimeDirArg $logDirArg $tmpDirArg $forceDisableUserChangeArg $showTraceArg "${extraParamsArg[@]}" --no-out-link "$path")
# Create groups and users
dysnomia-addgroups "$profilePath"

View File

@ -30,6 +30,9 @@ Options:
Forces to not create users, groups or change user
permissions
--show-trace Shows a trace of the output
--extra-params=PARAMS
A string with an attribute set in the Nix expression
language propagating extra parameters to the input models
-h, --help Shows the usage of this command
Environment:
@ -48,7 +51,7 @@ EOF
# Parse valid argument options
PARAMS=`@getopt@ -n $0 -o p:o:h -l profile:,old-profile:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,show-trace,help -- "$@"`
PARAMS=`@getopt@ -n $0 -o p:o:h -l profile:,old-profile:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,show-trace,extra-params:,help -- "$@"`
if [ $? != 0 ]
then
@ -87,6 +90,9 @@ do
--show-trace)
showTraceArg="--show-trace"
;;
--extra-params)
extraParamsArg=("--extra-params" "$2")
;;
-h|--help)
showUsage
exit 0

View File

@ -26,6 +26,9 @@ Options:
Forces to not create users, groups or change user
permissions
--show-trace Shows a trace of the output
--extra-params=PARAMS
A string with an attribute set in the Nix expression
language propagating extra parameters to the input models
-h, --help Shows the usage of this command
Environment:
@ -45,7 +48,7 @@ EOF
# Parse valid argument options
PARAMS=`@getopt@ -n $0 -o p:o:h -l profile:,old-profile:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,show-trace,help -- "$@"`
PARAMS=`@getopt@ -n $0 -o p:o:h -l profile:,old-profile:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,show-trace,extra-params:,help -- "$@"`
if [ $? != 0 ]
then
@ -84,6 +87,9 @@ do
--show-trace)
showTraceArg="--show-trace"
;;
--extra-params)
extraParamsArg=("--extra-params" "$2")
;;
-h|--help)
showUsage
exit 0

View File

@ -34,6 +34,9 @@ Options:
Forces to not create users, groups or change user
permissions
--show-trace Shows a trace of the output
--extra-params=PARAMS
A string with an attribute set in the Nix expression
language propagating extra parameters to the input models
-h, --help Shows the usage of this command
Environment:
@ -51,7 +54,7 @@ EOF
# Parse valid argument options
PARAMS=`@getopt@ -n $0 -o p:o:h -l profile:,old-profile:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,runlevel:,show-trace,help -- "$@"`
PARAMS=`@getopt@ -n $0 -o p:o:h -l profile:,old-profile:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,force-disable-user-change,runlevel:,show-trace,extra-params:,help -- "$@"`
if [ $? != 0 ]
then
@ -93,6 +96,9 @@ do
--show-trace)
showTraceArg="--show-trace"
;;
--extra-params)
extraParamsArg=("--extra-params" "$2")
;;
-h|--help)
showUsage
exit 0