]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
NSX: fix API payloads for dhcp/metadata setup
authorarmando-migliaccio <armamig@gmail.com>
Fri, 25 Apr 2014 22:29:14 +0000 (15:29 -0700)
committerThomas Goirand <thomas@goirand.fr>
Mon, 9 Jun 2014 15:06:54 +0000 (23:06 +0800)
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
neutron/tests/unit/vmware/nsxlib/test_lsn.py

index 5034969a29a677bc2c57415b665402d7ade8f4c6..bea677a5d9b81ffb33e845b07f51ea02482e9161 100644 (file)
@@ -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)
 
index c8e078674514b3b79ee93e24b130c12989c1f33c..3d3ba5399ff03a642cc7c69be01b9ae679baee40 100644 (file)
@@ -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)