-
Notifications
You must be signed in to change notification settings - Fork 31
Description
Bug description
The following requests to v1/cloud/instances create errors with verbose=true:
- provider aws and instance type ra3.4xlarge.
- provider aws and instance type ra3.16xlarge.
- provider gcp and instance type c4-highmem-192 .
- provider gcp and instance type c3d-standard-360 .
- provider gcp and instance type c3d-highmem-180 .
- provider gcp and instance type c3d-highmem-360 .
To Reproduce
curl -X 'POST'
'https://api.boavizta.org/v1/cloud/instance?verbose=true&criteria=gwp&criteria=adp&criteria=pe'
-H 'accept: application/json'
-H 'Content-Type: application/json'
-d '{
"provider": "aws",
"instance_type": "ra3.4xlarge",
"usage": {
"usage_location": "FRA",
"time_workload": [
{
"time_percentage": 50,
"load_percentage": 0
},
{
"time_percentage": 25,
"load_percentage": 60
},
{
"time_percentage": 25,
"load_percentage": 100
}
]
}
}'
==> Internal server error
When looking at the stack trace, I get (for aws and ra3.4xlarge):
File "/Users/vincentvillet/Library/Caches/pypoetry/virtualenvs/efootprint-DvRIyG39-py3.12/lib/python3.12/site-packages/boaviztapi/service/impacts_computation.py", line 471, in cloud_impact_embedded
allocation = cloud_instance.hdd_storage.value / cloud_instance.platform.get_total_disk_capacity("HDD")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ZeroDivisionError: float division by zero
Indeed, the platform ra3.16xlarge has 6 HDD.units but HDD.capacity=0
Expected behavior
The test test_all_instances should be able to detect such errors. I’ve tried in the branch fix-cloud-instances-testing to fix it by adding provider and instance_type to the tested url and setting verbose to true. However, I now get much more 500 errors because the data used is the test data. I’ve tried copying and pasting boaviztapi/data/archetypes/server.csv data to tests/data/archetypes/server.csv but it generates other errors so I’ve stopped there. I think it might be worthwhile to stop doing
if "pytest" in sys.modules:
data_dir = os.path.join(os.path.dirname(file), '../tests/data')
else:
data_dir = os.path.join(os.path.dirname(file), 'data')
in boavizta/init.py and use mocks when we want to use test data, so that we can test what will be used in production. I would have the other nice side effect to allow boaviztapi to be used as a dependency in other python packages (it is used in e-footprint and at the moment I have to fallback to calling web api when doing tests, because the test folder isn’t included in boaviztapi package so I get an error because tests/data doesn’t exist).