summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsaku Yamahata <isaku.yamahata@intel.com>2017-03-01 06:47:42 -0800
committerTim Rozet <trozet@redhat.com>2017-05-22 14:53:44 +0000
commit6746be5665489ab5816ef963b2d22aea24319ca8 (patch)
treec53f2ed379d824170b87228d24cac39924ed9dd2
parent4919f0005e9813392da60d4bab05df72aaf6cc76 (diff)
port binding: trim port_prefix + PORT_ID to 14 length
Since Linux network interface name is limited to 14 characters, port_prefix + $PORT_ID needs to be up to 14 length. Not len($PORT_ID) = 14, but len(port_prefix + $PORT_ID) = 14 Change-Id: I5617e1745bb1b622e54054ea6e3c70af4f9e329b Closes-bug: #1668162 (cherry picked from commit 59a0ffe5f059472acd8aacab8919e85944c0a96c) (cherry picked from commit a9b2ebc62a56f43e0f17373fdf3d416accb72c22)
Notes
Notes (review): Code-Review+2: Brian Haley <haleyb.dev@gmail.com> Code-Review+1: Isaku Yamahata <isaku.yamahata@gmail.com> Code-Review+2: Armando Migliaccio <armamig@gmail.com> Workflow+1: Armando Migliaccio <armamig@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Tue, 06 Jun 2017 21:23:24 +0000 Reviewed-on: https://review.openstack.org/466760 Project: openstack/networking-odl Branch: refs/heads/stable/newton
-rwxr-xr-xnetworking_odl/cmd/set_ovs_hostconfigs.py2
-rw-r--r--networking_odl/ml2/pseudo_agentdb_binding.py31
-rw-r--r--networking_odl/tests/unit/cmd/test_set_ovs_hostconfigs.py2
-rw-r--r--networking_odl/tests/unit/ml2/test_pseudo_agentdb_binding.py44
4 files changed, 65 insertions, 14 deletions
diff --git a/networking_odl/cmd/set_ovs_hostconfigs.py b/networking_odl/cmd/set_ovs_hostconfigs.py
index 1c11360..96e4b36 100755
--- a/networking_odl/cmd/set_ovs_hostconfigs.py
+++ b/networking_odl/cmd/set_ovs_hostconfigs.py
@@ -345,7 +345,7 @@ def _vif_details_from_conf(conf, uuid, vif_type):
345 "vhostuser_mode": conf.vhostuser_mode, 345 "vhostuser_mode": conf.vhostuser_mode,
346 "vhostuser_socket": os.path.join( 346 "vhostuser_socket": os.path.join(
347 conf.vhostuser_socket_dir, 347 conf.vhostuser_socket_dir,
348 conf.vhostuser_port_prefix + '$PORTID')} 348 conf.vhostuser_port_prefix + '$PORT_ID')}
349 349
350 350
351def setup_conf(args=None): 351def setup_conf(args=None):
diff --git a/networking_odl/ml2/pseudo_agentdb_binding.py b/networking_odl/ml2/pseudo_agentdb_binding.py
index 18695f4..e65d692 100644
--- a/networking_odl/ml2/pseudo_agentdb_binding.py
+++ b/networking_odl/ml2/pseudo_agentdb_binding.py
@@ -177,17 +177,26 @@ class PseudoAgentDBBindingController(port_binding.PortBindingController):
177 def _substitute_hconfig_tmpl(self, port_context, hconfig): 177 def _substitute_hconfig_tmpl(self, port_context, hconfig):
178 # TODO(mzmalick): Explore options for inlines string splicing of 178 # TODO(mzmalick): Explore options for inlines string splicing of
179 # port-id to 14 bytes as required by vhostuser types 179 # port-id to 14 bytes as required by vhostuser types
180 subs_ids = { 180 port_id = port_context.current['id']
181 # $IDENTIFER string substitution in hostconfigs JSON string 181 conf = hconfig.get('configurations')
182 'PORT_ID': port_context.current['id'][:14] 182 vnics = conf.get('supported_vnic_types')
183 } 183 if vnics is None:
184 184 return hconfig
185 # Substitute identifiers and Convert JSON string to dict 185 for vnic in vnics:
186 hconfig_conf_json = Template( 186 if vnic.get('vif_type') is portbindings.VIF_TYPE_VHOST_USER:
187 jsonutils.dumps(hconfig['configurations'])) 187 details = vnic.get('vif_details')
188 substituted_str = hconfig_conf_json.safe_substitute(subs_ids) 188 if details is None:
189 hconfig['configurations'] = jsonutils.loads(substituted_str) 189 continue
190 190 port_prefix = details.get('port_prefix')
191 port_prefix = port_prefix[:14]
192 subs_ids = {
193 # $IDENTIFER string substitution in hostconfigs JSON string
194 'PORT_ID': port_id[:(14 - len(port_prefix))],
195 }
196 # Substitute identifiers and Convert JSON string to dict
197 hconfig_conf_json = Template(jsonutils.dumps(details))
198 substituted_str = hconfig_conf_json.safe_substitute(subs_ids)
199 vnic['vif_details'] = jsonutils.loads(substituted_str)
191 return hconfig 200 return hconfig
192 201
193 def bind_port(self, port_context): 202 def bind_port(self, port_context):
diff --git a/networking_odl/tests/unit/cmd/test_set_ovs_hostconfigs.py b/networking_odl/tests/unit/cmd/test_set_ovs_hostconfigs.py
index 7ee9cd3..4828a27 100644
--- a/networking_odl/tests/unit/cmd/test_set_ovs_hostconfigs.py
+++ b/networking_odl/tests/unit/cmd/test_set_ovs_hostconfigs.py
@@ -179,7 +179,7 @@ class TestSetOvsHostconfigs(base.DietTestCase):
179 "vhostuser_socket_dir": conf.vhostuser_socket_dir, 179 "vhostuser_socket_dir": conf.vhostuser_socket_dir,
180 "vhostuser_socket": os.path.join( 180 "vhostuser_socket": os.path.join(
181 conf.vhostuser_socket_dir, 181 conf.vhostuser_socket_dir,
182 conf.vhostuser_port_prefix + "$PORTID"), 182 conf.vhostuser_port_prefix + "$PORT_ID"),
183 } 183 }
184 184
185 _, actual_json = execute.call_args[0][0][4].split("=", 1) 185 _, actual_json = execute.call_args[0][0][4].split("=", 1)
diff --git a/networking_odl/tests/unit/ml2/test_pseudo_agentdb_binding.py b/networking_odl/tests/unit/ml2/test_pseudo_agentdb_binding.py
index d2c2acc..250e478 100644
--- a/networking_odl/tests/unit/ml2/test_pseudo_agentdb_binding.py
+++ b/networking_odl/tests/unit/ml2/test_pseudo_agentdb_binding.py
@@ -164,6 +164,29 @@ class TestPseudoAgentDBBindingController(base.DietTestCase):
164 "allowed_network_types": ["local", "vlan", "vxlan", "gre"], 164 "allowed_network_types": ["local", "vlan", "vxlan", "gre"],
165 "bridge_mappings": {"physnet1": "br-ex"}}} 165 "bridge_mappings": {"physnet1": "br-ex"}}}
166 166
167 # Test data for length of string
168 sample_odl_hconfigs_length = {
169 "host": "devstack", # host-id in ODL JSON
170 "agent_type": "ODL L2", # host-type in ODL JSON
171 # config in ODL JSON
172 "configurations": {"supported_vnic_types": [
173 {"vnic_type": "normal", "vif_type": "vhostuser",
174 "vif_details": {
175 "uuid": "TEST_UUID",
176 "has_datapath_type_netdev": True,
177 "support_vhost_user": True,
178 "port_prefix": "longprefix_",
179 "vhostuser_socket_dir": "/tmp",
180 "vhostuser_ovs_plug": True,
181 "vhostuser_mode": "server",
182 "vhostuser_socket":
183 "/tmp/longprefix_$PORT_ID"
184 }}],
185 "allowed_network_types": [
186 "local", "vlan", "vxlan", "gre"],
187 "bridge_mappings": {"physnet1": "br-ex"}}
188 }
189
167 # test data valid and invalid segments 190 # test data valid and invalid segments
168 test_valid_segment = { 191 test_valid_segment = {
169 api.ID: 'API_ID', 192 api.ID: 'API_ID',
@@ -347,11 +370,30 @@ class TestPseudoAgentDBBindingController(base.DietTestCase):
347 370
348 self.assertEqual(expected_str, test_string) 371 self.assertEqual(expected_str, test_string)
349 372
373 def test_str_template_substitution_length_in_configuration_string(self):
374 """Test for identifier substitution in config JSON string."""
375 port_context = self._fake_port_context(
376 fake_segments=[self.test_invalid_segment, self.test_valid_segment])
377
378 hconf_dict = self.mgr._substitute_hconfig_tmpl(
379 port_context, self.sample_odl_hconfigs_length)
380
381 test_string = hconf_dict['configurations'][
382 'supported_vnic_types'][0][
383 'vif_details'][portbindings.VHOST_USER_SOCKET]
384
385 expected_str = Template('/tmp/longprefix_$PORT_ID')
386 expected_str = expected_str.safe_substitute({
387 'PORT_ID': port_context.current['id']})
388
389 self.assertNotEqual(expected_str, test_string)
390 self.assertEqual(len(test_string) - len('/tmp/'), 14)
391
350 def _fake_port_context(self, fake_segments, host_agents=None): 392 def _fake_port_context(self, fake_segments, host_agents=None):
351 network = mock.MagicMock(spec=api.NetworkContext) 393 network = mock.MagicMock(spec=api.NetworkContext)
352 return mock.MagicMock( 394 return mock.MagicMock(
353 spec=ctx.PortContext, 395 spec=ctx.PortContext,
354 current={'id': 'CONTEXT_ID', 396 current={'id': 'PORTID',
355 portbindings.VNIC_TYPE: portbindings.VNIC_NORMAL}, 397 portbindings.VNIC_TYPE: portbindings.VNIC_NORMAL},
356 segments_to_bind=fake_segments, network=network, 398 segments_to_bind=fake_segments, network=network,
357 host_agents=lambda agent_type: host_agents) 399 host_agents=lambda agent_type: host_agents)