Skip to content

Commit 23099b2

Browse files
committed
CSCDESTINCLIMADT-794: Force the function get_in_queue_grouped_id to return a list.
- Added mypy types - Added unit and integration tests - Changed the order at which ``JobList.save_wrappers`` is called in ``autosubmit/autosubmit.py`` - Added docstrings, and fixed linter errors (to debug/see code execution)
1 parent 3c0c1e5 commit 23099b2

40 files changed

+1988
-1567
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
**Bug fixes:**
44

55
- Fixed issue with the verification of dirty Git local repositories in operational experiments #2446
6+
- Fixed "Unexpected error: 'list' object has no attribute 'status'" when running experiments #2463
67

78
**Enhancements:**
89

autosubmit/autosubmit.py

Lines changed: 490 additions & 533 deletions
Large diffs are not rendered by default.

autosubmit/config/configcommon.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,14 +1594,14 @@ def check_wrapper_conf(self, wrappers=None, no_log=False):
15941594
if 'horizontal' in self.get_wrapper_type(wrapper_values):
15951595
if not self.experiment_data["PLATFORMS"][platform_name].get('PROCESSORS_PER_NODE', None):
15961596
self.wrong_config["WRAPPERS"] += [
1597-
[wrapper_name, "PROCESSORS_PER_NODE no exist in the horizontal-wrapper platform"]]
1597+
[wrapper_name, "PROCESSORS_PER_NODE does not exist in the horizontal-wrapper platform"]]
15981598
if not self.experiment_data["PLATFORMS"][platform_name].get('MAX_PROCESSORS', ""):
15991599
self.wrong_config["WRAPPERS"] += [[wrapper_name,
1600-
"MAX_PROCESSORS no exist in the horizontal-wrapper platform"]]
1600+
"MAX_PROCESSORS does not exist in the horizontal-wrapper platform"]]
16011601
if 'vertical' in self.get_wrapper_type(wrapper_values):
16021602
if not self.experiment_data.get("PLATFORMS", {}).get(platform_name, {}).get('MAX_WALLCLOCK', ""):
16031603
self.wrong_config["WRAPPERS"] += [[wrapper_name,
1604-
"MAX_WALLCLOCK no exist in the vertical-wrapper platform"]]
1604+
"MAX_WALLCLOCK does not exist in the vertical-wrapper platform"]]
16051605
if "WRAPPERS" not in self.wrong_config:
16061606
if not no_log:
16071607
Log.result('wrappers OK')
@@ -2558,6 +2558,8 @@ def get_remote_dependencies(self) -> str:
25582558
"""
25592559
# Disabled, forced to "false" not working anymore in newer slurm versions.
25602560
# return str(self.get_section(['CONFIG', 'PRESUBMISSION'], "false")).lower()
2561+
# FIXME: deprecate and/or remove PRESUBMISSION as it's not working on Slurm now?
2562+
# https://github.com/BSC-ES/autosubmit/issues/2548
25612563
return "false"
25622564

25632565
def get_wrapper_type(self, wrapper=None) -> Optional[str]:

autosubmit/experiment/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2015-2025 Earth Sciences Department, BSC-CNS
2+
#
3+
# This file is part of Autosubmit.
4+
#
5+
# Autosubmit is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# Autosubmit is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with Autosubmit. If not, see <http://www.gnu.org/licenses/>.
17+
18+
"""Code to manage Autosubmit experiments."""

autosubmit/experiment/detail_updater.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
31
# Copyright 2015-2025 Earth Sciences Department, BSC-CNS
42
#
53
# This file is part of Autosubmit.
@@ -19,13 +17,13 @@
1917

2018
import datetime
2119
import pwd
22-
from pathlib import Path
2320
import sqlite3
24-
from autosubmit.database.db_common import get_experiment_id
25-
from autosubmit.config.configcommon import AutosubmitConfig
21+
from pathlib import Path
22+
2623
from autosubmit.config.basicconfig import BasicConfig
24+
from autosubmit.config.configcommon import AutosubmitConfig
2725
from autosubmit.config.yamlparser import YAMLParserFactory
28-
26+
from autosubmit.database.db_common import get_experiment_id
2927

3028
LOCAL_TZ = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo
3129

autosubmit/experiment/experiment_common.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717

1818
"""Module containing functions to manage autosubmit's experiments."""
1919

20+
import os
21+
import pwd
2022
import string
23+
from pathlib import Path
24+
from typing import Optional
2125

26+
from autosubmit.config.basicconfig import BasicConfig
2227
from autosubmit.database import db_common
2328
from autosubmit.log.log import Log, AutosubmitCritical
2429

@@ -109,7 +114,6 @@ def copy_experiment(experiment_id, description, version, test=False, operational
109114
f"as a new experiment in the db: {e}", 7011) from e
110115

111116

112-
113117
def next_experiment_id(current_id):
114118
"""
115119
Get next experiment identifier
@@ -184,3 +188,31 @@ def base36decode(number):
184188
:rtype: int
185189
"""
186190
return int(number, 36)
191+
192+
193+
def check_ownership(expid, raise_error=False) -> tuple[bool, bool, Optional[str]]:
194+
"""Check if the user owns and if it is eadmin.
195+
196+
:return: the owner, eadmin, and current_owner
197+
"""
198+
current_owner: Optional[str] = None
199+
current_owner_id = Path(BasicConfig.LOCAL_ROOT_DIR, expid).stat().st_uid
200+
try:
201+
current_owner = pwd.getpwuid(current_owner_id).pw_name
202+
except (TypeError, KeyError) as e:
203+
Log.warning(f"Current owner of experiment {expid} could not be retrieved. The owner is no longer in the "
204+
f"system database: {str(e)}")
205+
206+
eadmin: bool = False
207+
admin_user = "eadmin" # to be improved in #944
208+
current_user_id = os.getuid()
209+
try:
210+
eadmin = current_user_id == pwd.getpwnam(admin_user).pw_uid
211+
except Exception as e:
212+
Log.info(f"Autosubmit admin user: {admin_user} is not set: {str(e)}")
213+
214+
owner: bool = current_owner_id == current_user_id
215+
if not owner and raise_error:
216+
raise AutosubmitCritical(f"You don't own the experiment {expid}.", 7012)
217+
218+
return owner, eadmin, current_owner

autosubmit/helpers/processes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ def _match_autosubmit_cmdline(cmdline: List[str], command='run', expid: Optional
9898
>>> _match_autosubmit_cmdline(['autosubmit', 'running', 'a000'])
9999
100100
>>> _match_autosubmit_cmdline(['autosubmit', 'a000', 'run'])
101-
#
102-
>>> _match_autosubmit_cmdline(['autosubmit', 'run', 'a001'])
103101
102+
>>> _match_autosubmit_cmdline(['autosubmit', 'run', 'a001'])
103+
'a001'
104104
>>> _match_autosubmit_cmdline(['autosubmit', 'run', 'experiment'])
105105
106106
>>> _match_autosubmit_cmdline(['autosubmit', 'run', 'a000'], 'create')

autosubmit/history/data_classes/job_data.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
# You should have received a copy of the GNU General Public License
1717
# along with Autosubmit. If not, see <http://www.gnu.org/licenses/>.
1818

19-
import collections
2019
import autosubmit.history.utils as HUtils
2120
import autosubmit.history.database_managers.database_models as Models
2221
from datetime import datetime, timedelta
23-
from json import dumps, loads
22+
from json import loads
2423

2524

2625
class JobData(object):

autosubmit/history/database_managers/experiment_status_db_manager.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import os
2121
import textwrap
22-
import time
2322
from typing import Protocol, cast
2423
from autosubmit.config.basicconfig import BasicConfig
2524
import autosubmit.history.utils as HUtils
@@ -56,14 +55,6 @@ def _validate_status_database(self):
5655
)
5756
self.execute_statement_on_dbfile(self._as_times_file_path, create_table_query)
5857

59-
def print_current_table(self):
60-
for experiment in self._get_experiment_status_content():
61-
print(experiment)
62-
if self.current_experiment_status_row:
63-
print(("Current Row:\n\t" + self.current_experiment_status_row.name + "\n\t" +
64-
str(self.current_experiment_status_row.exp_id) +
65-
"\n\t" + self.current_experiment_status_row.status))
66-
6758
def set_existing_experiment_status_as_running(self, expid):
6859
""" Set the experiment_status row as running. """
6960
self.update_exp_status(expid, Models.RunningStatus.RUNNING)
@@ -144,8 +135,6 @@ def delete_exp_status(self, expid):
144135

145136

146137
class ExperimentStatusDatabaseManager(Protocol):
147-
def print_current_table(self): ...
148-
149138
def is_running(self, time_condition=600): ...
150139

151140
def set_existing_experiment_status_as_running(self, expid): ...

0 commit comments

Comments
 (0)