@@ -51,6 +51,13 @@ def test_cannot_create_with_restrictToHost_in_name(self):
5151 lambda : self .service .inputs .create ('tcp' , 'boris:10000' )
5252 )
5353
54+ def test_remove_host_restriction (self ):
55+ input = self .service .inputs .create ('tcp' , str (self .base_port ), restrictToHost = 'boris' )
56+ input .update (restrictToHost = '' )
57+ input .refresh ()
58+ self .check_entity (input )
59+ input .delete ()
60+
5461 def test_create_tcp_ports_with_restrictToHost (self ):
5562 for kind in ['tcp' , 'splunktcp' ]:
5663 # Make sure we can create two restricted inputs on the same port
@@ -101,9 +108,13 @@ def test_update_restrictToHost(self):
101108 def test_update_nonrestrictToHost (self ):
102109 for kind in ['tcp' , 'splunktcp' ]:
103110 input = self .service .inputs .create (kind , str (self .base_port ), restrictToHost = 'boris' )
104- input .update (host = 'meep' )
105- input .refresh ()
106- self .assertTrue (input .name .startswith ('boris' ))
111+ try :
112+ input .update (host = 'meep' )
113+ input .refresh ()
114+ self .assertTrue (input .name .startswith ('boris' ))
115+ except :
116+ input .delete ()
117+ raise
107118
108119class TestRead (testlib .SDKTestCase ):
109120 def test_read (self ):
@@ -170,20 +181,19 @@ class TestInput(testlib.SDKTestCase):
170181 def setUp (self ):
171182 super (TestInput , self ).setUp ()
172183 inputs = self .service .inputs
173- tcp_port = str (highest_port (self .service , 10000 , 'tcp' , 'splunktcp' )+ 1 )
174- udp_port = str (highest_port (self .service , 10000 , 'udp' )+ 1 )
175- restricted_tcp_port = str (highest_port (self .service , int (tcp_port )+ 1 , 'tcp' , 'splunktcp' )+ 1 )
176- test_inputs = [{'kind' : 'tcp' , 'name' : tcp_port , 'host' : 'sdk-test' },
177- {'kind' : 'udp' , 'name' : udp_port , 'host' : 'sdk-test' },
178- {'kind' : 'tcp' , 'name' : 'boris:' + restricted_tcp_port , 'host' : 'sdk-test' }]
184+ unrestricted_port = str (highest_port (self .service , 10000 , 'tcp' , 'splunktcp' , 'udp' )+ 1 )
185+ restricted_port = str (highest_port (self .service , int (unrestricted_port )+ 1 , 'tcp' , 'splunktcp' )+ 1 )
186+ test_inputs = [{'kind' : 'tcp' , 'name' : unrestricted_port , 'host' : 'sdk-test' },
187+ {'kind' : 'udp' , 'name' : unrestricted_port , 'host' : 'sdk-test' },
188+ {'kind' : 'tcp' , 'name' : 'boris:' + restricted_port , 'host' : 'sdk-test' }]
179189 self ._test_entities = {}
180190
181191 self ._test_entities ['tcp' ] = \
182- inputs .create ('tcp' , str ( tcp_port ) , host = 'sdk-test' )
192+ inputs .create ('tcp' , unrestricted_port , host = 'sdk-test' )
183193 self ._test_entities ['udp' ] = \
184- inputs .create ('udp' , str ( udp_port ) , host = 'sdk-test' )
194+ inputs .create ('udp' , unrestricted_port , host = 'sdk-test' )
185195 self ._test_entities ['restrictedTcp' ] = \
186- inputs .create ('tcp' , restricted_tcp_port , restrictToHost = 'boris' )
196+ inputs .create ('tcp' , restricted_port , restrictToHost = 'boris' )
187197
188198 def tearDown (self ):
189199 super (TestInput , self ).tearDown ()
@@ -260,8 +270,9 @@ def test_delete(self):
260270 inputs .delete (name )
261271 self .assertFalse (name in inputs )
262272 else :
263- self .assertRaises (client .AmbiguousReferenceException ,
264- inputs .delete , name )
273+ if not name .startswith ('boris' ):
274+ self .assertRaises (client .AmbiguousReferenceException ,
275+ inputs .delete , name )
265276 self .service .inputs .delete (kind , name )
266277 self .assertFalse ((kind ,name ) in inputs )
267278 self .assertRaises (client .EntityDeletedException ,
0 commit comments