From 520758a1c2fe5699b6b0216d5ef4fe0b57dd2833 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Sat, 18 Nov 2017 12:25:33 +0200 Subject: [PATCH] NSX|V3: ensure that metadata works with windows instances The 121 support required that we add a route for the metadata to be via the interface. There are some operting systems that do not support this. This needs to be '0.0.0.0'. we pass both options and the OS will decide which one to use. Change-Id: Id5d43c7b5eb7c7b7a12c47dc31f7f52af804494c --- vmware_nsx/plugins/nsx_v3/plugin.py | 2 ++ .../tests/unit/nsx_v3/test_dhcp_metadata.py | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index b6ab918bbc..0b6cbe2c2a 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -2153,6 +2153,8 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, # Always add option121. net_az = self.get_network_az_by_net_id(context, net_id) options = {'option121': {'static_routes': [ + {'network': '%s' % net_az.native_metadata_route, + 'next_hop': '0.0.0.0'}, {'network': '%s' % net_az.native_metadata_route, 'next_hop': ip}]}} if subnet: diff --git a/vmware_nsx/tests/unit/nsx_v3/test_dhcp_metadata.py b/vmware_nsx/tests/unit/nsx_v3/test_dhcp_metadata.py index 3f91c8f0ec..d4e2edf103 100644 --- a/vmware_nsx/tests/unit/nsx_v3/test_dhcp_metadata.py +++ b/vmware_nsx/tests/unit/nsx_v3/test_dhcp_metadata.py @@ -402,6 +402,9 @@ class NsxNativeDhcpTestCase(test_plugin.NsxV3PluginTestCaseMixin): ip = port['port']['fixed_ips'][0]['ip_address'] hostname = 'host-%s' % ip.replace('.', '-') options = {'option121': {'static_routes': [ + {'network': '%s' % + cfg.CONF.nsx_v3.native_metadata_route, + 'next_hop': '0.0.0.0'}, {'network': '%s' % cfg.CONF.nsx_v3.native_metadata_route, 'next_hop': ip}, @@ -441,6 +444,9 @@ class NsxNativeDhcpTestCase(test_plugin.NsxV3PluginTestCaseMixin): ip = port['port']['fixed_ips'][0]['ip_address'] hostname = 'host-%s' % ip.replace('.', '-') options = {'option121': {'static_routes': [ + {'network': '%s' % + cfg.CONF.nsx_v3.native_metadata_route, + 'next_hop': '0.0.0.0'}, {'network': '%s' % cfg.CONF.nsx_v3.native_metadata_route, 'next_hop': ip}, @@ -478,6 +484,9 @@ class NsxNativeDhcpTestCase(test_plugin.NsxV3PluginTestCaseMixin): ip = port['port']['fixed_ips'][0]['ip_address'] hostname = 'host-%s' % ip.replace('.', '-') options = {'option121': {'static_routes': [ + {'network': '%s' % + cfg.CONF.nsx_v3.native_metadata_route, + 'next_hop': '0.0.0.0'}, {'network': '%s' % cfg.CONF.nsx_v3.native_metadata_route, 'next_hop': ip}, @@ -610,6 +619,9 @@ class NsxNativeDhcpTestCase(test_plugin.NsxV3PluginTestCaseMixin): assert_data = {'host_name': 'host-%s' % new_ip.replace('.', '-'), 'ip_address': new_ip, 'options': {'option121': {'static_routes': [ + {'network': '%s' % + cfg.CONF.nsx_v3.native_metadata_route, + 'next_hop': '0.0.0.0'}, {'network': '%s' % cfg.CONF.nsx_v3.native_metadata_route, 'next_hop': new_ip}, @@ -629,6 +641,9 @@ class NsxNativeDhcpTestCase(test_plugin.NsxV3PluginTestCaseMixin): update_data = {'port': {'mac_address': new_mac}} assert_data = {'mac_address': new_mac, 'options': {'option121': {'static_routes': [ + {'network': '%s' % + cfg.CONF.nsx_v3.native_metadata_route, + 'next_hop': '0.0.0.0'}, {'network': '%s' % cfg.CONF.nsx_v3.native_metadata_route, 'next_hop': mock.ANY}, @@ -654,6 +669,9 @@ class NsxNativeDhcpTestCase(test_plugin.NsxV3PluginTestCaseMixin): 'mac_address': new_mac, 'ip_address': new_ip, 'options': {'option121': {'static_routes': [ + {'network': '%s' % + cfg.CONF.nsx_v3.native_metadata_route, + 'next_hop': '0.0.0.0'}, {'network': '%s' % cfg.CONF.nsx_v3.native_metadata_route, 'next_hop': new_ip}, @@ -682,6 +700,9 @@ class NsxNativeDhcpTestCase(test_plugin.NsxV3PluginTestCaseMixin): assert_data = {'mac_address': mac_address, 'ip_address': ip_addr, 'options': {'option121': {'static_routes': [ + {'network': '%s' % + cfg.CONF.nsx_v3.native_metadata_route, + 'next_hop': '0.0.0.0'}, {'network': '%s' % cfg.CONF.nsx_v3.native_metadata_route, 'next_hop': ip_addr}, @@ -711,6 +732,9 @@ class NsxNativeDhcpTestCase(test_plugin.NsxV3PluginTestCaseMixin): assert_data = {'mac_address': mac_address, 'ip_address': ip_addr, 'options': {'option121': {'static_routes': [ + {'network': '%s' % + cfg.CONF.nsx_v3.native_metadata_route, + 'next_hop': '0.0.0.0'}, {'network': '%s' % cfg.CONF.nsx_v3.native_metadata_route, 'next_hop': ip_addr}, @@ -743,6 +767,9 @@ class NsxNativeDhcpTestCase(test_plugin.NsxV3PluginTestCaseMixin): assert_data = {'mac_address': mac_address, 'ip_address': ip_addr, 'options': {'option121': {'static_routes': [ + {'network': '%s' % + cfg.CONF.nsx_v3.native_metadata_route, + 'next_hop': '0.0.0.0'}, {'network': '%s' % cfg.CONF.nsx_v3.native_metadata_route, 'next_hop': ip_addr}, @@ -851,6 +878,9 @@ class NsxNativeDhcpTestCase(test_plugin.NsxV3PluginTestCaseMixin): ip = port['port']['fixed_ips'][0]['ip_address'] hostname = 'host-%s' % ip.replace('.', '-') options = {'option121': {'static_routes': [ + {'network': '%s' % + self.az_metadata_route, + 'next_hop': '0.0.0.0'}, {'network': '%s' % self.az_metadata_route, 'next_hop': ip},