Skip to content

Commit

Permalink
tools: cron: Deep copy a config loaded as module
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
piotrnarajowski authored and mkasenberg committed Aug 14, 2024
1 parent 73e8b0a commit 535ea90
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions autoptsclient_bot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python

import copy
#
# auto-pts - The Bluetooth PTS Automation Framework
#
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tools/cron/autopts_bisect.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
If last_bad_commit is empty, then takes HEAD commit.
"""

import copy
import importlib
import os
import re
Expand Down Expand Up @@ -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=''):
Expand Down
2 changes: 1 addition & 1 deletion tools/cron/autopts_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down
3 changes: 2 additions & 1 deletion tools/cron/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
$ eval `ssh-agent`
$ ssh-add path/to/id_rsa
"""
import copy
import logging
import os
import re
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 535ea90

Please sign in to comment.