def test_addbr_delete(): br = brctl.addbr(b'br_test') try: check_output(b'brctl show', substr=[br.name]) finally: br.delete() check_output(b'brctl show', not_substr=[br.name])
def test_pause_param_settings(if1, rx, tx): if1.set_pause_param(False, rx, tx) expected = [ br'Autonegotiate:\s+off', br'RX:\s+' + (b'on' if rx else b'off'), br'TX:\s+' + (b'on' if tx else b'off'), ] check_output(b'ethtool -a ' + if1.name, regex=expected)
def test_pause_param_autonegotiate(if1): if1.set_pause_param(True, True, True) check_output(b'ethtool -a ' + if1.name, regex=[br'Autonegotiate:\s+on']) if1.set_pause_param(False, True, True) check_output(b'ethtool -a ' + if1.name, regex=[br'Autonegotiate:\s+off'])
def test_set_netmask(if1): if1.netmask = 16 assert if1.netmask == 16 check_output(b'ip addr show ' + if1.name, regex=[br'inet [0-9\.]+/16']) if1.netmask = 21 assert if1.netmask == 21 check_output(b'ip addr show ' + if1.name, regex=[br'inet [0-9\.]+/21'])
def test_up_down(if1): if1.down() assert not if1.is_up() check_output(b'ip link show ' + if1.name, regex=[if1.name + br': <.+>'], not_substr=[b'UP']) if1.up() assert if1.is_up() check_output(b'ip link show ' + if1.name, regex=[if1.name + br': <.+>'], substr=[b'UP'])
def test_set_link_auto(if1, ten, hundred, thousand): expected = br'Advertised link modes:\s+' if ten: expected += br'10baseT/Half 10baseT/Full\s+' if hundred: expected += br'100baseT/Half 100baseT/Full\s+' if thousand: expected += br'1000baseT/Full' if1.set_link_auto(ten, hundred, thousand) check_output(b'ethtool ' + if1.name, regex=[expected])
def test_addif(br1): cmd = b'brctl show ' + br1.name check_output(cmd, not_substr=[b'eth1', b'eth2']) br1.addif(b'eth1') check_output(cmd, substr=[b'eth1'], not_substr=[b'eth2']) br1.addif(b'eth2') check_output(cmd, substr=[b'eth1', b'eth2'])
def test_set_mac(if1): if1.mac = '00:11:22:33:44:55' assert if1.mac == '00:11:22:33:44:55' check_output(b'ip link show ' + if1.name, substr=[b'link/ether 00:11:22:33:44:55'])
def test_delif(br1): cmd = b'brctl show ' + br1.name br1.addif(b'eth1') check_output(cmd, substr=[b'eth1']) br1.delif(b'eth1') check_output(cmd, not_substr=[b'eth1'])
def test_get_index(if1, if2): for i in [if1, if2]: idx = str(i.index).encode('ascii') check_output(b'ip link show ' + i.name, substr=[idx + b': ' + i.name + b':'])
def test_set_forward_delay(br1): for value in [50, 100, 1000]: br1.set_forward_delay(value) check_output(b'brctl showstp ' + br1.name, regex=[br'forward delay\s+' + str(value).encode('ascii')])