Commit 5bd516bd authored by Łukasz Nowak's avatar Łukasz Nowak

promise: Cleanup plugin folder on each run

Promise can appear and disappear, and pyc or pyo files can stay in the folder,
so try hard to remove those stale files.

/reviewed-on !169
parent b5772299
Pipeline #7299 failed with stage
in 0 seconds
......@@ -289,7 +289,6 @@ class PromiseLauncher(object):
force
Set to True if force run promises without check their periodicity
"""
self.dry_run = dry_run
self.__config = {
'promise-timeout': 20,
......@@ -731,6 +730,17 @@ class PromiseLauncher(object):
success = 0
if os.path.exists(self.promise_folder) and os.path.isdir(self.promise_folder):
for promise_name in os.listdir(self.promise_folder):
for suffix in ['.pyc', '.pyo']:
if promise_name.endswith(suffix):
promise_path = os.path.join(self.promise_folder, promise_name)
if not os.path.exists(promise_path[:-1]):
try:
os.unlink(promise_path)
except Exception as e:
self.logger.warning('Failed to remove %r because of %s', promise_path, e)
else:
self.logger.debug('Removed stale %r', promise_path)
if promise_name.startswith('__init__') or \
not promise_name.endswith('.py'):
continue
......
......@@ -1576,6 +1576,18 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
self.assertEqual(result.item.hasFailed(), False)
self.assertTrue(isinstance(result.item.date, datetime))
def test_promise_cleanup_plugin_dir(self):
stale_pyc = os.path.join(self.plugin_dir, 'stale.pyc')
with open(stale_pyc, 'w') as fh:
fh.write('')
stale_pyo = os.path.join(self.plugin_dir, 'stale.pyo')
with open(stale_pyo, 'w') as fh:
fh.write('')
self.initialisePromise()
self.launcher.run()
self.assertFalse(os.path.exists(stale_pyc))
self.assertFalse(os.path.exists(stale_pyo))
def test_promise_anomaly_disabled(self):
self.initialisePromise()
promise_process = self.createPromiseProcess()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment