@@ -72,14 +72,6 @@ class SDKTestCase(unittest.TestCase):
7272 restart_already_required = False
7373 installedApps = []
7474
75- def assertEventuallyEqual (self , expected , func , timeout = 10 , pause_time = 0.5 ,
76- timeout_message = "Operation timed out." ):
77- self .assertEventuallyTrue (
78- lambda : expected == func (),
79- timeout = timeout , pause_time = pause_time ,
80- timeout_message = timeout_message
81- )
82-
8375 def assertEventuallyTrue (self , predicate , timeout = 10 , pause_time = 0.5 ,
8476 timeout_message = "Operation timed out." ):
8577 assert pause_time < timeout
@@ -134,6 +126,14 @@ def check_entity(self, entity):
134126 raise
135127
136128 def clearRestartMessage (self ):
129+ """Tell Splunk to forget that it needs to be restarted.
130+
131+ This is used mostly in cases such as deleting a temporary application.
132+ Splunk asks to be restarted when that happens, but unless the application
133+ contained modular input kinds or the like, it isn't necessary.
134+ """
135+ if not self .service .restart_required :
136+ raise ValueError ("Tried to clear restart message when there was none." )
137137 try :
138138 self .service .delete ("messages/restart_required" )
139139 except client .HTTPError as he :
@@ -158,20 +158,35 @@ def installAppFromCollection(self, name):
158158 def pathInApp (self , appName , pathComponents ):
159159 """Return a path to *pathComponents* in *appName*.
160160
161- *pathComponents* shold be a list of strings giving the components.
161+ `pathInApp` is used to refer to files in applications installed with
162+ `installAppFromCollection`. For example, the app `file_to_upload` in
163+ the collection contains `log.txt`. To get the path to it, call::
164+
165+ pathInApp('file_to_upload', ['log.txt'])
166+
167+ The path to `setup.xml` in `has_setup_xml` would be fetched with::
168+
169+ pathInApp('has_setup_xml', ['default', 'setup.xml'])
170+
171+ `pathInApp` figures out the correct separator to use (based on whether
172+ splunkd is running on Windows or Unix) and joins the elements in
173+ *pathComponents* into a path relative to the application specified by
174+ *appName*.
175+
176+ *pathComponents* should be a list of strings giving the components.
162177 This function will try to figure out the correct separator (/ or \)
163178 for the platform that splunkd is running on and construct the path
164179 as needed.
165180
166181 :return: A string giving the path.
167182 """
168183 splunkHome = self .service .settings ['SPLUNK_HOME' ]
169- if "/" in splunkHome and "\\ " in splunkHome :
170- raise ValueError ("There are both forward and back slashes in $SPLUNK_HOME. What system are you on?!?" )
184+ if "\\ " in splunkHome :
185+ # This clause must come first, since Windows machines may
186+ # have mixed \ and / in their paths.
187+ separator = "\\ "
171188 elif "/" in splunkHome :
172189 separator = "/"
173- elif "\\ " in splunkHome :
174- separator = "\\ "
175190 else :
176191 raise ValueError ("No separators in $SPLUNK_HOME. Can't determine what file separator to use." )
177192 appPath = separator .join ([splunkHome , "etc" , "apps" , appName ] + pathComponents )
@@ -198,6 +213,9 @@ def setUpClass(cls):
198213 def setUp (self ):
199214 unittest .TestCase .setUp (self )
200215 self .service = client .connect (** self .opts .kwargs )
216+ # If Splunk is in a state requiring restart, go ahead
217+ # and restart. That way we'll be sane for the rest of
218+ # the test.
201219 if self .service .restart_required :
202220 self .restartSplunk ()
203221 logging .debug ("Connected to splunkd version %s" , '.' .join (str (x ) for x in self .service .splunk_version ))
0 commit comments