From 90694e705ca9313abfd71c0095d8994185ebc324 Mon Sep 17 00:00:00 2001 From: armando-migliaccio Date: Fri, 25 Apr 2014 15:29:14 -0700 Subject: [PATCH] NSX: fix API payloads for dhcp/metadata setup NSX 4.2 GA has tweaked the way dhcp and metadata ports are configured. This patch takes care of that. Closes-bug: #1312822 Change-Id: I4e8496bf721c0f35df4228ec9c6f8066275e8c7a (cherry picked from commit bfdec043f1429ac4aa884e9422861b4e6c1ca815) --- neutron/plugins/vmware/nsxlib/lsn.py | 24 ++++++++++++-------- neutron/tests/unit/vmware/nsxlib/test_lsn.py | 13 +++++++---- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/neutron/plugins/vmware/nsxlib/lsn.py b/neutron/plugins/vmware/nsxlib/lsn.py index 5034969a2..bea677a5d 100644 --- a/neutron/plugins/vmware/nsxlib/lsn.py +++ b/neutron/plugins/vmware/nsxlib/lsn.py @@ -206,29 +206,33 @@ def _lsn_port_configure_action( cluster=cluster) +def _get_opts(name, value): + return {"name": name, "value": str(value)} + + def lsn_port_dhcp_configure( cluster, lsn_id, lsn_port_id, is_enabled=True, dhcp_options=None): dhcp_options = dhcp_options or {} - opts = ["%s=%s" % (key, val) for key, val in dhcp_options.iteritems()] - dhcp_obj = { - 'options': {'options': opts} - } + opts = [_get_opts(key, val) for key, val in dhcp_options.iteritems()] + dhcp_obj = {'options': opts} _lsn_port_configure_action( cluster, lsn_id, lsn_port_id, 'dhcp', is_enabled, dhcp_obj) def lsn_metadata_configure( cluster, lsn_id, is_enabled=True, metadata_info=None): - opts = [ - "%s=%s" % (opt, metadata_info[opt]) - for opt in SUPPORTED_METADATA_OPTIONS - if metadata_info.get(opt) - ] meta_obj = { 'metadata_server_ip': metadata_info['metadata_server_ip'], 'metadata_server_port': metadata_info['metadata_server_port'], - 'misc_options': opts } + if metadata_info: + opts = [ + _get_opts(opt, metadata_info[opt]) + for opt in SUPPORTED_METADATA_OPTIONS + if metadata_info.get(opt) + ] + if opts: + meta_obj["options"] = opts _lsn_configure_action( cluster, lsn_id, 'metadata-proxy', is_enabled, meta_obj) diff --git a/neutron/tests/unit/vmware/nsxlib/test_lsn.py b/neutron/tests/unit/vmware/nsxlib/test_lsn.py index c8e078674..3d3ba5399 100644 --- a/neutron/tests/unit/vmware/nsxlib/test_lsn.py +++ b/neutron/tests/unit/vmware/nsxlib/test_lsn.py @@ -249,7 +249,10 @@ class LSNTestCase(base.BaseTestCase): self, lsn_id, lsn_port_id, is_enabled, opts): lsnlib.lsn_port_dhcp_configure( self.cluster, lsn_id, lsn_port_id, is_enabled, opts) - opt_array = ["%s=%s" % (key, val) for key, val in opts.iteritems()] + opt_array = [ + {"name": key, "value": val} + for key, val in opts.iteritems() + ] self.mock_request.assert_has_calls([ mock.call("PUT", "/ws.v1/lservices-node/%s/dhcp" % lsn_id, json.dumps({"enabled": is_enabled}), @@ -257,7 +260,7 @@ class LSNTestCase(base.BaseTestCase): mock.call("PUT", ("/ws.v1/lservices-node/%s/" "lport/%s/dhcp") % (lsn_id, lsn_port_id), - json.dumps({"options": {"options": opt_array}}), + json.dumps({"options": opt_array}), cluster=self.cluster) ]) @@ -300,7 +303,6 @@ class LSNTestCase(base.BaseTestCase): expected_opts = { "metadata_server_ip": "1.2.3.4", "metadata_server_port": "8775", - "misc_options": [] } self._test_lsn_metadata_configure( lsn_id, is_enabled, opts, expected_opts) @@ -316,7 +318,10 @@ class LSNTestCase(base.BaseTestCase): expected_opts = { "metadata_server_ip": "1.2.3.4", "metadata_server_port": "8775", - "misc_options": ["metadata_proxy_shared_secret=foo_secret"] + "options": [{ + "name": "metadata_proxy_shared_secret", + "value": "foo_secret" + }] } self._test_lsn_metadata_configure( lsn_id, is_enabled, opts, expected_opts) -- 2.45.2