@@ -76,6 +76,14 @@ def wait(predicate, timeout=60, pause_time=0.5):
7676 logging .debug ("wait finished after %s seconds" , datetime .now () - start )
7777
7878
79+ def restart_splunk (service : client .Service ):
80+ service .restart (timeout = 120 )
81+ # Give Splunk some additional time. In our test suite, a subsequent
82+ # restart shortly after the initial restart can cause Splunk to crash
83+ # and fail to start.
84+ sleep (15 )
85+
86+
7987class SDKTestCase (unittest .TestCase ):
8088 restart_already_required = False
8189 installedApps = []
@@ -138,6 +146,9 @@ def check_entity(self, entity):
138146 continue
139147 raise
140148
149+ def restart_splunk (self ):
150+ restart_splunk (self .service )
151+
141152 def clear_restart_message (self ):
142153 """Tell Splunk to forget that it needs to be restarted.
143154
@@ -175,7 +186,7 @@ def install_app_from_collection(self, name):
175186 if he .status == 400 :
176187 raise IOError (f"App { name } not found in app collection" )
177188 if self .service .restart_required :
178- self .service . restart ( 120 )
189+ self .restart_splunk ( )
179190 self .installedApps .append (name )
180191
181192 def app_collection_installed (self ):
@@ -221,20 +232,14 @@ def pathInApp(self, appName, pathComponents):
221232 appPath = separator .join ([splunkHome , "etc" , "apps" , appName ] + pathComponents )
222233 return appPath
223234
224- def restartSplunk (self , timeout = 240 ):
225- if self .service .restart_required :
226- self .service .restart (timeout )
227- else :
228- raise NoRestartRequiredError ()
229-
230235 @classmethod
231236 def setUpClass (cls ):
232237 cls .opts = parse ([], {}, ".env" )
233238 cls .opts .kwargs .update ({"retries" : 3 })
234239 # Before we start, make sure splunk doesn't need a restart.
235240 service = client .connect (** cls .opts .kwargs )
236241 if service .restart_required :
237- service . restart ( timeout = 120 )
242+ self . restart_splunk ( )
238243
239244 def setUp (self ):
240245 unittest .TestCase .setUp (self )
@@ -244,7 +249,7 @@ def setUp(self):
244249 # and restart. That way we'll be sane for the rest of
245250 # the test.
246251 if self .service .restart_required :
247- self .restartSplunk ()
252+ self .restart_splunk ()
248253 logging .debug (
249254 "Connected to splunkd version %s" ,
250255 "." .join (str (x ) for x in self .service .splunk_version ),
0 commit comments