tests: Use general cmd_execute() for bridge setup commands

The hwsim tests used to execute shell commands in the tests using the
subprocess python module. Use the cmd_execute() general function for
executing shell commands to setup bridge so that this would also work on
remote setups.

Signed-off-by: Jonathan Afek <jonathanx.afek@intel.com>
This commit is contained in:
Jonathan Afek 2016-06-23 20:16:29 +03:00 committed by Jouni Malinen
parent 12129dda8e
commit bb04a9a9a3
4 changed files with 76 additions and 70 deletions

View file

@ -7,7 +7,6 @@
import logging import logging
logger = logging.getLogger() logger = logging.getLogger()
import os import os
import subprocess
import hwsim_utils import hwsim_utils
import hostapd import hostapd
@ -161,17 +160,17 @@ def test_ap_wds_sta(dev, apdev):
hapd = hostapd.add_ap(apdev[0], params) hapd = hostapd.add_ap(apdev[0], params)
try: try:
subprocess.call(['brctl', 'addbr', 'wds-br0']) dev[0].cmd_execute(['brctl', 'addbr', 'wds-br0'])
subprocess.call(['brctl', 'setfd', 'wds-br0', '0']) dev[0].cmd_execute(['brctl', 'setfd', 'wds-br0', '0'])
subprocess.call(['ip', 'link', 'set', 'dev', 'wds-br0', 'up']) dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'up'])
subprocess.call(['iw', dev[0].ifname, 'set', '4addr', 'on']) dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'on'])
dev[0].connect(ssid, psk=passphrase, scan_freq="2412") dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0", hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
max_tries=15) max_tries=15)
finally: finally:
subprocess.call(['iw', dev[0].ifname, 'set', '4addr', 'off']) dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'off'])
subprocess.call(['ip', 'link', 'set', 'dev', 'wds-br0', 'down']) dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'down'])
subprocess.call(['brctl', 'delbr', 'wds-br0']) dev[0].cmd_execute(['brctl', 'delbr', 'wds-br0'])
def test_ap_inactivity_poll(dev, apdev): def test_ap_inactivity_poll(dev, apdev):
"""AP using inactivity poll""" """AP using inactivity poll"""

View file

@ -340,30 +340,27 @@ def test_ap_wpa2_strict_rekey(dev, apdev):
def test_ap_wpa2_bridge_fdb(dev, apdev): def test_ap_wpa2_bridge_fdb(dev, apdev):
"""Bridge FDB entry removal""" """Bridge FDB entry removal"""
hapd = None
try: try:
ssid = "test-wpa2-psk" ssid = "test-wpa2-psk"
passphrase = "12345678" passphrase = "12345678"
params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase) params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
params['bridge'] = 'ap-br0' params['bridge'] = 'ap-br0'
hostapd.add_ap(apdev[0], params) hapd = hostapd.add_ap(apdev[0], params)
subprocess.call(['brctl', 'setfd', 'ap-br0', '0']) hapd.cmd_execute(['brctl', 'setfd', 'ap-br0', '0'])
subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up']) hapd.cmd_execute(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
dev[0].connect(ssid, psk=passphrase, scan_freq="2412", dev[0].connect(ssid, psk=passphrase, scan_freq="2412",
bssid=apdev[0]['bssid']) bssid=apdev[0]['bssid'])
dev[1].connect(ssid, psk=passphrase, scan_freq="2412", dev[1].connect(ssid, psk=passphrase, scan_freq="2412",
bssid=apdev[0]['bssid']) bssid=apdev[0]['bssid'])
addr0 = dev[0].p2p_interface_addr() addr0 = dev[0].p2p_interface_addr()
hwsim_utils.test_connectivity_sta(dev[0], dev[1]) hwsim_utils.test_connectivity_sta(dev[0], dev[1])
cmd = subprocess.Popen(['brctl', 'showmacs', 'ap-br0'], err, macs1 = hapd.cmd_execute(['brctl', 'showmacs', 'ap-br0'])
stdout=subprocess.PIPE) hapd.cmd_execute(['brctl', 'setageing', 'ap-br0', '1'])
macs1 = cmd.stdout.read()
cmd = subprocess.call(['brctl', 'setageing', 'ap-br0', '1'])
dev[0].request("DISCONNECT") dev[0].request("DISCONNECT")
dev[1].request("DISCONNECT") dev[1].request("DISCONNECT")
time.sleep(1) time.sleep(1)
cmd = subprocess.Popen(['brctl', 'showmacs', 'ap-br0'], err, macs2 = hapd.cmd_execute(['brctl', 'showmacs', 'ap-br0'])
stdout=subprocess.PIPE)
macs2 = cmd.stdout.read()
addr1 = dev[1].p2p_interface_addr() addr1 = dev[1].p2p_interface_addr()
if addr0 not in macs1 or addr1 not in macs1: if addr0 not in macs1 or addr1 not in macs1:
@ -371,8 +368,9 @@ def test_ap_wpa2_bridge_fdb(dev, apdev):
if addr0 in macs2 or addr1 in macs2: if addr0 in macs2 or addr1 in macs2:
raise Exception("Bridge FDB entry was not removed") raise Exception("Bridge FDB entry was not removed")
finally: finally:
subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down']) hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', 'ap-br0',
subprocess.call(['brctl', 'delbr', 'ap-br0']) 'down'])
hostapd.cmd_execute(apdev[0], ['brctl', 'delbr', 'ap-br0'])
def test_ap_wpa2_already_in_bridge(dev, apdev): def test_ap_wpa2_already_in_bridge(dev, apdev):
"""hostapd behavior with interface already in bridge""" """hostapd behavior with interface already in bridge"""
@ -381,21 +379,23 @@ def test_ap_wpa2_already_in_bridge(dev, apdev):
try: try:
ssid = "test-wpa2-psk" ssid = "test-wpa2-psk"
passphrase = "12345678" passphrase = "12345678"
subprocess.call(['brctl', 'addbr', br_ifname]) hostapd.cmd_execute(apdev[0], ['brctl', 'addbr', br_ifname])
subprocess.call(['brctl', 'setfd', br_ifname, '0']) hostapd.cmd_execute(apdev[0], ['brctl', 'setfd', br_ifname, '0'])
subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up']) hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', br_ifname,
subprocess.call(['iw', ifname, 'set', 'type', '__ap']) 'up'])
subprocess.call(['brctl', 'addif', br_ifname, ifname]) hostapd.cmd_execute(apdev[0], ['iw', ifname, 'set', 'type', '__ap'])
hostapd.cmd_execute(apdev[0], ['brctl', 'addif', br_ifname, ifname])
params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase) params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
hapd = hostapd.add_ap(apdev[0], params) hapd = hostapd.add_ap(apdev[0], params)
if hapd.get_driver_status_field('brname') != br_ifname: if hapd.get_driver_status_field('brname') != br_ifname:
raise Exception("Bridge name not identified correctly") raise Exception("Bridge name not identified correctly")
dev[0].connect(ssid, psk=passphrase, scan_freq="2412") dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
finally: finally:
subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'down']) hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', br_ifname,
subprocess.call(['brctl', 'delif', br_ifname, ifname]) 'down'])
subprocess.call(['iw', ifname, 'set', 'type', 'station']) hostapd.cmd_execute(apdev[0], ['brctl', 'delif', br_ifname, ifname])
subprocess.call(['brctl', 'delbr', br_ifname]) hostapd.cmd_execute(apdev[0], ['iw', ifname, 'set', 'type', 'station'])
hostapd.cmd_execute(apdev[0], ['brctl', 'delbr', br_ifname])
def test_ap_wpa2_in_different_bridge(dev, apdev): def test_ap_wpa2_in_different_bridge(dev, apdev):
"""hostapd behavior with interface in different bridge""" """hostapd behavior with interface in different bridge"""
@ -404,17 +404,19 @@ def test_ap_wpa2_in_different_bridge(dev, apdev):
try: try:
ssid = "test-wpa2-psk" ssid = "test-wpa2-psk"
passphrase = "12345678" passphrase = "12345678"
subprocess.call(['brctl', 'addbr', br_ifname]) hostapd.cmd_execute(apdev[0], ['brctl', 'addbr', br_ifname])
subprocess.call(['brctl', 'setfd', br_ifname, '0']) hostapd.cmd_execute(apdev[0], ['brctl', 'setfd', br_ifname, '0'])
subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up']) hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', br_ifname,
subprocess.call(['iw', ifname, 'set', 'type', '__ap']) 'up'])
subprocess.call(['brctl', 'addif', br_ifname, ifname]) hostapd.cmd_execute(apdev[0], ['iw', ifname, 'set', 'type', '__ap'])
hostapd.cmd_execute(apdev[0], ['brctl', 'addif', br_ifname, ifname])
time.sleep(0.5) time.sleep(0.5)
params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase) params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
params['bridge'] = 'ap-br0' params['bridge'] = 'ap-br0'
hapd = hostapd.add_ap(apdev[0], params) hapd = hostapd.add_ap(apdev[0], params)
subprocess.call(['brctl', 'setfd', 'ap-br0', '0']) hostapd.cmd_execute(apdev[0], ['brctl', 'setfd', 'ap-br0', '0'])
subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up']) hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', 'ap-br0',
'up'])
brname = hapd.get_driver_status_field('brname') brname = hapd.get_driver_status_field('brname')
if brname != 'ap-br0': if brname != 'ap-br0':
raise Exception("Incorrect bridge: " + brname) raise Exception("Incorrect bridge: " + brname)
@ -427,10 +429,11 @@ def test_ap_wpa2_in_different_bridge(dev, apdev):
dev[0].request("DISCONNECT") dev[0].request("DISCONNECT")
hapd.disable() hapd.disable()
finally: finally:
subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'down']) hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', br_ifname,
subprocess.call(['brctl', 'delif', br_ifname, ifname], 'down'])
stderr=open('/dev/null', 'w')) hostapd.cmd_execute(apdev[0], ['brctl', 'delif', br_ifname, ifname,
subprocess.call(['brctl', 'delbr', br_ifname]) "2>", "/dev/null"], shell=True)
hostapd.cmd_execute(apdev[0], ['brctl', 'delbr', br_ifname])
def test_ap_wpa2_ext_add_to_bridge(dev, apdev): def test_ap_wpa2_ext_add_to_bridge(dev, apdev):
"""hostapd behavior with interface added to bridge externally""" """hostapd behavior with interface added to bridge externally"""
@ -442,17 +445,19 @@ def test_ap_wpa2_ext_add_to_bridge(dev, apdev):
params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase) params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
hapd = hostapd.add_ap(apdev[0], params) hapd = hostapd.add_ap(apdev[0], params)
subprocess.call(['brctl', 'addbr', br_ifname]) hostapd.cmd_execute(apdev[0], ['brctl', 'addbr', br_ifname])
subprocess.call(['brctl', 'setfd', br_ifname, '0']) hostapd.cmd_execute(apdev[0], ['brctl', 'setfd', br_ifname, '0'])
subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up']) hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', br_ifname,
subprocess.call(['brctl', 'addif', br_ifname, ifname]) 'up'])
hostapd.cmd_execute(apdev[0], ['brctl', 'addif', br_ifname, ifname])
dev[0].connect(ssid, psk=passphrase, scan_freq="2412") dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
if hapd.get_driver_status_field('brname') != br_ifname: if hapd.get_driver_status_field('brname') != br_ifname:
raise Exception("Bridge name not identified correctly") raise Exception("Bridge name not identified correctly")
finally: finally:
subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'down']) hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', br_ifname,
subprocess.call(['brctl', 'delif', br_ifname, ifname]) 'down'])
subprocess.call(['brctl', 'delbr', br_ifname]) hostapd.cmd_execute(apdev[0], ['brctl', 'delif', br_ifname, ifname])
hostapd.cmd_execute(apdev[0], ['brctl', 'delbr', br_ifname])
def test_ap_wpa2_psk_ext(dev, apdev): def test_ap_wpa2_psk_ext(dev, apdev):
"""WPA2-PSK AP using external EAPOL I/O""" """WPA2-PSK AP using external EAPOL I/O"""

View file

@ -426,16 +426,16 @@ def test_autogo_bridge(dev):
raise Exception("Failed to set autoscan") raise Exception("Failed to set autoscan")
autogo(dev[0]) autogo(dev[0])
ifname = dev[0].get_group_ifname() ifname = dev[0].get_group_ifname()
subprocess.call(['brctl', 'addbr', 'p2p-br0']) dev[0].cmd_execute(['brctl', 'addbr', 'p2p-br0'])
subprocess.call(['brctl', 'setfd', 'p2p-br0', '0']) dev[0].cmd_execute(['brctl', 'setfd', 'p2p-br0', '0'])
subprocess.call(['brctl', 'addif', 'p2p-br0', ifname]) dev[0].cmd_execute(['brctl', 'addif', 'p2p-br0', ifname])
subprocess.call(['ip', 'link', 'set', 'dev', 'p2p-br0', 'up']) dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'p2p-br0', 'up'])
time.sleep(0.1) time.sleep(0.1)
subprocess.call(['brctl', 'delif', 'p2p-br0', ifname]) dev[0].cmd_execute(['brctl', 'delif', 'p2p-br0', ifname])
time.sleep(0.1) time.sleep(0.1)
subprocess.call(['ip', 'link', 'set', 'dev', 'p2p-br0', 'down']) dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'p2p-br0', 'down'])
time.sleep(0.1) time.sleep(0.1)
subprocess.call(['brctl', 'delbr', 'p2p-br0']) dev[0].cmd_execute(['brctl', 'delbr', 'p2p-br0'])
ev = dev[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout=1) ev = dev[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout=1)
if ev is not None: if ev is not None:
raise Exception("P2P group removed unexpectedly") raise Exception("P2P group removed unexpectedly")
@ -444,12 +444,12 @@ def test_autogo_bridge(dev):
dev[0].remove_group() dev[0].remove_group()
finally: finally:
dev[0].request("AUTOSCAN ") dev[0].request("AUTOSCAN ")
subprocess.Popen(['brctl', 'delif', 'p2p-br0', ifname], dev[0].cmd_execute(['brctl', 'delif', 'p2p-br0', ifname,
stderr=open('/dev/null', 'w')) '2>', '/dev/null'], shell=True)
subprocess.Popen(['ip', 'link', 'set', 'dev', 'p2p-br0', 'down'], dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'p2p-br0', 'down',
stderr=open('/dev/null', 'w')) '2>', '/dev/null'], shell=True)
subprocess.Popen(['brctl', 'delbr', 'p2p-br0'], dev[0].cmd_execute(['brctl', 'delbr', 'p2p-br0', '2>', '/dev/null'],
stderr=open('/dev/null', 'w')) shell=True)
def test_presence_req_on_group_interface(dev): def test_presence_req_on_group_interface(dev):
"""P2P_PRESENCE_REQ on group interface""" """P2P_PRESENCE_REQ on group interface"""

View file

@ -393,8 +393,8 @@ def generic_pmksa_cache_preauth(dev, apdev, extraparams, identity, databridge,
params[key] = value params[key] = value
hapd = hostapd.add_ap(apdev[0], params) hapd = hostapd.add_ap(apdev[0], params)
subprocess.call(['brctl', 'setfd', 'ap-br0', '0']) hapd.cmd_execute(['brctl', 'setfd', 'ap-br0', '0'])
subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up']) hapd.cmd_execute(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
eap_connect(dev[0], hapd, "PAX", identity, eap_connect(dev[0], hapd, "PAX", identity,
password_hex="0123456789abcdef0123456789abcdef") password_hex="0123456789abcdef0123456789abcdef")
@ -456,10 +456,11 @@ def generic_pmksa_cache_preauth(dev, apdev, extraparams, identity, databridge,
hapd.request("DISABLE") hapd.request("DISABLE")
finally: finally:
subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'], hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev',
stderr=open('/dev/null', 'w')) 'ap-br0', 'down', '2>', '/dev/null'],
subprocess.call(['brctl', 'delbr', 'ap-br0'], shell=True)
stderr=open('/dev/null', 'w')) hostapd.cmd_execute(apdev[0], ['brctl', 'delbr', 'ap-br0',
'2>', '/dev/null'], shell=True)
def test_pmksa_cache_preauth(dev, apdev): def test_pmksa_cache_preauth(dev, apdev):
"""RSN pre-authentication to generate PMKSA cache entry""" """RSN pre-authentication to generate PMKSA cache entry"""
@ -701,15 +702,16 @@ def test_pmksa_cache_preauth_oom(dev, apdev):
try: try:
_test_pmksa_cache_preauth_oom(dev, apdev) _test_pmksa_cache_preauth_oom(dev, apdev)
finally: finally:
subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down']) hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', 'ap-br0',
subprocess.call(['brctl', 'delbr', 'ap-br0']) 'down'])
hostapd.cmd_execute(apdev[0], ['brctl', 'delbr', 'ap-br0'])
def _test_pmksa_cache_preauth_oom(dev, apdev): def _test_pmksa_cache_preauth_oom(dev, apdev):
params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap") params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
params['bridge'] = 'ap-br0' params['bridge'] = 'ap-br0'
hapd = hostapd.add_ap(apdev[0], params) hapd = hostapd.add_ap(apdev[0], params)
subprocess.call(['brctl', 'setfd', 'ap-br0', '0']) hostapd.cmd_execute(apdev[0], ['brctl', 'setfd', 'ap-br0', '0'])
subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up']) hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
eap_connect(dev[0], hapd, "PAX", "pax.user@example.com", eap_connect(dev[0], hapd, "PAX", "pax.user@example.com",
password_hex="0123456789abcdef0123456789abcdef", password_hex="0123456789abcdef0123456789abcdef",
bssid=apdev[0]['bssid']) bssid=apdev[0]['bssid'])