Skip to content

Commit

Permalink
bot: Move stats files after bot run
Browse files Browse the repository at this point in the history
In backup mode, these files have to be moved/deleted to start fresh
bot start. Cron does this automatically, but without the cron, one had
to do it manually.
  • Loading branch information
mkasenberg committed Aug 26, 2024
1 parent 528a86f commit f5bb759
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
49 changes: 36 additions & 13 deletions autopts/bot/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,21 +281,27 @@ def bot_pre_cleanup(self):
"""Perform cleanup before test run
:return: None
"""
try:
files_to_save = [
self.file_paths['TMP_DIR'],
self.file_paths['IUT_LOGS_DIR'],
]
files_to_save = [
self.file_paths['TMP_DIR'],
self.file_paths['IUT_LOGS_DIR'],
]

save_dir = os.path.join(self.file_paths['OLD_LOGS_DIR'],
datetime.datetime.now().strftime("%Y_%m_%d_%H_%M"))
Path(save_dir).mkdir(parents=True, exist_ok=True)
save_dir = os.path.join(self.file_paths['OLD_LOGS_DIR'],
datetime.datetime.now().strftime("%Y_%m_%d_%H_%M"))
save_files(files_to_save, save_dir)

def bot_post_cleanup(self):
files_to_save = [
self.file_paths['ALL_STATS_RESULTS_XML_FILE'],
self.file_paths['TC_STATS_RESULTS_XML_FILE'],
self.file_paths['TEST_CASES_JSON_FILE'],
self.file_paths['ALL_STATS_JSON_FILE'],
self.file_paths['TC_STATS_JSON_FILE'],
self.file_paths['BOT_STATE_JSON_FILE'],
]

for file_path in files_to_save:
if os.path.exists(file_path):
shutil.move(file_path, os.path.join(save_dir, os.path.basename(file_path)))
except OSError as e:
pass
save_dir = self.file_paths['BOT_STATE_DIR']
save_files(files_to_save, save_dir)

def _yield_next_config(self):
limit_counter = 0
Expand Down Expand Up @@ -548,6 +554,8 @@ def start(self, args=None):
if 'mail' in self.bot_config:
self.send_email(report_data)

self.bot_post_cleanup()

print("Done")

def run_tests(self):
Expand Down Expand Up @@ -943,3 +951,18 @@ def load_module_from_path(cfg):
sys.path.remove(config_dirname)

return module


def save_files(files_to_save, save_dir: str):
try:
for file_path in files_to_save:
if os.path.exists(file_path):
Path(save_dir).mkdir(parents=True, exist_ok=True)
break

for file_path in files_to_save:
if os.path.exists(file_path):
dst_file_path = os.path.join(save_dir, os.path.basename(file_path))
shutil.move(file_path, dst_file_path)
except OSError as e:
pass
1 change: 1 addition & 0 deletions autopts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def generate_file_paths(file_paths=None, autopts_root_dir=AUTOPTS_ROOT_DIR):
'TC_STATS_JSON_FILE': os.path.join(FILE_PATHS['TMP_DIR'], 'tc_stats.json'),
'TEST_CASE_DB_FILE': os.path.join(FILE_PATHS['TMP_DIR'], 'TestCase.db'),
'BOT_STATE_JSON_FILE': os.path.join(FILE_PATHS['TMP_DIR'], 'bot_state.json'),
'BOT_STATE_DIR': os.path.join(FILE_PATHS['TMP_DIR'], 'final_state'),
'REPORT_README_MD_FILE': os.path.join(FILE_PATHS['TMP_DIR'], 'README.md'),
'REPORT_DIR': os.path.join(FILE_PATHS['TMP_DIR'], 'autopts_report'),
'IUT_LOGS_DIR': os.path.join(autopts_root_dir, 'logs'),
Expand Down

0 comments on commit f5bb759

Please sign in to comment.