Sync when writing the file
Glean does not attempt to do os.fsync after writing files, which is not safe in Python since Python does not guarantee the file being written even if it is closed on Python level. This might result in ifup complaining with unknown interface as the file is still in cache. Depends-On: https://review.opendev.org/677796 Change-Id: I05fd94662c409660857d4bc66b9f6354ac21496a
This commit is contained in:
parent
113107da7d
commit
68f25b6bfb
|
@ -58,6 +58,8 @@ HAVE_SELINUX = os.path.exists(SELINUX_RESTORECON)
|
|||
def safe_open(*args, **kwargs):
|
||||
f = open(*args, **kwargs)
|
||||
yield f
|
||||
f.flush()
|
||||
os.fsync(f.fileno())
|
||||
f.close()
|
||||
path = os.path.abspath(f.name)
|
||||
if HAVE_SELINUX:
|
||||
|
|
|
@ -143,6 +143,7 @@ class TestGlean(base.BaseTestCase):
|
|||
return real_path_exists(path)
|
||||
|
||||
@mock.patch('subprocess.call', return_value=0, new_callable=mock.Mock)
|
||||
@mock.patch('os.fsync', return_value=0, new_callable=mock.Mock)
|
||||
@mock.patch('os.unlink', return_value=0, new_callable=mock.Mock)
|
||||
@mock.patch('os.symlink', return_value=0, new_callable=mock.Mock)
|
||||
@mock.patch('os.path.exists', new_callable=mock.Mock)
|
||||
|
@ -156,6 +157,7 @@ class TestGlean(base.BaseTestCase):
|
|||
mock_os_path_exists,
|
||||
mock_os_symlink,
|
||||
mock_os_unlink,
|
||||
mock_os_fsync,
|
||||
mock_call,
|
||||
skip_dns=False,
|
||||
use_nm=False):
|
||||
|
|
Loading…
Reference in New Issue