Skip to content

Commit f1d742f

Browse files
author
Eric Fried
committed
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
1 parent 45af14c commit f1d742f

5 files changed

Lines changed: 8 additions & 7 deletions

File tree

openstackclient/tests/functional/compute/v2/test_agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class ComputeAgentTests(base.TestCase):
2121

2222
# Generate two different md5hash
2323
MD5HASH1 = hashlib.md5()
24-
MD5HASH1.update('agent_1')
24+
MD5HASH1.update('agent_1'.encode('utf-8'))
2525
MD5HASH1 = MD5HASH1.hexdigest()
2626
MD5HASH2 = hashlib.md5()
27-
MD5HASH2.update('agent_2')
27+
MD5HASH2.update('agent_2'.encode('utf-8'))
2828
MD5HASH2 = MD5HASH2.hexdigest()
2929

3030
def test_compute_agent_delete(self):

openstackclient/tests/functional/compute/v2/test_keypair.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_keypair_create_public_key(self):
8888
1) Create keypair with given public key
8989
2) Delete keypair
9090
"""
91-
with tempfile.NamedTemporaryFile() as f:
91+
with tempfile.NamedTemporaryFile(mode='w+') as f:
9292
f.write(self.PUBLIC_KEY)
9393
f.flush()
9494

@@ -108,7 +108,7 @@ def test_keypair_create_private_key(self):
108108
1) Create keypair with private key file
109109
2) Delete keypair
110110
"""
111-
with tempfile.NamedTemporaryFile() as f:
111+
with tempfile.NamedTemporaryFile(mode='w+') as f:
112112
cmd_output = json.loads(self.openstack(
113113
'keypair create -f json --private-key %s tmpkey' % f.name,
114114
))

openstackclient/tests/functional/identity/v2/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# under the License.
1212

1313
import os
14+
import unittest
1415

1516
import fixtures
1617
from tempest.lib.common.utils import data_utils
@@ -62,7 +63,7 @@ def setUpClass(cls):
6263
# TODO(dtroyer): Actually determine if Identity v2 admin is
6364
# enabled in the target cloud. Tuens out OSC
6465
# doesn't make this easy as it should (yet).
65-
raise cls.skipException('No Identity v2 admin endpoint?')
66+
raise unittest.case.SkipTest('No Identity v2 admin endpoint?')
6667

6768
@classmethod
6869
def tearDownClass(cls):

openstackclient/tests/functional/identity/v3/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def _create_dummy_registered_limit(self, add_clean_up=True):
360360

361361
def _extract_value_from_items(self, key, items):
362362
for d in items:
363-
for k, v in d.iteritems():
363+
for k, v in d.items():
364364
if k == key:
365365
return v
366366

openstackclient/tests/functional/object/v1/test_object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def setUp(self):
3333
self.skipTest("No object-store service present")
3434

3535
def test_object(self):
36-
with tempfile.NamedTemporaryFile() as f:
36+
with tempfile.NamedTemporaryFile(mode='w+') as f:
3737
f.write('test content')
3838
f.flush()
3939
self._test_object(f.name)

0 commit comments

Comments
 (0)