From: ChangBo Guo(gcb) Date: Thu, 17 Nov 2016 10:55:53 +0000 (+0800) Subject: Port ironic unit tests to Python 3 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=9bfeecdd3d24b3d639ef8d37e58f5e8faa36cbc9;p=osstest%2Fopenstack-nova.git Port ironic unit tests to Python 3 * Use sorted(dict.keys()) because dict.keys() has no sort() method on Python 3 * Dicts are not orderable in Python 3, need work around. For more information, please see: http://stackoverflow.com/questions/22333388/dicts-are-not-orderable-in-python-3 Partially-Implements: blueprint goal-python35 Co-Authored-By: Davanum Srinivas Change-Id: Icf7fd0e392fc0d174d6312badf024367ba72fd8f --- diff --git a/nova/tests/unit/virt/ironic/test_driver.py b/nova/tests/unit/virt/ironic/test_driver.py index a928b8cc8e..23e1e23814 100644 --- a/nova/tests/unit/virt/ironic/test_driver.py +++ b/nova/tests/unit/virt/ironic/test_driver.py @@ -281,8 +281,7 @@ class IronicDriverTestCase(test.NoDBTestCase): "stats", "numa_topology", "resource_class"] wantkeys.sort() - gotkeys = result.keys() - gotkeys.sort() + gotkeys = sorted(result.keys()) self.assertEqual(wantkeys, gotkeys) if has_inst_info: diff --git a/nova/tests/unit/virt/ironic/test_patcher.py b/nova/tests/unit/virt/ironic/test_patcher.py index 2fc7d094b7..4ae37ad8be 100644 --- a/nova/tests/unit/virt/ironic/test_patcher.py +++ b/nova/tests/unit/virt/ironic/test_patcher.py @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +import operator + from oslo_config import cfg from nova import context as nova_context @@ -60,6 +62,12 @@ class IronicDriverFieldsTestCase(test.NoDBTestCase): 'op': 'add'} ] + def assertPatchEqual(self, expected, observed): + self.assertEqual( + sorted(expected, key=operator.itemgetter('path', 'value')), + sorted(observed, key=operator.itemgetter('path', 'value')) + ) + def test_create_generic(self): node = ironic_utils.get_test_node(driver='pxe_fake') patcher_obj = patcher.create(node) @@ -69,7 +77,7 @@ class IronicDriverFieldsTestCase(test.NoDBTestCase): node = ironic_utils.get_test_node(driver='fake') patch = patcher.create(node).get_deploy_patch( self.instance, self.image_meta, self.flavor) - self.assertEqual(sorted(self._expected_deploy_patch), sorted(patch)) + self.assertPatchEqual(self._expected_deploy_patch, patch) def test_generic_get_deploy_patch_capabilities(self): node = ironic_utils.get_test_node(driver='fake') @@ -80,7 +88,7 @@ class IronicDriverFieldsTestCase(test.NoDBTestCase): expected += self._expected_deploy_patch patch = patcher.create(node).get_deploy_patch( self.instance, self.image_meta, self.flavor) - self.assertEqual(sorted(expected), sorted(patch)) + self.assertPatchEqual(expected, patch) def test_generic_get_deploy_patch_capabilities_op(self): node = ironic_utils.get_test_node(driver='fake') @@ -91,7 +99,7 @@ class IronicDriverFieldsTestCase(test.NoDBTestCase): expected += self._expected_deploy_patch patch = patcher.create(node).get_deploy_patch( self.instance, self.image_meta, self.flavor) - self.assertEqual(sorted(expected), sorted(patch)) + self.assertPatchEqual(expected, patch) def test_generic_get_deploy_patch_capabilities_nested_key(self): node = ironic_utils.get_test_node(driver='fake') @@ -102,7 +110,7 @@ class IronicDriverFieldsTestCase(test.NoDBTestCase): expected += self._expected_deploy_patch patch = patcher.create(node).get_deploy_patch( self.instance, self.image_meta, self.flavor) - self.assertEqual(sorted(expected), sorted(patch)) + self.assertPatchEqual(expected, patch) def test_generic_get_deploy_patch_ephemeral(self): CONF.set_override('default_ephemeral_format', 'testfmt') @@ -120,7 +128,7 @@ class IronicDriverFieldsTestCase(test.NoDBTestCase): 'value': 'testfmt', 'op': 'add'}] expected += self._expected_deploy_patch - self.assertEqual(sorted(expected), sorted(patch)) + self.assertPatchEqual(expected, patch) def test_generic_get_deploy_patch_preserve_ephemeral(self): node = ironic_utils.get_test_node(driver='fake') @@ -131,4 +139,4 @@ class IronicDriverFieldsTestCase(test.NoDBTestCase): expected = [{'path': '/instance_info/preserve_ephemeral', 'value': str(preserve), 'op': 'add', }] expected += self._expected_deploy_patch - self.assertEqual(sorted(expected), sorted(patch)) + self.assertPatchEqual(expected, patch) diff --git a/tests-py3.txt b/tests-py3.txt index 4180632eac..3e7c2c4c90 100644 --- a/tests-py3.txt +++ b/tests-py3.txt @@ -37,8 +37,6 @@ nova.tests.unit.test_configdrive2.ConfigDriveTestCase nova.tests.unit.test_matchers.TestDictMatches.test__str__ nova.tests.unit.test_wsgi.TestWSGIServerWithSSL nova.tests.unit.virt.disk.mount.test_nbd.NbdTestCase -nova.tests.unit.virt.ironic.test_driver.IronicDriverTestCase -nova.tests.unit.virt.ironic.test_patcher.IronicDriverFieldsTestCase nova.tests.unit.virt.libvirt.storage.test_rbd.RbdTestCase nova.tests.unit.virt.libvirt.test_driver.LibvirtConnTestCase nova.tests.unit.virt.libvirt.test_driver.LibvirtDriverTestCase