mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-22 06:29:23 +01:00
auto-t: Ensure storage_dir exists, clean up
In iwd.py make sure all the static methods that touch IWD storage take the storage_dir parameter instead of hardcoding IWD_STORAGE_DIR, and make sure that parameter is actually used. Create the directory if it doesn't exist before copying files into it. This fixes a problem in testNetconfig where `IWD.copy_to_storage('ssidTKIP.psk', '/tmp/storage')` would result in /tmp/storage being created as a file, rather than a directory containing a file, and resulting in IWD failing to start with: `Failed to create /tmp/storage` runner.py creates /tmp/iwd but that doesn't account for IWD sessions with a custom storage dir path.
This commit is contained in:
parent
57888632a3
commit
a46707a595
@ -91,7 +91,7 @@ class Test(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
IWD.clear_storage()
|
||||
IWD.clear_storage(storage_dir='/tmp/storage')
|
||||
cls.dhcpd_pid.kill()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -1086,7 +1086,7 @@ class IWD(AsyncOpAbstract):
|
||||
psk_agent = None
|
||||
|
||||
def __init__(self, start_iwd_daemon = False, iwd_config_dir = '/tmp',
|
||||
iwd_storage_dir = '/tmp/iwd', namespace=ctx):
|
||||
iwd_storage_dir = IWD_STORAGE_DIR, namespace=ctx):
|
||||
self.namespace = namespace
|
||||
self._bus = namespace.get_bus()
|
||||
|
||||
@ -1197,40 +1197,49 @@ class IWD(AsyncOpAbstract):
|
||||
os.system('rm -rf ' + storage_dir + '/ap/*')
|
||||
|
||||
@staticmethod
|
||||
def create_in_storage(file_name, file_content):
|
||||
fo = open(IWD_STORAGE_DIR + '/' + file_name, 'w')
|
||||
def create_in_storage(file_name, file_content, storage_dir=IWD_STORAGE_DIR):
|
||||
fo = open(storage_dir + '/' + file_name, 'w')
|
||||
|
||||
fo.write(file_content)
|
||||
fo.close()
|
||||
|
||||
@staticmethod
|
||||
def _ensure_storage_dir_exists(storage_dir):
|
||||
if not os.path.exists(storage_dir):
|
||||
os.mkdir(storage_dir)
|
||||
|
||||
@staticmethod
|
||||
def copy_to_storage(source, storage_dir=IWD_STORAGE_DIR, name=None):
|
||||
import shutil
|
||||
|
||||
assert not os.path.isabs(source)
|
||||
|
||||
target = storage_dir
|
||||
if name:
|
||||
storage_dir += '/%s' % name
|
||||
target += '/%s' % name
|
||||
|
||||
shutil.copy(source, storage_dir)
|
||||
IWD._ensure_storage_dir_exists(storage_dir)
|
||||
shutil.copy(source, target)
|
||||
|
||||
@staticmethod
|
||||
def copy_to_hotspot(source):
|
||||
if not os.path.exists(IWD_STORAGE_DIR + "/hotspot"):
|
||||
os.mkdir(IWD_STORAGE_DIR + "/hotspot")
|
||||
def copy_to_hotspot(source, storage_dir=IWD_STORAGE_DIR):
|
||||
IWD._ensure_storage_dir_exists(storage_dir)
|
||||
|
||||
IWD.copy_to_storage(source, IWD_STORAGE_DIR + "/hotspot")
|
||||
if not os.path.exists(storage_dir + "/hotspot"):
|
||||
os.mkdir(storage_dir + "/hotspot")
|
||||
|
||||
IWD.copy_to_storage(source, storage_dir + "/hotspot")
|
||||
|
||||
@staticmethod
|
||||
def copy_to_ap(source):
|
||||
if not os.path.exists(IWD_STORAGE_DIR + "/ap"):
|
||||
os.mkdir(IWD_STORAGE_DIR + "/ap")
|
||||
def copy_to_ap(source, storage_dir=IWD_STORAGE_DIR):
|
||||
if not os.path.exists(storage_dir + "/ap"):
|
||||
os.mkdir(storage_dir + "/ap")
|
||||
|
||||
IWD.copy_to_storage(source, IWD_STORAGE_DIR + '/ap/')
|
||||
IWD.copy_to_storage(source, storage_dir + '/ap/')
|
||||
|
||||
@staticmethod
|
||||
def remove_from_storage(file_name):
|
||||
os.system('rm -rf ' + IWD_STORAGE_DIR + '/\'' + file_name + '\'')
|
||||
def remove_from_storage(file_name, storage_dir=IWD_STORAGE_DIR):
|
||||
os.system('rm -rf ' + storage_dir + '/\'' + file_name + '\'')
|
||||
|
||||
def list_devices(self, wait_to_appear = 0, max_wait = 50, p2p = False):
|
||||
if not wait_to_appear:
|
||||
|
Loading…
Reference in New Issue
Block a user