From ce567d7410aa92b09072a8030c89ab9d52707e86 Mon Sep 17 00:00:00 2001 From: armando-migliaccio Date: Mon, 4 Aug 2014 12:24:19 -0700 Subject: [PATCH] Make _build_uri_path output predictable This is done by ensuring that filters are serialized in their alphabetical order. Tweak tests affected by this. This is done in the context as defined by etherpad: neutron-random-hashseed Partial-bug: #1348818 Change-Id: Ibe79716a340195ca0365f276ef6e3e728f1a94a1 --- neutron/plugins/vmware/nsxlib/__init__.py | 5 ++++- neutron/tests/unit/vmware/nsxlib/test_l2gateway.py | 2 +- neutron/tests/unit/vmware/nsxlib/test_lsn.py | 8 ++++---- neutron/tests/unit/vmware/test_nsx_utils.py | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/neutron/plugins/vmware/nsxlib/__init__.py b/neutron/plugins/vmware/nsxlib/__init__.py index b09460b5939..e455965e64f 100644 --- a/neutron/plugins/vmware/nsxlib/__init__.py +++ b/neutron/plugins/vmware/nsxlib/__init__.py @@ -56,7 +56,10 @@ def _build_uri_path(resource, params.append(relations and "relations=%s" % relations) params.append(types and "types=%s" % types) if filters: - params.extend(['%s=%s' % (k, v) for (k, v) in filters.iteritems()]) + sorted_filters = [ + '%s=%s' % (k, filters[k]) for k in sorted(filters.keys()) + ] + params.extend(sorted_filters) uri_path = "%s/%s" % (URI_PREFIX, res_path) non_empty_params = [x for x in params if x is not None] if non_empty_params: diff --git a/neutron/tests/unit/vmware/nsxlib/test_l2gateway.py b/neutron/tests/unit/vmware/nsxlib/test_l2gateway.py index 477233d6fa3..e3b92f25f81 100644 --- a/neutron/tests/unit/vmware/nsxlib/test_l2gateway.py +++ b/neutron/tests/unit/vmware/nsxlib/test_l2gateway.py @@ -281,7 +281,7 @@ class L2GatewayTestCase(base.NsxlibTestCase): "GET", ("/ws.v1/transport-node?fields=uuid,tags&" "relations=TransportNodeStatus&" - "tag_scope=os_tid&tag=ssc_napoli&" + "tag=ssc_napoli&tag_scope=os_tid&" "_page_length=1000&tag_scope=quantum"), cluster=self.fake_cluster) diff --git a/neutron/tests/unit/vmware/nsxlib/test_lsn.py b/neutron/tests/unit/vmware/nsxlib/test_lsn.py index 41c50b6c3be..6a26efa3038 100644 --- a/neutron/tests/unit/vmware/nsxlib/test_lsn.py +++ b/neutron/tests/unit/vmware/nsxlib/test_lsn.py @@ -81,8 +81,8 @@ class LSNTestCase(base.BaseTestCase): self.assertEqual(lsn_id, result) self.mock_request.assert_called_once_with( "GET", - ("/ws.v1/lservices-node?fields=uuid&tag_scope=" - "n_network_id&tag=%s" % net_id), + ("/ws.v1/lservices-node?fields=uuid&tag=%s&" + "tag_scope=n_network_id" % net_id), cluster=self.cluster) def test_lsn_for_network_get_none(self): @@ -179,8 +179,8 @@ class LSNTestCase(base.BaseTestCase): self.assertEqual(result, port_id) self.mock_request.assert_called_once_with( "GET", - ("/ws.v1/lservices-node/%s/lport?fields=uuid&tag_scope=%s&" - "tag=%s" % (lsn_id, filters["tag_scope"], filters["tag"])), + ("/ws.v1/lservices-node/%s/lport?fields=uuid&tag=%s&" + "tag_scope=%s" % (lsn_id, filters["tag"], filters["tag_scope"])), cluster=self.cluster) def test_lsn_port_get_with_filters_return_none(self): diff --git a/neutron/tests/unit/vmware/test_nsx_utils.py b/neutron/tests/unit/vmware/test_nsx_utils.py index 569af8f7eb3..44b72bfa01d 100644 --- a/neutron/tests/unit/vmware/test_nsx_utils.py +++ b/neutron/tests/unit/vmware/test_nsx_utils.py @@ -220,7 +220,7 @@ class NsxUtilsTestCase(base.BaseTestCase): filters = {"tag": 'foo', "tag_scope": "scope_foo"} result = nsxlib._build_uri_path('RESOURCE', filters=filters) expected = ( - "%s/%s?tag_scope=scope_foo&tag=foo" % + "%s/%s?tag=foo&tag_scope=scope_foo" % (nsxlib.URI_PREFIX, 'RESOURCE')) self.assertEqual(expected, result)