Commit c5ba49d9 authored by Jérome Perrin's avatar Jérome Perrin

python3 tests

parent c1ce2d8a
......@@ -24,6 +24,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from __future__ import absolute_import
from setuptools import setup, find_packages
version = '0.0.1.dev0'
......
......@@ -25,34 +25,37 @@
#
##############################################################################
from __future__ import absolute_import
import glob
import os
import requests
import httplib
import six.moves.http_client
from requests_toolbelt.adapters import source
import json
import multiprocessing
import subprocess
from unittest import skip
import ssl
from BaseHTTPServer import HTTPServer
from BaseHTTPServer import BaseHTTPRequestHandler
from SocketServer import ThreadingMixIn
from six.moves.BaseHTTPServer import HTTPServer
from six.moves.BaseHTTPServer import BaseHTTPRequestHandler
from six.moves.socketserver import ThreadingMixIn
import time
import tempfile
import ipaddress
import StringIO
from io import StringIO
import gzip
import base64
import re
from slapos.recipe.librecipe import generateHashFromFiles
import xml.etree.ElementTree as ET
import urlparse
import six.moves.urllib.parse
import socket
import sys
import logging
import random
import string
import six
from six.moves import range
try:
......@@ -133,7 +136,7 @@ def patch_broken_pipe_error():
"""Monkey Patch BaseServer.handle_error to not write
a stacktrace to stderr on broken pipe.
https://stackoverflow.com/a/7913160"""
from SocketServer import BaseServer
from six.moves.socketserver import BaseServer
handle_error = BaseServer.handle_error
......@@ -165,7 +168,7 @@ def createKey():
def createSelfSignedCertificate(name_list):
key, key_pem = createKey()
subject_alternative_name_list = x509.SubjectAlternativeName(
[x509.DNSName(unicode(q)) for q in name_list]
[x509.DNSName(six.text_type(q)) for q in name_list]
)
subject = issuer = x509.Name([
x509.NameAttribute(NameOID.COMMON_NAME, u'Test Self Signed Certificate'),
......@@ -195,10 +198,10 @@ def createCSR(common_name, ip=None):
subject_alternative_name_list = []
if ip is not None:
subject_alternative_name_list.append(
x509.IPAddress(ipaddress.ip_address(unicode(ip)))
x509.IPAddress(ipaddress.ip_address(six.text_type(ip)))
)
csr = x509.CertificateSigningRequestBuilder().subject_name(x509.Name([
x509.NameAttribute(NameOID.COMMON_NAME, unicode(common_name)),
x509.NameAttribute(NameOID.COMMON_NAME, six.text_type(common_name)),
]))
if len(subject_alternative_name_list):
......@@ -222,10 +225,10 @@ class CertificateAuthority(object):
public_key = self.key.public_key()
builder = x509.CertificateBuilder()
builder = builder.subject_name(x509.Name([
x509.NameAttribute(NameOID.COMMON_NAME, unicode(common_name)),
x509.NameAttribute(NameOID.COMMON_NAME, six.text_type(common_name)),
]))
builder = builder.issuer_name(x509.Name([
x509.NameAttribute(NameOID.COMMON_NAME, unicode(common_name)),
x509.NameAttribute(NameOID.COMMON_NAME, six.text_type(common_name)),
]))
builder = builder.not_valid_before(
datetime.datetime.utcnow() - datetime.timedelta(days=2))
......@@ -591,7 +594,7 @@ class TestHandler(BaseHTTPRequestHandler):
if compress:
self.send_header('Content-Encoding', 'gzip')
out = StringIO.StringIO()
out = StringIO()
# compress with level 0, to find out if in the middle someting would
# like to alter the compression
with gzip.GzipFile(fileobj=out, mode="w", compresslevel=0) as f:
......@@ -700,7 +703,7 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
master_parameter_dict = self.parseConnectionParameterDict()
caucase_url = master_parameter_dict['backend-client-caucase-url']
ca_certificate = requests.get(caucase_url + '/cas/crt/ca.crt.pem')
assert ca_certificate.status_code == httplib.OK
assert ca_certificate.status_code == six.moves.http_client.OK
ca_certificate_file = os.path.join(
self.working_directory, 'ca-backend-client.crt.pem')
with open(ca_certificate_file, 'w') as fh:
......@@ -746,18 +749,18 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
parameter_dict = cls.requestDefaultInstance().getConnectionParameterDict()
ca_certificate = requests.get(
parameter_dict['kedifa-caucase-url'] + '/cas/crt/ca.crt.pem')
assert ca_certificate.status_code == httplib.OK
assert ca_certificate.status_code == six.moves.http_client.OK
cls.ca_certificate_file = os.path.join(cls.working_directory, 'ca.crt.pem')
open(cls.ca_certificate_file, 'w').write(ca_certificate.text)
auth = requests.get(
parameter_dict['master-key-generate-auth-url'],
verify=cls.ca_certificate_file)
assert auth.status_code == httplib.CREATED
assert auth.status_code == six.moves.http_client.CREATED
upload = requests.put(
parameter_dict['master-key-upload-url'] + auth.text,
data=cls.key_pem + cls.certificate_pem,
verify=cls.ca_certificate_file)
assert upload.status_code == httplib.CREATED
assert upload.status_code == six.moves.http_client.CREATED
cls.runKedifaUpdater()
@classmethod
......@@ -855,7 +858,7 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
frontend, url = entry
result = requests.get(url, verify=False)
self.assertEqual(
httplib.OK,
six.moves.http_client.OK,
result.status_code,
'While accessing %r of %r the status code was %r' % (
url, frontend, result.status_code))
......@@ -869,11 +872,11 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
sorted([q['name'] for q in result.json()]),
['access.log', 'backend.log', 'error.log'])
self.assertEqual(
httplib.OK,
six.moves.http_client.OK,
requests.get(url + 'access.log', verify=False).status_code
)
self.assertEqual(
httplib.OK,
six.moves.http_client.OK,
requests.get(url + 'error.log', verify=False).status_code
)
# assert only for few tests, as backend log is not available for many of
......@@ -882,7 +885,7 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
'test_url', 'test_auth_to_backend', 'test_compressed_result']:
if self.id().endswith(test_name):
self.assertEqual(
httplib.OK,
six.moves.http_client.OK,
requests.get(url + 'backend.log', verify=False).status_code
)
......@@ -919,7 +922,7 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
backend_haproxy_statistic_url_dict[key] = parameter_dict.pop(key)
self.assertEqual(
[url_key],
backend_haproxy_statistic_url_dict.keys()
list(backend_haproxy_statistic_url_dict.keys())
)
backend_haproxy_statistic_url = backend_haproxy_statistic_url_dict[url_key]
......@@ -927,7 +930,7 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
backend_haproxy_statistic_url,
verify=False,
)
self.assertEqual(httplib.OK, result.status_code)
self.assertEqual(six.moves.http_client.OK, result.status_code)
self.assertIn('testing partition 0', result.text)
self.assertIn('Statistics Report for HAProxy', result.text)
......@@ -1822,12 +1825,12 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
self.certificate_pem,
der2pem(result.peercert))
self.assertEqual(httplib.SERVICE_UNAVAILABLE, result.status_code)
self.assertEqual(six.moves.http_client.SERVICE_UNAVAILABLE, result.status_code)
result_http = fakeHTTPResult(
parameter_dict['domain'], 'test-path')
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result_http.status_code
)
......@@ -1839,7 +1842,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
# check that 404 is as configured
result_missing = fakeHTTPSResult(
'forsuredoesnotexists.example.com', '')
self.assertEqual(httplib.NOT_FOUND, result_missing.status_code)
self.assertEqual(six.moves.http_client.NOT_FOUND, result_missing.status_code)
self.assertEqual(
"""<html>
<head>
......@@ -1984,7 +1987,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
'test-path/deep/.././deeper')
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result_http.status_code
)
......@@ -2103,7 +2106,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
self.assertEqual(
result.status_code,
httplib.BAD_GATEWAY
six.moves.http_client.BAD_GATEWAY
)
finally:
self.stopAuthenticatedServerProcess()
......@@ -2145,7 +2148,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
'test-path/deep/.././deeper')
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result_http.status_code
)
......@@ -2310,7 +2313,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
der2pem(result.peercert))
self.assertEqual(
httplib.MOVED_PERMANENTLY,
six.moves.http_client.MOVED_PERMANENTLY,
result.status_code
)
......@@ -2520,7 +2523,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
auth = requests.get(
generate_auth,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, auth.status_code)
self.assertEqual(six.moves.http_client.CREATED, auth.status_code)
data = self.customdomain_ca_certificate_pem + \
self.customdomain_ca_key_pem + \
......@@ -2530,7 +2533,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
upload_url + auth.text,
data=data,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, upload.status_code)
self.assertEqual(six.moves.http_client.CREATED, upload.status_code)
self.runKedifaUpdater()
result = fakeHTTPSResult(
......@@ -2570,7 +2573,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
auth = requests.get(
generate_auth,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, auth.status_code)
self.assertEqual(six.moves.http_client.CREATED, auth.status_code)
data = self.ca.certificate_pem
......@@ -2579,7 +2582,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
data=data,
verify=self.ca_certificate_file)
self.assertEqual(httplib.UNPROCESSABLE_ENTITY, upload.status_code)
self.assertEqual(six.moves.http_client.UNPROCESSABLE_ENTITY, upload.status_code)
self.assertEqual('Key incorrect', upload.text)
def test_ssl_ca_crt_garbage(self):
......@@ -2603,7 +2606,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
auth = requests.get(
generate_auth,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, auth.status_code)
self.assertEqual(six.moves.http_client.CREATED, auth.status_code)
_, ca_key_pem, csr, _ = createCSR(
parameter_dict['domain'])
......@@ -2615,7 +2618,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
data=data,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, upload.status_code)
self.assertEqual(six.moves.http_client.CREATED, upload.status_code)
self.runKedifaUpdater()
result = fakeHTTPSResult(
......@@ -2656,7 +2659,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
auth = requests.get(
generate_auth,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, auth.status_code)
self.assertEqual(six.moves.http_client.CREATED, auth.status_code)
data = self.certificate_pem + self.key_pem + self.ca.certificate_pem
......@@ -2665,7 +2668,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
data=data,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, upload.status_code)
self.assertEqual(six.moves.http_client.CREATED, upload.status_code)
self.runKedifaUpdater()
result = fakeHTTPSResult(
......@@ -2817,14 +2820,14 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
auth = requests.get(
generate_auth,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, auth.status_code)
self.assertEqual(six.moves.http_client.CREATED, auth.status_code)
data = self.customdomain_certificate_pem + \
self.customdomain_key_pem
upload = requests.put(
upload_url + auth.text,
data=data,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, upload.status_code)
self.assertEqual(six.moves.http_client.CREATED, upload.status_code)
self.runKedifaUpdater()
result = fakeHTTPSResult(
......@@ -2865,7 +2868,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
'test-path/deep/.././deeper')
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result.status_code
)
......@@ -2984,7 +2987,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
'test-path/deep/.././deeper')
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result.status_code
)
......@@ -3025,7 +3028,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
headers={'Accept-Encoding': 'gzip, deflate'})
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result.status_code
)
......@@ -3160,7 +3163,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
j = result.json()
except Exception:
raise ValueError('JSON decode problem in:\n%s' % (result.text,))
parsed = urlparse.urlparse(self.backend_url)
parsed = six.moves.urllib.parse.urlparse(self.backend_url)
self.assertBackendHeaders(
j['Incoming Headers'], parsed.hostname, port='17', proto='irc',
ignore_header_list=['Host'])
......@@ -3266,7 +3269,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
j = result.json()
except Exception:
raise ValueError('JSON decode problem in:\n%s' % (result.text,))
parsed = urlparse.urlparse(self.backend_url)
parsed = six.moves.urllib.parse.urlparse(self.backend_url)
self.assertBackendHeaders(
j['Incoming Headers'], parsed.hostname, port='17', proto='irc',
ignore_header_list=['Host'])
......@@ -3332,7 +3335,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
der2pem(result.peercert))
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result.status_code
)
......@@ -3368,7 +3371,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
der2pem(result.peercert))
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result.status_code
)
......@@ -3405,7 +3408,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
der2pem(result.peercert))
self.assertEqual(
httplib.SERVICE_UNAVAILABLE,
six.moves.http_client.SERVICE_UNAVAILABLE,
result.status_code
)
......@@ -3413,7 +3416,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
parameter_dict['domain'], 'test-path')
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result_http.status_code
)
......@@ -3452,7 +3455,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
parameter_dict['domain'], 'test-path')
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result_http.status_code
)
......@@ -3473,7 +3476,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
der2pem(result.peercert))
self.assertEqual(
httplib.SERVICE_UNAVAILABLE,
six.moves.http_client.SERVICE_UNAVAILABLE,
result.status_code
)
......@@ -3487,12 +3490,12 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
self.certificate_pem,
der2pem(result.peercert))
self.assertEqual(httplib.SERVICE_UNAVAILABLE, result.status_code)
self.assertEqual(six.moves.http_client.SERVICE_UNAVAILABLE, result.status_code)
result_http = fakeHTTPResult(
parameter_dict['domain'], 'test-path')
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result_http.status_code
)
......@@ -3524,12 +3527,12 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
self.certificate_pem,
der2pem(result.peercert))
self.assertEqual(httplib.SERVICE_UNAVAILABLE, result.status_code)
self.assertEqual(six.moves.http_client.SERVICE_UNAVAILABLE, result.status_code)
result_http = fakeHTTPResult(
parameter_dict['domain'], 'test-path')
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result_http.status_code
)
......@@ -3562,13 +3565,13 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
self.certificate_pem,
der2pem(result.peercert))
self.assertEqual(httplib.SERVICE_UNAVAILABLE, result.status_code)
self.assertEqual(six.moves.http_client.SERVICE_UNAVAILABLE, result.status_code)
result_http = fakeHTTPResult(
parameter_dict['domain'], 'test-path')
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result_http.status_code
)
......@@ -3691,7 +3694,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
'X-Reply-Header-Cache-Control': 'max-age=1, stale-while-'
'revalidate=3600, stale-if-error=3600'})
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result.status_code
)
......@@ -3740,7 +3743,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
'X-Reply-Header-Cache-Control': 'max-age=1, stale-while-'
'revalidate=3600, stale-if-error=3600'})
self.assertEqual(httplib.OK, result.status_code)
self.assertEqual(six.moves.http_client.OK, result.status_code)
self.assertEqualResultJson(result, 'Path', '/HTTPS/test')
headers = result.headers.copy()
......@@ -3751,7 +3754,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
'X-Reply-Header-Cache-Control': 'max-age=1, stale-while-'
'revalidate=3600, stale-if-error=3600'})
self.assertEqual(httplib.OK, result.status_code)
self.assertEqual(six.moves.http_client.OK, result.status_code)
self.assertEqualResultJson(result, 'Path', '/HTTP/test')
headers = result.headers.copy()
......@@ -3911,7 +3914,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
# https://github.com/apache/trafficserver/issues/7880
'X-Drop-Header': 'Content-Length',
})
self.assertEqual(result.status_code, httplib.CREATED)
self.assertEqual(result.status_code, six.moves.http_client.CREATED)
def checkResult(status_code, body):
result = fakeHTTPSResult(
......@@ -3923,39 +3926,39 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
# backend returns something correctly
configureResult('200', body_200)
checkResult(httplib.OK, body_200)
checkResult(six.moves.http_client.OK, body_200)
configureResult('502', body_502)
time.sleep(1)
# even if backend returns 502, ATS gives cached result
checkResult(httplib.OK, body_200)
checkResult(six.moves.http_client.OK, body_200)
# interesting moment, time is between max_age and max_stale_age, triggers
# https://github.com/apache/trafficserver/issues/7880
time.sleep(max_age + 1)
checkResult(httplib.OK, body_200)
checkResult(six.moves.http_client.OK, body_200)
# max_stale_age passed, time to return 502 from the backend
time.sleep(max_stale_age + 2)
checkResult(httplib.BAD_GATEWAY, body_502)
checkResult(six.moves.http_client.BAD_GATEWAY, body_502)
configureResult('502', body_502_new)
time.sleep(1)
# even if there is new negative response on the backend, the old one is
# served from the cache
checkResult(httplib.BAD_GATEWAY, body_502)
checkResult(six.moves.http_client.BAD_GATEWAY, body_502)
time.sleep(max_age + 2)
# now as max-age of negative response passed, the new one is served
checkResult(httplib.BAD_GATEWAY, body_502_new)
checkResult(six.moves.http_client.BAD_GATEWAY, body_502_new)
configureResult('200', body_200_new)
time.sleep(1)
checkResult(httplib.BAD_GATEWAY, body_502_new)
checkResult(six.moves.http_client.BAD_GATEWAY, body_502_new)
time.sleep(max_age + 2)
# backend is back to normal, as soon as negative response max-age passed
# the new response is served
checkResult(httplib.OK, body_200_new)
checkResult(six.moves.http_client.OK, body_200_new)
@skip('Feature postponed')
def test_enable_cache_stale_if_error_respected(self):
......@@ -4020,7 +4023,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
},
source_ip=source_ip
)
self.assertEqual(result.status_code, httplib.BAD_GATEWAY)
self.assertEqual(result.status_code, six.moves.http_client.BAD_GATEWAY)
finally:
self.startServerProcess()
# END: check stale-if-error support
......@@ -4038,7 +4041,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
# ATS timed out
self.assertEqual(
httplib.GATEWAY_TIMEOUT,
six.moves.http_client.GATEWAY_TIMEOUT,
result.status_code
)
......@@ -4151,7 +4154,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
j = result.json()
except Exception:
raise ValueError('JSON decode problem in:\n%s' % (result.text,))
self.assertFalse('pragma' in j['Incoming Headers'].keys())
self.assertFalse('pragma' in list(j['Incoming Headers'].keys()))
def test_enable_cache_disable_via_header(self):
parameter_dict = self.assertSlaveBase('enable_cache-disable-via-header')
......@@ -4402,7 +4405,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
headers={'Accept-Encoding': 'gzip, deflate'})
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result.status_code
)
......@@ -4417,7 +4420,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
headers={'Accept-Encoding': 'deflate'})
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result.status_code
)
......@@ -4431,7 +4434,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
'test-path/deep/.././deeper')
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result.status_code
)
......@@ -4445,7 +4448,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
'test-path/deep/.././deeper')
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result.status_code
)
......@@ -4498,7 +4501,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
'test-path/deep/.././deeper')
self.assertEqual(
httplib.FOUND,
six.moves.http_client.FOUND,
result_http.status_code
)
......@@ -4605,7 +4608,7 @@ class TestReplicateSlave(SlaveHttpFrontendTestCase, TestDataMixin):
result_http = fakeHTTPResult(
parameter_dict['domain'], 'test-path')
self.assertEqual(httplib.FOUND, result_http.status_code)
self.assertEqual(six.moves.http_client.FOUND, result_http.status_code)
# prove 2nd frontend by inspection of the instance
slave_configuration_name = '_replicate.conf'
......@@ -5133,7 +5136,7 @@ class TestSlaveSlapOSMasterCertificateCompatibilityOverrideMaster(
parameter_dict = cls.requestDefaultInstance().getConnectionParameterDict()
ca_certificate = requests.get(
parameter_dict['kedifa-caucase-url'] + '/cas/crt/ca.crt.pem')
assert ca_certificate.status_code == httplib.OK
assert ca_certificate.status_code == six.moves.http_client.OK
cls.ca_certificate_file = os.path.join(cls.working_directory, 'ca.crt.pem')
open(cls.ca_certificate_file, 'w').write(ca_certificate.text)
# Do not upload certificates for the master partition
......@@ -5223,7 +5226,7 @@ class TestSlaveSlapOSMasterCertificateCompatibility(
parameter_dict = cls.requestDefaultInstance().getConnectionParameterDict()
ca_certificate = requests.get(
parameter_dict['kedifa-caucase-url'] + '/cas/crt/ca.crt.pem')
assert ca_certificate.status_code == httplib.OK
assert ca_certificate.status_code == six.moves.http_client.OK
cls.ca_certificate_file = os.path.join(cls.working_directory, 'ca.crt.pem')
open(cls.ca_certificate_file, 'w').write(ca_certificate.text)
# Do not upload certificates for the master partition
......@@ -5488,7 +5491,7 @@ class TestSlaveSlapOSMasterCertificateCompatibility(
auth = requests.get(
generate_auth,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, auth.status_code)
self.assertEqual(six.moves.http_client.CREATED, auth.status_code)
data = certificate_pem + key_pem
......@@ -5496,7 +5499,7 @@ class TestSlaveSlapOSMasterCertificateCompatibility(
upload_url + auth.text,
data=data,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, upload.status_code)
self.assertEqual(six.moves.http_client.CREATED, upload.status_code)
self.runKedifaUpdater()
result = fakeHTTPSResult(
......@@ -5579,7 +5582,7 @@ class TestSlaveSlapOSMasterCertificateCompatibility(
auth = requests.get(
generate_auth,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, auth.status_code)
self.assertEqual(six.moves.http_client.CREATED, auth.status_code)
data = certificate_pem + key_pem
......@@ -5587,7 +5590,7 @@ class TestSlaveSlapOSMasterCertificateCompatibility(
upload_url + auth.text,
data=data,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, upload.status_code)
self.assertEqual(six.moves.http_client.CREATED, upload.status_code)
self.runKedifaUpdater()
......@@ -5663,7 +5666,7 @@ class TestSlaveSlapOSMasterCertificateCompatibility(
auth = requests.get(
generate_auth,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, auth.status_code)
self.assertEqual(six.moves.http_client.CREATED, auth.status_code)
data = certificate_pem + key_pem
......@@ -5671,7 +5674,7 @@ class TestSlaveSlapOSMasterCertificateCompatibility(
upload_url + auth.text,
data=data,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, upload.status_code)
self.assertEqual(six.moves.http_client.CREATED, upload.status_code)
self.runKedifaUpdater()
......@@ -5756,7 +5759,7 @@ class TestSlaveSlapOSMasterCertificateCompatibility(
auth = requests.get(
generate_auth,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, auth.status_code)
self.assertEqual(six.moves.http_client.CREATED, auth.status_code)
data = certificate_pem + key_pem
......@@ -5764,7 +5767,7 @@ class TestSlaveSlapOSMasterCertificateCompatibility(
upload_url + auth.text,
data=data,
verify=self.ca_certificate_file)
self.assertEqual(httplib.CREATED, upload.status_code)
self.assertEqual(six.moves.http_client.CREATED, upload.status_code)
self.runKedifaUpdater()
......@@ -5983,7 +5986,7 @@ class TestSlaveSlapOSMasterCertificateCompatibilityUpdate(
parameter_dict = cls.requestDefaultInstance().getConnectionParameterDict()
ca_certificate = requests.get(
parameter_dict['kedifa-caucase-url'] + '/cas/crt/ca.crt.pem')
assert ca_certificate.status_code == httplib.OK
assert ca_certificate.status_code == six.moves.http_client.OK
cls.ca_certificate_file = os.path.join(cls.working_directory, 'ca.crt.pem')
open(cls.ca_certificate_file, 'w').write(ca_certificate.text)
# Do not upload certificates for the master partition
......@@ -6152,11 +6155,11 @@ class TestSlaveCiphers(SlaveHttpFrontendTestCase, TestDataMixin):
self.certificate_pem,
der2pem(result.peercert))
self.assertEqual(httplib.OK, result.status_code)
self.assertEqual(six.moves.http_client.OK, result.status_code)
result_http = fakeHTTPResult(
parameter_dict['domain'], 'test-path')
self.assertEqual(httplib.FOUND, result_http.status_code)
self.assertEqual(six.moves.http_client.FOUND, result_http.status_code)
configuration_file = glob.glob(
os.path.join(
......@@ -6178,11 +6181,11 @@ class TestSlaveCiphers(SlaveHttpFrontendTestCase, TestDataMixin):
self.certificate_pem,
der2pem(result.peercert))
self.assertEqual(httplib.OK, result.status_code)
self.assertEqual(six.moves.http_client.OK, result.status_code)
result_http = fakeHTTPResult(
parameter_dict['domain'], 'test-path')
self.assertEqual(httplib.FOUND, result_http.status_code)
self.assertEqual(six.moves.http_client.FOUND, result_http.status_code)
configuration_file = glob.glob(
os.path.join(
......@@ -6645,7 +6648,7 @@ class TestSlaveRejectReportUnsafeDamaged(SlaveHttpFrontendTestCase):
der2pem(result.peercert))
self.assertEqual(
httplib.MOVED_PERMANENTLY,
six.moves.http_client.MOVED_PERMANENTLY,
result.status_code
)
......@@ -6678,11 +6681,11 @@ class TestSlaveRejectReportUnsafeDamaged(SlaveHttpFrontendTestCase):
self.certificate_pem,
der2pem(result.peercert))
self.assertEqual(httplib.SERVICE_UNAVAILABLE, result.status_code)
self.assertEqual(six.moves.http_client.SERVICE_UNAVAILABLE, result.status_code)
result_http = fakeHTTPResult(
parameter_dict['domain'], 'test-path')
self.assertEqual(httplib.FOUND, result_http.status_code)
self.assertEqual(six.moves.http_client.FOUND, result_http.status_code)
monitor_file = glob.glob(
os.path.join(
......@@ -6722,11 +6725,11 @@ class TestSlaveRejectReportUnsafeDamaged(SlaveHttpFrontendTestCase):
self.certificate_pem,
der2pem(result.peercert))
self.assertEqual(httplib.SERVICE_UNAVAILABLE, result.status_code)
self.assertEqual(six.moves.http_client.SERVICE_UNAVAILABLE, result.status_code)
result_http = fakeHTTPResult(
parameter_dict['domain'], 'test-path')
self.assertEqual(httplib.FOUND, result_http.status_code)
self.assertEqual(six.moves.http_client.FOUND, result_http.status_code)
monitor_file = glob.glob(
os.path.join(
......@@ -7053,8 +7056,8 @@ class TestPassedRequestParameter(HttpFrontendTestCase):
expected_partition_parameter_dict_dict = {
'caddy-frontend-1': {
'X-software_release_url': base_software_url,
u'apache-certificate': unicode(self.certificate_pem),
u'apache-key': unicode(self.key_pem),
u'apache-certificate': six.text_type(self.certificate_pem),
u'apache-key': six.text_type(self.key_pem),
u'authenticate-to-backend': u'True',
u'backend-client-caucase-url': backend_client_caucase_url,
u'backend-connect-retries': u'1',
......@@ -7080,8 +7083,8 @@ class TestPassedRequestParameter(HttpFrontendTestCase):
},
'caddy-frontend-2': {
'X-software_release_url': self.frontend_2_sr,
u'apache-certificate': unicode(self.certificate_pem),
u'apache-key': unicode(self.key_pem),
u'apache-certificate': six.text_type(self.certificate_pem),
u'apache-key': six.text_type(self.key_pem),
u'authenticate-to-backend': u'True',
u'backend-client-caucase-url': backend_client_caucase_url,
u'backend-connect-retries': u'1',
......@@ -7107,8 +7110,8 @@ class TestPassedRequestParameter(HttpFrontendTestCase):
},
'caddy-frontend-3': {
'X-software_release_url': self.frontend_3_sr,
u'apache-certificate': unicode(self.certificate_pem),
u'apache-key': unicode(self.key_pem),
u'apache-certificate': six.text_type(self.certificate_pem),
u'apache-key': six.text_type(self.key_pem),
u'authenticate-to-backend': u'True',
u'backend-client-caucase-url': backend_client_caucase_url,
u'backend-connect-retries': u'1',
......@@ -7153,8 +7156,8 @@ class TestPassedRequestParameter(HttpFrontendTestCase):
'-sla-2-computer_guid': 'local',
'-sla-3-computer_guid': 'local',
'X-software_release_url': base_software_url,
'apache-certificate': unicode(self.certificate_pem),
'apache-key': unicode(self.key_pem),
'apache-certificate': six.text_type(self.certificate_pem),
'apache-key': six.text_type(self.key_pem),
'authenticate-to-backend': 'True',
'automatic-internal-backend-client-caucase-csr': 'False',
'automatic-internal-kedifa-caucase-csr': 'False',
......@@ -7306,7 +7309,7 @@ class TestSlaveHealthCheck(SlaveHttpFrontendTestCase, TestDataMixin):
@classmethod
def setUpAssertionDict(cls):
backend = urlparse.urlparse(cls.backend_url).netloc
backend = six.moves.urllib.parse.urlparse(cls.backend_url).netloc
cls.assertion_dict = {
'health-check-disabled': """\
backend _health-check-disabled-http
......@@ -7391,7 +7394,7 @@ backend _health-check-default-http
self.backend_url + slave_parameter_dict[
'health-check-http-path'].strip('/'),
headers={'X-Reply-Status-Code': '502'})
self.assertEqual(result.status_code, httplib.CREATED)
self.assertEqual(result.status_code, six.moves.http_client.CREATED)
def restoreBackend():
result = requests.put(
......@@ -7498,7 +7501,7 @@ backend _health-check-default-http
self.backend_url + slave_parameter_dict[
'health-check-http-path'].strip('/'),
headers={'X-Reply-Status-Code': '502'})
self.assertEqual(result.status_code, httplib.CREATED)
self.assertEqual(result.status_code, six.moves.http_client.CREATED)
time.sleep(3) # > health-check-timeout + health-check-interval
......@@ -7531,7 +7534,7 @@ backend _health-check-default-http
self.backend_url + slave_parameter_dict[
'health-check-http-path'].strip('/'),
headers={'X-Reply-Status-Code': '502'})
self.assertEqual(result.status_code, httplib.CREATED)
self.assertEqual(result.status_code, six.moves.http_client.CREATED)
time.sleep(3) # > health-check-timeout + health-check-interval
......@@ -7560,7 +7563,7 @@ backend _health-check-default-http
self.backend_url + slave_parameter_dict[
'health-check-http-path'].strip('/'),
headers={'X-Reply-Status-Code': '502'})
self.assertEqual(result.status_code, httplib.CREATED)
self.assertEqual(result.status_code, six.moves.http_client.CREATED)
time.sleep(3) # > health-check-timeout + health-check-interval
......@@ -7572,7 +7575,7 @@ backend _health-check-default-http
der2pem(result.peercert))
# as ssl proxy verification failed, service is unavailable
self.assertEqual(result.status_code, httplib.SERVICE_UNAVAILABLE)
self.assertEqual(result.status_code, six.moves.http_client.SERVICE_UNAVAILABLE)
def test_health_check_failover_url_ssl_proxy_missing(self):
parameter_dict = self.assertSlaveBase(
......@@ -7590,7 +7593,7 @@ backend _health-check-default-http
self.backend_url + slave_parameter_dict[
'health-check-http-path'].strip('/'),
headers={'X-Reply-Status-Code': '502'})
self.assertEqual(result.status_code, httplib.CREATED)
self.assertEqual(result.status_code, six.moves.http_client.CREATED)
time.sleep(3) # > health-check-timeout + health-check-interval
......@@ -7602,7 +7605,7 @@ backend _health-check-default-http
der2pem(result.peercert))
# as ssl proxy verification failed, service is unavailable
self.assertEqual(result.status_code, httplib.SERVICE_UNAVAILABLE)
self.assertEqual(result.status_code, six.moves.http_client.SERVICE_UNAVAILABLE)
if __name__ == '__main__':
......@@ -7617,5 +7620,5 @@ if __name__ == '__main__':
url_template = 'http://%s:%s/'
server = klass((ip, port), TestHandler)
print url_template % server.server_address[:2]
print(url_template % server.server_address[:2])
server.serve_forever()
......@@ -25,6 +25,7 @@
#
##############################################################################
from __future__ import absolute_import
import json
import os
......
from __future__ import absolute_import
import glob
import hashlib
import json
......@@ -8,9 +9,9 @@ import shutil
import subprocess
import tempfile
import time
import urllib
import urlparse
from BaseHTTPServer import BaseHTTPRequestHandler
import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error
import six.moves.urllib.parse
from six.moves.BaseHTTPServer import BaseHTTPRequestHandler
from typing import Dict
import mock
......@@ -28,6 +29,7 @@ from slapos.testing.utils import (CrontabMixin, ManagedHTTPServer,
findFreeTCPPort)
from . import ERP5InstanceTestCase, setUpModule
from six.moves import range
setUpModule # pyflakes
......@@ -214,7 +216,7 @@ class TestLog(BalancerTestCase, CrontabMixin):
def test_access_log_format(self):
# type: () -> None
requests.get(
urlparse.urljoin(self.default_balancer_url, '/url_path'),
six.moves.urllib.parse.urljoin(self.default_balancer_url, '/url_path'),
verify=False,
)
time.sleep(.5) # wait a bit more until access is logged
......@@ -373,7 +375,7 @@ class TestBalancer(BalancerTestCase):
# if backend provides a "SERVERID" cookie, balancer will overwrite it with the
# backend selected by balancing algorithm
self.assertIn(
requests.get(urlparse.urljoin(self.default_balancer_url, '/set_cookie'), verify=False).cookies['SERVERID'],
requests.get(six.moves.urllib.parse.urljoin(self.default_balancer_url, '/set_cookie'), verify=False).cookies['SERVERID'],
('default-0', 'default-1'),
)
......@@ -427,18 +429,18 @@ class TestTestRunnerEntryPoints(BalancerTestCase):
)['default-test-runner-url-list']
url_0, url_1, url_2 = test_runner_url_list
self.assertEqual(
urlparse.urlparse(url_0).netloc,
urlparse.urlparse(url_1).netloc)
six.moves.urllib.parse.urlparse(url_0).netloc,
six.moves.urllib.parse.urlparse(url_1).netloc)
self.assertEqual(
urlparse.urlparse(url_0).netloc,
urlparse.urlparse(url_2).netloc)
six.moves.urllib.parse.urlparse(url_0).netloc,
six.moves.urllib.parse.urlparse(url_2).netloc)
path_0 = '/VirtualHostBase/https/{netloc}/VirtualHostRoot/_vh_unit_test_0/something'.format(
netloc=urlparse.urlparse(url_0).netloc)
netloc=six.moves.urllib.parse.urlparse(url_0).netloc)
path_1 = '/VirtualHostBase/https/{netloc}/VirtualHostRoot/_vh_unit_test_1/something'.format(
netloc=urlparse.urlparse(url_0).netloc)
netloc=six.moves.urllib.parse.urlparse(url_0).netloc)
path_2 = '/VirtualHostBase/https/{netloc}/VirtualHostRoot/_vh_unit_test_2/something'.format(
netloc=urlparse.urlparse(url_0).netloc)
netloc=six.moves.urllib.parse.urlparse(url_0).netloc)
self.assertEqual(
{
......@@ -516,7 +518,7 @@ class TestHTTP(BalancerTestCase):
session.get(self.default_balancer_url).raise_for_status()
new_conn.assert_not_called()
parsed_url = urlparse.urlparse(self.default_balancer_url)
parsed_url = six.moves.urllib.parse.urlparse(self.default_balancer_url)
# check that we have an open file for the ip connection
self.assertTrue([
c for c in psutil.Process(os.getpid()).connections()
......@@ -588,7 +590,7 @@ class TestContentEncoding(BalancerTestCase):
'application/x-font-opentype',
'application/wasm',):
resp = requests.get(
urlparse.urljoin(self.default_balancer_url, content_type),
six.moves.urllib.parse.urljoin(self.default_balancer_url, content_type),
verify=False,
headers={"Accept-Encoding": "gzip, deflate",})
self.assertEqual(resp.headers['Content-Type'], content_type)
......@@ -600,7 +602,7 @@ class TestContentEncoding(BalancerTestCase):
def test_no_gzip_encoding(self):
# type: () -> None
resp = requests.get(urlparse.urljoin(self.default_balancer_url, '/image/png'), verify=False)
resp = requests.get(six.moves.urllib.parse.urljoin(self.default_balancer_url, '/image/png'), verify=False)
self.assertNotIn('Content-Encoding', resp.headers)
self.assertEqual(resp.text, 'OK')
......
......@@ -25,14 +25,15 @@
#
##############################################################################
from __future__ import absolute_import
import os
import json
import glob
import urlparse
import six.moves.urllib.parse
import socket
import time
import re
import BaseHTTPServer
import six.moves.BaseHTTPServer
import multiprocessing
import subprocess
......@@ -41,6 +42,9 @@ import requests
from . import ERP5InstanceTestCase
from . import setUpModule
import six
from six.moves import map
from six.moves import range
setUpModule # pyflakes
......@@ -52,7 +56,7 @@ class TestPublishedURLIsReachableMixin(object):
# We access ERP5 trough a "virtual host", which should make
# ERP5 produce URLs using https://virtual-host-name:1234/virtual_host_root
# as base.
virtual_host_url = urlparse.urljoin(
virtual_host_url = six.moves.urllib.parse.urljoin(
base_url,
'/VirtualHostBase/https/virtual-host-name:1234/{}/VirtualHostRoot/_vh_virtual_host_root/'
.format(site_id))
......@@ -80,7 +84,7 @@ class TestPublishedURLIsReachableMixin(object):
# login page can be rendered and contain the text "ERP5"
r = session.get(
urlparse.urljoin(base_url, '{}/login_form'.format(site_id)),
six.moves.urllib.parse.urljoin(base_url, '{}/login_form'.format(site_id)),
verify=verify,
allow_redirects=False,
)
......@@ -172,7 +176,7 @@ class TestApacheBalancerPorts(ERP5InstanceTestCase):
}
def checkValidHTTPSURL(self, url):
parsed = urlparse.urlparse(url)
parsed = six.moves.urllib.parse.urlparse(url)
self.assertEqual(parsed.scheme, 'https')
self.assertTrue(parsed.hostname)
self.assertTrue(parsed.port)
......@@ -291,7 +295,7 @@ class TestZopeNodeParameterOverride(ERP5InstanceTestCase, TestPublishedURLIsReac
storage["storage"] = "root"
storage["server"] = zeo_addr
with open('%s/etc/zope-%s.conf' % (partition, zope)) as f:
conf = map(str.strip, f.readlines())
conf = list(map(str.strip, f.readlines()))
i = conf.index("<zodb_db root>") + 1
conf = iter(conf[i:conf.index("</zodb_db>", i)])
for line in conf:
......@@ -300,23 +304,23 @@ class TestZopeNodeParameterOverride(ERP5InstanceTestCase, TestPublishedURLIsReac
if line == '</zeoclient>':
break
checkParameter(line, storage)
for k, v in storage.iteritems():
for k, v in six.iteritems(storage):
self.assertIsNone(v, k)
del storage
else:
checkParameter(line, zodb)
for k, v in zodb.iteritems():
for k, v in six.iteritems(zodb):
self.assertIsNone(v, k)
partition = self.getComputerPartitionPath('zope-a')
for zope in xrange(3):
for zope in range(3):
checkConf({
"cache-size-bytes": "20MB",
}, {
"cache-size": "50MB",
})
partition = self.getComputerPartitionPath('zope-bb')
for zope in xrange(5):
for zope in range(5):
checkConf({
"cache-size-bytes": "500MB" if zope else 1<<20,
}, {
......@@ -336,7 +340,7 @@ def popenCommunicate(command_list, input_=None, **kwargs):
return result
class TestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
class TestHandler(six.moves.BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
......@@ -464,7 +468,7 @@ class TestDeploymentScriptInstantiation(ERP5InstanceTestCase):
ip, port = re.search(
r'.*http:\/\/(.*):(\d*)\/.*', portal_slap_line).groups()
port = int(port)
server = BaseHTTPServer.HTTPServer((ip, port), TestHandler)
server = six.moves.BaseHTTPServer.HTTPServer((ip, port), TestHandler)
server_process = multiprocessing.Process(
target=server.serve_forever, name='HTTPServer')
server_process.start()
......
......@@ -26,10 +26,11 @@
#
##############################################################################
from __future__ import absolute_import
import os
import json
import glob
import urlparse
import six.moves.urllib.parse
import socket
import sys
import time
......@@ -80,7 +81,7 @@ class MariaDBTestCase(ERP5InstanceTestCase):
def getDatabaseConnection(self):
connection_parameter_dict = json.loads(
self.computer_partition.getConnectionParameterDict()['_'])
db_url = urlparse.urlparse(connection_parameter_dict['database-list'][0])
db_url = six.moves.urllib.parse.urlparse(connection_parameter_dict['database-list'][0])
self.assertEqual('mysql', db_url.scheme)
self.assertTrue(db_url.path.startswith('/'))
......
......@@ -16,6 +16,7 @@
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
from __future__ import absolute_import
import json
import os.path
import unittest
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment