Skip to content

Commit 083dd7e

Browse files
author
Frederick Ross
committed
Merge branch 'fross/restrictToHost' into develop
2 parents 2c25749 + 8e51160 commit 083dd7e

File tree

2 files changed

+16
-27
lines changed

2 files changed

+16
-27
lines changed

splunklib/client.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,13 +1684,6 @@ def __init__(self, service, path, kind=None, **kwargs):
16841684
if self.kind == 'splunktcp':
16851685
self.kind = 'tcp/cooked'
16861686

1687-
@property
1688-
def restrictToHost(self):
1689-
if 'restrictToHost' in self._state.content:
1690-
return self._state.content['restrictToHost']
1691-
else:
1692-
return ''
1693-
16941687
def update(self, **kwargs):
16951688
if self.kind not in ['tcp', 'splunktcp', 'tcp/raw', 'tcp/cooked']:
16961689
result = super(Input, self).update(**kwargs)
@@ -1709,7 +1702,7 @@ def update(self, **kwargs):
17091702
# TCP input, our update request will fail, since our reference to it still uses
17101703
# the old path.
17111704
to_update = kwargs.copy()
1712-
to_update['restrictToHost'] = kwargs.get('restrictToHost', self['restrictToHost'])
1705+
to_update['restrictToHost'] = kwargs.get('restrictToHost', self._state.content.get('restrictToHost', ''))
17131706

17141707
# Do the actual update operation.
17151708
result = super(Input, self).update(**to_update)
@@ -1723,7 +1716,8 @@ def update(self, **kwargs):
17231716
host = to_update['restrictToHost'] + ':' if to_update['restrictToHost'] != '' else ''
17241717
port = self.name.split(':', 1)[-1]
17251718
self.path = base_path + '/' + host + port
1726-
1719+
# We don't have to update self.name, since it's part of the data
1720+
# fetched from splunkd.
17271721
return result
17281722

17291723

tests/test_input.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ def tearDown(self):
3939
input.delete()
4040
super(TestTcpInputNameHandling, self).tearDown()
4141

42+
def create_tcp_input(self, base_port, kind, **options):
43+
port = base_port
44+
while True: # Find the next unbound port
45+
try:
46+
input = self.service.inputs.create(kind, str(port), **options)
47+
return input
48+
except client.HTTPError as he:
49+
if he.status == 400:
50+
port += 1
51+
4252
def test_create_tcp_port(self):
4353
for kind in ['tcp', 'splunktcp']:
4454
input = self.service.inputs.create(kind, str(self.base_port))
@@ -96,15 +106,7 @@ def test_unrestricted_to_restricted_collision(self):
96106

97107
def test_update_restrictToHost(self):
98108
for kind in ['tcp', 'splunktcp']: # No UDP, since it's broken in Splunk
99-
port = self.base_port
100-
while True: # Find the next unbound port
101-
try:
102-
boris = self.service.inputs.create(kind, str(port), restrictToHost='boris')
103-
except client.HTTPError as he:
104-
if he.status == 400:
105-
port += 1
106-
else:
107-
break
109+
boris = self.create_tcp_input(self.base_port, kind, restrictToHost='boris')
108110

109111
# No matter what version we're actually running against,
110112
# we can check that on Splunk < 5.0, we get an exception
@@ -126,15 +128,8 @@ def test_update_restrictToHost(self):
126128

127129
def test_update_nonrestrictToHost(self):
128130
for kind in ['tcp', 'splunktcp']: # No UDP since it's broken in Splunk
129-
port = self.base_port
130-
while True: # Find the next unbound port
131-
try:
132-
input = self.service.inputs.create(kind, str(port), restrictToHost='boris')
133-
except client.HTTPError as he:
134-
if he.status == 400:
135-
port += 1
136-
else:
137-
break
131+
input = self.create_tcp_input(self.base_port, kind, restrictToHost='boris')
132+
138133
try:
139134
input.update(host='meep')
140135
input.refresh()

0 commit comments

Comments
 (0)