2020-04-20 11:31:07 +00:00
{ system ? builtins . currentSystem
, config ? { }
, pkgs ? import ../.. { inherit system config ; }
, lib ? pkgs . lib
} :
let
inherit ( import ../lib/testing-python.nix { inherit system pkgs ; } ) makeTest ;
mkOCITest = backend : makeTest {
name = " o c i - c o n t a i n e r s - ${ backend } " ;
2023-04-30 14:26:18 +00:00
meta . maintainers = lib . teams . serokell . members
2024-11-13 11:56:11 +00:00
++ ( with lib . maintainers ; [ benley ] ) ;
2020-04-20 11:31:07 +00:00
nodes = {
$ { backend } = { pkgs , . . . }: {
virtualisation . oci-containers = {
inherit backend ;
containers . nginx = {
image = " n g i n x - c o n t a i n e r " ;
2024-08-24 02:38:27 +00:00
imageStream = pkgs . dockerTools . examples . nginxStream ;
2020-04-20 11:31:07 +00:00
ports = [ " 8 1 8 1 : 8 0 " ] ;
2024-12-05 17:48:41 +00:00
capAdd = {
CAP_AUDIT_READ = true ;
} ;
capDrop = {
CAP_AUDIT_WRITE = true ;
} ;
privileged = false ;
devices = [
" / d e v / r a n d o m : / d e v / r a n d o m "
] ;
2020-04-20 11:31:07 +00:00
} ;
} ;
2023-08-10 08:24:26 +00:00
# Stop systemd from killing remaining processes if ExecStop script
# doesn't work, so that proper stopping can be tested.
systemd . services . " ${ backend } - n g i n x " . serviceConfig . KillSignal = " S I G C O N T " ;
2020-04-20 11:31:07 +00:00
} ;
} ;
testScript = ''
2024-12-05 17:48:41 +00:00
import json
2020-04-20 11:31:07 +00:00
start_all ( )
$ { backend } . wait_for_unit ( " ${ backend } - n g i n x . s e r v i c e " )
$ { backend } . wait_for_open_port ( 8181 )
2020-09-16 15:31:34 +00:00
$ { backend } . wait_until_succeeds ( " c u r l - f h t t p : / / l o c a l h o s t : 8 1 8 1 | g r e p H e l l o " )
2024-12-05 17:48:41 +00:00
output = json . loads ( $ { backend } . succeed ( " ${ backend } i n s p e c t n g i n x - - f o r m a t j s o n " ) . strip ( ) ) [ 0 ]
2023-08-10 08:24:26 +00:00
$ { backend } . succeed ( " s y s t e m c t l s t o p ${ backend } - n g i n x . s e r v i c e " , timeout = 10 )
2024-12-05 17:48:41 +00:00
assert output [ ' HostConfig' ] [ ' CapAdd' ] == [ " C A P _ A U D I T _ R E A D " ]
assert output [ ' HostConfig' ] [ ' CapDrop' ] == $ { if backend == " d o c k e r " then " [ \" C A P _ A U D I T _ W R I T E \" ] " else " [ ] " } # Rootless podman runs with no capabilities so it cannot drop them
assert output [ ' HostConfig' ] [ ' Privileged' ] == False
assert output [ ' HostConfig' ] [ ' Devices' ] == [ { ' PathOnHost' : ' /dev/random ' , ' PathInContainer' : ' /dev/random ' , ' CgroupPermissions' : ' ${ if backend == " d o c k e r " then " r w m " else " " } ' } ]
2020-04-20 11:31:07 +00:00
'' ;
} ;
in
lib . foldl' ( attrs : backend : attrs // { ${ backend } = mkOCITest backend ; } ) { } [
" d o c k e r "
" p o d m a n "
]