Change in vdsm[ovirt-3.6]: hooks: ovs: set OVS devices UP

phoracek at redhat.com phoracek at redhat.com
Sat Apr 9 17:24:16 UTC 2016


Hello Ido Barkan, Dan Kenigsberg,

I'd like you to do a code review.  Please visit

    https://gerrit.ovirt.org/55897

to review the following change.

Change subject: hooks: ovs: set OVS devices UP
......................................................................

hooks: ovs: set OVS devices UP

Set all attached and created devices explicitly UP.

We need to do a minor change in tests: when we set OVS bond up,
it turns into UNKNOWN state, not UP state. Because of that we have
to return fake True from networkTests._waitForKnownOperstate.

Change-Id: Ia8af77c136a8f27d980f94647f78570b3da1e611
Signed-off-by: Petr Horáček <phoracek at redhat.com>
Reviewed-on: https://gerrit.ovirt.org/48388
Continuous-Integration: Jenkins CI
Reviewed-by: Ido Barkan <ibarkan at redhat.com>
Reviewed-by: Dan Kenigsberg <danken at redhat.com>
---
M tests/functional/networkTestsOVS.py
M vdsm_hooks/ovs/ovs_before_network_setup.py
M vdsm_hooks/ovs/ovs_utils.py
3 files changed, 43 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/97/55897/1

diff --git a/tests/functional/networkTestsOVS.py b/tests/functional/networkTestsOVS.py
index b26105d..e29b60f 100644
--- a/tests/functional/networkTestsOVS.py
+++ b/tests/functional/networkTestsOVS.py
@@ -25,6 +25,7 @@
 from testlib import expandPermutations, permutations
 from testValidation import RequireVethMod
 
+import networkTests
 from networkTests import (setupModule, tearDownModule, NetworkTest, dummyIf,
                           _get_source_route, dnsmasqDhcp, NETWORK_NAME,
                           IP_ADDRESS, IP_MASK, IP_CIDR, IP_GATEWAY,
@@ -32,6 +33,9 @@
 from utils import VdsProxy
 import veth
 import dhcp
+
+# WARNING: because of this module changes networkTests module, we cannot run
+# networkTests.py and networkTestsOVS.py in one run
 
 # Make Pyflakes happy
 setupModule
@@ -150,6 +154,12 @@
     delattr(NetworkTest, t)
 
 
+# When we set OVS bond device up, it does not turn UP, but only UNKNOWN
+def _fakeWaitForKnownOperstate(*args, **kwargs):
+    pass
+networkTests._waitForKnownOperstate = _fakeWaitForKnownOperstate
+
+
 class OVSVdsProxy(VdsProxy):
 
     def setupNetworks(self, networks, bonds, options):
diff --git a/vdsm_hooks/ovs/ovs_before_network_setup.py b/vdsm_hooks/ovs/ovs_before_network_setup.py
index fa8cfb5..f0e2a35 100755
--- a/vdsm_hooks/ovs/ovs_before_network_setup.py
+++ b/vdsm_hooks/ovs/ovs_before_network_setup.py
@@ -32,14 +32,15 @@
 from libvirt import libvirtError
 import six
 
+from vdsm.ipwrapper import linkSet
 from vdsm.netconfpersistence import RunningConfig
 
 from hooking import execCmd
 import hooking
 
 from ovs_utils import (is_ovs_network, is_ovs_bond, iter_ovs_nets, suppress,
-                       destroy_ovs_bridge, EXT_IP, EXT_OVS_VSCTL,
-                       INIT_CONFIG_FILE)
+                       destroy_ovs_bridge, ovs_bridge_exists, EXT_IP,
+                       EXT_OVS_VSCTL, BRIDGE_NAME, INIT_CONFIG_FILE)
 from ovs_setup_ovs import configure_ovs, prepare_ovs
 from ovs_setup_ip import configure_ip
 from ovs_setup_mtu import configure_mtu
@@ -136,6 +137,24 @@
                    running_config, save_init_config=False)
 
 
+def _set_devices_up(nets, bonds):
+    devices = set()
+    for net, attrs in six.iteritems(nets):
+        if 'remove' not in attrs:
+            if 'vlan' in attrs:
+                devices.add(net)
+            if 'nic' in attrs or 'bond' in attrs:
+                devices.add(attrs.get('nic') or attrs.get('bond'))
+    for bond, attrs in six.iteritems(bonds):
+        if 'remove' not in attrs:
+            devices.add(bond)
+            devices.update(attrs['nics'])
+    if ovs_bridge_exists(BRIDGE_NAME):
+        devices.add(BRIDGE_NAME)
+    for device in devices:
+        linkSet(device, ['up'])
+
+
 def _configure(nets, bonds, running_config, save_init_config=True):
     initial_config = deepcopy(running_config)
 
@@ -151,6 +170,7 @@
     configure_ovs(commands, running_config)
     configure_mtu(running_config)
     configure_ip(nets, initial_config.networks)
+    _set_devices_up(nets, bonds)
 
     log('Saving running configuration: %s %s' % (running_config.networks,
                                                  running_config.bonds))
diff --git a/vdsm_hooks/ovs/ovs_utils.py b/vdsm_hooks/ovs/ovs_utils.py
index 5390a82..5b91a3f 100644
--- a/vdsm_hooks/ovs/ovs_utils.py
+++ b/vdsm_hooks/ovs/ovs_utils.py
@@ -122,3 +122,14 @@
 
 def log(message, tag='OVS: '):
     hooking.log('%s%s' % (tag, message))
+
+
+def ovs_bridge_exists(bridge):
+    commands = [EXT_OVS_VSCTL, 'br-exists', bridge]
+    rc, _, err = execCmd(commands)
+    if rc == 0:
+        return True
+    elif rc == 2:
+        return False
+    else:
+        raise Exception('\n'.join(err))


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia8af77c136a8f27d980f94647f78570b3da1e611
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.6
Gerrit-Owner: Petr Horáček <phoracek at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Ido Barkan <ibarkan at redhat.com>


More information about the vdsm-patches mailing list