@@ -1369,7 +1369,80 @@ def test_cgroup_v2_mount_options():
13691369
13701370 return 0
13711371
1372+ def _cgroup_disabled_config ():
1373+ """Return a config suitable for --cgroup-manager=disabled: no cgroup mount,
1374+ no resources, no cgroupsPath, no cgroup namespace."""
1375+ conf = base_config ()
1376+ add_all_namespaces (conf , cgroupns = False )
1377+ conf ['mounts' ] = [m for m in conf .get ('mounts' , [])
1378+ if m .get ('destination' ) != '/sys/fs/cgroup' ]
1379+ if 'resources' in conf .get ('linux' , {}):
1380+ del conf ['linux' ]['resources' ]
1381+ if 'cgroupsPath' in conf .get ('linux' , {}):
1382+ del conf ['linux' ]['cgroupsPath' ]
1383+ return conf
1384+
1385+
1386+ def _run_cgroup_disabled (detach ):
1387+ """Run a container with --cgroup-manager=disabled in foreground or detached
1388+ mode. Returns 0 on success, (77, reason) for environment skips, -1 on
1389+ failure.
1390+
1391+ Regression test for https://github.com/containers/crun/issues/1413.
1392+ When cgroups are disabled, crun must not call statfs on /sys/fs/cgroup,
1393+ which would fail on systems where it is not mounted as tmpfs or cgroup2.
1394+ """
1395+ conf = _cgroup_disabled_config ()
1396+ conf ['process' ]['args' ] = ['/init' , 'pause' ] if detach else ['/init' , 'true' ]
1397+
1398+ cid = None
1399+ try :
1400+ if detach :
1401+ _ , cid = run_and_get_output (conf , hide_stderr = False , command = 'run' ,
1402+ detach = True , cgroup_manager = 'disabled' )
1403+ state = json .loads (run_crun_command (['state' , cid ]))
1404+ if state ['status' ] not in ('running' , 'created' ):
1405+ logger .info ("container not running: %s" , state ['status' ])
1406+ return - 1
1407+ else :
1408+ run_and_get_output (conf , hide_stderr = False , cgroup_manager = 'disabled' )
1409+ return 0
1410+ except subprocess .CalledProcessError as e :
1411+ output = e .output .decode ('utf-8' , errors = 'ignore' ) if e .output else ''
1412+ if "invalid file system type" in output :
1413+ logger .info ("test failed: cgroup filesystem type checked despite --cgroups=disabled" )
1414+ return - 1
1415+ if any (kw in output .lower () for kw in ["mount" , "proc" , "rootfs" ]):
1416+ return (77 , "environment issue, not related to cgroup disabled" )
1417+ logger .info ("test failed: %s (output: %s)" , e , output )
1418+ return - 1
1419+ except Exception as e :
1420+ logger .info ("test failed: %s" , e )
1421+ return - 1
1422+ finally :
1423+ if cid is not None :
1424+ run_crun_command (["delete" , "-f" , cid ])
1425+
1426+
1427+ def test_cgroup_disabled ():
1428+ """Test --cgroup-manager=disabled skips cgroup filesystem type verification (foreground).
1429+
1430+ Regression test for https://github.com/containers/crun/issues/1413.
1431+ """
1432+ return _run_cgroup_disabled (detach = False )
1433+
1434+
1435+ def test_cgroup_disabled_detach ():
1436+ """Test --cgroup-manager=disabled works with run --detach.
1437+
1438+ Regression test for https://github.com/containers/crun/issues/1413.
1439+ """
1440+ return _run_cgroup_disabled (detach = True )
1441+
1442+
13721443all_tests = {
1444+ "cgroup-disabled" : test_cgroup_disabled ,
1445+ "cgroup-disabled-detach" : test_cgroup_disabled_detach ,
13731446 "cgroup-creation" : test_cgroup_creation ,
13741447 "cgroup-cleanup" : test_cgroup_cleanup ,
13751448 "cgroup-with-resources" : test_cgroup_with_resources ,
0 commit comments