Skip to content

Add a configuration registry and centralise where AutosubmitConfig is instantiated (avoid multiple copies/loads) - #3327

Open
kinow wants to merge 2 commits into
masterfrom
add-config-registry
Open

kinow wants to merge 2 commits into
masterfrom
add-config-registry

Conversation

@kinow

@kinow kinow commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Related to #3326

This pull request creates a central configuration registry. This works to give commands an easy way to retrieve a configuration object that may already have been loaded elsewhere.

By centralising the config, we are now able to confirm nowhere else basic_config or yaml_factory are modified. And since those arguments use the same value, in the future we can remove from the constructor list of parameters, simplifying function signature (lots of tests using it, so leaving for later to reduce the change here).

Added a second commit removing the indirect access to BasicConfig via AutosubmitConfig or other test classes. Now, the whole code accesses BasicConfig via its import + BasicConfig, and AutosubmitConfig's only dependency on BasicConfig is a call to .read() (which I'm not sure if it's really it's responsibility, but for a future issue), and accessing the attributes of the class.

Check List

  • I have read CONTRIBUTING.md.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • Applied any dependency changes to pyproject.toml.
  • Tests are included (or explain why tests are not needed).
  • Changelog entry included in CHANGELOG.md if this is a change that can affect users.
  • Documentation updated.
  • If this is a bug fix, PR should include a link to the issue (e.g. Closes #1234).

@kinow

kinow commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

After this pull request, the command-line parsing part of the code, in autosubmit.scripts will be able to preload configuration objects (one for create, for instance, or multiple for delete) and the subcommand code will be able to use the same object without having to create and reloading the YAML files.

There's still the bug that the mtime can be altered by AS when modifying MISC info, like last command used... thus, this is not "Closes" in the top-level description.

@kinow
kinow force-pushed the add-config-registry branch from 1663271 to 5a37871 Compare October 5, 2026 11:20
@kinow
kinow marked this pull request as draft October 5, 2026 11:20
@kinow
kinow force-pushed the add-config-registry branch 2 times, most recently from 670c8ac to 77a2008 Compare October 5, 2026 11:22
@kinow kinow changed the title Add a configuration registry. Add a configuration registry and centralise where AutosubmitConfig is instantiated Oct 5, 2026
@kinow kinow changed the title Add a configuration registry and centralise where AutosubmitConfig is instantiated Add a configuration registry and centralise where AutosubmitConfig is instantiated (avoid multiple copies/loads) Oct 5, 2026
@kinow kinow self-assigned this Oct 5, 2026
@kinow kinow added this to the 4.2.1 milestone Oct 5, 2026
@kinow
kinow force-pushed the add-config-registry branch 3 times, most recently from d032274 to 1a79f17 Compare October 7, 2026 09:28
Comment thread test/integration/conftest.py Outdated
basic_config.MAIL_FROM = 'notifier@localhost'
basic_config.SMTP_SERVER = f'127.0.0.1:{smtp_port}'
monkeypatch.setattr(BasicConfig, 'MAIL_FROM', 'notifier@localhost')
monkeypatch.setattr(BasicConfig, 'SMTP_SERVER', f'127.0.0.1:{smtp_port}')

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safer to use monkeypatch.

'FAILED': []
}
yield platform
local_root_dir.cleanup()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used.

basic_config.MAIL_FROM = 'notifier@localhost'
basic_config.SMTP_SERVER = f'127.0.0.1:{smtp_port}'
monkeypatch.setattr(BasicConfig, 'MAIL_FROM', 'notifier@localhost')
monkeypatch.setattr(BasicConfig, 'SMTP_SERVER', f'127.0.0.1:{smtp_port}')

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safer to use monkeypatch.

config_file = tmp_path / "autosubmitrc"
config_file.write_text(config_content)
os.environ = {'AUTOSUBMIT_CONFIGURATION': str(config_file)}
monkeypatch.setenv("AUTOSUBMIT_CONFIGURATION", str(config_file))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is safer, and avoids bugs. Running this test with others that access the env var AUTOSUBMIT_CONFIGURATION could result in unexpected issues (and that are hard to explain/understand).

f"base_{job_type.lower()}_{scheduler.lower()}.cmd")).read_text()
if not expected_data:
assert False, f"Could not find the expected data for {scheduler} and {job_type}"
pytest.fail(f"Could not find the expected data for {scheduler} and {job_type}")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing a SonarQube warning; PyCharm doesn't see this warning/error, interesting. asserting False also works... but probably better to use pytest.fail. Fixed that somewhere else here...

CONFIG_FILE_FOUND = False
DATABASE_BACKEND = "sqlite"
DATABASE_CONN_URL = ""
LOG_RECOVERY_TIMEOUT: int = 60 * 5

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not defined in __init__, but somewhere else, in a function. The constructor above is not needed either.

@kinow
kinow force-pushed the add-config-registry branch from a27aded to 0da64a4 Compare October 7, 2026 14:24
Comment thread test/unit/conftest.py
# expids a lot. This is because we do not really have experiments, it's a "fake" layer,
# and instead we only create a configuration instance here, and return it. Thus, the
# new instance is always created and used here, and not the configuration registry.
config = AutosubmitConfig(expid=expid)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just explaining why in the other conftest we have load_config, but not here.

@kinow
kinow force-pushed the add-config-registry branch 2 times, most recently from f8a3401 to 3a0ebdd Compare October 7, 2026 20:59
@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.33962% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.28%. Comparing base (b148ea1) to head (7d68a8c).

Files with missing lines Patch % Lines
autosubmit/experiment/manage.py 83.33% 1 Missing and 2 partials ⚠️
autosubmit/database/db_common.py 94.11% 1 Missing ⚠️
autosubmit/helpers/utils.py 0.00% 1 Missing ⚠️
autosubmit/workflow/manage.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3327      +/-   ##
==========================================
- Coverage   85.28%   85.28%   -0.01%     
==========================================
  Files         148      149       +1     
  Lines       22173    22171       -2     
  Branches     3934     3936       +2     
==========================================
- Hits        18911    18908       -3     
  Misses       2501     2501              
- Partials      761      762       +1     
Flag Coverage Δ
fast-tests 85.28% <94.33%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
autosubmit/config/basicconfig.py 90.96% <100.00%> (+0.58%) ⬆️
autosubmit/config/configcommon.py 86.06% <100.00%> (-0.02%) ⬇️
autosubmit/config/registry.py 100.00% <100.00%> (ø)
autosubmit/config/upgrade_scripts.py 94.96% <100.00%> (ø)
autosubmit/experiment/describe.py 100.00% <100.00%> (ø)
autosubmit/experiment/detail_updater.py 99.06% <100.00%> (-0.01%) ⬇️
autosubmit/job/manage.py 87.59% <100.00%> (-0.10%) ⬇️
autosubmit/job/notify.py 81.81% <ø> (-1.52%) ⬇️
autosubmit/notifications/cpmip_notifier.py 78.94% <ø> (-0.37%) ⬇️
autosubmit/notifications/mail_notifier.py 99.00% <100.00%> (-0.02%) ⬇️
... and 10 more

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

self.ignore_file_path = False
self.expid = expid
self.basic_config = basic_config
self.basic_config.read()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call is not needed.

The AutosubmitConfig class is created in @cli_function, in _cli_function.py. Before that, in _initialise.py, we make a call to BasicConfig.read().

That was done copying previous existing behaviour in autosubmit.py, but it was harder to see whether that was needed or not.

I've kept that call in _initialise.py, replaced the TODO asking if that was needed by a short comment explaining why we have that call there. And now when we get here, it' s on the assumption that BasicRead.read() was called (and other assumptions, like an existing working directory now, also system executables available, the required directories created, etc.).

dedent("""\
CONFIG:
SAFETYSLEEPTIME: 0
SAFETYSLEEPTIME: 3

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 3 instead of 0 as I noticed Slurm was suffering being hammered with SSH send_command calls. This should make our tests less brittle on GitHub Actions, as it will give Slurm some more time to process things, before getting a new SSH or Slurm command.

Comment thread test/conftest.py

session_mocker.patch('time.sleep', side_effect=my_sleep)


Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed as I noticed that the SSH server was getting a lot of requests every second 😶‍🌫️

I replaced two sleep calls in the last few months. I will chase other sleep calls in our tests, and try to remove them too. Our safety sleep time in the tests has been changed to three seconds. With that, I hope the tests with containers may finish sooner.

@kinow

kinow commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

I will try to add more tests to cover all configcommon.py and basicconfig.py. Will look into the missing coverage for the files updated, and then add the changelog.

@kinow
kinow requested a review from VindeeR October 8, 2026 13:46
@kinow
kinow marked this pull request as ready for review October 8, 2026 13:46
@kinow

kinow commented Oct 8, 2026 •

Copy link
Copy Markdown
Member Author

But maybe you can do a review, @VindeeR.

kinow added 2 commits October 8, 2026 19:45
The main goal with this is to centralise the creation of AutosubmitConfig
objects, and reduce the risk of re-loading the configuration
accidentally.
@kinow
kinow force-pushed the add-config-registry branch from bfb6860 to 7d68a8c Compare October 9, 2026 10:18
@kinow

kinow commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

Ok. This is a rabbit hole. @VindeeR I had a look at the coverage, and it's not very hard to fix one or two of the items pending here. They are simple, but I thought it'd still be worth adding the tests.

To do so, first I had to go around the AutosubmitConfig issues, especially type errors. So, I started fixing type errors, and adding docstrings. And the new commit got gigantic 😅

I've stashed it, and will push to another branch to fix mypy/docstrings and especially the type of parameters returned in AutosubmitConfig, so writing tests for those is a bit easier.

I've rebased, and left two commits only. The one adding a registry, and the other removing the link between AutosubmitConfig & BasicConfig, and updating tests (and some docstring/mypy 😶‍🌫️ ).

So from yesterday there shouldn't be any change, I believe, except for the rebase.

@kinow

kinow commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

For my future self: kinow/autosubmit@cc7d959

Your commit with the work-in-progress to improve coverage in autosubmit.config, and reduce mypy errors (remember to disable follow-imports).

@kinow kinow removed this from the 4.2.1 milestone Oct 9, 2026
@kinow kinow added this to the 4.2.0 milestone Oct 9, 2026
@kinow

kinow commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

72 files changed, but 20 are source, 1 pytest.ini and the rest are the tests updated due to changes in AutosubmitConfig constructor and to use monkeypatch instead of mock or other small test fixes.

I think it should be OK to include this one in 4.2.0 as it doesn't change any user-facing feature, only how configuration objects are handled internally.

Autosubmit is still loading the config twice, but it's because of the as_misc.yml mtime constantly changing (which is why the PR has "Related #..." and not "Closes #...").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant