py33: align the order of parameters for urlencode()
In Python 3, hash randomization is enabled by default. It causes the iteration order of dicts and sets to be unpredictable and differ across Python runs. In the test case, the fixed expecting string will not match the test result, it is relying on the dict order. This change transforms the input dict to a sequence of two-element list, with fixed order, and update the related expecitng string. Close-Bug #1231871 Change-Id: Ia998cdb6978fc024dd0d3c9bd161fbdebe68638a
This commit is contained in:
@@ -36,7 +36,7 @@ class MigrationsTest(utils.TestCase):
|
||||
ml = cs.migrations.list('host1', 'finished', 'child1')
|
||||
|
||||
cs.assert_called('GET',
|
||||
'/os-migrations?status=finished&host=host1'
|
||||
'&cell_name=child1')
|
||||
'/os-migrations?cell_name=child1&host=host1'
|
||||
'&status=finished')
|
||||
for m in ml:
|
||||
self.assertTrue(isinstance(m, migrations.Migration))
|
||||
|
||||
@@ -1799,5 +1799,5 @@ class ShellTest(utils.TestCase):
|
||||
self.run_command('migration-list --host host1 --cell_name child1 '
|
||||
'--status finished')
|
||||
self.assert_called('GET',
|
||||
'/os-migrations?status=finished&host=host1'
|
||||
'&cell_name=child1')
|
||||
'/os-migrations?cell_name=child1&host=host1'
|
||||
'&status=finished')
|
||||
|
||||
@@ -44,7 +44,11 @@ class MigrationManager(base.ManagerWithFind):
|
||||
if cell_name:
|
||||
opts['cell_name'] = cell_name
|
||||
|
||||
query_string = "?%s" % urlutils.urlencode(opts) if opts else ""
|
||||
# Transform the dict to a sequence of two-element tuples in fixed
|
||||
# order, then the encoded string will be consistent in Python 2&3.
|
||||
new_opts = sorted(opts.items(), key=lambda x: x[0])
|
||||
|
||||
query_string = "?%s" % urlutils.urlencode(new_opts) if new_opts else ""
|
||||
|
||||
return self._list("/os-migrations%s" % query_string, "migrations")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user