@@ -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