1111from infamy .util import until , curl
1212
1313
14- def _verify (server ):
14+ def _verify (server , silent = False ):
1515 # TODO: Should really use mDNS here....
1616 url = f"http://[{ server } ]:91/index.html"
17- response = curl (url )
17+ response = curl (url , silent = silent )
1818 return response is not None and "It works" in response
1919
2020
@@ -46,6 +46,10 @@ def _verify(server):
4646 "command" : "/usr/sbin/httpd -f -v -p 91" ,
4747 "network" : {
4848 "host" : True
49+ },
50+ "resource-limit" : {
51+ "memory" : 512 , # 512 KiB
52+ "cpu" : 50000 # 50% of one CPU
4953 }
5054 }
5155 ]
@@ -57,7 +61,23 @@ def _verify(server):
5761 until (lambda : c .running (NAME ), attempts = 60 )
5862
5963 with test .step ("Verify container 'web' is reachable on http://container-host.local:91" ):
60- until (lambda : _verify (addr ), attempts = 10 )
64+ until (lambda : _verify (addr , silent = True ), attempts = 10 )
65+
66+ with test .step ("Verify resource constraints and usage are available" ):
67+ data = target .get_data ("/infix-containers:containers" )
68+ containers = data .get ("containers" , {}).get ("container" , [])
69+ web = next ((c for c in containers if c ["name" ] == NAME ), None )
70+
71+ limits = web .get ("resource-limit" , {})
72+ assert limits .get ("memory" ) == 512 , "Memory limit not set correctly"
73+ assert limits .get ("cpu" ) == 50000 , "CPU limit not set correctly"
74+
75+ rusage = web .get ("resource-usage" , {})
76+ assert rusage is not None , "Resource usage data not available"
77+
78+ mem_used = rusage .get ("memory" )
79+ assert mem_used is not None , "Memory usage not reported"
80+ print (f"Container using { mem_used } KiB memory" )
6181
6282 with test .step ("Stop container 'web'" ):
6383 c = infamy .Container (target )
@@ -71,5 +91,5 @@ def _verify(server):
7191
7292 with test .step ("Verify container 'web' is reachable on http://container-host.local:91" ):
7393 # Wait for it to restart and respond, or fail
74- until (lambda : _verify (addr ), attempts = 60 )
94+ until (lambda : _verify (addr , silent = True ), attempts = 60 )
7595 test .succeed ()
0 commit comments