Skip to content

Commit 44eb11c

Browse files
Performance improvement for updating or deleting input (splunk#247)
1 parent e30936a commit 44eb11c

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

splunklib/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,13 @@ def info(self):
463463
response = self.get("/services/server/info")
464464
return _filter_content(_load_atom(response, MATCH_ENTRY_CONTENT))
465465

466+
def input(self, path, kind=None):
467+
"""Retrieves an input by path, and optionally kind.
468+
469+
:return: A :class:`Input` object.
470+
"""
471+
return Input(self, path, kind=kind).refresh()
472+
466473
@property
467474
def inputs(self):
468475
"""Returns the collection of inputs configured on this Splunk instance.

tests/test_input.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
from __future__ import absolute_import
1717
from __future__ import print_function
1818

19-
import unittest2
20-
2119
from splunklib.binding import HTTPError
2220

2321
from tests import testlib
@@ -30,6 +28,7 @@
3028

3129
import splunklib.client as client
3230

31+
3332
def highest_port(service, base_port, *kinds):
3433
"""Find the first port >= base_port not in use by any input in kinds."""
3534
highest_port = base_port
@@ -38,6 +37,7 @@ def highest_port(service, base_port, *kinds):
3837
highest_port = max(port, highest_port)
3938
return highest_port
4039

40+
4141
class TestTcpInputNameHandling(testlib.SDKTestCase):
4242
def setUp(self):
4343
super(TestTcpInputNameHandling, self).setUp()
@@ -116,6 +116,7 @@ def test_update_restrictToHost_fails(self):
116116
lambda: boris.update(restrictToHost='hilda')
117117
)
118118

119+
119120
class TestRead(testlib.SDKTestCase):
120121
def test_read(self):
121122
inputs = self.service.inputs
@@ -188,6 +189,7 @@ def test_oneshot_on_nonexistant_file(self):
188189
self.assertRaises(HTTPError,
189190
self.service.inputs.oneshot, name)
190191

192+
191193
class TestInput(testlib.SDKTestCase):
192194
def setUp(self):
193195
super(TestInput, self).setUp()
@@ -243,7 +245,6 @@ def test_lists_modular_inputs(self):
243245
input = inputs['abcd', 'test2']
244246
self.assertEqual(input.field1, 'boris')
245247

246-
247248
def test_create(self):
248249
inputs = self.service.inputs
249250
for entity in six.itervalues(self._test_entities):
@@ -264,6 +265,13 @@ def test_read(self):
264265
self.assertEqual(this_entity.name, read_entity.name)
265266
self.assertEqual(this_entity.host, read_entity.host)
266267

268+
def test_read_indiviually(self):
269+
tcp_input = self.service.input(self._test_entities['tcp'].path,
270+
self._test_entities['tcp'].kind)
271+
self.assertIsNotNone(tcp_input)
272+
self.assertTrue('tcp', tcp_input.kind)
273+
self.assertTrue(self._test_entities['tcp'].name, tcp_input.name)
274+
267275
def test_update(self):
268276
inputs = self.service.inputs
269277
for entity in six.itervalues(self._test_entities):
@@ -273,7 +281,7 @@ def test_update(self):
273281
entity.refresh()
274282
self.assertEqual(entity.host, kwargs['host'])
275283

276-
@unittest2.skip('flaky')
284+
@unittest.skip('flaky')
277285
def test_delete(self):
278286
inputs = self.service.inputs
279287
remaining = len(self._test_entities)-1

0 commit comments

Comments
 (0)