Skip to content
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
29 changes: 29 additions & 0 deletions coldfront/core/allocation/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from unittest.mock import MagicMock

from django.test import SimpleTestCase

from coldfront.core.allocation.utils import check_l3_tag


class CheckL3TagIsilonTests(SimpleTestCase):
"""Tests for the isilon rc_fasse_labs criterion of check_l3_tag in allocation/utils.py"""

def make(self, path, mount, resource_name='isilon01'):
allocation = MagicMock(path=path)
allocation.project.title = 'poisson_lab'
resource = MagicMock()
resource.name = resource_name
resource.get_attribute.return_value = mount
return allocation, resource

def test_check_l3_tag_fasse_in_path_returns_true(self):
self.assertTrue(check_l3_tag(*self.make('rc_fasse_labs/poisson_lab', None)))

def test_check_l3_tag_fasse_in_storage_mount_returns_true(self):
self.assertTrue(check_l3_tag(*self.make('poisson_lab', '/ifs/rc_fasse_labs')))

def test_check_l3_tag_fasse_in_neither_returns_false(self):
self.assertFalse(check_l3_tag(*self.make('poisson_lab', '/ifs/rc_labs')))

def test_check_l3_tag_fasse_mount_on_non_isilon_resource_returns_false(self):
self.assertFalse(check_l3_tag(*self.make('poisson_lab', '/ifs/rc_fasse_labs', 'holylfs09/tier1')))
5 changes: 3 additions & 2 deletions coldfront/core/allocation/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,14 @@ def test_allocationcreateview_post_offerlettercode_valid(self):

def test_allocationcreateview_post_bools(self):
"""ensure booleans are properly saved"""
aa_names = ['Heavy IO', 'Mounted', 'High Security', 'DUA', 'External Sharing']
# 'Mounted' is no longer an offered specification (see ALLOCATION_SPECIFICATIONS)
aa_names = ['Heavy IO', 'High Security', 'DUA', 'External Sharing']
self.post_data['additional_specifications'] = aa_names
response = self.client.post(self.url, data=self.post_data, follow=True)
aa_objs = AllocationAttribute.objects.filter(
allocation_attribute_type__name__in=aa_names
)
self.assertEqual(len(aa_objs), 5)
self.assertEqual(len(aa_objs), 4)

def test_allocationcreateview_post_offerlettercode_multiplefield_invalid(self):
"""Ensure that form won't pass if multiple expense codes are given"""
Expand Down
9 changes: 6 additions & 3 deletions coldfront/core/allocation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ def check_l3_tag(allocation, resource):
Criteria for l3 tagging:
Any allocation for a project named .*_l3
Any allocation on a lustre resource, with path matching ^F/|/F/ (I think?)
Any allocation on an isilon resource, with path matching rc_fasse_labs
Any allocation on an isilon resource, with path or the resource's storage_mount
matching rc_fasse_labs (auto-created allocations store the path without the mount)
Any allocation on h-nfse-01p
"""
if allocation.project.title.endswith('_l3'):
return True
if 'lfs' in resource.name.lower() and 'F/' in allocation.path:
return True
if 'isilon' in resource.name.lower() and 'rc_fasse_labs' in allocation.path:
return True
if 'isilon' in resource.name.lower():
mount = resource.get_attribute('storage_mount', expand=False, typed=False) or ''
if 'rc_fasse_labs' in allocation.path or 'rc_fasse_labs' in mount:
return True
if 'h-nfse-01p' in resource.name.lower():
return True
return False
Expand Down
12 changes: 8 additions & 4 deletions coldfront/core/project/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def __init__(self, request_user, project_pk, *args, **kwargs):

allocation_query_set = project_obj.allocation_set.filter(
resources__is_allocatable=True, is_locked=False,
resources__resource_type__name='Cluster',
status__name__in=PENDING_ACTIVE_ALLOCATION_STATUSES
).distinct()
allocation_choices = [(
Expand All @@ -86,11 +87,14 @@ def __init__(self, request_user, project_pk, *args, **kwargs):
)
) for allocation in allocation_query_set]

allocation_choices_sorted = []
allocation_choices_sorted = sorted(allocation_choices, key=lambda x: x[1][0].lower())
allocation_choices.insert(0, ('__select_all__', 'Select All'))
# The template's JS treats the first checkbox (allocation_0) as "Select All",
# so it must be inserted after sorting. With a single allocation, the JS
# handler on allocation_0 only toggles that one box, so omitting it is safe.
allocation_choices.sort(key=lambda x: x[1].lower())
if len(allocation_choices) > 1:
allocation_choices.insert(0, ('__select_all__', 'Select All'))
if allocation_query_set:
self.fields['allocation'].choices = allocation_choices_sorted
self.fields['allocation'].choices = allocation_choices
self.fields['allocation'].help_text = '<br/>Select allocations to add selected users to.'
else:
self.fields['allocation'].widget = forms.HiddenInput()
Expand Down
54 changes: 54 additions & 0 deletions coldfront/core/project/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import logging

from django.test import TestCase

from coldfront.core.project.forms import ProjectAddUsersToAllocationForm
from coldfront.core.test_helpers.factories import (
setup_models,
AllocationFactory,
ResourceFactory,
)

logging.disable(logging.CRITICAL)

SELECT_ALL = ('__select_all__', 'Select All')


class ProjectAddUsersToAllocationFormTest(TestCase):
"""Tests for ProjectAddUsersToAllocationForm"""

@classmethod
def setUpTestData(cls):
setup_models(cls)

def add_cluster_allocation(self, name):
resource = ResourceFactory(name=name, resource_type__name='Cluster')
allocation = AllocationFactory(project=self.project, justification=f'{name} test')
allocation.resources.add(resource)
return allocation

def get_choices(self):
form = ProjectAddUsersToAllocationForm(self.pi_user, self.project.pk)
return list(form.fields['allocation'].choices)

def test_allocation_choices_single_allocation_omits_select_all(self):
"""With only one allocation, "Select All" is not offered."""
choices = self.get_choices()
self.assertEqual(len(choices), 1)
self.assertNotIn(SELECT_ALL, choices)

def test_allocation_choices_multiple_allocations_first_choice_is_select_all(self):
"""The template's JS treats allocation_0 as "Select All"; if a real
allocation lands there, clicking it toggles every other checkbox."""
self.add_cluster_allocation('another cluster')
choices = self.get_choices()
self.assertEqual(len(choices), 3)
self.assertEqual(choices[0], SELECT_ALL)

def test_allocation_choices_multiple_allocations_sorted_by_full_label(self):
"""Allocation choices after "Select All" are sorted case-insensitively by full label."""
self.add_cluster_allocation('another cluster')
self.add_cluster_allocation('Test Cluster B')
labels = [label for _, label in self.get_choices()][1:]
self.assertEqual(len(labels), 3)
self.assertEqual(labels, sorted(labels, key=str.lower))
3 changes: 2 additions & 1 deletion coldfront/core/project/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,8 @@ def setUp(self):
'userform-MAX_NUM_FORMS': '1',
'userform-0-selected': 'on',
'userform-0-role': ProjectUserRoleChoice.objects.get(name='User').pk,
'allocationform-allocation': [self.storage_allocation.pk]
# the add-users allocation form only offers Cluster allocations
'allocationform-allocation': [self.cluster_allocation.pk]
}

@override_settings(PLUGIN_LDAP=True)
Expand Down
8 changes: 8 additions & 0 deletions coldfront/plugins/isilon/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@ def run_create(self, mock_conn_cls, mock_group_cls, **kwargs):
option_exceptions = create_isilon_allocation_quota(self.allocation, self.resource, **kwargs)
return mock_conn_cls.return_value, option_exceptions

def test_create_quota_subdirectory_excludes_storage_mount(
self, mock_conn_cls, _user, mock_group_cls, _attr_type, mock_attr, *_
):
conn, _ = self.run_create(mock_conn_cls, mock_group_cls)
conn.create_directory.assert_any_call('ifs/rc_labs/poisson_lab')
mock_attr.objects.create.assert_called_once()
self.assertEqual(mock_attr.objects.create.call_args.kwargs['value'], 'poisson_lab')

def test_create_quota_no_share_kwargs_skips_smb_share(self, mock_conn_cls, _user, mock_group_cls, *_):
conn, option_exceptions = self.run_create(mock_conn_cls, mock_group_cls)
conn.protocols_client.create_smb_share.assert_not_called()
Expand Down
4 changes: 3 additions & 1 deletion coldfront/plugins/isilon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,13 @@ def create_isilon_allocation_quota(
raise
actions_performed.append('quota set')

# Auto-created allocations store Subdirectory without the storage_mount prefix
# (path is '{storage_mount}/{lab_name}', so only lab_name remains)
subdir_type = AllocationAttributeType.objects.get(name='Subdirectory')
AllocationAttribute.objects.create(
allocation=allocation,
allocation_attribute_type_id=subdir_type.pk,
value=f'{subdir}/{lab_name}'
value=lab_name,
)

option_exceptions = {}
Expand Down
Loading