Skip to content

Commit

Permalink
Merge pull request #171 from mila-iqia/update-mila-account-name-for-user
Browse files Browse the repository at this point in the history
Rename mila_account_username as mila_cluster_username
  • Loading branch information
soline-b authored Oct 12, 2023
2 parents 48c1bad + f9c9fe3 commit 517ce47
Show file tree
Hide file tree
Showing 24 changed files with 76 additions and 76 deletions.
6 changes: 3 additions & 3 deletions clockwork_web/about_queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ when it comes to being set to 0 to represent a missing value.
There are three kinds of accounts that are relevant in our ecosystem.
We try to include them in the following fields:

- mila_account_username
- mila_cluster_username
- cc_account_username
- mila_email_username

Expand All @@ -73,15 +73,15 @@ When `query_filter` has the field "user", we are going to ignore it if
- it's "*".

Otherwise, we will try to match that "user" value against all of the four
fields "mila_account_username", "cc_account_username", "mila_email_username",
fields "mila_cluster_username", "cc_account_username", "mila_email_username",
"mila_user_account", provided they exist. The nice thing about it is that
we don't need to test for the presence of the fields using '$exists', because
we're using an OR clause with the four tests.

## what this means for mongodb

```python
{'$or': [ {'mila_account_username': user},
{'$or': [ {'mila_cluster_username': user},
{'cc_account_username': user},
{'mila_email_username': user}
]}
Expand Down
2 changes: 1 addition & 1 deletion clockwork_web/core/clusters_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_account_fields():
example of the returned dictionary:
{
"cc_account_username": ["beluga", "cedar", "graham", "narval"],
"mila_account_username": ["mila"],
"mila_cluster_username": ["mila"],
"test_cluster_username": ["test_cluster"]
}
"""
Expand Down
8 changes: 4 additions & 4 deletions clockwork_web/core/jobs_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,12 @@ def get_jobs_properties_list_per_page():
# """
#
# # create a table with one entry for each entry
# mila_account_usernames = set(e["cw"]["mila_account_username"] for e in L_entries)
# mila_cluster_usernames = set(e["cw"]["mila_cluster_username"] for e in L_entries)
# DD_counts = dict(
# (mila_account_username, {"PENDING": 0, "RUNNING": 0, "COMPLETED": 0, "ERROR": 0})
# for mila_account_username in mila_account_usernames
# (mila_cluster_username, {"PENDING": 0, "RUNNING": 0, "COMPLETED": 0, "ERROR": 0})
# for mila_cluster_username in mila_cluster_usernames
# )
# for e in L_entries:
# DD_counts[e["mila_account_username"]][mapping[e["job_state"]]] += 1
# DD_counts[e["mila_cluster_username"]][mapping[e["job_state"]]] += 1
#
# return DD_counts
10 changes: 5 additions & 5 deletions clockwork_web/core/users_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def get_available_clusters_from_user_dict(D_user):
"mila_email_username": "[email protected]",
"status": "enabled",
"clockwork_api_key": "000aaa00",
"mila_account_username": "milauser00",
"mila_cluster_username": "milauser00",
"cc_account_username": "ccuser00",
"cc_account_update_key": null,
"web_settings": {
Expand All @@ -338,19 +338,19 @@ def get_available_clusters_from_user_dict(D_user):
}
}
In this example, the fields we are interested in are the "mila_account_username"
In this example, the fields we are interested in are the "mila_cluster_username"
and the "cc_account_username". They are referred in the account fields (one
of the two input sources mentioned previously). The latter is as follows:
{
"cc_account_username": ["beluga", "cedar", "graham", "narval"],
"mila_account_username": ["mila"],
"mila_cluster_username": ["mila"],
"test_cluster_username": ["test_cluster"]
}
and is built from the cluster data provided by the configuration file.
Considering this example, the user "[email protected]" has access to the clusters:
"beluga", "cedar", "graham" and "narval" because of its field "cc_account_username",
and "mila" through the "mila_account_username". However, it does not have access to
and "mila" through the "mila_cluster_username". However, it does not have access to
the cluster "test_cluster" because its user dictionary does not contain a field
"test_cluster_username".
Expand Down Expand Up @@ -393,7 +393,7 @@ def get_available_clusters_from_db(mila_email_username):
"mila_email_username": "[email protected]",
"status": "enabled",
"clockwork_api_key": "000aaa00",
"mila_account_username": "milauser00",
"mila_cluster_username": "milauser00",
"cc_account_username": "ccuser00",
"cc_account_update_key": null,
"web_settings": {
Expand Down
2 changes: 1 addition & 1 deletion clockwork_web/rest_routes/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def route_api_v1_jobs_user_dict_update():
# then we refuse the update and return an error
# that describes the problem.

for key in ["mila_email_username", "mila_account_username", "cc_account_username"]:
for key in ["mila_email_username", "mila_cluster_username", "cc_account_username"]:
# Be as strict as possible here. If the job entry
# contains any of the three types of usernames (and it's not `None`),
# than it must be matched against that of the user
Expand Down
8 changes: 4 additions & 4 deletions clockwork_web/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(
status,
admin_access=False,
clockwork_api_key=None,
mila_account_username=None,
mila_cluster_username=None,
cc_account_username=None,
cc_account_update_key=None,
web_settings={},
Expand All @@ -77,7 +77,7 @@ def boolean(value):
self.status = status
self.admin_access = boolean(admin_access)
self.clockwork_api_key = clockwork_api_key
self.mila_account_username = mila_account_username
self.mila_cluster_username = mila_cluster_username
self.cc_account_username = cc_account_username
self.cc_account_update_key = cc_account_update_key
for k in ["nbr_items_per_page", "dark_mode", "language"]:
Expand Down Expand Up @@ -138,7 +138,7 @@ def get(mila_email_username: str):
status=e["status"],
admin_access=e.get("admin_access", False),
clockwork_api_key=e["clockwork_api_key"],
mila_account_username=e["mila_account_username"],
mila_cluster_username=e["mila_cluster_username"],
cc_account_username=e["cc_account_username"],
cc_account_update_key=e.get("cc_account_update_key", ""),
web_settings=e.get("web_settings", {}),
Expand Down Expand Up @@ -330,7 +330,7 @@ def __init__(self):
self.admin_access = False
self.clockwork_api_key = "deadbeef"
self.cc_account_username = None
self.mila_account_username = None
self.mila_cluster_username = None
self.cc_account_update_key = None
self.web_settings = get_default_web_settings_values()
self.web_settings["language"] = None
Expand Down
2 changes: 1 addition & 1 deletion clockwork_web_test/test_browser_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def test_cc_portal(client, fake_data):
"""
# Choose a user who have access to all the clusters
user_dict = fake_data["users"][0]
assert user_dict["mila_account_username"] is not None
assert user_dict["mila_cluster_username"] is not None
assert user_dict["cc_account_username"] is not None

# Log in to Clockwork as this user
Expand Down
2 changes: 1 addition & 1 deletion clockwork_web_test/test_browser_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_status_nb_users(client, fake_data):
"""
# Choose a user who have access to all the clusters
user_dict = fake_data["users"][0]
assert user_dict["mila_account_username"] is not None
assert user_dict["mila_cluster_username"] is not None
assert user_dict["cc_account_username"] is not None

# Log in to Clockwork as this user
Expand Down
4 changes: 2 additions & 2 deletions clockwork_web_test/test_browser_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def test_users_one_success(client, fake_data):

# Check if the response is the expected one
assert response.status_code == 200 # Success
if user["mila_account_username"]:
assert "{}".format(user["mila_account_username"]) in response.get_data(
if user["mila_cluster_username"]:
assert "{}".format(user["mila_cluster_username"]) in response.get_data(
as_text=True
)
if user["cc_account_username"]:
Expand Down
2 changes: 1 addition & 1 deletion clockwork_web_test/test_core_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_get_account_fields():

D_expected_account_fields = {
"cc_account_username": ["beluga", "cedar", "graham", "narval"],
"mila_account_username": ["mila"],
"mila_cluster_username": ["mila"],
}

D_retrieved_account_fields = get_account_fields()
Expand Down
4 changes: 2 additions & 2 deletions clockwork_web_test/test_core_clusters_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_get_all_clusters():
"mila": {
"organization": "Mila",
"timezone": ZoneInfo(key="America/Montreal"),
"account_field": "mila_account_username",
"account_field": "mila_cluster_username",
"allocations": "*",
"nbr_cpus": 4860, # Number of CPUs on this cluster
"nbr_gpus": 532, # Number of GPUs on this cluster
Expand Down Expand Up @@ -119,7 +119,7 @@ def test_get_account_fields():
"""
expected_clusters_for_account_fields = {
"cc_account_username": ["beluga", "cedar", "graham", "narval"],
"mila_account_username": ["mila"],
"mila_cluster_username": ["mila"],
}

retrieved_clusters_for_accound_fields = get_account_fields()
Expand Down
6 changes: 3 additions & 3 deletions clockwork_web_test/test_core_users_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ def test_get_users_one_known_user(app, fake_data):
"mila_email_username": "[email protected]",
"status": "enabled",
"clockwork_api_key": "000aaa01",
"mila_account_username": "milauser1",
"mila_cluster_username": "milauser1",
"cc_account_username": "ccuser1",
"cc_account_update_key": None,
"web_settings": {"nbr_items_per_page": 40, "dark_mode": False},
Expand All @@ -1247,7 +1247,7 @@ def test_get_users_one_known_user(app, fake_data):
"mila_email_username": "[email protected]",
"status": "enabled",
"clockwork_api_key": "000aaa01",
"mila_account_username": "milauser1",
"mila_cluster_username": "milauser1",
"cc_account_username": None,
"cc_account_update_key": None,
"web_settings": {"nbr_items_per_page": 40, "dark_mode": False},
Expand All @@ -1263,7 +1263,7 @@ def test_get_users_one_known_user(app, fake_data):
"mila_email_username": "[email protected]",
"status": "enabled",
"clockwork_api_key": "000aaa01",
"mila_account_username": None,
"mila_cluster_username": None,
"cc_account_username": "ccuser1",
"cc_account_update_key": None,
"web_settings": {"nbr_items_per_page": 40, "dark_mode": False},
Expand Down
8 changes: 4 additions & 4 deletions clockwork_web_test/test_rest_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_jobs_user_dict_update_successful_update(
},
"cw": {
"cc_account_username": None,
"mila_account_username": None,
"mila_cluster_username": None,
"mila_email_username": None,
},
"user": {
Expand All @@ -191,10 +191,10 @@ def test_jobs_user_dict_update_successful_update(
)
elif cluster_name in ["mila"]:
if update_allowed:
D_job["cw"]["mila_account_username"] = D_user["mila_account_username"]
D_job["cw"]["mila_cluster_username"] = D_user["mila_cluster_username"]
else:
D_job["cw"]["mila_account_username"] = (
"NOT_" + D_user["mila_account_username"]
D_job["cw"]["mila_cluster_username"] = (
"NOT_" + D_user["mila_cluster_username"]
)
else:
raise Exception("You're not handling properly the cluster_name parameter.")
Expand Down
2 changes: 1 addition & 1 deletion docs/clockwork_dev_guide/slurm_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Jobs are stored in the database in the following format:
},
"cw": {
"cc_account_username": "ccuser02",
"mila_account_username": null,
"mila_cluster_username": null,
"mila_email_username": null
},
"user": {}
Expand Down
6 changes: 3 additions & 3 deletions docs/clockwork_user_guide/rest_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs
"cluster_name": "beluga"},
"cw": {
"cc_account_username": "ccuser01",
"mila_account_username": null,
"mila_cluster_username": null,
"mila_email_username": null},
"user": {}
},
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs
"slurm": {
"job_id": "233874",
"name": "somejobname_942640",
"mila_account_username": "milauser12",
"mila_cluster_username": "milauser12",
"uid": "10012",
"account": "mila",
"job_state": "RUNNING",
Expand All @@ -120,7 +120,7 @@ jobs
"cluster_name": "mila"},
"cw": {
"cc_account_username": null,
"mila_account_username": "milauser12",
"mila_cluster_username": "milauser12",
"mila_email_username": null},
"user": {}
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/import_users_from_sarc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def process_user(D_sarc_user):
user = {
"mila_email_username": D_sarc_user["mila"]["email"],
"display_name": D_sarc_user["mila_ldap"]["display_name"],
"mila_account_username": D_sarc_user["mila_ldap"]["mila_account_username"],
"mila_cluster_username": D_sarc_user["mila_ldap"]["mila_cluster_username"],
"mila_cluster_uid": D_sarc_user["mila_ldap"]["mila_cluster_uid"],
"mila_cluster_gid": D_sarc_user["mila_ldap"]["mila_cluster_gid"],
"status": "enabled" if D_sarc_user["mila"]["active"] else "disabled",
Expand Down
4 changes: 2 additions & 2 deletions scripts/produce_fake_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"status": "enabled",
"clockwork_api_key": "000aaa"
"cc_account_username": "ccuser040",
"mila_account_username": milauser040",
"mila_cluster_username": milauser040",
"cc_account_update_key": None
},
{ ... },
Expand Down Expand Up @@ -57,7 +57,7 @@ def gen_single_user(n):
"mila_email_username": "student%[email protected]" % n,
"status": status,
"clockwork_api_key": "000aaa%0.2d" % n,
"mila_account_username": "milauser%0.2d" % n,
"mila_cluster_username": "milauser%0.2d" % n,
"cc_account_username": cc_account_username,
"_extra": {
"mila": {
Expand Down
4 changes: 2 additions & 2 deletions scripts/read_mila_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def process_user(user_raw: dict) -> dict:
them to contain only one element at [0].
mail[0] -> mila_email_username (includes the "@mila.quebec")
posixUid[0] -> mila_account_username
posixUid[0] -> mila_cluster_username
uidNumber[0] -> mila_cluster_uid
gidNumber[0] -> mila_cluster_gid
displayName[0] -> display_name
Expand All @@ -253,7 +253,7 @@ def process_user(user_raw: dict) -> dict:
user = {
# include the suffix "@mila.quebec"
"mila_email_username": user_raw["mail"][0],
"mila_account_username": user_raw["posixUid"][0],
"mila_cluster_username": user_raw["posixUid"][0],
"mila_cluster_uid": user_raw["uidNumber"][0],
"mila_cluster_gid": user_raw["gidNumber"][0],
"display_name": user_raw["displayName"][0],
Expand Down
Loading

0 comments on commit 517ce47

Please sign in to comment.