Skip to content

Commit fe4e198

Browse files
author
Frederick Ross
committed
Resolved comments from review.
1 parent 2745502 commit fe4e198

22 files changed

+399
-44
lines changed

splunklib/client.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def messages(self):
401401
@property
402402
def modular_input_kinds(self):
403403
"""Returns a collection of the modular input kinds on this Splunk instance."""
404-
if self.splunk_version[0] >= 5:
404+
if self.splunk_version >= (5,):
405405
return ReadOnlyCollection(self, PATH_MODULAR_INPUTS, item=ModularInputKind)
406406
else:
407407
raise IllegalOperationException("Modular inputs are not supported before Splunk version 5.")
@@ -1481,7 +1481,7 @@ def default(self):
14811481
return index['defaultDatabase']
14821482

14831483
def delete(self, name):
1484-
if self.service.splunk_version[0] >= 5:
1484+
if self.service.splunk_version >= (5,):
14851485
Collection.delete(self, name)
14861486
else:
14871487
raise IllegalOperationException("Deleting indexes via the REST API is "
@@ -1558,12 +1558,19 @@ def clean(self, timeout=60):
15581558
self.refresh()
15591559
tds = self['maxTotalDataSizeMB']
15601560
ftp = self['frozenTimePeriodInSecs']
1561+
was_disabled_initially = self.disabled
15611562
try:
1563+
if (not was_disabled_initially and \
1564+
self.service.splunk_version < (5,)):
1565+
# Need to disable the index first on Splunk 4.x,
1566+
# but it doesn't work to disable it on 5.0.
1567+
self.disable()
15621568
self.update(maxTotalDataSizeMB=1, frozenTimePeriodInSecs=1)
15631569
self.roll_hot_buckets()
15641570

15651571
start = datetime.now()
15661572
diff = timedelta(seconds=timeout)
1573+
# Wait until event count goes to 0.
15671574
while self.content.totalEventCount != '0' and datetime.now() < start+diff:
15681575
sleep(1)
15691576
self.refresh()
@@ -1573,6 +1580,10 @@ def clean(self, timeout=60):
15731580
if self.content.totalEventCount != '0':
15741581
raise OperationError, "Cleaning index %s took longer than %s seconds; timing out." % \
15751582
(self.name, timeout)
1583+
if (not was_disabled_initially and \
1584+
self.service.splunk_version < (5,)):
1585+
# Re-enable the index if it was originally enabled and we messed with it.
1586+
self.enable()
15761587
return self
15771588

15781589
def disable(self):

tests/test_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import splunklib.client as client
2121
import splunklib.data as data
2222

23-
class TestApp(testlib.TestCase):
23+
class TestApp(testlib.SDKTestCase):
2424
app = None
2525
app_name = None
2626
def setUp(self):

tests/test_binding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def isatom(body):
400400
root.find(XNAME_ID) is not None and \
401401
root.find(XNAME_TITLE) is not None
402402

403-
class TestPluggableHTTP(testlib.TestCase):
403+
class TestPluggableHTTP(testlib.SDKTestCase):
404404
# Verify pluggable HTTP reqeust handlers.
405405
def test_handlers(self):
406406
paths = ["/services", "authentication/users",

tests/test_collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
expected_fields_keys = set(['required', 'optional', 'wildcard'])
3838

3939

40-
class TestCase(testlib.TestCase):
40+
class CollectionTestCase(testlib.SDKTestCase):
4141
def setUp(self):
42-
super(TestCase, self).setUp()
42+
super(CollectionTestCase, self).setUp()
4343
if self.service.splunk_version[0] >= 5 and 'modular_input_kinds' not in collections:
4444
collections.append('modular_input_kinds') # Not supported before Splunk 5.0
4545
else:

tests/test_conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import splunklib.client as client
2121

22-
class TestRead(testlib.TestCase):
22+
class TestRead(testlib.SDKTestCase):
2323
def test_read(self):
2424
service = client.connect(**self.opts.kwargs)
2525

@@ -36,7 +36,7 @@ def test_read(self):
3636
for stanza in confs['indexes'].list(count=5):
3737
self.check_entity(stanza)
3838

39-
class TestConfs(testlib.TestCase):
39+
class TestConfs(testlib.SDKTestCase):
4040
def setUp(self):
4141
super(TestConfs, self).setUp()
4242
self.app_name = testlib.tmpname()

tests/test_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import splunklib.data as data
2323

24-
class TestCase(testlib.TestCase):
24+
class DataTestCase(testlib.SDKTestCase):
2525
def test_elems(self):
2626
result = data.load("")
2727
self.assertTrue(result is None)

tests/test_event_type.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
import splunklib.client as client
2121

22-
class TestRead(testlib.TestCase):
22+
class TestRead(testlib.SDKTestCase):
2323
def test_read(self):
2424
for event_type in self.service.event_types.list(count=1):
2525
self.check_entity(event_type)
2626

27-
class TestCreate(testlib.TestCase):
27+
class TestCreate(testlib.SDKTestCase):
2828
def test_create(self):
2929
self.event_type_name = testlib.tmpname()
3030
event_types = self.service.event_types
@@ -47,7 +47,7 @@ def tearDown(self):
4747
except KeyError:
4848
pass
4949

50-
class TestEventType(testlib.TestCase):
50+
class TestEventType(testlib.SDKTestCase):
5151
def setUp(self):
5252
super(TestEventType, self).setUp()
5353
self.event_type_name = testlib.tmpname()

0 commit comments

Comments
 (0)