import logging
logger = logging.getLogger()
import os
-import subprocess
from wpasupplicant import WpaSupplicant
"""wpa_supplicant config file parsing/writing"""
config = "/tmp/test_wpas_config_file.conf"
if os.path.exists(config):
- subprocess.call(['sudo', 'rm', config])
+ os.remove(config)
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
try:
if "OK" in wpas.global_request("SAVE_CONFIG"):
raise Exception("SAVE_CONFIG (global) succeeded unexpectedly")
- # symlink config file to itself to break writing
- subprocess.call(['rm', config])
- subprocess.call(['ln', '-s', config, config])
+ # replace the config file with a directory to break writing/renaming
+ os.remove(config)
+ os.mkdir(config)
wpas.request("SET update_config 1")
if "OK" in wpas.request("SAVE_CONFIG"):
raise Exception("SAVE_CONFIG succeeded unexpectedly")
raise Exception("SAVE_CONFIG (global) succeeded unexpectedly")
finally:
- subprocess.call(['sudo', 'rm', config])
+ try:
+ os.remove(config)
+ except:
+ pass
+ try:
+ os.rmdir(config)
+ except:
+ pass