Port test_pipelib and test_policy to Python 3
* policy_fixture: replace jsonutils.load() with jsonutils.loads() to support bytes and Unicode. Use also a context manager to open the file to fix a ResourceWarning on Python 3. * pipelib: replace str.encode("base64") with base64.b64encode(str) * cmd/manager.py: replace urllib.unquote() with urlparse.unquote(), urlparse comes from "import six.moves.urllib.parse as urlparse" * enable tests on Python 3 - test_pipelib - test_policy * enable also tests which already passed on Python 3: - test_quota - test_test_utils This change is partially based on the work of dims, change Ibb4fa47cd71d697a4996425b1797ac2f8cc363cd. Co-Authored-By: Davanum Srinivas <davanum@gmail.com> Partially-Implements: blueprint nova-python3-newton Change-Id: I726d867fafa2d21312e3f2542af9d9ee5e08d897
This commit is contained in:
parent
baaeec1b63
commit
3542060740
@ -20,6 +20,7 @@ an instance with it.
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import base64
|
||||||
import os
|
import os
|
||||||
import string
|
import string
|
||||||
import zipfile
|
import zipfile
|
||||||
@ -78,12 +79,13 @@ class CloudPipe(object):
|
|||||||
'server.crt')
|
'server.crt')
|
||||||
z.write(server_crt, 'server.crt')
|
z.write(server_crt, 'server.crt')
|
||||||
z.close()
|
z.close()
|
||||||
with open(zippath, "r") as zippy:
|
with open(zippath, "rb") as zippy:
|
||||||
# NOTE(vish): run instances expects encoded userdata,
|
# NOTE(vish): run instances expects encoded userdata,
|
||||||
# it is decoded in the get_metadata_call.
|
# it is decoded in the get_metadata_call.
|
||||||
# autorun.sh also decodes the zip file,
|
# autorun.sh also decodes the zip file,
|
||||||
# hence the double encoding.
|
# hence the double encoding.
|
||||||
encoded = zippy.read().encode("base64").encode("base64")
|
encoded = base64.b64encode(zippy.read())
|
||||||
|
encoded = base64.b64encode(encoded)
|
||||||
|
|
||||||
return encoded
|
return encoded
|
||||||
|
|
||||||
|
@ -100,7 +100,9 @@ class RoleBasedPolicyFixture(RealPolicyFixture):
|
|||||||
self.role = role
|
self.role = role
|
||||||
|
|
||||||
def _prepare_policy(self):
|
def _prepare_policy(self):
|
||||||
policy = jsonutils.load(open(CONF.oslo_policy.policy_file))
|
with open(CONF.oslo_policy.policy_file) as fp:
|
||||||
|
policy = fp.read()
|
||||||
|
policy = jsonutils.loads(policy)
|
||||||
|
|
||||||
# Convert all actions to require specified role
|
# Convert all actions to require specified role
|
||||||
for action, rule in six.iteritems(policy):
|
for action, rule in six.iteritems(policy):
|
||||||
|
@ -68,10 +68,6 @@ nova.tests.unit.test_metadata.MetadataHandlerTestCase
|
|||||||
nova.tests.unit.test_metadata.MetadataPasswordTestCase
|
nova.tests.unit.test_metadata.MetadataPasswordTestCase
|
||||||
nova.tests.unit.test_metadata.MetadataTestCase
|
nova.tests.unit.test_metadata.MetadataTestCase
|
||||||
nova.tests.unit.test_metadata.OpenStackMetadataTestCase
|
nova.tests.unit.test_metadata.OpenStackMetadataTestCase
|
||||||
nova.tests.unit.test_pipelib.PipelibTest
|
|
||||||
nova.tests.unit.test_policy.AdminRolePolicyTestCase
|
|
||||||
nova.tests.unit.test_quota.QuotaIntegrationTestCase
|
|
||||||
nova.tests.unit.test_test_utils.TestUtilsTestCase
|
|
||||||
nova.tests.unit.test_wsgi.TestWSGIServerWithSSL
|
nova.tests.unit.test_wsgi.TestWSGIServerWithSSL
|
||||||
nova.tests.unit.virt.disk.mount.test_nbd.NbdTestCase
|
nova.tests.unit.virt.disk.mount.test_nbd.NbdTestCase
|
||||||
nova.tests.unit.virt.ironic.test_driver.IronicDriverTestCase
|
nova.tests.unit.virt.ironic.test_driver.IronicDriverTestCase
|
||||||
|
Loading…
Reference in New Issue
Block a user