Giuseppe Vallarelli has uploaded a new change for review. Change subject: Hidden bonds[1/2]: Adding a test. ......................................................................
Hidden bonds[1/2]: Adding a test. Adding a test to cover the current implementation of nics(). Change-Id: Idde9ce51025e97c176ffa95aa0f81bcbc639f96f Signed-off-by: Giuseppe Vallarelli <[email protected]> --- M lib/vdsm/netinfo.py M tests/netinfoTests.py 2 files changed, 55 insertions(+), 3 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/38/16238/1 diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py index 0566920..37cd0b4 100644 --- a/lib/vdsm/netinfo.py +++ b/lib/vdsm/netinfo.py @@ -42,6 +42,7 @@ NET_CONF_PREF = NET_CONF_DIR + 'ifcfg-' PROC_NET_VLAN = '/proc/net/vlan/' +NET_FN_MATCH = '/sys/class/net/*' BONDING_MASTERS = '/sys/class/net/bonding_masters' BONDING_SLAVES = '/sys/class/net/%s/bonding/slaves' @@ -61,7 +62,7 @@ hidden_nics = config.get('vars', 'hidden_nics').split(',') fake_nics = config.get('vars', 'fake_nics').split(',') - for b in glob.glob('/sys/class/net/*'): + for b in glob.glob(NET_FN_MATCH): nic = b.split('/')[-1] if not os.path.exists(os.path.join(b, 'device')): if _match_nic_name(nic, fake_nics): diff --git a/tests/netinfoTests.py b/tests/netinfoTests.py index f6a6fc8..7f93ce0 100644 --- a/tests/netinfoTests.py +++ b/tests/netinfoTests.py @@ -18,13 +18,17 @@ # # Refer to the README and COPYING files for full details of the license # - import os -from testrunner import VdsmTestCase as TestCaseBase +from shutil import rmtree + import ethtool from vdsm import netinfo + from monkeypatch import MonkeyPatch +from testrunner import VdsmTestCase as TestCaseBase + +DEV_DIR_FIXTURE = '/tmp/net/' # speeds defined in ethtool ETHTOOL_SPEEDS = set([10, 100, 1000, 2500, 10000]) @@ -100,3 +104,50 @@ ipaddrs.append(dev.ipv4_address) for ip in ipaddrs: self.assertEqual(dev.device, netinfo.getIfaceByIP(ip)) + + def _dev_dirs_setup(): + """ + Creates test fixture which is a dir structure: + /tmp/net/em/device + /tmp/net/me/device + /tmp/net/fake0 + /tmp/net/fake1 + /tmp/net/hid0/device + /tmp/net/hideous/device + returns related fn-match pattern. + """ + + dev_dirs = [DEV_DIR_FIXTURE + dev for dev in + ('em/device', 'me/device', 'fake0', 'fake', + 'hid/device', 'hideous/device')] + for dev_dir in dev_dirs: + os.makedirs(dev_dir) + + return DEV_DIR_FIXTURE + '*' + + def _config_setup(): + """ + Returns an instance of a config stub. + """ + class Config(object): + def get(self, unused_vars, key): + if key == 'hidden_nics': + return 'hid*' + else: + return 'fake*' + + return Config() + + @MonkeyPatch(netinfo, 'NET_FN_MATCH', _dev_dirs_setup()) + @MonkeyPatch(netinfo, 'config', _config_setup()) + def testNics(self): + try: + self.assertEqual(set(netinfo.nics()), + set(['em', 'me', 'fake0', 'fake'])) + except: + # teardown test fixture + rmtree(DEV_DIR_FIXTURE) + raise + else: + # teardown test fixture + rmtree(DEV_DIR_FIXTURE) -- To view, visit http://gerrit.ovirt.org/16238 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idde9ce51025e97c176ffa95aa0f81bcbc639f96f Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Giuseppe Vallarelli <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
