@@ -147,6 +147,25 @@ def installAppFromCollection(self, name):
147147 collectionName = 'sdk-app-collection'
148148 if collectionName not in self .service .apps :
149149 raise ValueError ("sdk-test-application not installed in splunkd" )
150+ appPath = self .pathInApp (collectionName , ["build" , name + ".tar" ])
151+ kwargs = {"update" : 1 , "name" : appPath }
152+ try :
153+ self .service .post ("apps/appinstall" , ** kwargs )
154+ except client .HTTPError as he :
155+ if he .status == 400 :
156+ raise IOError ("App %s not found in app collection" % name )
157+ self .installedApps .append (name )
158+
159+ def pathInApp (self , appName , pathComponents ):
160+ """Return a path to *pathComponents* in *appName*.
161+
162+ *pathComponents* shold be a list of strings giving the components.
163+ This function will try to figure out the correct separator (/ or \)
164+ for the platform that splunkd is running on and construct the path
165+ as needed.
166+
167+ :return: A string giving the path.
168+ """
150169 splunkHome = self .service .settings ['SPLUNK_HOME' ]
151170 if "/" in splunkHome and "\\ " in splunkHome :
152171 raise ValueError ("There are both forward and back slashes in $SPLUNK_HOME. What system are you on?!?" )
@@ -156,15 +175,11 @@ def installAppFromCollection(self, name):
156175 separator = "\\ "
157176 else :
158177 raise ValueError ("No separators in $SPLUNK_HOME. Can't determine what file separator to use." )
159- appPath = separator .join ([splunkHome , "etc" , "apps" , collectionName ,
160- "build" , name + ".tar" ])
161- kwargs = {"update" : 1 , "name" : appPath }
162- try :
163- self .service .post ("apps/appinstall" , ** kwargs )
164- except client .HTTPError as he :
165- if he .status == 400 :
166- raise IOError ("App %s not found in app collection" % name )
167- self .installedApps .append (name )
178+ appPath = separator .join ([splunkHome , "etc" , "apps" , appName ] + pathComponents )
179+ return appPath
180+
181+ def uncheckedRestartSplunk (self , timeout = 120 ):
182+ self .service .restart (timeout )
168183
169184 def restartSplunk (self , timeout = 120 ):
170185 if self .service .restart_required :
@@ -178,19 +193,20 @@ def setUpClass(cls):
178193
179194 def setUp (self ):
180195 unittest .TestCase .setUp (self )
181- self .caused_restart_required = False
182196 self .service = client .connect (** self .opts .kwargs )
183197 if self .service .restart_required :
184- self .restart_already_required = True
198+ self .restartSplunk ()
185199 logging .debug ("Connected to splunkd version %s" , '.' .join (str (x ) for x in self .service .splunk_version ))
186200
187201 def tearDown (self ):
188- if self .service .restart_required and not self . restart_already_required :
202+ if self .service .restart_required :
189203 self .fail ("Test left Splunk in a state requiring a restart." )
190204 for appName in self .installedApps :
191205 if appName in self .service .apps :
192206 self .service .apps .delete (appName )
193207 wait (lambda : appName not in self .service .apps )
208+ if self .service .restart_required :
209+ self .clearRestartMessage ()
194210
195211def main ():
196212 unittest .main ()
0 commit comments