Add python 3 support
Replaced iter.next() with next(iter) Replaced __builtin__ with six.moves.builtin Replaced unicode with six.text_type Repleaced Configparser with six.moves.configparser Blueprint magnum-python3 Change-Id: I9f084ef4fae1ec1111e26142e2e89bad18acbf45
This commit is contained in:
parent
fb2e675057
commit
20aec0db19
|
@ -33,6 +33,7 @@ from datetime import datetime
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
# python 2 and python 3 compatibility library
|
# python 2 and python 3 compatibility library
|
||||||
|
import six
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
import six.moves.builtins as __builtin__
|
import six.moves.builtins as __builtin__
|
||||||
from six.moves.urllib import parse as urlparse
|
from six.moves.urllib import parse as urlparse
|
||||||
|
@ -184,7 +185,7 @@ class ApiClient(object):
|
||||||
"""
|
"""
|
||||||
if isinstance(obj, type(None)):
|
if isinstance(obj, type(None)):
|
||||||
return None
|
return None
|
||||||
elif isinstance(obj, (unicode, str, int, float, bool, tuple, file)):
|
elif isinstance(obj, (six.text_type, str, int, float, bool, tuple, file)):
|
||||||
return obj
|
return obj
|
||||||
elif isinstance(obj, list):
|
elif isinstance(obj, list):
|
||||||
return [self.sanitize_for_serialization(sub_obj)
|
return [self.sanitize_for_serialization(sub_obj)
|
||||||
|
@ -488,7 +489,7 @@ class ApiClient(object):
|
||||||
try:
|
try:
|
||||||
value = klass(data)
|
value = klass(data)
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
value = unicode(data)
|
value = six.text_type(data)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
value = data
|
value = data
|
||||||
return value
|
return value
|
||||||
|
|
|
@ -17,13 +17,13 @@ test_magnum
|
||||||
Tests for `magnum` module.
|
Tests for `magnum` module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import ConfigParser
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
|
from six.moves import configparser
|
||||||
|
|
||||||
from magnum.common.utils import rmtree_without_raise
|
from magnum.common.utils import rmtree_without_raise
|
||||||
from magnum.tests import base
|
from magnum.tests import base
|
||||||
|
@ -53,7 +53,7 @@ class BaseMagnumClient(base.TestCase):
|
||||||
keypair_id = cliutils.env('KEYPAIR_ID')
|
keypair_id = cliutils.env('KEYPAIR_ID')
|
||||||
copy_logs = cliutils.env('COPY_LOGS')
|
copy_logs = cliutils.env('COPY_LOGS')
|
||||||
|
|
||||||
config = ConfigParser.RawConfigParser()
|
config = configparser.RawConfigParser()
|
||||||
if config.read('functional_creds.conf'):
|
if config.read('functional_creds.conf'):
|
||||||
# the OR pattern means the environment is preferred for
|
# the OR pattern means the environment is preferred for
|
||||||
# override
|
# override
|
||||||
|
@ -68,7 +68,7 @@ class BaseMagnumClient(base.TestCase):
|
||||||
keypair_id = keypair_id or config.get('magnum', 'keypair_id')
|
keypair_id = keypair_id or config.get('magnum', 'keypair_id')
|
||||||
try:
|
try:
|
||||||
copy_logs = copy_logs or config.get('magnum', 'copy_logs')
|
copy_logs = copy_logs or config.get('magnum', 'copy_logs')
|
||||||
except ConfigParser.NoOptionError:
|
except configparser.NoOptionError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
cls.image_id = image_id
|
cls.image_id = image_id
|
||||||
|
|
|
@ -106,7 +106,7 @@ class TestLocalManager(base.BaseTestCase):
|
||||||
def _store_cert(self):
|
def _store_cert(self):
|
||||||
file_mock = mock.mock_open()
|
file_mock = mock.mock_open()
|
||||||
# Attempt to store the cert
|
# Attempt to store the cert
|
||||||
with mock.patch('__builtin__.open', file_mock, create=True):
|
with mock.patch('six.moves.builtins.open', file_mock, create=True):
|
||||||
cert_id = local_cert_manager.CertManager.store_cert(
|
cert_id = local_cert_manager.CertManager.store_cert(
|
||||||
certificate=self.certificate,
|
certificate=self.certificate,
|
||||||
intermediates=self.intermediates,
|
intermediates=self.intermediates,
|
||||||
|
@ -131,7 +131,7 @@ class TestLocalManager(base.BaseTestCase):
|
||||||
def _get_cert(self, cert_id):
|
def _get_cert(self, cert_id):
|
||||||
file_mock = mock.mock_open()
|
file_mock = mock.mock_open()
|
||||||
# Attempt to retrieve the cert
|
# Attempt to retrieve the cert
|
||||||
with mock.patch('__builtin__.open', file_mock, create=True):
|
with mock.patch('six.moves.builtins.open', file_mock, create=True):
|
||||||
data = local_cert_manager.CertManager.get_cert(cert_id)
|
data = local_cert_manager.CertManager.get_cert(cert_id)
|
||||||
|
|
||||||
# Verify the correct files were opened
|
# Verify the correct files were opened
|
||||||
|
@ -154,7 +154,7 @@ class TestLocalManager(base.BaseTestCase):
|
||||||
file_mock = mock.mock_open()
|
file_mock = mock.mock_open()
|
||||||
file_mock.side_effect = fake_open
|
file_mock.side_effect = fake_open
|
||||||
# Attempt to retrieve the cert
|
# Attempt to retrieve the cert
|
||||||
with mock.patch('__builtin__.open', file_mock, create=True):
|
with mock.patch('six.moves.builtins.open', file_mock, create=True):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
exception.CertificateStorageException,
|
exception.CertificateStorageException,
|
||||||
local_cert_manager.CertManager.get_cert,
|
local_cert_manager.CertManager.get_cert,
|
||||||
|
@ -187,7 +187,7 @@ class TestLocalManager(base.BaseTestCase):
|
||||||
def test_store_cert(self):
|
def test_store_cert(self):
|
||||||
self._store_cert()
|
self._store_cert()
|
||||||
|
|
||||||
@mock.patch('__builtin__.open', create=True)
|
@mock.patch('six.moves.builtins.open', create=True)
|
||||||
def test_store_cert_with_io_error(self, file_mock):
|
def test_store_cert_with_io_error(self, file_mock):
|
||||||
file_mock.side_effect = IOError
|
file_mock.side_effect = IOError
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ class TestValidators(unittest.TestCase):
|
||||||
key_usage = self._build_key_usage(critical=True)
|
key_usage = self._build_key_usage(critical=True)
|
||||||
|
|
||||||
with self.assertRaises(CertificateValidationError):
|
with self.assertRaises(CertificateValidationError):
|
||||||
v.filter_allowed_extensions([key_usage], ['subjectAltName']).next()
|
next(v.filter_allowed_extensions([key_usage], ['subjectAltName']))
|
||||||
|
|
||||||
def test_merge_key_usage(self):
|
def test_merge_key_usage(self):
|
||||||
key_usage = self._build_key_usage(critical=True)
|
key_usage = self._build_key_usage(critical=True)
|
||||||
|
|
Loading…
Reference in New Issue