@@ -291,24 +291,26 @@ def test_resources_cpu_weight_systemd():
291291 sys .stderr .write ("found wrong CPUWeight for the systemd scope\n " )
292292 return 1
293293
294- cpu_shares = 4321
295- run_crun_command ([ 'update' , '--cpu-share' , str ( cpu_shares ), cid ])
296- # this is the expected cpu weight after the conversion from the CPUShares
297- expected_weight = str (max ( 1 , min ( 10000 , cpu_shares * 100 // 1024 )) )
294+ for values in [( 2 , 1 ), ( 1024 , 100 ), ( 262144 , 10000 )]:
295+ cpu_shares = values [ 0 ]
296+ # this is the expected cpu weight after the conversion from the CPUShares
297+ expected_weight = str (values [ 1 ] )
298298
299- out = run_crun_command (["exec" , cid , "/init" , "cat" , "/sys/fs/cgroup/cpu.weight" ])
300- if expected_weight not in out :
301- sys .stderr .write ("found wrong CPUWeight %s instead of %s for the container cgroup\n " % (out , expected_weight ))
302- return - 1
299+ run_crun_command (['update' , '--cpu-share' , str (cpu_shares ), cid ])
303300
304- out = subprocess . check_output ([ 'systemctl' , 'show' , '-PCPUWeight' , scope ], close_fds = False ). decode (). strip ( )
305- # as above
306- if out != expected_weight :
307- out = subprocess . check_output ([ 'systemctl' , '--user' , 'show' , '-PCPUWeight' , scope ], close_fds = False ). decode (). strip ()
301+ out = run_crun_command ([ "exec" , cid , "/init" , "cat" , "/sys/fs/cgroup/cpu.weight" ] )
302+ if expected_weight not in out :
303+ sys . stderr . write ( "found wrong CPUWeight %s instead of %s for the container cgroup \n " % ( out , expected_weight ))
304+ return - 1
308305
309- if out != expected_weight :
310- sys .stderr .write ("found wrong CPUWeight for the systemd scope\n " )
311- return 1
306+ out = subprocess .check_output (['systemctl' , 'show' ,'-PCPUWeight' , scope ], close_fds = False ).decode ().strip ()
307+ # as above
308+ if out != expected_weight :
309+ out = subprocess .check_output (['systemctl' , '--user' , 'show' ,'-PCPUWeight' , scope ], close_fds = False ).decode ().strip ()
310+
311+ if out != expected_weight :
312+ sys .stderr .write ("found wrong CPUWeight for the systemd scope\n " )
313+ return 1
312314 finally :
313315 if cid is not None :
314316 run_crun_command (["delete" , "-f" , cid ])
0 commit comments