Skip to content

Commit 9cfcb03

Browse files
author
Frederick Ross
committed
Switched to server-side app collection. Fixed a couple restart issues in the index test suite. Added support for version key in .splunkrc (for compatibility with JavaScript).
1 parent 5d325e1 commit 9cfcb03

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

tests/test_index.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ def tearDown(self):
4242
logging.warning("test_index.py:TestDeleteIndex: Skipped: cannot "
4343
"delete indexes via the REST API in Splunk 4.x")
4444

45-
46-
class IndexWithoutRestart(IndexTest):
4745
def totalEventCount(self):
4846
self.index.refresh()
4947
return int(self.index['totalEventCount'])
@@ -57,6 +55,7 @@ def test_default(self):
5755

5856
def test_disable_enable(self):
5957
self.index.disable()
58+
self.restartSplunk()
6059
self.index.refresh()
6160
self.assertEqual(self.index['disabled'], '1')
6261
self.index.enable()
@@ -65,10 +64,15 @@ def test_disable_enable(self):
6564

6665
def test_submit_and_clean(self):
6766
self.index.refresh()
68-
6967
originalCount = int(self.index['totalEventCount'])
7068
self.index.submit("Hello again!", sourcetype="Boris", host="meep")
7169
self.assertEventuallyEqual(originalCount+1, self.totalEventCount)
70+
71+
# Cleaning an enabled index on 4.x takes forever, so we disable it.
72+
# However, cleaning it on 5 requires it to be enabled.
73+
if self.service.splunk_version < (5,):
74+
self.index.disable()
75+
self.restartSplunk()
7276
self.index.clean(timeout=500)
7377
self.assertEqual(self.index['totalEventCount'], '0')
7478

tests/testlib.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,27 @@ def clearRestartMessage(self):
143143
else:
144144
raise
145145

146-
def appCollectionPath(self):
147-
if 'appcollection' not in self.opts.kwargs:
148-
raise ValueError('No path to appcollection found in .splunkrc')
149-
elif not os.path.isdir(self.opts.kwargs['appcollection']):
150-
raise ValueError('appcollection not found at %s' % \
151-
self.opts.kwargs['appcollection'])
152-
else:
153-
return self.opts.kwargs['appcollection']
154-
155146
def installAppFromCollection(self, name):
156-
basePath = self.appCollectionPath()
157-
appPath = os.path.abspath(os.path.join(basePath, "build", name + ".tar"))
158-
if not os.path.isfile(appPath):
159-
raise ValueError("No such application at %s" % appPath)
147+
collectionName = 'sdk-app-collection'
148+
if collectionName not in self.service.apps:
149+
raise ValueError("sdk-test-application not installed in splunkd")
150+
splunkHome = self.service.settings['SPLUNK_HOME']
151+
if "/" in splunkHome and "\\" in splunkHome:
152+
raise ValueError("There are both forward and back slashes in $SPLUNK_HOME. What system are you on?!?")
153+
elif "/" in splunkHome:
154+
separator = "/"
155+
elif "\\" in splunkHome:
156+
separator = "\\"
157+
else:
158+
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"])
160161
kwargs = {"update": 1, "name": appPath}
161-
self.service.post("apps/appinstall", **kwargs)
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)
162167
self.installedApps.append(name)
163168

164169
def restartSplunk(self, timeout=120):

utils/__init__.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,10 @@ def config(option, opt, value, parser):
6363
'default': None,
6464
'help': "Password to login with"
6565
},
66-
# This is introduced for the Java SDK's test suite. It has
67-
# to be here in order to share a single .splunkrc among the
68-
# SDKs, but is not yet used in Python (though it will probably
69-
# be used in future). It's optional, though, so we don't need
70-
# to change the README or otherwise document it in the Python
71-
# SDK for now.
72-
'appcollection': {
73-
'flags': ["--appcollection"],
66+
'version': {
67+
'flags': ["--version"],
7468
'default': None,
75-
'help': "Path to appcollection"
69+
'help': 'Ignore. Used by JavaScript SDK.'
7670
}
7771
}
7872

0 commit comments

Comments
 (0)