Skip to content

Commit ccc69e4

Browse files
committed
Return string from validate port
Validate port was returning an int, which was causing casting problems. Change to return a string Testing: unit tests, update product test, manual verification
1 parent ad509e5 commit ccc69e4

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

prestoadmin/util/validators.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ def validate_username(username):
3131

3232

3333
def validate_port(port):
34+
if not isinstance(port, basestring):
35+
raise ConfigurationError('Port must be of type string, but found %s.' %
36+
str(type(port)))
3437
try:
3538
port_int = int(port)
36-
except TypeError:
37-
raise ConfigurationError('Port must be of type string, but '
38-
'found ' + str(type(port)) + '.')
3939
except ValueError:
4040
raise ConfigurationError('Invalid value ' + port + ': '
4141
'port must be a number between 1 and 65535.')
4242
if not port_int > 0 or not port_int < 65535:
4343
raise ConfigurationError('Invalid port number ' + port +
4444
': port must be between 1 and 65535')
45-
return port_int
45+
return port
4646

4747

4848
def validate_host(host):

tests/product/test_server_install.py

+4
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ def test_install_interactive_with_hostnames(self):
351351
self.assert_has_default_connector(container)
352352
self.assert_has_jmx_connector(container)
353353

354+
# make sure that we don't get an error when using the written out
355+
# configs
356+
self.run_prestoadmin('server start')
357+
354358
def test_install_interactive_with_ips(self):
355359
ips = self.cluster.get_ip_address_dict()
356360
rpm_name = self.installer.copy_presto_rpm_to_master()

tests/unit/util/test_validators.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,18 @@ def test_invalid_host_type(self):
5252
(["my", "list"]))
5353

5454
def test_valid_port(self):
55-
port = 1234
55+
port = '1234'
5656
self.assertEqual(validators.validate_port(port), port)
5757

58+
def test_invalid_port_type(self):
59+
self.assertRaisesRegexp(ConfigurationError,
60+
"Port must be of type string, "
61+
"but found <type 'int'>.",
62+
validators.validate_port, 1234)
63+
5864
def test_invalid_port(self):
5965
self.assertRaisesRegexp(ConfigurationError,
6066
"Invalid port number 99999999: port must be "
6167
"between 1 and 65535",
6268
validators.validate_port,
6369
("99999999"))
64-
65-
def test_invalid_port_type(self):
66-
self.assertRaises(ConfigurationError,
67-
validators.validate_port, (["123"]))

0 commit comments

Comments
 (0)