-
Notifications
You must be signed in to change notification settings - Fork 84
Add global quotas and quota usage support for OBJ services #661
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
base: dev
Are you sure you want to change the base?
Changes from 3 commits
94d74de
b8bb6e0
c467c3e
daab10f
48ebe5a
592d23f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "data": [ | ||
| { | ||
| "quota_id": "obj-access-keys-per-account", | ||
| "quota_type": "obj-access-keys", | ||
| "quota_name": "Object Storage Access Keys per Account", | ||
| "description": "Maximum number of access keys this customer is allowed to have on their account.", | ||
| "resource_metric": "access_key", | ||
| "quota_limit": 100, | ||
| "has_usage": true | ||
| }, | ||
| { | ||
| "quota_id": "obj-total-capacity-per-account", | ||
| "quota_type": "obj-total-capacity", | ||
| "quota_name": "Object Storage Total Capacity per Account", | ||
| "description": "Maximum total storage capacity in bytes this customer is allowed on their account.", | ||
| "resource_metric": "byte", | ||
| "quota_limit": 1099511627776, | ||
| "has_usage": true | ||
| } | ||
| ], | ||
| "page": 1, | ||
| "pages": 1, | ||
| "results": 2 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "quota_id": "obj-access-keys-per-account", | ||
| "quota_type": "obj-access-keys", | ||
| "quota_name": "Object Storage Access Keys per Account", | ||
| "description": "Maximum number of access keys this customer is allowed to have on their account.", | ||
| "resource_metric": "access_key", | ||
| "quota_limit": 100, | ||
| "has_usage": true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "quota_limit": 100, | ||
| "usage": 25 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| import pytest | ||
|
|
||
| from linode_api4.errors import ApiError | ||
| from linode_api4.objects.object_storage import ( | ||
| ObjectStorageGlobalQuota, | ||
| ObjectStorageQuota, | ||
| ObjectStorageQuotaUsage, | ||
| ) | ||
|
|
@@ -25,6 +27,8 @@ def test_list_and_get_obj_storage_quotas(test_linode_client): | |
| assert found_quota.description == get_quota.description | ||
| assert found_quota.quota_limit == get_quota.quota_limit | ||
| assert found_quota.resource_metric == get_quota.resource_metric | ||
| assert found_quota.quota_type == get_quota.quota_type | ||
| assert found_quota.has_usage == get_quota.has_usage | ||
|
|
||
|
|
||
| def test_get_obj_storage_quota_usage(test_linode_client): | ||
|
|
@@ -33,7 +37,22 @@ def test_get_obj_storage_quota_usage(test_linode_client): | |
| if len(quotas) < 1: | ||
| pytest.skip("No available quota for testing. Skipping now...") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we skip silently?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe keep it verbose, so we would know when it's skipped. I think most account will be with a quota, so this branch is very unlikely to be triggered.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zliang-akamai this test (and the others too) will fail when Object Storage is disabled in the account settings, i.e. |
||
|
|
||
| quota_id = quotas[0].quota_id | ||
| quota_with_usage = next( | ||
| (quota for quota in quotas if quota.has_usage), None | ||
| ) | ||
|
|
||
| if quota_with_usage is None: | ||
| quota_id = quotas[0].quota_id | ||
| quota = test_linode_client.load(ObjectStorageQuota, quota_id) | ||
|
|
||
| with pytest.raises(ApiError) as exc: | ||
| quota.usage() | ||
|
|
||
| assert exc.value.status == 404 | ||
| assert "Usage not supported" in str(exc.value) | ||
zliang-akamai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return | ||
|
|
||
| quota_id = quota_with_usage.quota_id | ||
| quota = test_linode_client.load(ObjectStorageQuota, quota_id) | ||
|
|
||
| quota_usage = quota.usage() | ||
|
|
@@ -43,3 +62,67 @@ def test_get_obj_storage_quota_usage(test_linode_client): | |
|
|
||
| if quota_usage.usage is not None: | ||
| assert quota_usage.usage >= 0 | ||
|
|
||
|
|
||
| def test_list_and_get_obj_storage_global_quotas(test_linode_client): | ||
| try: | ||
| quotas = test_linode_client.object_storage.global_quotas() | ||
| except ApiError as err: | ||
| if err.status == 404: | ||
| pytest.skip("Object Storage is not enabled on this account.") | ||
zliang-akamai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| raise | ||
|
|
||
| if len(quotas) < 1: | ||
| pytest.skip("No available global quota for testing. Skipping now...") | ||
|
|
||
| found_quota = quotas[0] | ||
|
|
||
| get_quota = test_linode_client.load( | ||
| ObjectStorageGlobalQuota, found_quota.quota_id | ||
| ) | ||
|
|
||
| assert found_quota.quota_id == get_quota.quota_id | ||
| assert found_quota.quota_type == get_quota.quota_type | ||
| assert found_quota.quota_name == get_quota.quota_name | ||
| assert found_quota.description == get_quota.description | ||
| assert found_quota.resource_metric == get_quota.resource_metric | ||
| assert found_quota.quota_limit == get_quota.quota_limit | ||
| assert found_quota.has_usage == get_quota.has_usage | ||
|
|
||
|
|
||
| def test_get_obj_storage_global_quota_usage(test_linode_client): | ||
| try: | ||
| quotas = test_linode_client.object_storage.global_quotas() | ||
| except ApiError as err: | ||
| if err.status == 404: | ||
| pytest.skip("Object Storage is not enabled on this account.") | ||
zliang-akamai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| raise | ||
|
|
||
| if len(quotas) < 1: | ||
| pytest.skip("No available global quota for testing. Skipping now...") | ||
|
|
||
| quota_with_usage = next( | ||
| (quota for quota in quotas if quota.has_usage), None | ||
| ) | ||
|
|
||
| if quota_with_usage is None: | ||
| quota_id = quotas[0].quota_id | ||
| quota = test_linode_client.load(ObjectStorageGlobalQuota, quota_id) | ||
|
|
||
| with pytest.raises(ApiError) as exc: | ||
| quota.usage() | ||
|
|
||
| assert exc.value.status == 404 | ||
| assert "Usage not supported" in str(exc.value) | ||
| return | ||
zliang-akamai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| quota_id = quota_with_usage.quota_id | ||
| quota = test_linode_client.load(ObjectStorageGlobalQuota, quota_id) | ||
|
|
||
| quota_usage = quota.usage() | ||
|
|
||
| assert isinstance(quota_usage, ObjectStorageQuotaUsage) | ||
| assert quota_usage.quota_limit >= 0 | ||
|
|
||
| if quota_usage.usage is not None: | ||
| assert quota_usage.usage >= 0 | ||
Uh oh!
There was an error while loading. Please reload this page.