tests: Allow to use remote hostapd_cli in Hostapd classes
Signed-off-by: Janusz Dziedzic <janusz.dziedzic@gmail.com>
This commit is contained in:
parent
871bfdcdf6
commit
9ff4fd30ff
1 changed files with 56 additions and 12 deletions
|
@ -15,6 +15,7 @@ import wpaspy
|
||||||
import remotehost
|
import remotehost
|
||||||
import utils
|
import utils
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from remotectrl import RemoteCtrl
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
hapd_ctrl = '/var/run/hostapd'
|
hapd_ctrl = '/var/run/hostapd'
|
||||||
|
@ -28,12 +29,18 @@ class HostapdGlobal:
|
||||||
try:
|
try:
|
||||||
hostname = apdev['hostname']
|
hostname = apdev['hostname']
|
||||||
port = apdev['port']
|
port = apdev['port']
|
||||||
|
if 'remote_cli' in apdev:
|
||||||
|
remote_cli = apdev['remote_cli']
|
||||||
|
else:
|
||||||
|
remote_cli = False
|
||||||
except:
|
except:
|
||||||
hostname = None
|
hostname = None
|
||||||
port = 8878
|
port = 8878
|
||||||
|
remote_cli = False
|
||||||
self.host = remotehost.Host(hostname)
|
self.host = remotehost.Host(hostname)
|
||||||
self.hostname = hostname
|
self.hostname = hostname
|
||||||
self.port = port
|
self.port = port
|
||||||
|
self.remote_cli = remote_cli
|
||||||
if hostname is None:
|
if hostname is None:
|
||||||
global_ctrl = hapd_global
|
global_ctrl = hapd_global
|
||||||
if global_ctrl_override:
|
if global_ctrl_override:
|
||||||
|
@ -41,6 +48,14 @@ class HostapdGlobal:
|
||||||
self.ctrl = wpaspy.Ctrl(global_ctrl)
|
self.ctrl = wpaspy.Ctrl(global_ctrl)
|
||||||
self.mon = wpaspy.Ctrl(global_ctrl)
|
self.mon = wpaspy.Ctrl(global_ctrl)
|
||||||
self.dbg = ""
|
self.dbg = ""
|
||||||
|
else:
|
||||||
|
if remote_cli:
|
||||||
|
global_ctrl = hapd_global
|
||||||
|
if global_ctrl_override:
|
||||||
|
global_ctrl = global_ctrl_override
|
||||||
|
self.ctrl = RemoteCtrl(global_ctrl, port, hostname=hostname)
|
||||||
|
self.mon = RemoteCtrl(global_ctrl, port, hostname=hostname)
|
||||||
|
self.dbg = hostname + "/global"
|
||||||
else:
|
else:
|
||||||
self.ctrl = wpaspy.Ctrl(hostname, port)
|
self.ctrl = wpaspy.Ctrl(hostname, port)
|
||||||
self.mon = wpaspy.Ctrl(hostname, port)
|
self.mon = wpaspy.Ctrl(hostname, port)
|
||||||
|
@ -119,6 +134,9 @@ class HostapdGlobal:
|
||||||
if self.hostname is None:
|
if self.hostname is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
if self.remote_cli:
|
||||||
|
return None
|
||||||
|
|
||||||
res = self.request("INTERFACES ctrl")
|
res = self.request("INTERFACES ctrl")
|
||||||
lines = res.splitlines()
|
lines = res.splitlines()
|
||||||
found = False
|
found = False
|
||||||
|
@ -147,14 +165,21 @@ class HostapdGlobal:
|
||||||
|
|
||||||
class Hostapd:
|
class Hostapd:
|
||||||
def __init__(self, ifname, bssidx=0, hostname=None, ctrl=hapd_ctrl,
|
def __init__(self, ifname, bssidx=0, hostname=None, ctrl=hapd_ctrl,
|
||||||
port=8877):
|
port=8877, remote_cli=False):
|
||||||
self.hostname = hostname
|
self.hostname = hostname
|
||||||
self.host = remotehost.Host(hostname, ifname)
|
self.host = remotehost.Host(hostname, ifname)
|
||||||
self.ifname = ifname
|
self.ifname = ifname
|
||||||
|
self.remote_cli = remote_cli
|
||||||
if hostname is None:
|
if hostname is None:
|
||||||
self.ctrl = wpaspy.Ctrl(os.path.join(ctrl, ifname))
|
self.ctrl = wpaspy.Ctrl(os.path.join(ctrl, ifname))
|
||||||
self.mon = wpaspy.Ctrl(os.path.join(ctrl, ifname))
|
self.mon = wpaspy.Ctrl(os.path.join(ctrl, ifname))
|
||||||
self.dbg = ifname
|
self.dbg = ifname
|
||||||
|
else:
|
||||||
|
if remote_cli:
|
||||||
|
self.ctrl = RemoteCtrl(ctrl, port, hostname=hostname,
|
||||||
|
ifname=ifname)
|
||||||
|
self.mon = RemoteCtrl(ctrl, port, hostname=hostname,
|
||||||
|
ifname=ifname)
|
||||||
else:
|
else:
|
||||||
self.ctrl = wpaspy.Ctrl(hostname, port)
|
self.ctrl = wpaspy.Ctrl(hostname, port)
|
||||||
self.mon = wpaspy.Ctrl(hostname, port)
|
self.mon = wpaspy.Ctrl(hostname, port)
|
||||||
|
@ -638,22 +663,31 @@ def add_ap(apdev, params, wait_enabled=True, no_enable=False, timeout=30,
|
||||||
try:
|
try:
|
||||||
hostname = apdev['hostname']
|
hostname = apdev['hostname']
|
||||||
port = apdev['port']
|
port = apdev['port']
|
||||||
logger.info("Starting AP " + hostname + "/" + port + " " + ifname)
|
if 'remote_cli' in apdev:
|
||||||
|
remote_cli = apdev['remote_cli']
|
||||||
|
else:
|
||||||
|
remote_cli = False
|
||||||
|
if 'global_ctrl_override' in apdev:
|
||||||
|
global_ctrl_override = apdev['global_ctrl_override']
|
||||||
|
logger.info("Starting AP " + hostname + "/" + port + " " + ifname + " remote_cli " + str(remote_cli))
|
||||||
except:
|
except:
|
||||||
logger.info("Starting AP " + ifname)
|
logger.info("Starting AP " + ifname)
|
||||||
hostname = None
|
hostname = None
|
||||||
port = 8878
|
port = 8878
|
||||||
|
remote_cli = False
|
||||||
else:
|
else:
|
||||||
ifname = apdev
|
ifname = apdev
|
||||||
logger.info("Starting AP " + ifname + " (old add_ap argument type)")
|
logger.info("Starting AP " + ifname + " (old add_ap argument type)")
|
||||||
hostname = None
|
hostname = None
|
||||||
port = 8878
|
port = 8878
|
||||||
|
remote_cli = False
|
||||||
hapd_global = HostapdGlobal(apdev,
|
hapd_global = HostapdGlobal(apdev,
|
||||||
global_ctrl_override=global_ctrl_override)
|
global_ctrl_override=global_ctrl_override)
|
||||||
hapd_global.remove(ifname)
|
hapd_global.remove(ifname)
|
||||||
hapd_global.add(ifname, driver=driver)
|
hapd_global.add(ifname, driver=driver)
|
||||||
port = hapd_global.get_ctrl_iface_port(ifname)
|
port = hapd_global.get_ctrl_iface_port(ifname)
|
||||||
hapd = Hostapd(ifname, hostname=hostname, port=port)
|
hapd = Hostapd(ifname, hostname=hostname, port=port,
|
||||||
|
remote_cli=remote_cli)
|
||||||
if not hapd.ping():
|
if not hapd.ping():
|
||||||
raise Exception("Could not ping hostapd")
|
raise Exception("Could not ping hostapd")
|
||||||
hapd.set_defaults(set_channel=set_channel)
|
hapd.set_defaults(set_channel=set_channel)
|
||||||
|
@ -688,17 +722,22 @@ def add_bss(apdev, ifname, confname, ignore_error=False):
|
||||||
try:
|
try:
|
||||||
hostname = apdev['hostname']
|
hostname = apdev['hostname']
|
||||||
port = apdev['port']
|
port = apdev['port']
|
||||||
logger.info("Starting BSS " + hostname + "/" + port + " phy=" + phy + " ifname=" + ifname)
|
if 'remote_cli' in apdev:
|
||||||
|
remote_cli = apdev['remote_cli']
|
||||||
|
else:
|
||||||
|
remote_cli = False
|
||||||
|
logger.info("Starting BSS " + hostname + "/" + port + " phy=" + phy + " ifname=" + ifname + " remote_cli=" + str(remote_cli))
|
||||||
except:
|
except:
|
||||||
logger.info("Starting BSS phy=" + phy + " ifname=" + ifname)
|
logger.info("Starting BSS phy=" + phy + " ifname=" + ifname)
|
||||||
hostname = None
|
hostname = None
|
||||||
port = 8878
|
port = 8878
|
||||||
|
remote_cli = False
|
||||||
hapd_global = HostapdGlobal(apdev)
|
hapd_global = HostapdGlobal(apdev)
|
||||||
confname = cfg_file(apdev, confname, ifname)
|
confname = cfg_file(apdev, confname, ifname)
|
||||||
hapd_global.send_file(confname, confname)
|
hapd_global.send_file(confname, confname)
|
||||||
hapd_global.add_bss(phy, confname, ignore_error)
|
hapd_global.add_bss(phy, confname, ignore_error)
|
||||||
port = hapd_global.get_ctrl_iface_port(ifname)
|
port = hapd_global.get_ctrl_iface_port(ifname)
|
||||||
hapd = Hostapd(ifname, hostname=hostname, port=port)
|
hapd = Hostapd(ifname, hostname=hostname, port=port, remote_cli=remote_cli)
|
||||||
if not hapd.ping():
|
if not hapd.ping():
|
||||||
raise Exception("Could not ping hostapd")
|
raise Exception("Could not ping hostapd")
|
||||||
return hapd
|
return hapd
|
||||||
|
@ -708,17 +747,22 @@ def add_iface(apdev, confname):
|
||||||
try:
|
try:
|
||||||
hostname = apdev['hostname']
|
hostname = apdev['hostname']
|
||||||
port = apdev['port']
|
port = apdev['port']
|
||||||
logger.info("Starting interface " + hostname + "/" + port + " " + ifname)
|
if 'remote_cli' in apdev:
|
||||||
|
remote_cli = apdev['remote_cli']
|
||||||
|
else:
|
||||||
|
remote_cli = False
|
||||||
|
logger.info("Starting interface " + hostname + "/" + port + " " + ifname + "remote_cli=" + str(remote_cli))
|
||||||
except:
|
except:
|
||||||
logger.info("Starting interface " + ifname)
|
logger.info("Starting interface " + ifname)
|
||||||
hostname = None
|
hostname = None
|
||||||
port = 8878
|
port = 8878
|
||||||
|
remote_cli = False
|
||||||
hapd_global = HostapdGlobal(apdev)
|
hapd_global = HostapdGlobal(apdev)
|
||||||
confname = cfg_file(apdev, confname, ifname)
|
confname = cfg_file(apdev, confname, ifname)
|
||||||
hapd_global.send_file(confname, confname)
|
hapd_global.send_file(confname, confname)
|
||||||
hapd_global.add_iface(ifname, confname)
|
hapd_global.add_iface(ifname, confname)
|
||||||
port = hapd_global.get_ctrl_iface_port(ifname)
|
port = hapd_global.get_ctrl_iface_port(ifname)
|
||||||
hapd = Hostapd(ifname, hostname=hostname, port=port)
|
hapd = Hostapd(ifname, hostname=hostname, port=port, remote_cli=remote_cli)
|
||||||
if not hapd.ping():
|
if not hapd.ping():
|
||||||
raise Exception("Could not ping hostapd")
|
raise Exception("Could not ping hostapd")
|
||||||
return hapd
|
return hapd
|
||||||
|
|
Loading…
Reference in a new issue