Skip to content

Commit

Permalink
[OVS] VLAN tag should be set in the Port register
Browse files Browse the repository at this point in the history
In OVS, the VLAN tag for a device is set in the Port register,
not the Interface [1][2]. Method "BaseOVS.create_ovs_vif_port"
should implement it.

[1] http://docs.openvswitch.org/en/latest/faq/configuration/
[2] https://github.com/openstack/neutron/blob/1d354f75776fca6bf12beae70f7e3206459c84c4/neutron/agent/common/ovs_lib.py#L346-L347

Change-Id: Iaebd42af6d5b8e3165cf10e269addae0ff3665fb
Closes-Bug: #1860329
  • Loading branch information
ralonsoh authored and SeanMooney committed Jan 30, 2020
1 parent bb5e513 commit d5b61d1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions vif_plug_ovs/ovsdb/ovsdb_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ def create_ovs_vif_port(self, bridge, dev, iface_id, mac, instance_id,
if vhost_server_path:
col_values.append(('options',
{'vhost-server-path': vhost_server_path}))
if tag:
col_values.append(('tag', tag))
if (interface_type == constants.OVS_DPDK_INTERFACE_TYPE and
pf_pci and vf_num):
devargs_string = "{PF_PCI},representor=[{VF_NUM}]".format(
Expand All @@ -103,6 +101,8 @@ def create_ovs_vif_port(self, bridge, dev, iface_id, mac, instance_id,
{'dpdk-devargs': devargs_string}))
with self.ovsdb.transaction() as txn:
txn.add(self.ovsdb.add_port(bridge, dev))
if tag:
txn.add(self.ovsdb.db_set('Port', dev, ('tag', tag)))
txn.add(self.ovsdb.db_set('Interface', dev, *col_values))
self.update_device_mtu(dev, mtu, interface_type=interface_type)

Expand Down
22 changes: 14 additions & 8 deletions vif_plug_ovs/tests/functional/ovsdb/test_ovsdb_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def setUp(self):
impl_idl.OvsVsctlTransaction, 'post_commit',
side_effect=impl_idl.OvsVsctlTransaction.do_post_commit).start()

def _check_interface(self, port, parameter, expected_value):
def _check_parameter(self, table, port, parameter, expected_value):
def check_value():
return (self._ovsdb.db_get(
'Interface', port, parameter).execute() == expected_value)
table, port, parameter).execute() == expected_value)

self.assertTrue(base.wait_until_true(check_value, timeout=2,
sleep=0.5))
Expand Down Expand Up @@ -97,9 +97,9 @@ def test__set_mtu_request(self):
self._add_port(self.brname, port_name)
if self.ovs._ovs_supports_mtu_requests():
self.ovs._set_mtu_request(port_name, 1000)
self._check_interface(port_name, 'mtu', 1000)
self._check_parameter('Interface', port_name, 'mtu', 1000)
self.ovs._set_mtu_request(port_name, 1500)
self._check_interface(port_name, 'mtu', 1500)
self._check_parameter('Interface', port_name, 'mtu', 1500)
else:
self.skipTest('Current version of Open vSwitch does not support '
'"mtu_request" parameter')
Expand All @@ -118,16 +118,22 @@ def test_create_ovs_vif_port(self):
self.ovs.create_ovs_vif_port(self.brname, port_name, iface_id, mac,
instance_id, mtu=mtu,
interface_type=interface_type,
vhost_server_path=vhost_server_path)
vhost_server_path=vhost_server_path,
tag=2000)

expected_external_ids = {'iface-status': 'active',
'iface-id': iface_id,
'attached-mac': mac,
'vm-uuid': instance_id}
self._check_interface(port_name, 'external_ids', expected_external_ids)
self._check_interface(port_name, 'type', interface_type)
self._check_parameter('Interface', port_name, 'external_ids',
expected_external_ids)
self._check_parameter('Interface', port_name, 'type', interface_type)
expected_vhost_server_path = {'vhost-server-path': vhost_server_path}
self._check_interface(port_name, 'options', expected_vhost_server_path)
self._check_parameter('Interface', port_name, 'options',
expected_vhost_server_path)
self._check_parameter('Interface', port_name, 'options',
expected_vhost_server_path)
self._check_parameter('Port', port_name, 'tag', 2000)

@mock.patch.object(linux_net, 'delete_net_dev')
def test_delete_ovs_vif_port(self, *mock):
Expand Down
6 changes: 4 additions & 2 deletions vif_plug_ovs/tests/unit/ovsdb/test_ovsdb_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ def test_create_ovs_vif_port(self):
self.br.create_ovs_vif_port(bridge, device, iface_id, mac,
instance_id, mtu=mtu,
interface_type=interface_type,
vhost_server_path=vhost_server_path)
vhost_server_path=vhost_server_path,
tag=4000)
self.mock_add_port.assert_has_calls([mock.call(bridge, device)])
self.mock_db_set.assert_has_calls(
[mock.call('Interface', device, *values)])
[mock.call('Port', device, ('tag', 4000)),
mock.call('Interface', device, *values)])
mock_update_device_mtu.assert_has_calls(
[mock.call(device, mtu, interface_type=interface_type)])

Expand Down

0 comments on commit d5b61d1

Please sign in to comment.