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
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
IWD.clear_storage()
|
IWD.clear_storage(storage_dir='/tmp/storage')
|
||||||
cls.dhcpd_pid.kill()
|
cls.dhcpd_pid.kill()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -1086,7 +1086,7 @@ class IWD(AsyncOpAbstract):
|
||||||
psk_agent = None
|
psk_agent = None
|
||||||
|
|
||||||
def __init__(self, start_iwd_daemon = False, iwd_config_dir = '/tmp',
|
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.namespace = namespace
|
||||||
self._bus = namespace.get_bus()
|
self._bus = namespace.get_bus()
|
||||||
|
|
||||||
|
@ -1197,40 +1197,49 @@ class IWD(AsyncOpAbstract):
|
||||||
os.system('rm -rf ' + storage_dir + '/ap/*')
|
os.system('rm -rf ' + storage_dir + '/ap/*')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_in_storage(file_name, file_content):
|
def create_in_storage(file_name, file_content, storage_dir=IWD_STORAGE_DIR):
|
||||||
fo = open(IWD_STORAGE_DIR + '/' + file_name, 'w')
|
fo = open(storage_dir + '/' + file_name, 'w')
|
||||||
|
|
||||||
fo.write(file_content)
|
fo.write(file_content)
|
||||||
fo.close()
|
fo.close()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _ensure_storage_dir_exists(storage_dir):
|
||||||
|
if not os.path.exists(storage_dir):
|
||||||
|
os.mkdir(storage_dir)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def copy_to_storage(source, storage_dir=IWD_STORAGE_DIR, name=None):
|
def copy_to_storage(source, storage_dir=IWD_STORAGE_DIR, name=None):
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
assert not os.path.isabs(source)
|
assert not os.path.isabs(source)
|
||||||
|
|
||||||
|
target = storage_dir
|
||||||
if name:
|
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
|
@staticmethod
|
||||||
def copy_to_hotspot(source):
|
def copy_to_hotspot(source, storage_dir=IWD_STORAGE_DIR):
|
||||||
if not os.path.exists(IWD_STORAGE_DIR + "/hotspot"):
|
IWD._ensure_storage_dir_exists(storage_dir)
|
||||||
os.mkdir(IWD_STORAGE_DIR + "/hotspot")
|
|
||||||
|
|
||||||
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
|
@staticmethod
|
||||||
def copy_to_ap(source):
|
def copy_to_ap(source, storage_dir=IWD_STORAGE_DIR):
|
||||||
if not os.path.exists(IWD_STORAGE_DIR + "/ap"):
|
if not os.path.exists(storage_dir + "/ap"):
|
||||||
os.mkdir(IWD_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
|
@staticmethod
|
||||||
def remove_from_storage(file_name):
|
def remove_from_storage(file_name, storage_dir=IWD_STORAGE_DIR):
|
||||||
os.system('rm -rf ' + IWD_STORAGE_DIR + '/\'' + file_name + '\'')
|
os.system('rm -rf ' + storage_dir + '/\'' + file_name + '\'')
|
||||||
|
|
||||||
def list_devices(self, wait_to_appear = 0, max_wait = 50, p2p = False):
|
def list_devices(self, wait_to_appear = 0, max_wait = 50, p2p = False):
|
||||||
if not wait_to_appear:
|
if not wait_to_appear:
|
||||||
|
|
Loading…
Reference in New Issue