11import pytest
22import json
3+ import signal
34import time
45import os
56
89from flaky import flaky
910
1011
12+ def get_running_allocation (nomad_setup ):
13+ max_iterations = 6
14+ for _ in range (max_iterations ):
15+ try :
16+ return next (
17+ alloc
18+ for alloc in nomad_setup .allocations .get_allocations ()
19+ if alloc ["ClientStatus" ] == "running"
20+ )
21+ except StopIteration :
22+ # No alloc running
23+ time .sleep (5 )
24+ raise ValueError ("No allocations running" )
25+
26+
1127# integration tests requires nomad Vagrant VM or Binary running
1228def test_register_job (nomad_setup ):
1329
@@ -17,7 +33,6 @@ def test_register_job(nomad_setup):
1733 assert "example" in nomad_setup .job
1834
1935 max_iterations = 6
20-
2136 while nomad_setup .job ["example" ]["Status" ] != "running" :
2237 time .sleep (5 )
2338 if max_iterations == 0 :
@@ -70,11 +85,37 @@ def test_read_allocation_stats(nomad_setup):
7085 f = nomad_setup .client .allocation .read_allocation_stats (a )
7186
7287
88+ @pytest .mark .skipif (
89+ tuple (int (i ) for i in os .environ .get ("NOMAD_VERSION" ).split ("." )) < (0 , 9 , 1 ), reason = "Not supported in version"
90+ )
91+ def test_signal_allocation (nomad_setup ):
92+ alloc_id = get_running_allocation (nomad_setup )["ID" ]
93+ nomad_setup .client .allocation .signal_allocation (alloc_id , signal .SIGUSR1 .name )
94+
95+
96+ @pytest .mark .skipif (
97+ tuple (int (i ) for i in os .environ .get ("NOMAD_VERSION" ).split ("." )) < (0 , 9 , 1 ), reason = "Not supported in version"
98+ )
99+ def test_signal_allocation_task (nomad_setup ):
100+ allocation = get_running_allocation (nomad_setup )
101+ alloc_id = allocation ["ID" ]
102+ task = list (allocation ["TaskStates" ].keys ())[0 ]
103+ nomad_setup .client .allocation .signal_allocation (alloc_id , signal .SIGUSR1 .name , task )
104+
105+
106+ @pytest .mark .skipif (
107+ tuple (int (i ) for i in os .environ .get ("NOMAD_VERSION" ).split ("." )) < (0 , 9 , 1 ), reason = "Not supported in version"
108+ )
109+ def test_signal_allocation_invalid_signal (nomad_setup ):
110+ alloc_id = get_running_allocation (nomad_setup )["ID" ]
111+ with pytest .raises (nomad .api .exceptions .BaseNomadException , match = "invalid signal" ):
112+ nomad_setup .client .allocation .signal_allocation (alloc_id , "INVALID-SIGNAL" )
113+
114+
73115@pytest .mark .skipif (
74116 tuple (int (i ) for i in os .environ .get ("NOMAD_VERSION" ).split ("." )) < (0 , 8 , 1 ), reason = "Not supported in version"
75117)
76118def test_gc_all_allocations (nomad_setup ):
77-
78119 node_id = nomad_setup .nodes .get_nodes ()[0 ]["ID" ]
79120 nomad_setup .client .gc_all_allocations .garbage_collect (node_id )
80121 nomad_setup .client .gc_all_allocations .garbage_collect ()
0 commit comments