python3 fixes
Update uses of b64encode() as describe in OpenStack docs [1]. Also add tests. [1]: https://wiki.openstack.org/wiki/Python3#Serialization:_base64.2C_JSON.2C_etc. Change-Id: I5aa6ba509979e0532d2837153aa5363d1e13631e
This commit is contained in:
parent
37e602d160
commit
3f7b994acd
magnumclient
@ -15,7 +15,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import base64
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
@ -24,6 +23,7 @@ from cryptography.hazmat.primitives import hashes
|
|||||||
from cryptography.hazmat.primitives import serialization
|
from cryptography.hazmat.primitives import serialization
|
||||||
from cryptography import x509
|
from cryptography import x509
|
||||||
from cryptography.x509.oid import NameOID
|
from cryptography.x509.oid import NameOID
|
||||||
|
from oslo_serialization import base64
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
from magnumclient import exceptions as exc
|
from magnumclient import exceptions as exc
|
||||||
@ -215,9 +215,9 @@ def _config_cluster_kubernetes(cluster, cluster_template, cfg_dir,
|
|||||||
" client-key-data: %(key)s\n"
|
" client-key-data: %(key)s\n"
|
||||||
% {'name': cluster.name,
|
% {'name': cluster.name,
|
||||||
'api_address': cluster.api_address,
|
'api_address': cluster.api_address,
|
||||||
'key': base64.b64encode(certs['key']),
|
'key': base64.encode_as_text(certs['key']),
|
||||||
'cert': base64.b64encode(certs['cert']),
|
'cert': base64.encode_as_text(certs['cert']),
|
||||||
'ca': base64.b64encode(certs['ca'])})
|
'ca': base64.encode_as_text(certs['ca'])})
|
||||||
else:
|
else:
|
||||||
cfg = ("apiVersion: v1\n"
|
cfg = ("apiVersion: v1\n"
|
||||||
"clusters:\n"
|
"clusters:\n"
|
||||||
@ -250,7 +250,7 @@ def _config_cluster_kubernetes(cluster, cluster_template, cfg_dir,
|
|||||||
" fi\n"
|
" fi\n"
|
||||||
% {'name': cluster.name,
|
% {'name': cluster.name,
|
||||||
'api_address': cluster.api_address,
|
'api_address': cluster.api_address,
|
||||||
'ca': base64.b64encode(certs['ca'])})
|
'ca': base64.encode_as_text(certs['ca'])})
|
||||||
|
|
||||||
if os.path.exists(cfg_file) and not force:
|
if os.path.exists(cfg_file) and not force:
|
||||||
raise exc.CommandError("File %s exists, aborting." % cfg_file)
|
raise exc.CommandError("File %s exists, aborting." % cfg_file)
|
||||||
|
@ -62,12 +62,17 @@ class FakeQuotasModelManager(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class FakeCertificatesModelManager(FakeBaseModelManager):
|
||||||
|
def get(self, cluster_uuid):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MagnumFakeContainerInfra(object):
|
class MagnumFakeContainerInfra(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.cluster_templates = FakeBaseModelManager()
|
self.cluster_templates = FakeBaseModelManager()
|
||||||
self.clusters = FakeBaseModelManager()
|
self.clusters = FakeBaseModelManager()
|
||||||
self.mservices = FakeBaseModelManager()
|
self.mservices = FakeBaseModelManager()
|
||||||
self.certificates = FakeBaseModelManager()
|
self.certificates = FakeCertificatesModelManager()
|
||||||
self.stats = FakeStatsModelManager()
|
self.stats = FakeStatsModelManager()
|
||||||
self.quotas = FakeQuotasModelManager()
|
self.quotas = FakeQuotasModelManager()
|
||||||
|
|
||||||
@ -237,6 +242,11 @@ class FakeCluster(object):
|
|||||||
return cluster
|
return cluster
|
||||||
|
|
||||||
|
|
||||||
|
class FakeCert(object):
|
||||||
|
def __init__(self, pem):
|
||||||
|
self.pem = pem
|
||||||
|
|
||||||
|
|
||||||
class FakeQuota(object):
|
class FakeQuota(object):
|
||||||
"""Fake one or more Quota"""
|
"""Fake one or more Quota"""
|
||||||
|
|
||||||
|
@ -37,6 +37,8 @@ class TestCluster(magnum_fakes.TestMagnumClientOSCV1):
|
|||||||
super(TestCluster, self).setUp()
|
super(TestCluster, self).setUp()
|
||||||
|
|
||||||
self.clusters_mock = self.app.client_manager.container_infra.clusters
|
self.clusters_mock = self.app.client_manager.container_infra.clusters
|
||||||
|
self.certificates_mock = \
|
||||||
|
self.app.client_manager.container_infra.certificates
|
||||||
|
|
||||||
|
|
||||||
class TestClusterCreate(TestCluster):
|
class TestClusterCreate(TestCluster):
|
||||||
@ -360,10 +362,15 @@ class TestClusterConfig(TestCluster):
|
|||||||
self.clusters_mock.get = mock.Mock()
|
self.clusters_mock.get = mock.Mock()
|
||||||
self.clusters_mock.get.return_value = self._cluster
|
self.clusters_mock.get.return_value = self._cluster
|
||||||
|
|
||||||
|
cert = magnum_fakes.FakeCert(pem='foo bar')
|
||||||
|
self.certificates_mock.create = mock.Mock()
|
||||||
|
self.certificates_mock.create.return_value = cert
|
||||||
|
self.certificates_mock.get = mock.Mock()
|
||||||
|
self.certificates_mock.get.return_value = cert
|
||||||
|
|
||||||
# Fake the cluster_template
|
# Fake the cluster_template
|
||||||
attr = dict()
|
attr = dict()
|
||||||
attr['name'] = 'fake-ct'
|
attr['name'] = 'fake-ct'
|
||||||
attr['tls_disabled'] = True
|
|
||||||
self._cluster_template = \
|
self._cluster_template = \
|
||||||
magnum_fakes.FakeClusterTemplate.create_one_cluster_template(attr)
|
magnum_fakes.FakeClusterTemplate.create_one_cluster_template(attr)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user