Add "master" parameter to ip.set() API function

This parameter is present in the IpCommand abstract class and both
Windows and Linux implementations.

This change modifies the pyroute2 driver to lookup the
interface index of the bridge when setting the master paramater
on a port.

This change add a functional test to use the master paramater
to add an interface to a bridge and validate it works correctly.

Change-Id: I54ded32281c6a5b67b6ccb9f1bdb6e3fb6731049
Closes-Bug: #1817919
This commit is contained in:
Rodolfo Alonso Hernandez 2019-02-27 15:12:04 +00:00 committed by Sean Mooney
parent 1546d349b1
commit 638861c37c
3 changed files with 17 additions and 3 deletions

View File

@ -14,10 +14,10 @@ from os_vif.internal.command.ip import api
def set(device, check_exit_code=None, state=None, mtu=None, address=None,
promisc=None):
promisc=None, master=None):
"""Method to set a parameter in an interface."""
return api.ip.set(device, check_exit_code=check_exit_code, state=state,
mtu=mtu, address=address, promisc=promisc)
mtu=mtu, address=address, promisc=promisc, master=master)
def add(device, dev_type, check_exit_code=None, peer=None, link=None,

View File

@ -59,7 +59,7 @@ class PyRoute2(ip_command.IpCommand):
if promisc is True else
utils.unset_mask(flags, ifinfmsg.IFF_PROMISC))
if master:
args['master'] = master
args['master'] = ip.link_lookup(ifname=master)
if isinstance(check_exit_code, int):
check_exit_code = [check_exit_code]

View File

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
import re
from oslo_concurrency import processutils
@ -220,3 +221,16 @@ class TestIpCommand(ShellIpCommands, base.BaseFunctionalTestCase):
self.assertEqual("0", f.readline().rstrip('\n'))
with open(base_path % "multicast_snooping", "r") as f:
self.assertEqual("0", f.readline().rstrip('\n'))
def test_add_port_to_bridge(self):
device = "test_dev_12"
bridge = "test_dev_13"
self.addCleanup(self.del_device, device)
self.addCleanup(self.del_device, bridge)
self.add_device(device, 'dummy')
_ip_cmd_add(bridge, 'bridge')
self.assertTrue(self.exist_device(device))
self.assertTrue(self.exist_device(bridge))
_ip_cmd_set(device, master=bridge)
path = "/sys/class/net/{}/brif/{}".format(bridge, device)
self.assertTrue(os.path.exists(path))