2121
2222import sys
2323from splunklib import six
24+
2425# Run the test suite on the SDK without installing it.
2526sys .path .insert (0 , '../' )
2627sys .path .insert (0 , '../examples' )
2728
2829import splunklib .client as client
2930from time import sleep
3031from datetime import datetime , timedelta
32+
3133try :
3234 import unittest2 as unittest
3335except ImportError :
4345import time
4446
4547import logging
48+
4649logging .basicConfig (
4750 filename = 'test.log' ,
4851 level = logging .DEBUG ,
4952 format = "%(asctime)s:%(levelname)s:%(message)s" )
5053
54+
5155class NoRestartRequiredError (Exception ):
5256 pass
5357
58+
5459class WaitTimedOutError (Exception ):
5560 pass
5661
62+
5763def to_bool (x ):
5864 if x == '1' :
5965 return True
@@ -64,7 +70,7 @@ def to_bool(x):
6470
6571
6672def tmpname ():
67- name = 'delete-me-' + str (os .getpid ()) + str (time .time ()).replace ('.' ,'-' )
73+ name = 'delete-me-' + str (os .getpid ()) + str (time .time ()).replace ('.' , '-' )
6874 return name
6975
7076
@@ -77,7 +83,7 @@ def wait(predicate, timeout=60, pause_time=0.5):
7783 logging .debug ("wait timed out after %d seconds" , timeout )
7884 raise WaitTimedOutError
7985 sleep (pause_time )
80- logging .debug ("wait finished after %s seconds" , datetime .now ()- start )
86+ logging .debug ("wait finished after %s seconds" , datetime .now () - start )
8187
8288
8389class SDKTestCase (unittest .TestCase ):
@@ -94,7 +100,7 @@ def assertEventuallyTrue(self, predicate, timeout=30, pause_time=0.5,
94100 logging .debug ("wait timed out after %d seconds" , timeout )
95101 self .fail (timeout_message )
96102 sleep (pause_time )
97- logging .debug ("wait finished after %s seconds" , datetime .now ()- start )
103+ logging .debug ("wait finished after %s seconds" , datetime .now () - start )
98104
99105 def check_content (self , entity , ** kwargs ):
100106 for k , v in six .iteritems (kwargs ):
@@ -163,12 +169,11 @@ def fake_splunk_version(self, version):
163169 finally :
164170 self .service ._splunk_version = original_version
165171
166-
167172 def install_app_from_collection (self , name ):
168173 collectionName = 'sdkappcollection'
169174 if collectionName not in self .service .apps :
170175 raise ValueError ("sdk-test-application not installed in splunkd" )
171- appPath = self .pathInApp (collectionName , ["build" , name + ".tar" ])
176+ appPath = self .pathInApp (collectionName , ["build" , name + ".tar" ])
172177 kwargs = {"update" : True , "name" : appPath , "filename" : True }
173178
174179 try :
@@ -235,13 +240,13 @@ def setUpClass(cls):
235240 cls .opts = parse ([], {}, ".env" )
236241
237242 # Before we start, make sure splunk doesn't need a restart.
238- service = client .connect (retries = 5 , retryBackoff = 10 , ** cls .opts .kwargs )
243+ service = client .connect (retries = 5 , ** cls .opts .kwargs )
239244 if service .restart_required :
240245 service .restart (timeout = 120 )
241246
242247 def setUp (self ):
243248 unittest .TestCase .setUp (self )
244- self .service = client .connect (** self .opts .kwargs )
249+ self .service = client .connect (retries = 5 , ** self .opts .kwargs )
245250 # If Splunk is in a state requiring restart, go ahead
246251 # and restart. That way we'll be sane for the rest of
247252 # the test.
0 commit comments