-
Notifications
You must be signed in to change notification settings - Fork 15
Move hardcoded quota names from attributes.py to tests #324
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: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
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. Removing the hardcoded quota strings from this file will be more complicated, as we are trying to do a more significant refactor. Refer to this comment to understand the bigger idea of what we are trying to achieve. In summary, we want to encode in the quota display name information about the key of the quota on This refactor will be somewhat significant, so for now, I would suggest that you revert this file, and replace references to |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -322,7 +322,6 @@ def process_invoice_row(allocation, attrs, su_name, rate): | |
| f, delimiter=",", quotechar="|", quoting=csv.QUOTE_MINIMAL | ||
| ) | ||
| csv_invoice_writer.writerow(InvoiceRow.get_headers()) | ||
|
|
||
|
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. Stray whitespace removal |
||
| for allocation in openstack_allocations: | ||
| allocation_str = ( | ||
| f'{allocation.pk} of project "{allocation.project.title}"' | ||
|
|
@@ -337,29 +336,32 @@ def process_invoice_row(allocation, attrs, su_name, rate): | |
| quotaspec.invoice_name, | ||
| openstack_nese_storage_rate, | ||
| ) | ||
| openshift_storage_rates = { | ||
| "OpenShift NESE Storage": openshift_nese_storage_rate, | ||
| "OpenShift IBM Scale Storage": openshift_ibm_storage_rate, | ||
| } | ||
|
|
||
| for allocation in openshift_allocations: | ||
| allocation_str = ( | ||
| f'{allocation.pk} of project "{allocation.project.title}"' | ||
| ) | ||
| logger.debug(f"Starting billing for allocation {allocation_str}.") | ||
|
|
||
| process_invoice_row( | ||
| allocation, | ||
| [ | ||
| attributes.QUOTA_LIMITS_EPHEMERAL_STORAGE_GB, | ||
| attributes.QUOTA_REQUESTS_NESE_STORAGE, | ||
| ], | ||
| "OpenShift NESE Storage", | ||
| openshift_nese_storage_rate, | ||
| ) | ||
| attrs_by_invoice_name = {} | ||
| for quota_name, quotaspec in get_storage_quotaspecs(allocation).items(): | ||
| attrs_by_invoice_name.setdefault(quotaspec.invoice_name, []).append( | ||
| quota_name | ||
| ) | ||
|
|
||
| process_invoice_row( | ||
| allocation, | ||
| [attributes.QUOTA_REQUESTS_IBM_STORAGE], | ||
| "OpenShift IBM Scale Storage", | ||
| openshift_ibm_storage_rate, | ||
| ) | ||
| for invoice_name, quota_names in attrs_by_invoice_name.items(): | ||
| rate = openshift_storage_rates.get(invoice_name) | ||
| if rate is None: | ||
| logger.warning( | ||
| f"No rate configured for invoice name {invoice_name!r} " | ||
| f"on allocation {allocation_str}, skipping." | ||
| ) | ||
| continue | ||
| process_invoice_row(allocation, quota_names, invoice_name, rate) | ||
|
|
||
| if options["upload_to_s3"]: | ||
| logger.info(f"Uploading to S3 endpoint {options['s3_endpoint_url']}.") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -222,12 +222,12 @@ def _set_object_quota(self, project_id, payload): | |
| # Note(knikolla): For consistency with other OpenStack | ||
| # quotas we're storing this as GB on the attribute and | ||
| # converting to bytes for Swift. | ||
| _, obj_q_mapping = self._extract_quota_label( | ||
| self.resource_quotaspecs.root[attributes.QUOTA_OBJECT_GB] | ||
| ) | ||
| payload[obj_q_mapping] *= GB_IN_BYTES | ||
| if payload[obj_q_mapping] <= 0: | ||
| payload[obj_q_mapping] = 1 | ||
| for obj_q_mapping in self._get_resource_quota_labels_by_service("object"): | ||
| if obj_q_mapping not in payload: | ||
| continue | ||
|
Comment on lines
+225
to
+227
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. As it stands, this function expects the object service to only have one quota ( obj_q_mapping = self._get_resource_quota_labels_by_service("object")[0]
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. Also, why was there a need for the |
||
| payload[obj_q_mapping] *= GB_IN_BYTES | ||
| if payload[obj_q_mapping] <= 0: | ||
| payload[obj_q_mapping] = 1 | ||
| self.object(project_id).post_account(headers=payload) | ||
| except ksa_exceptions.catalog.EndpointNotFound: | ||
| logger.debug("No swift available, skipping its quota.") | ||
|
|
@@ -291,10 +291,7 @@ def get_quota(self, project_id): | |
|
|
||
| quotas = self._get_network_quota(quotas, project_id) | ||
|
|
||
| if object_quotaspec := self.resource_quotaspecs.root.get( | ||
| attributes.QUOTA_OBJECT_GB | ||
| ): | ||
| _, key = self._extract_quota_label(object_quotaspec) | ||
| for key in self._get_resource_quota_labels_by_service("object"): | ||
|
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. This does look aesthetically neater, but could lead to the same confusion mentioned above. |
||
| try: | ||
| swift = self.object(project_id).head_account() | ||
| except ksa_exceptions.catalog.EndpointNotFound: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| from coldfront_plugin_cloud.attributes import * # noqa: F403 | ||
|
|
||
|
|
||
| # OpenStack Quota Attributes | ||
| QUOTA_INSTANCES = "OpenStack Compute Instance Quota" | ||
| QUOTA_RAM = "OpenStack Compute RAM Quota (MiB)" | ||
| QUOTA_VCPU = "OpenStack Compute vCPU Quota" | ||
|
|
||
| QUOTA_VOLUMES = "OpenStack Number of Volumes Quota" | ||
| QUOTA_VOLUMES_GB = "OpenStack Volume Quota (GiB)" | ||
|
|
||
| QUOTA_FLOATING_IPS = "OpenStack Floating IP Quota" | ||
| QUOTA_NETWORKS = "Openstack Network Quota" | ||
|
|
||
| QUOTA_OBJECT_GB = "OpenStack Swift Quota (GiB)" | ||
|
|
||
| # OpenShift Quota Attributes | ||
| QUOTA_LIMITS_CPU = "OpenShift Limit on CPU Quota" | ||
| QUOTA_LIMITS_MEMORY = "OpenShift Limit on RAM Quota (MiB)" | ||
| QUOTA_LIMITS_EPHEMERAL_STORAGE_GB = "OpenShift Limit on Ephemeral Storage Quota (GiB)" | ||
| QUOTA_REQUESTS_NESE_STORAGE = "OpenShift Request on NESE Storage Quota (GiB)" | ||
| QUOTA_REQUESTS_IBM_STORAGE = "OpenShift Request on IBM Storage Quota (GiB)" | ||
| QUOTA_REQUESTS_GPU = "OpenShift Request on GPU Quota" | ||
| QUOTA_REQUESTS_VM_GPU_A100_SXM4 = "OpenShift Request on GPU A100 SXM4" | ||
| QUOTA_REQUESTS_VM_GPU_V100 = "OpenShift Request on GPU V100" | ||
| QUOTA_REQUESTS_VM_GPU_H100 = "OpenShift Request on GPU H100" | ||
| QUOTA_PVC = "OpenShift Persistent Volume Claims Quota" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the comment! It helps clarify why we still have one attribute