Skip to content

Commit

Permalink
test validate_allocations fix for object quota = 0
Browse files Browse the repository at this point in the history
  • Loading branch information
jtriley committed May 14, 2024
1 parent 8e7459f commit af75e98
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def handle(self, *args, **options):

failed_validation = Command.sync_users(project_id, allocation, allocator, options["apply"])

obj_key = openstack.QUOTA_KEY_MAPPING['object']['keys'][attributes.QUOTA_OBJECT_GB]

for attr in attributes.ALLOCATION_QUOTA_ATTRIBUTES:
if 'OpenStack' in attr.name:
key = openstack.QUOTA_KEY_MAPPING_ALL_KEYS.get(attr.name, None)
Expand All @@ -116,7 +118,15 @@ def handle(self, *args, **options):

expected_value = allocation.get_attribute(attr.name)
current_value = quota.get(key, None)
if expected_value is None and current_value:
if key == obj_key and expected_value <= 0:
expected_obj_value = 1
current_value = allocator.object(project_id).head_account().get(obj_key)
if current_value != expected_obj_value:
failed_validation = True
msg = (f'Value for quota for {attr.name} = {current_value} does not match expected'
f' value of {expected_obj_value} on allocation {allocation_str}')
logger.warning(msg)
elif expected_value is None and current_value:
msg = (f'Attribute "{attr.name}" expected on allocation {allocation_str} but not set.'
f' Current quota is {current_value}.')
if options['apply']:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,28 @@ def test_new_allocation_with_quantity(self):
allocation.get_attribute(attributes.QUOTA_OBJECT_GB),
allocator.get_quota(openstack_project.id)[obj_key]
)

# setting 0 object quota in coldfront -> 1 byte quota in swift/rgw
utils.set_attribute_on_allocation(allocation, attributes.QUOTA_OBJECT_GB, 0)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_OBJECT_GB), 0)
tasks.activate_allocation(allocation.pk)
obj_quota = allocator.object(project_id).head_account().get(obj_key)
self.assertEqual(int(obj_quota), 1)

# test validate_allocations works for object quota set to 0
utils.set_attribute_on_allocation(allocation, attributes.QUOTA_OBJECT_GB, 3)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_OBJECT_GB), 3)
tasks.activate_allocation(allocation.pk)
self.assertEqual(
allocation.get_attribute(attributes.QUOTA_OBJECT_GB),
allocator.get_quota(openstack_project.id)[obj_key]
)
utils.set_attribute_on_allocation(allocation, attributes.QUOTA_OBJECT_GB, 0)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_OBJECT_GB), 0)
call_command('validate_allocations', apply=True)
obj_quota = allocator.object(project_id).head_account().get(obj_key)
self.assertEqual(int(obj_quota), 1)


def test_reactivate_allocation(self):
user = self.new_user()
Expand Down

0 comments on commit af75e98

Please sign in to comment.