Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reana-admin: fix setting storage quota for users after global default… #628

Merged

Conversation

DaanRosendal
Copy link
Member

Consideration: the code assumes a default quota limit of zero. This assumption can lead to unexpected behaviour for admins when they change their default quota limit from a previously defined value to a new one. This is because any previously set default limits will be treated as custom limits and thus won't be automatically updated to match the new default limit.

I tested several scenarios:

Single User Scenarios

Scenario CPU Limit Disk Limit Outcome
1 0 Custom ✅ CPU updated to default
2 Custom 0 ✅ Disk updated to default
3 0 0 ✅ Disk and CPU updated to default

Multiple Users Scenarios

Scenario Outcome
1. Multiple Users (No Custom Quota Limits, all limits = 0) ✅ All updated to default
2. Multiple Users (All default Quota Limits) ✅ None updated
3. Multiple Users (All custom Quota Limits) ✅ None updated
4. CPU: 0, Disk: Custom (All Users) ✅ CPU updated for all users
5. CPU: Custom, Disk: 0 (All Users) ✅ Disk updated for all users
6. User 1: CPU: 0 for CPU and disk, User 2: Custom, User 3: Default ✅ User 1 updated to default

Closes #625

@codecov
Copy link

codecov bot commented Sep 16, 2023

Codecov Report

Merging #628 (7e84d56) into master (a339846) will increase coverage by 0.01%.
The diff coverage is 38.46%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #628      +/-   ##
==========================================
+ Coverage   59.48%   59.50%   +0.01%     
==========================================
  Files          32       32              
  Lines        3283     3289       +6     
==========================================
+ Hits         1953     1957       +4     
- Misses       1330     1332       +2     
Files Coverage Δ
reana_server/reana_admin/cli.py 51.91% <38.46%> (+0.18%) ⬆️

@DaanRosendal DaanRosendal force-pushed the fix-setting-default-quota-limit branch 3 times, most recently from 92dee0a to b71fe57 Compare September 21, 2023 10:39
emails=[user.email],
resource_name=resource.name,
resource_type=resource.type_.name,
limit=DEFAULT_QUOTA_LIMITS.get(resource.type_.name),
Copy link
Member

Choose a reason for hiding this comment

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

Works nicely, but perhaps we should check whether the setting is actually needed here, because otherwise some unnecessary operations would be called:

Quota limit 0 for 'cpu (processing time)' successfully set to users ['[email protected]'].                                       │
Quota limit 0 for 'cpu (processing time)' successfully set to users ['[email protected]'].

This populates the table with zeros which may not be necessary. (Even though later upgrade to a real value would well.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a check so an update is only performed when a custom default limit has been set (default limit != 0). The table is populated by zeros anyway, but it's nice to keep the output clean and not perform any unnecessary actions like you said.

check_interactive_sessions,
check_workflows,
Copy link
Member

Choose a reason for hiding this comment

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

We can sync in the team about using common import sorting technique across editors.

@@ -968,3 +970,33 @@ def test_check_workspaces(
if workflow:
assert len(result.errors) == 2
assert any(workflow.workspace_path in str(error) for error in result.errors)


def test_quota_set_default_limits_with_user_with_custom_limits(default_user, session):
Copy link
Member

Choose a reason for hiding this comment

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

You can squash the test commit together with the feature commit. It's nice if features are coming with tests in the same atomic unit. Helps to make sure things work already from the start.

(And while squashing, you may want to restrict the commit log message line length.)

Copy link
Member

Choose a reason for hiding this comment

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

Cosmetics: "_with_user_with_custom_limits" might be better said "for_users_with_custom_limits".

Copy link
Member Author

Choose a reason for hiding this comment

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

Noted and done!

@DaanRosendal DaanRosendal force-pushed the fix-setting-default-quota-limit branch 5 times, most recently from 47d735f to e7fd11d Compare September 26, 2023 09:55
This commit fixes a bug in the reana-admin CLI command
``quota-set-default-limits`` that prevented admins from retroactively
setting a default quota limit for all existing users who do not have a
custom quota limit set. Specifically, the bug was caused by the fact
that the code assumed that all users who do not have a custom quota
limit set have a quota limit of ``null``. This assumption is incorrect
because when there is no default global quota limit set, each user's
initial quota limit is set to zero, not ``null``.

Note that any previously set user limits, either via old defaults or via
custom settings, will be kept during the upgrade, and won't be
automatically updated to match the new default limit value.

Closes reanahub#625
@tiborsimko tiborsimko merged commit 7e84d56 into reanahub:master Sep 26, 2023
11 checks passed
@DaanRosendal DaanRosendal deleted the fix-setting-default-quota-limit branch September 26, 2023 11:41
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.

reana-admin: fix setting storage quota for users after global default updates
2 participants