def test_ifconfig(): addr = subprocess.check_output('ip addr', shell=True) names = [] addrs = {} up = {} cname = None for ln in addr.split('\n'): rr = re.match(r"\d+:\s+(?P<name>.*?): <", ln) if rr: cname = rr.group('name') names.append(cname) if re.search(r'\WUP\W', ln): up[cname] = True else: up[cname] = False rr = re.match(r"\s+inet\s+(?P<ip>[\d.]+)/(?P<sz>\d+)", ln) if rr: addrs[cname] = (rr.group('ip'), int(rr.group('sz'))) ifnames = ifconfig.getInterfaceList() ifnames.sort() names.sort() ok(ifnames) == names for name in names: ok(ifconfig.getAddr(name)) == addrs[name][0] ok(netmask2netsz(ifconfig.getMask(name))) == addrs[name][1] ok(ifconfig.isUp(name)) == up[name]
def test_ping(): for iname in ifconfig.getInterfaceList(): ip = ifconfig.getAddr(iname) ok(ping(ip, 0.1)) <= 0.1 ok(is_host_alive(ip, 0.1)) == True