Fix functional tests for py3
Fix various things so the functional tests will work under python3: - A hashlib.md5() can only be update()d with an encoded string in py3. - There's no dict.iteritems(), change to dict.items() (which is already an iterator). - Open temp files with 'w+' mode rather than the default 'w+b' (as an alternative to encoding all the write and expected-read payloads as bytes). - (This is a weird one) Explicitly raise SkipTest from unittest (rather than unittest2, which is where cls.skipException landed). Not sure why this is busted, but this moves the ball. Change-Id: Ic9b2b47848a600e87a3674289ae7ae8c3e091fee
This commit is contained in:
parent
45af14ca72
commit
f1d742f32a
|
@ -21,10 +21,10 @@ class ComputeAgentTests(base.TestCase):
|
||||||
|
|
||||||
# Generate two different md5hash
|
# Generate two different md5hash
|
||||||
MD5HASH1 = hashlib.md5()
|
MD5HASH1 = hashlib.md5()
|
||||||
MD5HASH1.update('agent_1')
|
MD5HASH1.update('agent_1'.encode('utf-8'))
|
||||||
MD5HASH1 = MD5HASH1.hexdigest()
|
MD5HASH1 = MD5HASH1.hexdigest()
|
||||||
MD5HASH2 = hashlib.md5()
|
MD5HASH2 = hashlib.md5()
|
||||||
MD5HASH2.update('agent_2')
|
MD5HASH2.update('agent_2'.encode('utf-8'))
|
||||||
MD5HASH2 = MD5HASH2.hexdigest()
|
MD5HASH2 = MD5HASH2.hexdigest()
|
||||||
|
|
||||||
def test_compute_agent_delete(self):
|
def test_compute_agent_delete(self):
|
||||||
|
|
|
@ -88,7 +88,7 @@ class KeypairTests(KeypairBase):
|
||||||
1) Create keypair with given public key
|
1) Create keypair with given public key
|
||||||
2) Delete keypair
|
2) Delete keypair
|
||||||
"""
|
"""
|
||||||
with tempfile.NamedTemporaryFile() as f:
|
with tempfile.NamedTemporaryFile(mode='w+') as f:
|
||||||
f.write(self.PUBLIC_KEY)
|
f.write(self.PUBLIC_KEY)
|
||||||
f.flush()
|
f.flush()
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ class KeypairTests(KeypairBase):
|
||||||
1) Create keypair with private key file
|
1) Create keypair with private key file
|
||||||
2) Delete keypair
|
2) Delete keypair
|
||||||
"""
|
"""
|
||||||
with tempfile.NamedTemporaryFile() as f:
|
with tempfile.NamedTemporaryFile(mode='w+') as f:
|
||||||
cmd_output = json.loads(self.openstack(
|
cmd_output = json.loads(self.openstack(
|
||||||
'keypair create -f json --private-key %s tmpkey' % f.name,
|
'keypair create -f json --private-key %s tmpkey' % f.name,
|
||||||
))
|
))
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import unittest
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
from tempest.lib.common.utils import data_utils
|
from tempest.lib.common.utils import data_utils
|
||||||
|
@ -62,7 +63,7 @@ class IdentityTests(base.TestCase):
|
||||||
# TODO(dtroyer): Actually determine if Identity v2 admin is
|
# TODO(dtroyer): Actually determine if Identity v2 admin is
|
||||||
# enabled in the target cloud. Tuens out OSC
|
# enabled in the target cloud. Tuens out OSC
|
||||||
# doesn't make this easy as it should (yet).
|
# doesn't make this easy as it should (yet).
|
||||||
raise cls.skipException('No Identity v2 admin endpoint?')
|
raise unittest.case.SkipTest('No Identity v2 admin endpoint?')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
|
|
|
@ -360,7 +360,7 @@ class IdentityTests(base.TestCase):
|
||||||
|
|
||||||
def _extract_value_from_items(self, key, items):
|
def _extract_value_from_items(self, key, items):
|
||||||
for d in items:
|
for d in items:
|
||||||
for k, v in d.iteritems():
|
for k, v in d.items():
|
||||||
if k == key:
|
if k == key:
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ class ObjectTests(common.ObjectStoreTests):
|
||||||
self.skipTest("No object-store service present")
|
self.skipTest("No object-store service present")
|
||||||
|
|
||||||
def test_object(self):
|
def test_object(self):
|
||||||
with tempfile.NamedTemporaryFile() as f:
|
with tempfile.NamedTemporaryFile(mode='w+') as f:
|
||||||
f.write('test content')
|
f.write('test content')
|
||||||
f.flush()
|
f.flush()
|
||||||
self._test_object(f.name)
|
self._test_object(f.name)
|
||||||
|
|
Loading…
Reference in New Issue