Change in vdsm[master]: network: Force blocking DHCP when restoring networks

ibarkan at redhat.com ibarkan at redhat.com
Tue Mar 31 07:55:21 UTC 2015


Ido Barkan has uploaded a new change for review.

Change subject: network: Force blocking DHCP when restoring networks
......................................................................

network: Force blocking DHCP when restoring networks

This is done right before restoring the network configuration, and
before calling setupNetworks. It forces the configurator to wait for
an IP address to be configured on the devices before restoration is
completed. This prevents VDSM from possibly report missing IP
addresses on interfaces that had been restored right before it was
started.

Change-Id: Ibc8b84a82794ac97eba6d34ec9d54430e387b659
Signed-off-by: Ido Barkan <ibarkan at redhat.com>
---
M tests/functional/networkTests.py
M vdsm/vdsm-restore-net-config
2 files changed, 54 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/81/39381/1

diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py
index 8671244..3a6772a 100644
--- a/tests/functional/networkTests.py
+++ b/tests/functional/networkTests.py
@@ -1480,6 +1480,42 @@
             self.vdsm_net.save_config()
 
     @cleanupNet
+    @RequireVethMod
+    @ValidateRunningAsRoot
+    def testRestoreToBlockingDHCP(self):
+        def _get_blocking_dhcp(net_name):
+            self.vdsm_net.refreshNetinfo()
+            return self.vdsm_net.config.networks[net_name].get('blockingdhcp')
+
+        with vethIf() as (server, client):
+            veth.setIP(server, IP_ADDRESS, IP_CIDR)
+            veth.setLinkUp(server)
+            dhcp_async_net = {'nic': client, 'bridged': False,
+                              'bootproto': 'dhcp', 'blockingdhcp': False}
+            status, msg = self.vdsm_net.setupNetworks(
+                {NETWORK_NAME: dhcp_async_net}, {}, NOCHK)
+            self.assertEquals(status, SUCCESS, msg)
+
+            self.assertNetworkExists(NETWORK_NAME)
+            self.assertFalse(_get_blocking_dhcp(NETWORK_NAME))
+
+            self.vdsm_net.save_config()
+
+            with dnsmasqDhcp(server, _system_is_el6()):
+                with namedTemporaryDir(dir='/var/lib/dhclient') as dhdir:
+                    dhclient_runner = dhcp.DhclientRunner(client, 4, dhdir,
+                                                          'default')
+                    with running(dhclient_runner):
+                        self.vdsm_net.restoreNetConfig()
+                        self.assertTrue(_get_blocking_dhcp(NETWORK_NAME))
+
+            # cleanup
+            status, msg = self.vdsm_net.setupNetworks(
+                {NETWORK_NAME: {'remove': True}}, {}, NOCHK)
+            self.assertEquals(status, SUCCESS, msg)
+
+
+    @cleanupNet
     @permutations([[True], [False]])
     def testVolatileConfig(self, bridged):
         """
diff --git a/vdsm/vdsm-restore-net-config b/vdsm/vdsm-restore-net-config
index c88f2bb..21d6592 100755
--- a/vdsm/vdsm-restore-net-config
+++ b/vdsm/vdsm-restore-net-config
@@ -76,12 +76,28 @@
     persistentConfig = PersistentConfig()
     nets, bonds = _filter_nets_bonds(persistentConfig.networks,
                                      persistentConfig.bonds)
-    logging.debug('Calling setupNetworks with networks (%s) and bond (%s).',
-                  nets, bonds)
     if nets or bonds:
+        _convert_to_blocking_dhcp(nets)
+        logging.debug('Calling setupNetworks with networks (%s) '
+                      'and bond (%s).', nets, bonds)
         setupNetworks(nets, bonds, connectivityCheck=False, _inRollback=True)
 
 
+def _convert_to_blocking_dhcp(networks):
+    """
+    This function changes DHCP configuration, if present, to be blocking.
+
+    This is done right before restoring the network configuration, and forces
+    the configurator to wait for an IP address to be configured on the devices
+    before restoration is completed. This prevents VDSM to possibly report
+    missing IP address on interfaces that had been restored right before it was
+    started.
+    """
+    for net, net_attr in networks.iteritems():
+        if net_attr.get('bootproto') == 'dhcp':
+            net_attr['blockingdhcp'] = True
+
+
 def _filter_nets_bonds(nets, bonds):
     """Returns only nets and bonds that can be configured with the devices
     present in the system"""


-- 
To view, visit https://gerrit.ovirt.org/39381
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibc8b84a82794ac97eba6d34ec9d54430e387b659
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ido Barkan <ibarkan at redhat.com>


More information about the vdsm-patches mailing list