[node-patches] Change in ovirt-node[master]: test: Add some more bond unit tests
fabiand at fedoraproject.org
fabiand at fedoraproject.org
Tue Jun 18 14:58:04 UTC 2013
Fabian Deutsch has uploaded a new change for review.
Change subject: test: Add some more bond unit tests
......................................................................
test: Add some more bond unit tests
The tests now also cover cleaning of bond devices and the subsequent
removal and adjustment of all related config files.
Change-Id: I8b51908f044f81e9c9db98af5dedcacaf78cae8f
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M tests/nose/network_config.py
1 file changed, 49 insertions(+), 19 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/57/15857/1
diff --git a/tests/nose/network_config.py b/tests/nose/network_config.py
index eeecd29..0d89160 100644
--- a/tests/nose/network_config.py
+++ b/tests/nose/network_config.py
@@ -24,6 +24,7 @@
from ovirt.node.utils.fs import ShellVarFile, FakeFs
from ovirt.node.utils.network import UdevNICInfo, SysfsNICInfo
import logging
+import pprint
# http://ivory.idyll.org/articles/nose-intro.html
@@ -70,11 +71,11 @@
run_tx_by_name(m.transaction(), "WriteConfiguration")
- assert_ifcfg_has_items("eth0",
+ assert ifcfg_has_items("eth0",
[('BRIDGE', 'breth0'), ('DEVICE', 'eth0'),
('HWADDR', 'th:em:ac:ad:dr'),
('ONBOOT', 'yes')])
- assert_ifcfg_has_items("breth0",
+ assert ifcfg_has_items("breth0",
[('BOOTPROTO', 'dhcp'), ('DELAY', '0'),
('DEVICE', 'breth0'), ('ONBOOT', 'yes'),
('PEERNTP', 'yes'), ('TYPE', 'Bridge')])
@@ -89,11 +90,11 @@
run_tx_by_name(m.transaction(), "WriteConfiguration")
- assert_ifcfg_has_items("ens1",
+ assert ifcfg_has_items("ens1",
[('BRIDGE', 'brens1'), ('DEVICE', 'ens1'),
('HWADDR', 'th:em:ac:ad:dr'),
('ONBOOT', 'yes')])
- assert_ifcfg_has_items("brens1",
+ assert ifcfg_has_items("brens1",
[('DELAY', '0'),
('DEVICE', 'brens1'),
('GATEWAY', '192.168.122.1'),
@@ -129,7 +130,7 @@
run_tx_by_name(m.transaction(), "WriteConfiguration")
- assert_ifcfg_has_items("eth0",
+ assert ifcfg_has_items("eth0",
[('BOOTPROTO', 'dhcp'), ('DEVICE', 'eth0'),
('HWADDR', 'th:em:ac:ad:dr'), ('ONBOOT', 'yes'),
('PEERNTP', 'yes')])
@@ -148,7 +149,7 @@
run_tx_by_name(m.transaction(), "WriteConfiguration")
- assert_ifcfg_has_items("ens1",
+ assert ifcfg_has_items("ens1",
[('DEVICE', 'ens1'),
('GATEWAY', '192.168.122.1'),
('HWADDR', 'th:em:ac:ad:dr'),
@@ -161,6 +162,8 @@
@patch("ovirt.node.utils.fs.File", FakeFs.File)
+ at patch("os.listdir", FakeFs.listdir)
+ at patch("ovirt.node.utils.process.call")
@patch.object(UdevNICInfo, "vendor")
@patch.object(UdevNICInfo, "devtype")
@patch.object(SysfsNICInfo, "hwaddr", "th:em:ac:ad:dr")
@@ -185,22 +188,22 @@
run_tx_by_name(m.transaction(), "WriteConfiguration")
- assert_ifcfg_has_items("bond0",
+ assert ifcfg_has_items("bond0",
[('BONDING_OPTS', 'mode=4'),
('BOOTPROTO', 'dhcp'),
('DEVICE', 'bond0'),
('HWADDR', 'th:em:ac:ad:dr'),
('ONBOOT', 'yes'), ('PEERNTP', 'yes')])
- assert_ifcfg_has_items("ens1",
+ assert ifcfg_has_items("ens1",
[('DEVICE', 'ens1'), ('MASTER', 'bond0'),
('ONBOOT', 'yes'), ('SLAVE', 'yes')])
- assert_ifcfg_has_items("ens2",
+ assert ifcfg_has_items("ens2",
[('DEVICE', 'ens2'), ('MASTER', 'bond0'),
('ONBOOT', 'yes'), ('SLAVE', 'yes')])
- assert_ifcfg_has_items("ens3",
+ assert ifcfg_has_items("ens3",
[('DEVICE', 'ens3'), ('MASTER', 'bond0'),
('ONBOOT', 'yes'), ('SLAVE', 'yes')])
@@ -217,27 +220,28 @@
run_tx_by_name(m.transaction(), "WriteConfiguration")
- assert_ifcfg_has_items("bond0",
+ assert ifcfg_has_items("bond0",
[('BONDING_OPTS', 'mode=4'),
('BRIDGE', 'brbond0'),
('DEVICE', 'bond0'),
('HWADDR', 'th:em:ac:ad:dr'),
('ONBOOT', 'yes')])
- assert_ifcfg_has_items("ens1",
+ assert ifcfg_has_items("ens1",
[('DEVICE', 'ens1'), ('MASTER', 'bond0'),
('ONBOOT', 'yes'), ('SLAVE', 'yes')])
- assert_ifcfg_has_items("ens2",
+ assert ifcfg_has_items("ens2",
[('DEVICE', 'ens2'), ('MASTER', 'bond0'),
('ONBOOT', 'yes'), ('SLAVE', 'yes')])
- assert_ifcfg_has_items("ens3",
+ assert ifcfg_has_items("ens3",
[('DEVICE', 'ens3'), ('MASTER', 'bond0'),
('ONBOOT', 'yes'), ('SLAVE', 'yes')])
- assert_ifcfg_has_items("brbond0",
- [('BOOTPROTO', 'dhcp'),
+ assert ifcfg_has_items("brbond0",
+ [('BONDING_OPTS', 'mode=4'),
+ ('BOOTPROTO', 'dhcp'),
('DELAY', '0'),
('DEVICE', 'brbond0'),
('ONBOOT', 'yes'),
@@ -255,11 +259,14 @@
mb.configure_8023ad("bond0", ["ens1", "ens2", "ens3"])
m.configure_dhcp("ens1")
+ had_exception = False
try:
run_tx_by_name(m.transaction(), "WriteConfiguration")
except RuntimeError as e:
+ had_exception = True
assert e.message == ("Bond slave can not be used as " +
"primary device")
+ assert had_exception
def test_unused_bond(self, *args, **kwargs):
mb = defaults.NicBonding()
@@ -274,6 +281,25 @@
except RuntimeError as e:
assert e.message == "Bond configured but not used"
+ def test_no_bond_and_clean(self, *args, **kwargs):
+ mb = defaults.NicBonding()
+
+ self.test_unused_bond()
+
+ # bond0 is created, but ens42 is used
+ mb.configure_no_bond()
+ mb.transaction().run()
+
+ pprint.pprint(FakeFs.filemap)
+
+ assert ifcfgfilename("bond0") not in FakeFs.filemap
+ assert ifcfg_has_items("ens1", [('DEVICE', 'ens1'),
+ ('ONBOOT', 'yes')])
+ assert ifcfg_has_items("ens2", [('DEVICE', 'ens2'),
+ ('ONBOOT', 'yes')])
+ assert ifcfg_has_items("ens3", [('DEVICE', 'ens3'),
+ ('ONBOOT', 'yes')])
+
def run_tx_by_name(txs, name):
tx = None
@@ -285,10 +311,14 @@
tx()
-def assert_ifcfg_has_items(ifname, expected_items):
- ifcfg = ShellVarFile("/etc/sysconfig/network-scripts/ifcfg-" + ifname)
+def ifcfgfilename(ifname):
+ return "/etc/sysconfig/network-scripts/ifcfg-" + ifname
+
+
+def ifcfg_has_items(ifname, expected_items):
+ ifcfg = ShellVarFile(ifcfgfilename(ifname))
ifcfg_items = sorted(ifcfg.get_dict().items())
logging.info("ifcfg : %s" % ifname)
logging.info("expect: %s" % expected_items)
logging.info("got : %s" % ifcfg_items)
- assert ifcfg_items == expected_items
+ return ifcfg_items == expected_items
--
To view, visit http://gerrit.ovirt.org/15857
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8b51908f044f81e9c9db98af5dedcacaf78cae8f
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