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

feat: track scratch and work separately on tier1 (#177) #179

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 66 additions & 18 deletions usersec/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,24 @@
HpcUserCreateRequest,
)

DEFAULT_USER_RESOURCES = {"tier1": 1, "tier2_mirrored": 0, "tier2_unmirrored": 0}
DEFAULT_GROUP_RESOURCES = {"tier1": 1, "tier2_mirrored": 0, "tier2_unmirrored": 0}
DEFAULT_PROJECT_RESOURCES = {"tier1": 1, "tier2_mirrored": 0, "tier2_unmirrored": 0}
DEFAULT_USER_RESOURCES = {
"tier1_scratch": 1,
"tier1_work": 1,
"tier2_mirrored": 0,
"tier2_unmirrored": 0,
}
DEFAULT_GROUP_RESOURCES = {
"tier1_scratch": 1,
"tier1_work": 1,
"tier2_mirrored": 0,
"tier2_unmirrored": 0,
}
DEFAULT_PROJECT_RESOURCES = {
"tier1_scratch": 1,
"tier1_work": 1,
"tier2_mirrored": 0,
"tier2_unmirrored": 0,
}


class HpcGroupCreateRequestForm(forms.ModelForm):
Expand Down Expand Up @@ -100,16 +115,27 @@ def __init__(self, *args, user, group, **kwargs):
)

# Add fields for storage. Will be merged into resources_requested field.
self.fields["tier1"] = forms.IntegerField(
self.fields["tier1_scratch"] = forms.IntegerField(
required=True,
help_text=(
"Amount of storage on the fast primary ('tier 1') storage that can be used with parallel access "
"for computation."
"Amount of scratch storage on the fast primary ('tier 1') storage that can be used "
"with parallel access for computation."
),
label="Fast Active Storage [TB]",
)
self.fields["tier1"].initial = group.resources_requested["tier1"]
self.fields["tier1"].widget.attrs["class"] = "form-control mergeToJson"
self.fields["tier1_scratch"].initial = group.resources_requested["tier1_scratch"]
self.fields["tier1_scratch"].widget.attrs["class"] = "form-control mergeToJson"

self.fields["tier1_work"] = forms.IntegerField(
required=True,
help_text=(
"Amount of work storage on the fast primary ('tier 1') storage that can be used "
"with parallel access for computation."
),
label="Fast Active Storage [TB]",
)
self.fields["tier1_work"].initial = group.resources_requested["tier1_work"]
self.fields["tier1_work"].widget.attrs["class"] = "form-control mergeToJson"

self.fields["tier2_unmirrored"] = forms.IntegerField(
required=True,
Expand Down Expand Up @@ -296,16 +322,27 @@ def __init__(self, *args, user=None, group=None, **kwargs):
self.fields["members_dropdown"].widget.attrs["class"] = "form-control"

# Add fields for storage. Will be merged into resources_requested field.
self.fields["tier1"] = forms.IntegerField(
self.fields["tier1_scratch"] = forms.IntegerField(
required=True,
help_text=(
"Amount of scratch storage on the fast primary ('tier 1') storage that can be used "
"with parallel access for computation."
),
label="Fast Active Storage [TB]",
)
self.fields["tier1_scratch"].initial = DEFAULT_PROJECT_RESOURCES["tier1_scratch"]
self.fields["tier1_scratch"].widget.attrs["class"] = "form-control mergeToJson"

self.fields["tier1_work"] = forms.IntegerField(
required=True,
help_text=(
"Amount of storage on the fast primary ('tier 1') storage that can be used with parallel access "
"for computation."
"Amount of work storage on the fast primary ('tier 1') storage that can be used "
"with parallel access for computation."
),
label="Fast Active Storage [TB]",
)
self.fields["tier1"].initial = DEFAULT_PROJECT_RESOURCES["tier1"]
self.fields["tier1"].widget.attrs["class"] = "form-control mergeToJson"
self.fields["tier1_work"].initial = DEFAULT_PROJECT_RESOURCES["tier1_work"]
self.fields["tier1_work"].widget.attrs["class"] = "form-control mergeToJson"

self.fields["tier2_unmirrored"] = forms.IntegerField(
required=True,
Expand Down Expand Up @@ -412,16 +449,27 @@ def __init__(self, *args, user=None, project=None, **kwargs):
self.fields["members_dropdown"].widget.attrs["class"] = "form-control"

# Add fields for storage. Will be merged into resources_requested field.
self.fields["tier1"] = forms.IntegerField(
self.fields["tier1_scratch"] = forms.IntegerField(
required=True,
help_text=(
"Amount of scratch storage on the fast primary ('tier 1') storage that can be used "
"with parallel access for computation."
),
label="Fast Active Storage [TB]",
)
self.fields["tier1_scratch"].initial = DEFAULT_PROJECT_RESOURCES["tier1_scratch"]
self.fields["tier1_scratch"].widget.attrs["class"] = "form-control mergeToJson"

self.fields["tier1_work"] = forms.IntegerField(
required=True,
help_text=(
"Amount of storage on the fast primary ('tier 1') storage that can be used with parallel access "
"for computation."
"Amount of work storage on the fast primary ('tier 1') storage that can be used "
"with parallel access for computation."
),
label="Fast Active Storage [TB]",
)
self.fields["tier1"].initial = DEFAULT_PROJECT_RESOURCES["tier1"]
self.fields["tier1"].widget.attrs["class"] = "form-control mergeToJson"
self.fields["tier1_work"].initial = DEFAULT_PROJECT_RESOURCES["tier1_work"]
self.fields["tier1_work"].widget.attrs["class"] = "form-control mergeToJson"

self.fields["tier2_unmirrored"] = forms.IntegerField(
required=True,
Expand Down
49 changes: 32 additions & 17 deletions usersec/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ def hpc_obj_to_dict(obj):
#: Valid data for HpcGroupCreateRequestForm.
HPCGROUPCREATEREQUEST_FORM_DATA_VALID = {
"resources_requested": json.dumps({"resource": 100}),
"tier1": 100,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"tier1_scratch": 100,
"tier1_work": 200,
"tier2_mirrored": 300,
"tier2_unmirrored": 400,
"description": "some group description",
"expiration": "2022-01-01",
"comment": "nothing",
Expand All @@ -57,9 +58,10 @@ def hpc_obj_to_dict(obj):
#: Valid data for HpcGroupChangeRequestForm.
HPCGROUPCHANGEREQUEST_FORM_DATA_VALID = {
"resources_requested": json.dumps({"resource": 111}),
"tier1": 111,
"tier2_mirrored": 222,
"tier2_unmirrored": 333,
"tier1_scratch": 111,
"tier1_work": 222,
"tier2_mirrored": 333,
"tier2_unmirrored": 444,
"description": "updated group description",
"expiration": "2023-01-01",
"comment": "nothing",
Expand All @@ -69,9 +71,10 @@ def hpc_obj_to_dict(obj):
#: Valid data for HpcUserCreateRequestForm.
HPCUSERCREATEREQUEST_FORM_DATA_VALID = {
"resources_requested": json.dumps({"resource": 100}),
"tier1": 100,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"tier1_scratch": 100,
"tier1_work": 200,
"tier2_mirrored": 300,
"tier2_unmirrored": 400,
"email": "user@" + settings.INSTITUTE_EMAIL_DOMAINS.split(",")[0],
"expiration": "2022-01-01",
"comment": "nothing",
Expand All @@ -88,9 +91,10 @@ def hpc_obj_to_dict(obj):
#: Valid data for HpcProjectCreateRequestForm.
HPCPROJECTCREATEREQUEST_FORM_DATA_VALID = {
"resources_requested": json.dumps({"resource": 100}),
"tier1": 100,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"tier1_scratch": 100,
"tier1_work": 200,
"tier2_mirrored": 300,
"tier2_unmirrored": 400,
"description": "some project description",
"name": "some-project",
"expiration": "2022-01-01",
Expand All @@ -102,9 +106,10 @@ def hpc_obj_to_dict(obj):
#: Valid data for HpcProjectCreateRequestForm.
HPCPROJECTCHANGEREQUEST_FORM_DATA_VALID = {
"resources_requested": json.dumps({"resource": 111}),
"tier1": 111,
"tier2_mirrored": 222,
"tier2_unmirrored": 333,
"tier1_scratch": 111,
"tier1_work": 222,
"tier2_mirrored": 333,
"tier2_unmirrored": 444,
"description": "updated project description",
"expiration": "2022-01-01",
"comment": "nothing",
Expand Down Expand Up @@ -156,8 +161,18 @@ class Meta:

owner = None # HpcUser
delegate = None # HpcUser
resources_requested = {"tier1": 1, "tier2_mirrored": 0, "tier2_unmirrored": 0}
resources_used = {"tier1": 0.5, "tier2_mirrored": 0, "tier2_unmirrored": 0}
resources_requested = {
"tier1_scratch": 1,
"tier1_work": 1,
"tier2_mirrored": 0,
"tier2_unmirrored": 0,
}
resources_used = {
"tier1_scratch": 0.5,
"tier1_work": 0.5,
"tier2_mirrored": 0,
"tier2_unmirrored": 0,
}
description = "this is a group"
creator = factory.SubFactory(UserFactory) # User
gid = 2000
Expand Down
14 changes: 12 additions & 2 deletions usersec/tests/snapshots/snap_test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@
"name": "hpc-group0",
"owner": None,
"phone_number": "phone_number_placeholder",
"resources_requested": {"tier1": 1, "tier2_mirrored": 0, "tier2_unmirrored": 0},
"resources_used": {"tier1": 0.5, "tier2_mirrored": 0, "tier2_unmirrored": 0},
"resources_requested": {
"tier1_scratch": 1,
"tier1_work": 1,
"tier2_mirrored": 0,
"tier2_unmirrored": 0,
},
"resources_used": {
"tier1_scratch": 0.5,
"tier1_work": 0.5,
"tier2_mirrored": 0,
"tier2_unmirrored": 0,
},
"status": "INITIAL",
"uuid": "uuid_placeholder",
}
Expand Down
6 changes: 5 additions & 1 deletion usersec/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ def test_form_initials(self):
form.fields["resources_requested"].initial, self.hpc_group.resources_requested
)
self.assertEqual(
form.fields["tier1"].initial, self.hpc_group.resources_requested.get("tier1")
form.fields["tier1_scratch"].initial,
self.hpc_group.resources_requested.get("tier1_scratch"),
)
self.assertEqual(
form.fields["tier1_work"].initial, self.hpc_group.resources_requested.get("tier1_work")
)
self.assertEqual(
form.fields["tier2_mirrored"].initial,
Expand Down
56 changes: 32 additions & 24 deletions usersec/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,10 @@ def test_post(self):
"comment": "I made a comment!",
"resources_requested": '{"updated": 400}',
"description": "description changed",
"tier1": 100,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"tier1_scratch": 100,
"tier1_work": 200,
"tier2_mirrored": 300,
"tier2_unmirrored": 400,
"expiration": "2050-01-01",
}

Expand Down Expand Up @@ -312,9 +313,10 @@ def test_post_fail(self):
"comment": "I made a comment!",
"resources_requested": "",
"description": "description changed",
"tier1": 100,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"tier1_scratch": 100,
"tier1_work": 200,
"tier2_mirrored": 300,
"tier2_unmirrored": 400,
"expiration": "2050-01-01",
}

Expand Down Expand Up @@ -545,9 +547,10 @@ def test_post(self):
"comment": "I made a comment!",
"resources_requested": '{"updated": 400}',
"description": "description changed",
"tier1": 100,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"tier1_scratch": 100,
"tier1_work": 200,
"tier2_mirrored": 300,
"tier2_unmirrored": 400,
"expiration": "2050-01-01",
}

Expand Down Expand Up @@ -591,9 +594,10 @@ def test_post_fail(self):
"comment": "I made a comment!",
"resources_requested": "",
"description": "description changed",
"tier1": 100,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"tier1_scratch": 100,
"tier1_work": 200,
"tier2_mirrored": 300,
"tier2_unmirrored": 400,
"expiration": "2050-01-01",
}

Expand Down Expand Up @@ -931,9 +935,10 @@ def test_post(self):
update = {
"comment": "I made a comment!",
"resources_requested": '{"updated": 400}',
"tier1": 100,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"tier1_scratch": 100,
"tier1_work": 200,
"tier2_mirrored": 300,
"tier2_unmirrored": 400,
"email": "other@" + settings.INSTITUTE_EMAIL_DOMAINS.split(",")[0],
"expiration": "2050-01-01",
}
Expand Down Expand Up @@ -977,9 +982,10 @@ def test_post_fail(self):
update = {
"comment": "I made a comment!",
"resources_requested": "",
"tier1": 100,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"tier1_scratch": 100,
"tier1_work": 200,
"tier2_mirrored": 300,
"tier2_unmirrored": 400,
"email": "other@" + settings.INSTITUTE_EMAIL_DOMAINS.split(",")[0],
"expiration": "2050-01-01",
}
Expand Down Expand Up @@ -1593,9 +1599,10 @@ def test_post(self):
update = {
"comment": "I made a comment!",
"resources_requested": '{"updated": 400}',
"tier1": 100,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"tier1_scratch": 100,
"tier1_work": 200,
"tier2_mirrored": 300,
"tier2_unmirrored": 400,
"expiration": self.obj.expiration,
"name": self.obj.name,
"description": self.obj.description,
Expand Down Expand Up @@ -1956,9 +1963,10 @@ def test_post(self):
update = {
"comment": "I made a comment!",
"resources_requested": '{"updated": 444}',
"tier1": 111,
"tier2_mirrored": 222,
"tier2_unmirrored": 333,
"tier1_scratch": 111,
"tier1_work": 222,
"tier2_mirrored": 333,
"tier2_unmirrored": 444,
"expiration": self.obj.expiration,
"description": self.obj.description,
"members": [m.id for m in self.obj.members.all()],
Expand Down
Loading