Edward Haas has uploaded a new change for review.

Change subject: net: Adding the 'link' package with an iface module
......................................................................

net: Adding the 'link' package with an iface module

The link package is to be used for all iface, bond and other related actions.
Its main purpose is to provide an api to access these devices and their
attributes.

The plan is to add drivers for the underlying devices access.

This patch adds the first link module: iface, which present an api to
iface related actions (link up, link down, etc)

Change-Id: Icb723b8d893575ef14e71cacb6b6e391a6a84831
Signed-off-by: Edward Haas <edwa...@redhat.com>
---
M configure.ac
M lib/vdsm/network/Makefile.am
A lib/vdsm/network/link/Makefile.am
A lib/vdsm/network/link/__init__.py
A lib/vdsm/network/link/iface.py
M lib/vdsm/network/netswitch.py
A tests/network/link_iface_test.py
M vdsm.spec.in
8 files changed, 158 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/27/62827/1

diff --git a/configure.ac b/configure.ac
index 02770fa..5756499 100644
--- a/configure.ac
+++ b/configure.ac
@@ -397,6 +397,7 @@
        lib/vdsm/network/Makefile
        lib/vdsm/network/configurators/Makefile
        lib/vdsm/network/ip/Makefile
+       lib/vdsm/network/link/Makefile
        lib/vdsm/network/netinfo/Makefile
        lib/vdsm/network/netlink/Makefile
        lib/vdsm/network/ovs/Makefile
diff --git a/lib/vdsm/network/Makefile.am b/lib/vdsm/network/Makefile.am
index 403ffd2..0fc9d85 100644
--- a/lib/vdsm/network/Makefile.am
+++ b/lib/vdsm/network/Makefile.am
@@ -17,7 +17,7 @@
 # Refer to the README and COPYING files for full details of the license
 #
 
-SUBDIRS = configurators ip netinfo netlink ovs tc
+SUBDIRS = configurators ip link netinfo netlink ovs tc
 
 include $(top_srcdir)/build-aux/Makefile.subs
 
diff --git a/lib/vdsm/network/link/Makefile.am 
b/lib/vdsm/network/link/Makefile.am
new file mode 100644
index 0000000..64823ac
--- /dev/null
+++ b/lib/vdsm/network/link/Makefile.am
@@ -0,0 +1,22 @@
+# Copyright 2016 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+include $(top_srcdir)/build-aux/Makefile.subs
+
+vdsmnetworklinkdir = $(vdsmpylibdir)/network/link
+dist_vdsmnetworklink_PYTHON = *.py
diff --git a/lib/vdsm/network/link/__init__.py 
b/lib/vdsm/network/link/__init__.py
new file mode 100644
index 0000000..4a67f47
--- /dev/null
+++ b/lib/vdsm/network/link/__init__.py
@@ -0,0 +1,19 @@
+# Copyright 2016 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+from __future__ import absolute_import
diff --git a/lib/vdsm/network/link/iface.py b/lib/vdsm/network/link/iface.py
new file mode 100644
index 0000000..ee49cfe
--- /dev/null
+++ b/lib/vdsm/network/link/iface.py
@@ -0,0 +1,64 @@
+# Copyright 2016 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+from __future__ import absolute_import
+
+from contextlib import contextmanager
+
+from vdsm.network import ipwrapper
+from vdsm.network.netlink import link
+from vdsm.network.netlink.monitor import Monitor
+
+
+IFF_RUNNING = 1 << 6
+IFF_PROMISC = 1 << 8
+
+STATE_UP = 'up'
+STATE_DOWN = 'down'
+
+
+def up(dev):
+    _up_blocking(dev)
+
+
+def down(dev):
+    ipwrapper.linkSet(dev, ['down'])
+
+
+def is_up(dev):
+    return bool(link.get_link(dev)['flags'] & IFF_RUNNING)
+
+
+def is_promisc(dev):
+    return bool(link.get_link(dev)['flags'] & IFF_PROMISC)
+
+
+@contextmanager
+def _up_blocking(dev):
+    with Monitor(groups=('link',), timeout=2) as mon:
+        ipwrapper.linkSet(dev, [STATE_UP])
+        if is_up(dev):
+            return
+        mon_device = (e for e in mon if e.get('name') == dev)
+        for event in mon_device:
+            if event.get('state') == STATE_UP:
+                return
+            # With some devices (seen on dummy), the state event arrives
+            # as 'unknown', therefore we are forced to check again explicitly.
+            if is_up(dev):
+                return
diff --git a/lib/vdsm/network/netswitch.py b/lib/vdsm/network/netswitch.py
index 6df8ed8..0d23354 100644
--- a/lib/vdsm/network/netswitch.py
+++ b/lib/vdsm/network/netswitch.py
@@ -22,10 +22,10 @@
 
 import six
 
-from vdsm.network import ipwrapper
 from vdsm.network.ip import address
 from vdsm.network.ip import dhclient
 from vdsm.network.libvirt import networks as libvirt_nets
+from vdsm.network.link import iface
 from vdsm.network.netinfo.cache import (libvirtNets2vdsm, get as netinfo_get,
                                         CachingNetInfo)
 from vdsm.tool.service import service_status
@@ -239,8 +239,7 @@
 def _set_ovs_links_up(nets2add, bonds2add, bonds2edit):
     # TODO: Make this universal for legacy and ovs.
     for dev in _gather_ovs_ifaces(nets2add, bonds2add, bonds2edit):
-        # TODO: Create a link package/module and use link.up(dev).
-        ipwrapper.linkSet(dev, ['up'])
+        iface.up(dev)
 
 
 def _gather_ovs_ifaces(nets2add, bonds2add, bonds2edit):
diff --git a/tests/network/link_iface_test.py b/tests/network/link_iface_test.py
new file mode 100644
index 0000000..c359b7a
--- /dev/null
+++ b/tests/network/link_iface_test.py
@@ -0,0 +1,47 @@
+# Copyright 2016 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+from __future__ import absolute_import
+
+from nose.plugins.attrib import attr
+
+from testlib import VdsmTestCase as TestCaseBase
+
+from .nettestlib import dummy_device
+
+from vdsm.network.link import iface
+
+
+@attr(type='integration')
+class LinkIfaceTests(TestCaseBase):
+
+    def test_iface_up(self):
+        with dummy_device() as nic:
+            iface.up(nic)
+            self.assertTrue(iface.is_up(nic))
+
+    def test_iface_down(self):
+        with dummy_device() as nic:
+            iface.up(nic)
+            iface.down(nic)
+            self.assertFalse(iface.is_up(nic))
+
+    def test_iface_notpromisc(self):
+        with dummy_device() as nic:
+            iface.up(nic)
+            self.assertFalse(iface.is_promisc(nic))
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 6bc2b26..feb071e 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -1127,6 +1127,7 @@
 %dir %{python_sitelib}/%{vdsm_name}/network
 %dir %{python_sitelib}/%{vdsm_name}/network/configurators
 %dir %{python_sitelib}/%{vdsm_name}/network/ip
+%dir %{python_sitelib}/%{vdsm_name}/network/link
 %dir %{python_sitelib}/%{vdsm_name}/network/netinfo
 %dir %{python_sitelib}/%{vdsm_name}/network/netlink
 %dir %{python_sitelib}/%{vdsm_name}/network/ovs
@@ -1185,6 +1186,7 @@
 %{python_sitelib}/%{vdsm_name}/network/ip/*.py*
 %{python_sitelib}/%{vdsm_name}/network/ifacquire.py*
 %{python_sitelib}/%{vdsm_name}/network/ipwrapper.py*
+%{python_sitelib}/%{vdsm_name}/network/link/*.py*
 %{python_sitelib}/%{vdsm_name}/network/kernelconfig.py*
 %{python_sitelib}/%{vdsm_name}/network/legacy_switch.py*
 %{python_sitelib}/%{vdsm_name}/network/libvirt.py*


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icb723b8d893575ef14e71cacb6b6e391a6a84831
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Edward Haas <edwa...@redhat.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org

Reply via email to