Skip to content

Commit 7526b82

Browse files
committed
Resolve issue #13 by making cluster_utils.get_cluster_info less brittle.
1 parent faf5cc7 commit 7526b82

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

django_elasticache/cluster_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def get_cluster_info(host, port):
3232
client.write(b'version\n')
3333
res = client.read_until(b'\r\n').strip()
3434
version_list = res.split(b' ')
35-
if len(version_list) != 2 or version_list[0] != b'VERSION':
35+
if not len(version_list) in [2, 3] or version_list[0] != b'VERSION':
3636
raise WrongProtocolData('version', res)
3737
version = version_list[1]
3838
if StrictVersion(smart_text(version)) >= StrictVersion('1.4.14'):

tests/test_protocol.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
b'CONFIG cluster 0 138\r\n1\nhost|ip|port host||port\n\r\nEND\r\n',
1919
]
2020

21+
TEST_PROTOCOL_3 = [
22+
b'VERSION 1.4.14 (Ubuntu)',
23+
b'CONFIG cluster 0 138\r\n1\nhost|ip|port host||port\n\r\nEND\r\n',
24+
]
2125

2226
@patch('django_elasticache.cluster_utils.Telnet')
2327
def test_happy_path(Telnet):
@@ -54,3 +58,20 @@ def test_prev_versions(Telnet):
5458
call(b'version\n'),
5559
call(b'get AmazonElastiCache:cluster\n'),
5660
])
61+
62+
63+
@patch('django_elasticache.cluster_utils.Telnet')
64+
def test_ubuntu_protocol(Telnet):
65+
client = Telnet.return_value
66+
client.read_until.side_effect = TEST_PROTOCOL_3
67+
68+
try:
69+
get_cluster_info('', 0)
70+
except WrongProtocolData:
71+
raise AssertionError('Raised WrongProtocolData with Ubuntu version.')
72+
73+
client.write.assert_has_calls([
74+
call(b'version\n'),
75+
call(b'config get cluster\n'),
76+
])
77+

0 commit comments

Comments
 (0)