diff --git a/novaproxy/authd.py b/novaproxy/authd.py index 2cf23e2..68fdf73 100644 --- a/novaproxy/authd.py +++ b/novaproxy/authd.py @@ -14,14 +14,14 @@ # under the License. import base64 -import Cookie import hashlib import json import os import socket import ssl -import urlparse +from six.moves import http_cookies as Cookie +import six.moves.urllib.parse as urlparse import websockify @@ -36,7 +36,7 @@ VMAD_CONNECT_CMD = "CONNECT" def expect(sock, code): - line = sock.recv(1024) + line = sock.recv(1024).decode('ascii') recv_code, msg = line.split()[0:2] recv_code = int(recv_code) if code != recv_code: @@ -55,16 +55,18 @@ def handshake(host, port, ticket, cfg_file, thumbprint): h.update(cert) if thumbprint != h.hexdigest(): raise Exception("Server thumbprint doesn't match") - sock.write("%s %s\r\n" % (VMAD_USER_CMD, ticket)) + sock.sendall(("%s %s\r\n" % (VMAD_USER_CMD, ticket)).encode('ascii')) expect(sock, VMAD_NEEDPASSWD) - sock.write("%s %s\r\n" % (VMAD_PASS_CMD, ticket)) + sock.sendall(("%s %s\r\n" % (VMAD_PASS_CMD, ticket)).encode('ascii')) expect(sock, VMAD_LOGINOK) rand = os.urandom(12) - rand = base64.b64encode(rand) - sock.write("%s %s\r\n" % (VMAD_THUMB_CMD, rand)) + rand_b = base64.b64encode(rand) + rand_s = rand_b.decode('ascii') + sock.sendall(("%s %s\r\n" % (VMAD_THUMB_CMD, rand_s)).encode('ascii')) thumbprint2 = expect(sock, VMAD_OK) thumbprint2 = thumbprint2.replace(':', '').lower() - sock.write("%s %s mks\r\n" % (VMAD_CONNECT_CMD, cfg_file)) + sock.sendall( + ("%s %s mks\r\n" % (VMAD_CONNECT_CMD, cfg_file)).encode('ascii')) expect(sock, VMAD_OK) sock2 = ssl.wrap_socket(sock) cert2 = sock2.getpeercert(binary_form=True) @@ -72,7 +74,7 @@ def handshake(host, port, ticket, cfg_file, thumbprint): h.update(cert2) if thumbprint2 != h.hexdigest(): raise Exception("Second thumbprint doesn't match") - sock2.write(rand) + sock2.sendall(rand_b) return sock2 diff --git a/novaproxy/mksproxy.py b/novaproxy/mksproxy.py index f67ea56..280809e 100644 --- a/novaproxy/mksproxy.py +++ b/novaproxy/mksproxy.py @@ -16,8 +16,8 @@ import os import sys import argparse -import authd from novaclient import client +from novaproxy import authd import websockify import logging diff --git a/novaproxy/tests/test_authd.py b/novaproxy/tests/test_authd.py index 1859b75..1a0a212 100644 --- a/novaproxy/tests/test_authd.py +++ b/novaproxy/tests/test_authd.py @@ -33,10 +33,10 @@ class AuthdRequestHandler(testtools.TestCase): '200 OK'] def fake_recv(len): - return msgs.pop(0) + return msgs.pop(0).encode('ascii') def fake_getpeercert(binary_form=True): - return 'fake-certificate' + return 'fake-certificate'.encode('ascii') sock = mock.MagicMock() sock.recv = fake_recv @@ -56,10 +56,10 @@ class AuthdRequestHandler(testtools.TestCase): '200 OK'] def fake_recv(len): - return msgs.pop(0) + return msgs.pop(0).encode('ascii') def fake_getpeercert(binary_form=True): - return 'fake-certificate' + return 'fake-certificate'.encode('ascii') sock = mock.MagicMock() sock.recv = fake_recv @@ -79,10 +79,10 @@ class AuthdRequestHandler(testtools.TestCase): '200 OK'] def fake_recv(len): - return msgs.pop(0) + return msgs.pop(0).encode('ascii') def fake_getpeercert(binary_form=True): - return 'fake-certificate' + return 'fake-certificate'.encode('ascii') sock = mock.MagicMock() sock.recv = fake_recv diff --git a/requirements.txt b/requirements.txt index ea2e1a8..dea9ba4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ python-novaclient +six websockify diff --git a/tox.ini b/tox.ini index 7c930e9..eab96e9 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,pep8 +envlist = py35,py27,pep8 skipsdist = True [testenv]