Change in vdsm[master]: network: bridge inherits DHCP client identifier from its DHC...
osvoboda at redhat.com
osvoboda at redhat.com
Thu Aug 6 22:50:26 UTC 2015
Ondřej Svoboda has uploaded a new change for review.
Change subject: network: bridge inherits DHCP client identifier from its DHCP-enabled port
......................................................................
network: bridge inherits DHCP client identifier from its DHCP-enabled port
Change-Id: If91b46657be8a5a42a118b23155d059df379727e
Bug-Url: https://bugzilla.redhat.com/??????
Signed-off-by: Ondřej Svoboda <osvoboda at redhat.com>
---
M tests/functional/networkTests.py
M vdsm/network/api.py
M vdsm/network/configurators/ifcfg.py
M vdsm/network/models.py
4 files changed, 70 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/39/44539/1
diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py
index e811955..39d8dab 100644
--- a/tests/functional/networkTests.py
+++ b/tests/functional/networkTests.py
@@ -2108,6 +2108,58 @@
@cleanupNet
@RequireVethMod
+ def testDhcpReplaceNicWithBridge(self):
+ with veth.pair() as (left, right):
+ veth.setIP(left, IP_ADDRESS, IP_CIDR)
+ veth.setIP(left, IPv6_ADDRESS, IPv6_CIDR, 6)
+ veth.setLinkUp(left)
+ with dnsmasqDhcp(left):
+
+ # first, a network without a bridge should get a certain
+ # address
+
+ network = {NETWORK_NAME: {'nic': right, 'bridged': False,
+ 'bootproto': 'dhcp',
+ 'blockingdhcp': True}}
+ try:
+ status, msg = self.setupNetworks(network, {}, NOCHK)
+ self.assertEqual(status, SUCCESS, msg)
+ self.assertNetworkExists(NETWORK_NAME)
+
+ test_net = self.vdsm_net.netinfo.networks[NETWORK_NAME]
+ self.assertEqual(test_net['dhcpv4'], True)
+ devs = self.vdsm_net.netinfo.nics
+ device_name = right
+
+ self.assertIn(device_name, devs)
+ net_attrs = devs[device_name]
+ self.assertEqual(net_attrs['dhcpv4'], True)
+
+ self.assertEqual(test_net['gateway'], IP_GATEWAY)
+ ip_addr = test_net['addr']
+ self.assertSourceRoutingConfiguration(device_name, ip_addr)
+
+ # now, a bridged network should get the same address
+ # (because dhclient should send the same dhcp-client-
+ # identifier)
+
+ network[NETWORK_NAME]['bridged'] = True
+ status, msg = self.setupNetworks(network, {}, NOCHK)
+ self.assertEqual(status, SUCCESS, msg)
+ test_net = self.vdsm_net.netinfo.networks[NETWORK_NAME]
+ self.assertEqual(ip_addr, test_net['addr'])
+
+ network = {NETWORK_NAME: {'remove': True}}
+ status, msg = self.setupNetworks(network, {}, NOCHK)
+ self.assertEqual(status, SUCCESS, msg)
+ self.assertNetworkDoesntExist(NETWORK_NAME)
+
+ finally:
+ dhcp.delete_dhclient_leases(right, True, False)
+ dhcp.delete_dhclient_leases(NETWORK_NAME, True, False)
+
+ @cleanupNet
+ @RequireVethMod
def testSetupNetworksReconfigureBridge(self):
def setup_test_network(dhcp=True):
network_params = {'nic': right, 'bridged': True}
diff --git a/vdsm/network/api.py b/vdsm/network/api.py
index 5c8bed5..42e4245 100755
--- a/vdsm/network/api.py
+++ b/vdsm/network/api.py
@@ -317,6 +317,9 @@
else:
net_ent_to_configure = net_ent
+ if bridged and net_ent.port and bootproto == 'dhcp':
+ _inherit_dhcp_client_identifier(net_ent, _netinfo)
+
if net_ent_to_configure is not None:
logging.info("Configuring device %s", net_ent_to_configure)
net_ent_to_configure.configure(**options)
@@ -600,6 +603,17 @@
"Unknown nics in: %r" % list(nics))
+def _inherit_dhcp_client_identifier(bridge, _netinfo):
+ """
+ If there is dhclient already running on a bridge's port we have to use the
+ same dhcp_client_identifier in order to get the same IP address.
+ """
+ for devices in (_netinfo.nics, _netinfo.bondings, _netinfo.vlans):
+ port = devices.get(bridge.port.name)
+ if port and port['dhcpv4']:
+ bridge.inherit_dhcp_client_identifier = True
+
+
def _handleBondings(bondings, configurator, in_rollback):
""" Add/Edit/Remove bond interface """
logger = logging.getLogger("_handleBondings")
diff --git a/vdsm/network/configurators/ifcfg.py b/vdsm/network/configurators/ifcfg.py
index e1cb96d..7802031 100644
--- a/vdsm/network/configurators/ifcfg.py
+++ b/vdsm/network/configurators/ifcfg.py
@@ -551,6 +551,9 @@
if bridge.stp is not None:
conf += 'STP=%s\n' % ('on' if bridge.stp else 'off')
conf += 'ONBOOT=yes\n'
+ if bridge.inherit_dhcp_client_identifier:
+ conf += ('DHCLIENTARGS="-df /var/lib/dhclient/'
+ 'dhclient--%s.lease"\n' % bridge.port.name)
if 'custom' in opts and 'bridge_opts' in opts['custom']:
opts['bridging_opts'] = opts['custom']['bridge_opts']
diff --git a/vdsm/network/models.py b/vdsm/network/models.py
index 64cae6e..9ed1d0e 100644
--- a/vdsm/network/models.py
+++ b/vdsm/network/models.py
@@ -167,6 +167,7 @@
port.master = self
self.port = port
self.stp = stp
+ self.inherit_dhcp_client_identifier = False
super(Bridge, self).__init__(name, configurator, ipv4, ipv6,
blockingdhcp, mtu)
--
To view, visit https://gerrit.ovirt.org/44539
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If91b46657be8a5a42a118b23155d059df379727e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ondřej Svoboda <osvoboda at redhat.com>
More information about the vdsm-patches
mailing list