Skip to content
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

Bugfix/unittests #451

Merged
merged 4 commits into from
Sep 26, 2024
Merged

Bugfix/unittests #451

merged 4 commits into from
Sep 26, 2024

Conversation

Mark-Powers
Copy link
Contributor

@Mark-Powers Mark-Powers commented Sep 23, 2024

  • Removes outdated unit tests (no longer part of portal)
  • Adds balance service tests for API functions and helps
  • Fixes migrations that could not be ran (required external values)
  • Uses sqlite3 for testing DB for ease of running tests

@Mark-Powers Mark-Powers marked this pull request as ready for review September 24, 2024 19:38
@@ -70,6 +70,10 @@ def _str_to_localtime(utctimestr):


def init_charge_from_openstack_db(apps, schema_editor):
# No initial charges in test DB
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just to skip migrations when running in CI?
Do we know why this needs to access an external resource to run a migration anyway?

Copy link
Contributor Author

@Mark-Powers Mark-Powers Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

settings.TESTING is added in this PR, and is true when the code is run with ./manage.py test.

This code initially loaded existing reservations at openstack sites into the charges database table.
3a6d518

@msherman64 msherman64 self-requested a review September 24, 2024 19:53
Copy link
Contributor

@msherman64 msherman64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely better than before, and I'm really happy to see where we explicitly need to mock calls to keystone and keycloak in order for it to work.

comments so far are mostly pointing at potential tech debt, but this seems good to me.
Are there any particularly annoying test cases where we should add comments describing the intended behavior?

Comment on lines +147 to +265

if not include_update:
return {
"context": {
"user_id": "c631173e-dec0-4bb7-a0c3-f7711153c06c",
"project_id": "a0b86a98-b0d3-43cb-948e-00689182efd4",
"auth_url": "https://api.example.com:5000/v3",
"region_name": "RegionOne",
},
"lease": {
"start_date": lease_start,
"end_date": lease_end,
"project_id": "a0b86a98-b0d3-43cb-948e-00689182efd4",
"user_id": "c631173e-dec0-4bb7-a0c3-f7711153c06c",
"name": "my_lease",
"reservations": [
{
"resource_type": "physical:host",
"min": allocations_per_res,
"max": allocations_per_res,
"hypervisor_properties": "[]",
"resource_properties": '["==", "$availability_zone", "az1"]',
"id": str(j),
"allocations": [
{
"id": str(i),
"hypervisor_hostname": "32af5a7a-e7a3-4883-a643-828e3f63bf54",
"extra": {"availability_zone": "az1"},
"su_factor": su_factor,
}
for i in range(allocations_per_res)
],
}
for j in range(reservations)
],
},
}
else:
return {
"context": {
"user_id": "c631173e-dec0-4bb7-a0c3-f7711153c06c",
"project_id": "a0b86a98-b0d3-43cb-948e-00689182efd4",
"auth_url": "https://api.example.com:5000/v3",
"region_name": "RegionOne",
},
"current_lease": {
"start_date": lease_start,
"end_date": lease_end,
"project_id": "a0b86a98-b0d3-43cb-948e-00689182efd4",
"user_id": "c631173e-dec0-4bb7-a0c3-f7711153c06c",
"name": "my_lease",
"reservations": [
{
"resource_type": "physical:host",
"min": allocations_per_res,
"max": allocations_per_res,
"hypervisor_properties": "[]",
"resource_properties": '["==", "$availability_zone", "az1"]',
"id": str(j),
"allocations": [
{
"id": str(i),
"hypervisor_hostname": "32af5a7a-e7a3-4883-a643-828e3f63bf54",
"extra": {"availability_zone": "az1"},
"su_factor": su_factor,
}
for i in range(allocations_per_res)
],
}
for j in range(reservations)
],
},
"lease": {
"start_date": update_start,
"end_date": update_end,
"project_id": "a0b86a98-b0d3-43cb-948e-00689182efd4",
"user_id": "c631173e-dec0-4bb7-a0c3-f7711153c06c",
"name": "my_lease",
"reservations": [
{
"resource_type": "physical:host",
"min": update_allocations_per_res,
"max": update_allocations_per_res,
"hypervisor_properties": "[]",
"resource_properties": '["==", "$availability_zone", "az1"]',
"id": str(j),
"allocations": [
{
"id": str(i),
"hypervisor_hostname": "32af5a7a-e7a3-4883-a643-828e3f63bf54",
"extra": {"availability_zone": "az1"},
"su_factor": update_su_factor,
}
for i in range(update_allocations_per_res)
],
}
for j in range(update_reservations)
],
},
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to comment, at a glance it's not clear to me which values are actually important, and which are just placeholders. Is this basically generating test data to help parametrize other tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is generating blazar API data to test the methods that our API view calls. https://docs.openstack.org/blazar/2024.1/admin/usage-enforcement.html

The most relevant parts are # of reservations, # of allocations in each reservation, and su factor, along with the lease duration.

@Mark-Powers
Copy link
Contributor Author

Also calling out this functional change:

resource_id = reservation.get(
"id",
TMP_RESOURCE_ID.format(
prefix=TMP_RESOURCE_ID_PREFIX,
project_id=lease["project_id"],
user_id=lease["user_id"],
start_date=lease["start_date"],
name=lease["name"],
),
)

Before, it always used a temp ID, as the blazar enforcement API does not give reservation IDs on create. Now, this first looks for a real ID, and falls back on a temp ID. A celery task renames the temp IDs. I'm working to add a real ID to this API call in blazar. The temp IDs are not reliable, and cause errors when a user extends their lease.

@Mark-Powers Mark-Powers merged commit 69e6a80 into master Sep 26, 2024
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants