[node-patches] Change in ovirt-node[master]: test: Add a unit test for bridgeless networking

fabiand at fedoraproject.org fabiand at fedoraproject.org
Thu Jun 13 13:05:47 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: test: Add a unit test for bridgeless networking
......................................................................

test: Add a unit test for bridgeless networking

And enhance some doctests.

Change-Id: I5ec5225713981201ae158f9810ccf915cdb2efa1
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M src/ovirt/node/config/defaults.py
M tests/nose/network_config.py
2 files changed, 104 insertions(+), 32 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/68/15668/1

diff --git a/src/ovirt/node/config/defaults.py b/src/ovirt/node/config/defaults.py
index 6039fef..c847bcc 100644
--- a/src/ovirt/node/config/defaults.py
+++ b/src/ovirt/node/config/defaults.py
@@ -205,11 +205,11 @@
 
     >>> from ovirt.node.utils import fs
     >>> n = Network(fs.FakeFs.File("dst"))
-    >>> n.update("eth0", "static", "10.0.0.1", "255.0.0.0", "10.0.0.255",
+    >>> n.update("eth0", None, "10.0.0.1", "255.0.0.0", "10.0.0.255",
     ...          "20")
     >>> data = sorted(n.retrieve().items())
     >>> data[:3]
-    [('bootproto', 'static'), ('gateway', '10.0.0.255'), ('iface', 'eth0')]
+    [('bootproto', None), ('gateway', '10.0.0.255'), ('iface', 'eth0')]
     >>> data[3:]
     [('ipaddr', '10.0.0.1'), ('netmask', '255.0.0.0'), ('vlanid', '20')]
 
@@ -230,12 +230,30 @@
     @NodeConfigFileSection.map_and_update_defaults_decorator
     def update(self, iface, bootproto, ipaddr=None, netmask=None, gateway=None,
                vlanid=None):
-        if bootproto not in ["static", "none", "dhcp", None]:
+        if bootproto not in ["dhcp", None]:
             raise exceptions.InvalidData("Unknown bootprotocol: %s" %
                                          bootproto)
         (valid.IPv4Address() | valid.Empty(or_none=True))(ipaddr)
         (valid.IPv4Address() | valid.Empty(or_none=True))(netmask)
         (valid.IPv4Address() | valid.Empty(or_none=True))(gateway)
+
+    def configure_no_networking(self, iface=None):
+        """Can be used to disable all networking
+        """
+        #iface = iface or self.retrieve()["iface"]
+        #name = iface + "-DISABLED"
+        # FIXME why should we use ifname-DISABLED here?
+        self.update(None, None, None, None, None, None)
+
+    def configure_dhcp(self, iface, vlanid=None):
+        """Can be used to configure NIC iface on the vlan vlanid with DHCP
+        """
+        self.update(iface, "dhcp", None, None, None, vlanid)
+
+    def configure_static(self, iface, ipaddr, netmask, gateway, vlanid):
+        """Can be used to configure a static IP on a NIC
+        """
+        self.update(iface, None, ipaddr, netmask, gateway, vlanid)
 
     def transaction(self):
         """Return all transactions to re-configure networking
@@ -401,24 +419,6 @@
         tx.append(StartNetworkServices())
         return tx
 
-    def configure_no_networking(self, iface=None):
-        """Can be used to disable all networking
-        """
-        #iface = iface or self.retrieve()["iface"]
-        #name = iface + "-DISABLED"
-        # FIXME why should we use ifname-DISABLED here?
-        self.update(None, None, None, None, None, None)
-
-    def configure_dhcp(self, iface, vlanid=None):
-        """Can be used to configure NIC iface on the vlan vlanid with DHCP
-        """
-        self.update(iface, "dhcp", None, None, None, vlanid)
-
-    def configure_static(self, iface, ipaddr, netmask, gateway, vlanid):
-        """Can be used to configure a static IP on a NIC
-        """
-        self.update(iface, "static", ipaddr, netmask, gateway, vlanid)
-
 
 class NetworkTopology(NodeConfigFileSection):
     """Sets the network topology
@@ -442,6 +442,12 @@
     def update(self, topology="legacy"):
         assert topology in self.known_topologies
 
+    def configure_bridged(self):
+        return self.update("legacy")
+
+    def configure_direct(self):
+        return self.update("direct")
+
 
 class IPv6(NodeConfigFileSection):
     """Sets IPv6 network stuff
diff --git a/tests/nose/network_config.py b/tests/nose/network_config.py
index 5d9aa5c..0eb77f1 100644
--- a/tests/nose/network_config.py
+++ b/tests/nose/network_config.py
@@ -28,16 +28,25 @@
 # http://ivory.idyll.org/articles/nose-intro.html
 
 
-def test_fake():
-    """Ensure that FakeFs is working
-    """
-    with patch("ovirt.node.utils.fs.File", FakeFs.File):
-        f = fs.File("new-file")
-        f.touch()
-        assert "new-file" in FakeFs.filemap
+class TestFakeFs():
+    def setUp(self):
+        FakeFs.erase()
 
-        f.delete()
-        assert FakeFs.filemap == {}
+    def tearDown(self):
+        FakeFs.erase()
+
+    def test_basic(self):
+        """Ensure that FakeFs is working
+        """
+        FakeFs.erase()
+        with patch("ovirt.node.utils.fs.File", FakeFs.File):
+            f = fs.File("new-file")
+            f.touch()
+            assert "new-file" in FakeFs.filemap
+
+            f.delete()
+            print FakeFs.filemap
+            assert FakeFs.filemap == {}
 
 
 @patch("ovirt.node.utils.fs.File", FakeFs.File)
@@ -87,8 +96,7 @@
                                 ('HWADDR', 'th:em:ac:ad:dr'),
                                 ('ONBOOT', 'yes')])
         assert_ifcfg_has_items("brens1",
-                               [('BOOTPROTO', 'static'),
-                                ('DELAY', '0'),
+                               [('DELAY', '0'),
                                 ('DEVICE', 'brens1'),
                                 ('GATEWAY', '192.168.122.1'),
                                 ('IPADDR', '192.168.122.42'),
@@ -98,6 +106,64 @@
                                 ('TYPE', 'Bridge')])
 
 
+ at patch("ovirt.node.utils.fs.File", FakeFs.File)
+ at patch.object(UdevNICInfo, "vendor")
+ at patch.object(UdevNICInfo, "devtype")
+ at patch.object(SysfsNICInfo, "hwaddr", "th:em:ac:ad:dr")
+class TestDirectNIC():
+    """Test the bridgeless configuration
+    """
+    def setUp(self):
+        FakeFs.erase()
+        FakeFs.File("/etc/default/ovirt").touch()
+
+    def tearDown(self):
+        FakeFs.erase()
+
+    def test_dhcp(self, *args, **kwargs):
+        """Test bridgeless with DHCP configuration file creation
+        """
+        mt = defaults.NetworkTopology()
+        mt.configure_direct()
+
+        m = defaults.Network()
+
+        m.configure_dhcp("eth0")
+
+        run_tx_by_name(m.transaction(), "WriteConfiguration")
+
+        assert_ifcfg_has_items("eth0",
+                               [('BOOTPROTO', 'dhcp'), ('DEVICE', 'eth0'),
+                               ('HWADDR', 'th:em:ac:ad:dr'), ('ONBOOT', 'yes'),
+                               ('PEERNTP', 'yes')])
+
+        assert "breth0" not in FakeFs.filemap
+
+    def test_static(self, *args, **kwargs):
+        """Test bridgeless with static IP configuration file creation
+        """
+        mt = defaults.NetworkTopology()
+        mt.configure_direct()
+
+        m = defaults.Network()
+
+        m.configure_static("ens1", "192.168.122.42", "255.255.255.0",
+                           "192.168.122.1", None)
+
+        run_tx_by_name(m.transaction(), "WriteConfiguration")
+
+        assert_ifcfg_has_items("ens1",
+                               [('DEVICE', 'ens1'),
+                                ('GATEWAY', '192.168.122.1'),
+                                ('HWADDR', 'th:em:ac:ad:dr'),
+                                ('IPADDR', '192.168.122.42'),
+                                ('NETMASK', '255.255.255.0'),
+                                ('ONBOOT', 'yes'),
+                                ('PEERNTP', 'yes')])
+
+        assert "brens1" not in FakeFs.filemap
+
+
 def run_tx_by_name(txs, name):
     tx = None
     for _tx in txs:


-- 
To view, visit http://gerrit.ovirt.org/15668
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5ec5225713981201ae158f9810ccf915cdb2efa1
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list