Skip to content

Commit

Permalink
feat: split tier2 resource to mirrored and unmirrored (#148) (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
stolpeo authored Feb 14, 2024
1 parent 9c8804f commit 34f36bc
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 37 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ test:
ENABLE_LDAP=0 ENABLE_LDAP_SECONDARY=0 $(manage) test -v2 --settings=config.settings.test


.PHONY: test-keepdb
test-keepdb:
ENABLE_LDAP=0 ENABLE_LDAP_SECONDARY=0 $(manage) test -v2 --settings=config.settings.test --keepdb


.PHONY: isort
isort:
isort --force-sort-within-sections --profile=black .
Expand Down
75 changes: 57 additions & 18 deletions usersec/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
HpcUserCreateRequest,
)

DEFAULT_USER_RESOURCES = {"tier1": "1", "tier2": "0"}
DEFAULT_GROUP_RESOURCES = {"tier1": "1", "tier2": "0"}
DEFAULT_PROJECT_RESOURCES = {"tier1": "1", "tier2": "0"}
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}


class HpcGroupCreateRequestForm(forms.ModelForm):
Expand Down Expand Up @@ -111,16 +111,29 @@ def __init__(self, *args, user, group, **kwargs):
self.fields["tier1"].initial = group.resources_requested["tier1"]
self.fields["tier1"].widget.attrs["class"] = "form-control mergeToJson"

self.fields["tier2"] = forms.IntegerField(
self.fields["tier2_unmirrored"] = forms.IntegerField(
required=True,
help_text=(
"Amount of storage on the slower ('tier 2') storage that is meant for long-term storage. "
"Alternatively, you can use your group storage at Charite or MDC."
"This storage is not mirrored and should be used for data that can be reconstructed from "
"other sources. Alternatively, you can use your group storage at Charite or MDC."
),
label="Long-Term Storage [TB]",
label="Long-Term Storage Unmirrored [TB]",
)
self.fields["tier2"].initial = group.resources_requested["tier2"]
self.fields["tier2"].widget.attrs["class"] = "form-control mergeToJson"
self.fields["tier2_unmirrored"].initial = group.resources_requested["tier2_unmirrored"]
self.fields["tier2_unmirrored"].widget.attrs["class"] = "form-control mergeToJson"

self.fields["tier2_mirrored"] = forms.IntegerField(
required=True,
help_text=(
"Amount of storage on the slower ('tier 2') storage that is meant for long-term storage. "
"This storage is mirrored and should be used for data that cannot be reconstructed from "
"other sources. Alternatively, you can use your group storage at Charite or MDC."
),
label="Long-Term Storage Mirrored [TB]",
)
self.fields["tier2_mirrored"].initial = group.resources_requested["tier2_mirrored"]
self.fields["tier2_mirrored"].widget.attrs["class"] = "form-control mergeToJson"

else:
self.fields["delegate"].widget = forms.HiddenInput()
Expand Down Expand Up @@ -294,16 +307,29 @@ def __init__(self, *args, user=None, group=None, **kwargs):
self.fields["tier1"].initial = DEFAULT_PROJECT_RESOURCES["tier1"]
self.fields["tier1"].widget.attrs["class"] = "form-control mergeToJson"

self.fields["tier2"] = forms.IntegerField(
self.fields["tier2_unmirrored"] = forms.IntegerField(
required=True,
help_text=(
"Amount of storage on the slower ('tier 2') storage that is meant for long-term storage. "
"This storage is not mirrored and should be used for data that can be reconstructed from "
"other sources. Alternatively, you can use your group storage at Charite or MDC."
),
label="Long-Term Storage Unmirrored [TB]",
)
self.fields["tier2_unmirrored"].initial = DEFAULT_PROJECT_RESOURCES["tier2_unmirrored"]
self.fields["tier2_unmirrored"].widget.attrs["class"] = "form-control mergeToJson"

self.fields["tier2_mirrored"] = forms.IntegerField(
required=True,
help_text=(
"Amount of storage on the slower ('tier 2') storage that is meant for long-term storage. "
"Alternatively, you can use your group storage at Charite or MDC."
"This storage is mirrored and should be used for data that cannot be reconstructed from "
"other sources. Alternatively, you can use your group storage at Charite or MDC."
),
label="Long-Term Storage [TB]",
label="Long-Term Storage Mirrored [TB]",
)
self.fields["tier2"].initial = DEFAULT_PROJECT_RESOURCES["tier2"]
self.fields["tier2"].widget.attrs["class"] = "form-control mergeToJson"
self.fields["tier2_mirrored"].initial = DEFAULT_PROJECT_RESOURCES["tier2_mirrored"]
self.fields["tier2_mirrored"].widget.attrs["class"] = "form-control mergeToJson"

else:
self.fields["delegate"].widget = forms.HiddenInput()
Expand Down Expand Up @@ -397,16 +423,29 @@ def __init__(self, *args, user=None, project=None, **kwargs):
self.fields["tier1"].initial = DEFAULT_PROJECT_RESOURCES["tier1"]
self.fields["tier1"].widget.attrs["class"] = "form-control mergeToJson"

self.fields["tier2"] = forms.IntegerField(
self.fields["tier2_unmirrored"] = forms.IntegerField(
required=True,
help_text=(
"Amount of storage on the slower ('tier 2') storage that is meant for long-term storage. "
"This storage is not mirrored and should be used for data that can be reconstructed from "
"other sources. Alternatively, you can use your group storage at Charite or MDC."
),
label="Long-Term Storage Unmirrored [TB]",
)
self.fields["tier2_unmirrored"].initial = DEFAULT_PROJECT_RESOURCES["tier2_unmirrored"]
self.fields["tier2_unmirrored"].widget.attrs["class"] = "form-control mergeToJson"

self.fields["tier2_mirrored"] = forms.IntegerField(
required=True,
help_text=(
"Amount of storage on the slower ('tier 2') storage that is meant for long-term storage. "
"Alternatively, you can use your group storage at Charite or MDC."
"This storage is mirrored and should be used for data that cannot be reconstructed from "
"other sources. Alternatively, you can use your group storage at Charite or MDC."
),
label="Long-Term Storage [TB]",
label="Long-Term Storage Mirrored [TB]",
)
self.fields["tier2"].initial = DEFAULT_PROJECT_RESOURCES["tier2"]
self.fields["tier2"].widget.attrs["class"] = "form-control mergeToJson"
self.fields["tier2_mirrored"].initial = DEFAULT_PROJECT_RESOURCES["tier2_mirrored"]
self.fields["tier2_mirrored"].widget.attrs["class"] = "form-control mergeToJson"

else:
self.fields["delegate"].widget = forms.HiddenInput()
Expand Down
19 changes: 12 additions & 7 deletions usersec/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def hpc_obj_to_dict(obj):
HPCGROUPCREATEREQUEST_FORM_DATA_VALID = {
"resources_requested": json.dumps({"resource": 100}),
"tier1": 100,
"tier2": 200,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"description": "some group description",
"expiration": "2022-01-01",
"comment": "nothing",
Expand All @@ -56,7 +57,8 @@ def hpc_obj_to_dict(obj):
HPCGROUPCHANGEREQUEST_FORM_DATA_VALID = {
"resources_requested": json.dumps({"resource": 111}),
"tier1": 111,
"tier2": 222,
"tier2_mirrored": 222,
"tier2_unmirrored": 333,
"description": "updated group description",
"expiration": "2023-01-01",
"comment": "nothing",
Expand All @@ -67,7 +69,8 @@ def hpc_obj_to_dict(obj):
HPCUSERCREATEREQUEST_FORM_DATA_VALID = {
"resources_requested": json.dumps({"resource": 100}),
"tier1": 100,
"tier2": 200,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"email": "user@" + settings.INSTITUTE_EMAIL_DOMAINS.split(",")[0],
"expiration": "2022-01-01",
"comment": "nothing",
Expand All @@ -85,7 +88,8 @@ def hpc_obj_to_dict(obj):
HPCPROJECTCREATEREQUEST_FORM_DATA_VALID = {
"resources_requested": json.dumps({"resource": 100}),
"tier1": 100,
"tier2": 200,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"description": "some project description",
"name": "some-project",
"expiration": "2022-01-01",
Expand All @@ -98,7 +102,8 @@ def hpc_obj_to_dict(obj):
HPCPROJECTCHANGEREQUEST_FORM_DATA_VALID = {
"resources_requested": json.dumps({"resource": 111}),
"tier1": 111,
"tier2": 222,
"tier2_mirrored": 222,
"tier2_unmirrored": 333,
"description": "updated project description",
"expiration": "2022-01-01",
"comment": "nothing",
Expand Down Expand Up @@ -150,8 +155,8 @@ class Meta:

owner = None # HpcUser
delegate = None # HpcUser
resources_requested = {"tier1": 1, "tier2": 0}
resources_used = {"tier1": 0.5, "tier2": 0}
resources_requested = {"tier1": 1, "tier2_mirrored": 0, "tier2_unmirrored": 0}
resources_used = {"tier1": 0.5, "tier2_mirrored": 0, "tier2_unmirrored": 0}
description = "this is a group"
creator = None # User
gid = 2000
Expand Down
4 changes: 2 additions & 2 deletions usersec/tests/snapshots/snap_test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"gid": 2000,
"name": "hpc-group0",
"owner": None,
"resources_requested": {"tier1": 1, "tier2": 0},
"resources_used": {"tier1": 0.5, "tier2": 0},
"resources_requested": {"tier1": 1, "tier2_mirrored": 0, "tier2_unmirrored": 0},
"resources_used": {"tier1": 0.5, "tier2_mirrored": 0, "tier2_unmirrored": 0},
"status": "INITIAL",
"uuid": "uuid_placeholder",
}
Expand Down
7 changes: 6 additions & 1 deletion usersec/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ def test_form_initials(self):
form.fields["tier1"].initial, self.hpc_group.resources_requested.get("tier1")
)
self.assertEqual(
form.fields["tier2"].initial, self.hpc_group.resources_requested.get("tier2")
form.fields["tier2_mirrored"].initial,
self.hpc_group.resources_requested.get("tier2_mirrored"),
)
self.assertEqual(
form.fields["tier2_unmirrored"].initial,
self.hpc_group.resources_requested.get("tier2_unmirrored"),
)

def test_form_valid(self):
Expand Down
1 change: 0 additions & 1 deletion usersec/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


class ResetSequenceMixin:

def setUp(self):
super().setUp()
HpcUserFactory.reset_sequence()
Expand Down
24 changes: 16 additions & 8 deletions usersec/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ def test_post(self):
"resources_requested": '{"updated": 400}',
"description": "description changed",
"tier1": 100,
"tier2": 200,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"expiration": "2050-01-01",
}

Expand Down Expand Up @@ -312,7 +313,8 @@ def test_post_fail(self):
"resources_requested": "",
"description": "description changed",
"tier1": 100,
"tier2": 200,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"expiration": "2050-01-01",
}

Expand Down Expand Up @@ -544,7 +546,8 @@ def test_post(self):
"resources_requested": '{"updated": 400}',
"description": "description changed",
"tier1": 100,
"tier2": 200,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"expiration": "2050-01-01",
}

Expand Down Expand Up @@ -589,7 +592,8 @@ def test_post_fail(self):
"resources_requested": "",
"description": "description changed",
"tier1": 100,
"tier2": 200,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"expiration": "2050-01-01",
}

Expand Down Expand Up @@ -928,7 +932,8 @@ def test_post(self):
"comment": "I made a comment!",
"resources_requested": '{"updated": 400}',
"tier1": 100,
"tier2": 200,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"email": "other@" + settings.INSTITUTE_EMAIL_DOMAINS.split(",")[0],
"expiration": "2050-01-01",
}
Expand Down Expand Up @@ -973,7 +978,8 @@ def test_post_fail(self):
"comment": "I made a comment!",
"resources_requested": "",
"tier1": 100,
"tier2": 200,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"email": "other@" + settings.INSTITUTE_EMAIL_DOMAINS.split(",")[0],
"expiration": "2050-01-01",
}
Expand Down Expand Up @@ -1588,7 +1594,8 @@ def test_post(self):
"comment": "I made a comment!",
"resources_requested": '{"updated": 400}',
"tier1": 100,
"tier2": 200,
"tier2_mirrored": 200,
"tier2_unmirrored": 300,
"expiration": self.obj.expiration,
"name": self.obj.name,
"description": self.obj.description,
Expand Down Expand Up @@ -1950,7 +1957,8 @@ def test_post(self):
"comment": "I made a comment!",
"resources_requested": '{"updated": 444}',
"tier1": 111,
"tier2": 222,
"tier2_mirrored": 222,
"tier2_unmirrored": 333,
"expiration": self.obj.expiration,
"description": self.obj.description,
"members": [m.id for m in self.obj.members.all()],
Expand Down

0 comments on commit 34f36bc

Please sign in to comment.