Browse Source

Do not rely on hash ordering in tests

With tox 1.7.2 hash randomization will be on by default, causing
random failures of our tests. How to reproduce:
* Update tox
* Run something like:
  $ for i in {1..20}; do tox -epy27 || break; done

Change-Id: I52c10c47a7a1c0e6a9e436efb090bbcb0fb02edc
Closes-bug: #1348818
changes/39/109939/2
Dmitry Tantsur 8 years ago
parent
commit
b056fca278
  1. 2
      ironic/tests/api/v1/test_drivers.py
  2. 7
      ironic/tests/objects/test_objects.py
  3. 28
      ironic/tests/test_glance_service.py

2
ironic/tests/api/v1/test_drivers.py

@ -51,7 +51,7 @@ class TestListDrivers(base.FunctionalTest):
for i in range(len(expected)):
d = drivers[i]
self.assertEqual(expected[i]['name'], d['name'])
self.assertEqual(expected[i]['hosts'], d['hosts'])
self.assertEqual(sorted(expected[i]['hosts']), sorted(d['hosts']))
self.validate_link(d['links'][0]['href'])
self.validate_link(d['links'][1]['href'])

7
ironic/tests/objects/test_objects.py

@ -429,7 +429,12 @@ class _TestObject(object):
'updated_at': timeutils.isotime(dt),
}
}
self.assertEqual(expected, obj.obj_to_primitive())
actual = obj.obj_to_primitive()
# ironic_object.changes is built from a set and order is undefined
self.assertEqual(sorted(expected['ironic_object.changes']),
sorted(actual['ironic_object.changes']))
del expected['ironic_object.changes'], actual['ironic_object.changes']
self.assertEqual(expected, actual)
def test_contains(self):
obj = MyObj()

28
ironic/tests/test_glance_service.py

@ -28,6 +28,7 @@ from ironic.common.glance_service import base_image_service
from ironic.common.glance_service import service_utils
from ironic.common import image_service as service
from ironic.openstack.common import context
from ironic.openstack.common import jsonutils
from ironic.tests import base
from ironic.tests import matchers
from ironic.tests import stubs
@ -66,19 +67,26 @@ class TestGlanceSerializer(testtools.TestCase):
'name': 'image1',
'is_public': True,
'foo': 'bar',
'properties': {
'prop1': 'propvalue1',
'mappings':
'[{"device": "bbb", "virtual": "aaa"}, '
'{"device": "yyy", "virtual": "xxx"}]',
'block_device_mapping':
'[{"virtual_device": "fake", "device_name": "/dev/fake"}, '
'{"virtual_device": "ephemeral0", '
'"device_name": "/dev/fake0"}]'}}
'properties': {'prop1': 'propvalue1'}
}
converted = service_utils._convert(metadata, 'to')
self.assertEqual(converted_expected, converted)
self.assertEqual(metadata,
service_utils._convert(converted, 'from'))
# Fields that rely on dict ordering can't be compared as text
mappings = jsonutils.loads(converted['properties']
.pop('mappings'))
self.assertEqual([{"device": "bbb", "virtual": "aaa"},
{"device": "yyy", "virtual": "xxx"}],
mappings)
bd_mapping = jsonutils.loads(converted['properties']
.pop('block_device_mapping'))
self.assertEqual([{"virtual_device": "fake",
"device_name": "/dev/fake"},
{"virtual_device": "ephemeral0",
"device_name": "/dev/fake0"}],
bd_mapping)
# Compare the remaining
self.assertEqual(converted_expected, converted)
class TestGlanceImageService(base.TestCase):

Loading…
Cancel
Save