Fixed test to work with random PYTHONHASHSEED
to compare objects, that contains nested collections new method assertJsonEqual was used. Its usage allows not to rely on constant order of nested collections elements. new method assertJsonEqual was used Partial-Bug: #1348818 Change-Id: I0857d3793fb7fca7c5fde3b87dc187088cf965ac
This commit is contained in:
parent
1fb09cc821
commit
bb6a7bda2a
|
@ -1017,15 +1017,15 @@ class CloudTestCase(test.TestCase):
|
|||
fake_change_instance_metadata)
|
||||
|
||||
utc = iso8601.iso8601.Utc()
|
||||
|
||||
flavor = flavors.get_flavor(1)
|
||||
# Create some test images
|
||||
sys_meta = flavors.save_flavor_info(
|
||||
{}, flavors.get_flavor(1))
|
||||
{}, flavor)
|
||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||
inst1_kwargs = {
|
||||
'reservation_id': 'a',
|
||||
'image_ref': image_uuid,
|
||||
'instance_type_id': 1,
|
||||
'instance_type_id': flavor.id,
|
||||
'host': 'host1',
|
||||
'vm_state': 'active',
|
||||
'launched_at': timeutils.utcnow(),
|
||||
|
@ -1038,7 +1038,7 @@ class CloudTestCase(test.TestCase):
|
|||
inst2_kwargs = {
|
||||
'reservation_id': 'b',
|
||||
'image_ref': image_uuid,
|
||||
'instance_type_id': 1,
|
||||
'instance_type_id': flavor.id,
|
||||
'host': 'host2',
|
||||
'vm_state': 'active',
|
||||
'launched_at': timeutils.utcnow(),
|
||||
|
@ -1084,7 +1084,7 @@ class CloudTestCase(test.TestCase):
|
|||
'instanceId': 'i-00000001',
|
||||
'instanceState': {'code': 16,
|
||||
'name': 'running'},
|
||||
'instanceType': u'm1.medium',
|
||||
'instanceType': flavor.name,
|
||||
'ipAddress': '1.2.3.4',
|
||||
'keyName': 'None (None, host1)',
|
||||
'launchTime':
|
||||
|
@ -1115,7 +1115,7 @@ class CloudTestCase(test.TestCase):
|
|||
'instanceId': 'i-00000002',
|
||||
'instanceState': {'code': 16,
|
||||
'name': 'running'},
|
||||
'instanceType': u'm1.medium',
|
||||
'instanceType': flavor.name,
|
||||
'ipAddress': '1.2.3.4',
|
||||
'keyName': u'None (None, host2)',
|
||||
'launchTime':
|
||||
|
@ -1139,33 +1139,36 @@ class CloudTestCase(test.TestCase):
|
|||
|
||||
# No filter
|
||||
result = self.cloud.describe_instances(self.context)
|
||||
self.assertEqual(result, {'reservationSet': [inst1_ret, inst2_ret]})
|
||||
self.assertJsonEqual(result, {'reservationSet':
|
||||
[inst1_ret, inst2_ret]})
|
||||
|
||||
# Key search
|
||||
# Both should have tags with key 'foo' and value 'bar'
|
||||
filters = {'filter': [{'name': 'tag:foo',
|
||||
'value': ['bar']}]}
|
||||
result = self.cloud.describe_instances(self.context, **filters)
|
||||
self.assertEqual(result, {'reservationSet': [inst1_ret, inst2_ret]})
|
||||
self.assertJsonEqual(result, {'reservationSet':
|
||||
[inst1_ret, inst2_ret]})
|
||||
|
||||
# Both should have tags with key 'foo'
|
||||
filters = {'filter': [{'name': 'tag-key',
|
||||
'value': ['foo']}]}
|
||||
result = self.cloud.describe_instances(self.context, **filters)
|
||||
self.assertEqual(result, {'reservationSet': [inst1_ret, inst2_ret]})
|
||||
self.assertJsonEqual(result, {'reservationSet':
|
||||
[inst1_ret, inst2_ret]})
|
||||
|
||||
# Value search
|
||||
# Only inst2 should have tags with key 'baz' and value 'quux'
|
||||
filters = {'filter': [{'name': 'tag:baz',
|
||||
'value': ['quux']}]}
|
||||
result = self.cloud.describe_instances(self.context, **filters)
|
||||
self.assertEqual(result, {'reservationSet': [inst2_ret]})
|
||||
self.assertJsonEqual(result, {'reservationSet': [inst2_ret]})
|
||||
|
||||
# Only inst2 should have tags with value 'quux'
|
||||
filters = {'filter': [{'name': 'tag-value',
|
||||
'value': ['quux']}]}
|
||||
result = self.cloud.describe_instances(self.context, **filters)
|
||||
self.assertEqual(result, {'reservationSet': [inst2_ret]})
|
||||
self.assertJsonEqual(result, {'reservationSet': [inst2_ret]})
|
||||
|
||||
# Multiple values
|
||||
# Both should have tags with key 'baz' and values in the set
|
||||
|
@ -1173,7 +1176,8 @@ class CloudTestCase(test.TestCase):
|
|||
filters = {'filter': [{'name': 'tag:baz',
|
||||
'value': ['quux', 'wibble']}]}
|
||||
result = self.cloud.describe_instances(self.context, **filters)
|
||||
self.assertEqual(result, {'reservationSet': [inst1_ret, inst2_ret]})
|
||||
self.assertJsonEqual(result, {'reservationSet':
|
||||
[inst1_ret, inst2_ret]})
|
||||
|
||||
# Both should have tags with key 'baz' or tags with value 'bar'
|
||||
filters = {'filter': [{'name': 'tag-key',
|
||||
|
@ -1181,7 +1185,8 @@ class CloudTestCase(test.TestCase):
|
|||
{'name': 'tag-value',
|
||||
'value': ['bar']}]}
|
||||
result = self.cloud.describe_instances(self.context, **filters)
|
||||
self.assertEqual(result, {'reservationSet': [inst1_ret, inst2_ret]})
|
||||
self.assertJsonEqual(result, {'reservationSet':
|
||||
[inst1_ret, inst2_ret]})
|
||||
|
||||
# Confirm deletion of tags
|
||||
# Check for format 'tag:'
|
||||
|
@ -1189,17 +1194,17 @@ class CloudTestCase(test.TestCase):
|
|||
filters = {'filter': [{'name': 'tag:foo',
|
||||
'value': ['bar']}]}
|
||||
result = self.cloud.describe_instances(self.context, **filters)
|
||||
self.assertEqual(result, {'reservationSet': [inst2_ret]})
|
||||
self.assertJsonEqual(result, {'reservationSet': [inst2_ret]})
|
||||
|
||||
# Check for format 'tag-'
|
||||
filters = {'filter': [{'name': 'tag-key',
|
||||
'value': ['foo']}]}
|
||||
result = self.cloud.describe_instances(self.context, **filters)
|
||||
self.assertEqual(result, {'reservationSet': [inst2_ret]})
|
||||
self.assertJsonEqual(result, {'reservationSet': [inst2_ret]})
|
||||
filters = {'filter': [{'name': 'tag-value',
|
||||
'value': ['bar']}]}
|
||||
result = self.cloud.describe_instances(self.context, **filters)
|
||||
self.assertEqual(result, {'reservationSet': [inst2_ret]})
|
||||
self.assertJsonEqual(result, {'reservationSet': [inst2_ret]})
|
||||
|
||||
# destroy the test instances
|
||||
db.instance_destroy(self.context, inst1['uuid'])
|
||||
|
|
|
@ -247,7 +247,7 @@ class CreateserverextTest(test.TestCase):
|
|||
response = request.get_response(fakes.wsgi_app(
|
||||
init_only=('servers', 'os-create-server-ext')))
|
||||
self.assertEqual(response.status_int, 202)
|
||||
self.assertEqual(self.security_group, security_groups)
|
||||
self.assertJsonEqual(self.security_group, security_groups)
|
||||
|
||||
def test_get_server_by_id_verify_security_groups_json(self):
|
||||
self.stubs.Set(db, 'instance_get', fakes.fake_instance_get())
|
||||
|
|
|
@ -236,8 +236,12 @@ class TestTrustedFilter(test.NoDBTestCase):
|
|||
host = fakes.FakeHostState('host1', 'node1', {})
|
||||
|
||||
self.filt_cls.host_passes(host, filter_properties) # Fill the caches
|
||||
req_mock.assert_called_once_with("POST", "PollHosts",
|
||||
["node1", "node2"])
|
||||
self.assertTrue(req_mock.called)
|
||||
self.assertEqual(1, req_mock.call_count)
|
||||
call_args = list(req_mock.call_args[0])
|
||||
|
||||
expected_call_args = ['POST', 'PollHosts', ['node2', 'node1']]
|
||||
self.assertJsonEqual(call_args, expected_call_args)
|
||||
|
||||
def test_trusted_filter_trusted_and_locale_formated_vtime_passes(self,
|
||||
req_mock):
|
||||
|
|
|
@ -229,10 +229,12 @@ class AvailabilityZoneTestCases(test.TestCase):
|
|||
zones, not_zones = az.get_availability_zones(self.context,
|
||||
with_hosts=True)
|
||||
|
||||
self.assertEqual(zones, [(u'nova-test2', set([u'host3'])),
|
||||
self.assertJsonEqual(zones,
|
||||
[(u'nova-test2', set([u'host3'])),
|
||||
(u'nova-test', set([u'host1']))])
|
||||
self.assertEqual(not_zones, [(u'nova-test3', set([u'host4'])),
|
||||
(u'nova', set([u'host5']))])
|
||||
self.assertJsonEqual(not_zones,
|
||||
[(u'nova-test3', set([u'host4'])),
|
||||
(u'nova', set([u'host5']))])
|
||||
|
||||
def test_get_instance_availability_zone_default_value(self):
|
||||
"""Test get right availability zone by given an instance."""
|
||||
|
|
|
@ -926,7 +926,7 @@ class ResourceFilterTestCase(test.NoDBTestCase):
|
|||
def _assert_filtering(self, res_list, filts, expected_tags):
|
||||
actual_tags = utils.filter_and_format_resource_metadata('instance',
|
||||
res_list, filts, 'metadata')
|
||||
self.assertEqual(expected_tags, actual_tags)
|
||||
self.assertJsonEqual(expected_tags, actual_tags)
|
||||
|
||||
def test_filter_and_format_resource_metadata(self):
|
||||
# Create some tags
|
||||
|
|
|
@ -2264,7 +2264,7 @@ class ChildVHDsTestCase(test.NoDBTestCase):
|
|||
|
||||
result = vm_utils._child_vhds("session", "sr_ref", ["my-uuid"])
|
||||
|
||||
self.assertEqual(['uuid-child', 'uuid-child-snap'], result)
|
||||
self.assertJsonEqual(['uuid-child', 'uuid-child-snap'], result)
|
||||
|
||||
@mock.patch.object(vm_utils, '_get_all_vdis_in_sr')
|
||||
def test_child_vhds_only_snapshots(self, mock_get_all):
|
||||
|
|
|
@ -638,8 +638,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
|
|||
key = 'vm-data/networking/DEADBEEF0001'
|
||||
xenstore_value = xenstore_data[key]
|
||||
tcpip_data = ast.literal_eval(xenstore_value)
|
||||
self.assertEqual(tcpip_data,
|
||||
{'broadcast': '192.168.1.255',
|
||||
self.assertJsonEqual({'broadcast': '192.168.1.255',
|
||||
'dns': ['192.168.1.4', '192.168.1.3'],
|
||||
'gateway': '192.168.1.1',
|
||||
'gateway_v6': '2001:db8:0:1::1',
|
||||
|
@ -656,7 +655,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
|
|||
'netmask': '255.255.255.0',
|
||||
'gateway': '192.168.1.1'}],
|
||||
'label': 'test1',
|
||||
'mac': 'DE:AD:BE:EF:00:01'})
|
||||
'mac': 'DE:AD:BE:EF:00:01'}, tcpip_data)
|
||||
|
||||
def check_vm_params_for_windows(self):
|
||||
self.assertEqual(self.vm['platform']['nx'], 'true')
|
||||
|
|
Loading…
Reference in New Issue