diff options
author | Jacek Swiderski <jacek.swiderski@codilime.com> | 2014-08-06 11:23:16 +0200 |
---|---|---|
committer | Jacek Swiderski <jacek.swiderski@codilime.com> | 2014-09-23 17:46:20 +0000 |
commit | d5b90315d2ff647179fd91512377a7f21a57ef0a (patch) | |
tree | 48cb46c3c960e6ecf6d792e8bbbd80e6bec99439 | |
parent | a76af4ade3c751a4372a427989035cf8c32342b0 (diff) | |
download | neutron-d5b90315d2ff647179fd91512377a7f21a57ef0a.tar.gz |
Do not assume order of body and tags elements
This fixes the l2gateway unit test that breaks with a randomized PYTHONHASHSEED
(see the bug report).
The test assumed that the body dict from self._create_expected_req_body
had elements (including contents of tags list) in a particular order.
Found with PYTHONHASHSEED=2455351445.
The fix ensures that body is in predictable order.
Partial-bug: #1348818
Note: There are several other unrelated unit tests that also break with a
randomized PYTHONHASHSEED, but they are not addressed here. They will be
addressed in separate patches.
Change-Id: I423b68aff58486c113d0e5c5f4726f9eabf6920e
-rw-r--r-- | neutron/plugins/vmware/common/utils.py | 2 | ||||
-rw-r--r-- | neutron/plugins/vmware/nsxlib/l2gateway.py | 4 | ||||
-rw-r--r-- | neutron/tests/unit/vmware/nsxlib/test_l2gateway.py | 7 |
3 files changed, 7 insertions, 6 deletions
diff --git a/neutron/plugins/vmware/common/utils.py b/neutron/plugins/vmware/common/utils.py index fb21e55e69..fd5f2fc295 100644 --- a/neutron/plugins/vmware/common/utils.py +++ b/neutron/plugins/vmware/common/utils.py @@ -40,7 +40,7 @@ def get_tags(**kwargs): tags = ([dict(tag=value, scope=key) for key, value in kwargs.iteritems()]) tags.append({"tag": NEUTRON_VERSION, "scope": "quantum"}) - return tags + return sorted(tags) def device_id_to_vm_id(device_id, obfuscate=False): diff --git a/neutron/plugins/vmware/nsxlib/l2gateway.py b/neutron/plugins/vmware/nsxlib/l2gateway.py index f5a6e3053b..0848ed591f 100644 --- a/neutron/plugins/vmware/nsxlib/l2gateway.py +++ b/neutron/plugins/vmware/nsxlib/l2gateway.py @@ -149,7 +149,7 @@ def create_gateway_device(cluster, tenant_id, display_name, neutron_id, try: return nsxlib.do_request( HTTP_POST, nsxlib._build_uri_path(TRANSPORTNODE_RESOURCE), - jsonutils.dumps(body), cluster=cluster) + jsonutils.dumps(body, sort_keys=True), cluster=cluster) except api_exc.InvalidSecurityCertificate: raise nsx_exc.InvalidSecurityCertificate() @@ -166,7 +166,7 @@ def update_gateway_device(cluster, gateway_id, tenant_id, HTTP_PUT, nsxlib._build_uri_path(TRANSPORTNODE_RESOURCE, resource_id=gateway_id), - jsonutils.dumps(body), cluster=cluster) + jsonutils.dumps(body, sort_keys=True), cluster=cluster) except api_exc.InvalidSecurityCertificate: raise nsx_exc.InvalidSecurityCertificate() diff --git a/neutron/tests/unit/vmware/nsxlib/test_l2gateway.py b/neutron/tests/unit/vmware/nsxlib/test_l2gateway.py index e3b92f25f8..006ad38648 100644 --- a/neutron/tests/unit/vmware/nsxlib/test_l2gateway.py +++ b/neutron/tests/unit/vmware/nsxlib/test_l2gateway.py @@ -165,6 +165,7 @@ class L2GatewayTestCase(base.NsxlibTestCase): "type": '%sConnector' % connector_type}], "admin_status_enabled": True } + body.get("tags").sort() if client_certificate: body["credential"] = { "client_certificate": { @@ -191,7 +192,7 @@ class L2GatewayTestCase(base.NsxlibTestCase): request_mock.assert_called_once_with( "POST", "/ws.v1/transport-node", - jsonutils.dumps(expected_req_body), + jsonutils.dumps(expected_req_body, sort_keys=True), cluster=self.fake_cluster) def test_update_gw_device(self): @@ -215,7 +216,7 @@ class L2GatewayTestCase(base.NsxlibTestCase): request_mock.assert_called_once_with( "PUT", "/ws.v1/transport-node/whatever", - jsonutils.dumps(expected_req_body), + jsonutils.dumps(expected_req_body, sort_keys=True), cluster=self.fake_cluster) def test_update_gw_device_without_certificate(self): @@ -238,7 +239,7 @@ class L2GatewayTestCase(base.NsxlibTestCase): request_mock.assert_called_once_with( "PUT", "/ws.v1/transport-node/whatever", - jsonutils.dumps(expected_req_body), + jsonutils.dumps(expected_req_body, sort_keys=True), cluster=self.fake_cluster) def test_get_gw_device_status(self): |