From 535ea901b74486faf8595798a5f7f31d341917e4 Mon Sep 17 00:00:00 2001 From: Piotr Narajowski Date: Mon, 12 Aug 2024 15:06:45 +0200 Subject: [PATCH] tools: cron: Deep copy a config loaded as module A .py file loaded as a module is cached until it is explicitly removed from sys.modules. So subsequent attempts to load the file only return a reference to the existing module-dictionary. So we need to deep-copy a config.py to prevent overwriting its original values and reuse it e.g. in subsequent PR jobs. --- autoptsclient_bot.py | 4 ++-- tools/cron/autopts_bisect.py | 4 ++-- tools/cron/autopts_cron.py | 2 +- tools/cron/common.py | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/autoptsclient_bot.py b/autoptsclient_bot.py index 9a33adde15..e135e43d8f 100755 --- a/autoptsclient_bot.py +++ b/autoptsclient_bot.py @@ -1,5 +1,5 @@ #!/usr/bin/env python - +import copy # # auto-pts - The Bluetooth PTS Automation Framework # @@ -59,7 +59,7 @@ def import_bot_projects(): return None, config_path module = load_module_from_path(config_path) - return getattr(module, "BotProjects", None), config_path + return copy.deepcopy(getattr(module, "BotProjects", None)), config_path def import_bot_module(project): diff --git a/tools/cron/autopts_bisect.py b/tools/cron/autopts_bisect.py index 411f216de7..5374eb4dff 100644 --- a/tools/cron/autopts_bisect.py +++ b/tools/cron/autopts_bisect.py @@ -24,7 +24,7 @@ If last_bad_commit is empty, then takes HEAD commit. """ - +import copy import importlib import os import re @@ -110,7 +110,7 @@ def load_cfg(cfg): raise Exception('{} does not exists!'.format(cfg_path)) mod = load_module_from_path(cfg_path) - return mod.BotProjects[0], cfg_path + return copy.deepcopy(mod.BotProjects[0]), cfg_path def bisect(cfg, test_case, good_commit, bad_commit=''): diff --git a/tools/cron/autopts_cron.py b/tools/cron/autopts_cron.py index ff536b688d..4fd55f3d56 100644 --- a/tools/cron/autopts_cron.py +++ b/tools/cron/autopts_cron.py @@ -381,7 +381,7 @@ def sigint_handler(sig, frame): args = CliParser().parse_args() global cron_config - cron_config = load_module_from_path(args.config_path) + cron_config = copy.deepcopy(load_module_from_path(args.config_path)) if not cron_config: sys.exit(f'Could not load cron config from path {args.config_path}') diff --git a/tools/cron/common.py b/tools/cron/common.py index ec7795cecd..241afe0385 100644 --- a/tools/cron/common.py +++ b/tools/cron/common.py @@ -24,6 +24,7 @@ $ eval `ssh-agent` $ ssh-add path/to/id_rsa """ +import copy import logging import os import re @@ -233,7 +234,7 @@ def load_config(cfg): if not mod: raise Exception(f'Could not load the config {cfg}') - return mod.BotProjects[0] + return copy.deepcopy(mod.BotProjects[0]) def find_workspace_in_tree(tree_path, workspace, init_depth=4):