Commit 687beaae authored by Łukasz Nowak's avatar Łukasz Nowak

monitor: Cleanup stale history.json files

parent c163275d
...@@ -123,6 +123,21 @@ def generateMonitoringData(config, public_folder, private_folder, public_url, ...@@ -123,6 +123,21 @@ def generateMonitoringData(config, public_folder, private_folder, public_url,
except ValueError: except ValueError:
pass pass
# clean up stale history files
expected_history_json_name_list = [
os.path.basename(q).replace('status.json', 'history.json') for q in file_list]
cleanup_history_json_path_list = []
for history_json_name in [q for q in os.listdir(public_folder) if q.endswith('history.json')]:
if history_json_name not in expected_history_json_name_list:
cleanup_history_json_path_list.append(os.path.join(public_folder, history_json_name))
for cleanup_path in cleanup_history_json_path_list:
try:
os.unlink(cleanup_path)
except Exception:
print('ERROR: Failed to remove stale %s' % (cleanup_path,))
else:
print('OK: Removed stale %s' % (cleanup_path,))
for file in file_list: for file in file_list:
try: try:
with open(file, 'r') as temp_file: with open(file, 'r') as temp_file:
......
...@@ -166,8 +166,22 @@ exit %(code)s ...@@ -166,8 +166,22 @@ exit %(code)s
self.assertTrue(os.path.exists(os.path.join(self.output_dir, 'promise_4.status.json'))) self.assertTrue(os.path.exists(os.path.join(self.output_dir, 'promise_4.status.json')))
os.symlink(self.output_dir, '%s/public/promise' % self.base_dir) os.symlink(self.output_dir, '%s/public/promise' % self.base_dir)
# create files for cleanup
must_stay_public = os.path.join(self.public_dir, 'must_stay')
must_unlink_public = os.path.join(self.public_dir, 'must_unlink.history.json')
for f in [must_stay_public, must_unlink_public]:
with open(f, 'w') as fh:
fh.write('data')
# generate instance state files # generate instance state files
document_list_file = os.path.join(self.public_dir, '_document_list')
with open(document_list_file, 'a+') as fh:
fh.write('must_unlink.history')
globalstate.run(self.monitor_config_file) globalstate.run(self.monitor_config_file)
with open(document_list_file) as fh:
self.assertNotIn('must_unlink.history', fh.read())
self.assertTrue(os.path.exists(must_stay_public))
self.assertFalse(os.path.exists(must_unlink_public))
self.assertTrue(os.path.exists(os.path.join(self.public_dir, 'feed'))) self.assertTrue(os.path.exists(os.path.join(self.public_dir, 'feed')))
self.assertTrue(os.path.exists(os.path.join(self.public_dir, 'monitor.global.json'))) self.assertTrue(os.path.exists(os.path.join(self.public_dir, 'monitor.global.json')))
self.assertTrue(os.path.exists(os.path.join(self.private_dir, 'monitor.global.json'))) self.assertTrue(os.path.exists(os.path.join(self.private_dir, 'monitor.global.json')))
......
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