diff options
author | melanie witt <melwittt@gmail.com> | 2017-05-31 18:53:34 +0000 |
---|---|---|
committer | melanie witt <melwittt@gmail.com> | 2017-06-15 18:23:37 +0000 |
commit | 77224c1feb350245b9fbba1d8b31d6e5904714b6 (patch) | |
tree | e81b2a84a203bd09da3820fde8045f74f3a33a3c /nova/tests/functional/api/openstack | |
parent | a909673682cdd8f02ef0ae5e8c6f061640e320ff (diff) | |
download | nova-77224c1feb350245b9fbba1d8b31d6e5904714b6.tar.gz |
placement: Add GET /usages to placement API
This adds GET /usages as part of a new microversion 1.9 of the
placement API. Usages can be queried by project or project/user:
GET /usages?project_id=<project id>
GET /usages?project_id=<project id>&user_id=<user id>
and will be returned as a sum of usages, for example:
200 OK
Content-Type: application/json
{
"usages": {
"VCPU": 2,
"MEMORY_MB": 1024,
"DISK_GB": 50,
...
}
}
A new method UsageList.get_all_by_project_user() has been added
for usage queries.
Part of blueprint placement-project-user
Change-Id: I8b948a4dfe6a50bea053b5dcae8f039229e2e364
Diffstat (limited to 'nova/tests/functional/api/openstack')
4 files changed, 126 insertions, 14 deletions
diff --git a/nova/tests/functional/api/openstack/placement/fixtures.py b/nova/tests/functional/api/openstack/placement/fixtures.py index 3c31f21b47..3b72723e32 100644 --- a/nova/tests/functional/api/openstack/placement/fixtures.py +++ b/nova/tests/functional/api/openstack/placement/fixtures.py @@ -95,6 +95,13 @@ class AllocationFixture(APIFixture): def start_fixture(self): super(AllocationFixture, self).start_fixture() self.context = context.get_admin_context() + + # For use creating and querying allocations/usages + os.environ['ALT_USER_ID'] = uuidutils.generate_uuid() + project_id = os.environ['PROJECT_ID'] + user_id = os.environ['USER_ID'] + alt_user_id = os.environ['ALT_USER_ID'] + # Stealing from the super rp_name = os.environ['RP_NAME'] rp_uuid = os.environ['RP_UUID'] @@ -103,6 +110,9 @@ class AllocationFixture(APIFixture): rp.create() # Create some DISK_GB inventory and allocations. + # Each set of allocations must have the same consumer_id because only + # the first allocation is used for the project/user association. + consumer_id = uuidutils.generate_uuid() inventory = objects.Inventory( self.context, resource_provider=rp, resource_class='DISK_GB', total=2048, @@ -112,36 +122,67 @@ class AllocationFixture(APIFixture): alloc1 = objects.Allocation( self.context, resource_provider=rp, resource_class='DISK_GB', - consumer_id=uuidutils.generate_uuid(), + consumer_id=consumer_id, used=500) alloc2 = objects.Allocation( self.context, resource_provider=rp, resource_class='DISK_GB', - consumer_id=uuidutils.generate_uuid(), + consumer_id=consumer_id, used=500) - alloc_list = objects.AllocationList(self.context, - objects=[alloc1, alloc2]) + alloc_list = objects.AllocationList( + self.context, + objects=[alloc1, alloc2], + project_id=project_id, + user_id=user_id, + ) alloc_list.create_all() # Create some VCPU inventory and allocations. + # Each set of allocations must have the same consumer_id because only + # the first allocation is used for the project/user association. + consumer_id = uuidutils.generate_uuid() inventory = objects.Inventory( self.context, resource_provider=rp, - resource_class='VCPU', total=8, + resource_class='VCPU', total=10, max_unit=4) inventory.obj_set_defaults() rp.add_inventory(inventory) alloc1 = objects.Allocation( self.context, resource_provider=rp, resource_class='VCPU', - consumer_id=uuidutils.generate_uuid(), + consumer_id=consumer_id, used=2) alloc2 = objects.Allocation( self.context, resource_provider=rp, resource_class='VCPU', - consumer_id=uuidutils.generate_uuid(), + consumer_id=consumer_id, used=4) - alloc_list = objects.AllocationList(self.context, - objects=[alloc1, alloc2]) + alloc_list = objects.AllocationList( + self.context, + objects=[alloc1, alloc2], + project_id=project_id, + user_id=user_id) + alloc_list.create_all() + + # Create a couple of allocations for a different user. + # Each set of allocations must have the same consumer_id because only + # the first allocation is used for the project/user association. + consumer_id = uuidutils.generate_uuid() + alloc1 = objects.Allocation( + self.context, resource_provider=rp, + resource_class='DISK_GB', + consumer_id=consumer_id, + used=20) + alloc2 = objects.Allocation( + self.context, resource_provider=rp, + resource_class='VCPU', + consumer_id=consumer_id, + used=1) + alloc_list = objects.AllocationList( + self.context, + objects=[alloc1, alloc2], + project_id=project_id, + user_id=alt_user_id) alloc_list.create_all() # The ALT_RP_XXX variables are for a resource provider that has diff --git a/nova/tests/functional/api/openstack/placement/gabbits/microversion.yaml b/nova/tests/functional/api/openstack/placement/gabbits/microversion.yaml index 33cdd3338d..d721c9be67 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/microversion.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/microversion.yaml @@ -39,13 +39,13 @@ tests: response_json_paths: $.errors[0].title: Not Acceptable -- name: latest microversion is 1.8 +- name: latest microversion is 1.9 GET: / request_headers: openstack-api-version: placement latest response_headers: vary: /OpenStack-API-Version/ - openstack-api-version: placement 1.8 + openstack-api-version: placement 1.9 - name: other accept header bad version GET: / diff --git a/nova/tests/functional/api/openstack/placement/gabbits/usage.yaml b/nova/tests/functional/api/openstack/placement/gabbits/usage.yaml index dbe3a767e3..b34c025572 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/usage.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/usage.yaml @@ -37,3 +37,47 @@ tests: content-type: application/json response_json_paths: usages: {} + +- name: get total usages earlier version + GET: /usages?project_id=$ENVIRON['PROJECT_ID'] + request_headers: + openstack-api-version: placement 1.8 + status: 404 + +- name: get total usages no project or user + GET: /usages + request_headers: + openstack-api-version: placement 1.9 + status: 400 + +- name: get total usages project_id less than min length + GET: /usages?project_id= + request_headers: + openstack-api-version: placement 1.9 + status: 400 + response_strings: + - "Failed validating 'minLength'" + +- name: get total usages user_id less than min length + GET: /usages?project_id=$ENVIRON['PROJECT_ID']&user_id= + request_headers: + openstack-api-version: placement 1.9 + status: 400 + response_strings: + - "Failed validating 'minLength'" + +- name: get total usages project_id exceeds max length + GET: /usages?project_id=78725f09-5c01-4c9e-97a5-98d75e1e32b178725f09-5c01-4c9e-97a5-98d75e1e32b178725f09-5c01-4c9e-97a5-98d75e1e32b178725f09-5c01-4c9e-97a5-98d75e1e32b178725f09-5c01-4c9e-97a5-98d75e1e32b178725f09-5c01-4c9e-97a5-98d75e1e32b178725f09-5c01-4c9e-97a5-98d75e1e32b178725f09-5c01-4c9e-97a5-98d75e1e32b1 + request_headers: + openstack-api-version: placement 1.9 + status: 400 + response_strings: + - "Failed validating 'maxLength'" + +- name: get total usages user_id exceeds max length + GET: /usages?project_id=$ENVIRON['PROJECT_ID']&user_id=78725f09-5c01-4c9e-97a5-98d75e1e32b178725f09-5c01-4c9e-97a5-98d75e1e32b178725f09-5c01-4c9e-97a5-98d75e1e32b178725f09-5c01-4c9e-97a5-98d75e1e32b178725f09-5c01-4c9e-97a5-98d75e1e32b178725f09-5c01-4c9e-97a5-98d75e1e32b178725f09-5c01-4c9e-97a5-98d75e1e32b178725f09-5c01-4c9e-97a5-98d75e1e32b1 + request_headers: + openstack-api-version: placement 1.9 + status: 400 + response_strings: + - "Failed validating 'maxLength'" diff --git a/nova/tests/functional/api/openstack/placement/gabbits/with-allocations.yaml b/nova/tests/functional/api/openstack/placement/gabbits/with-allocations.yaml index a2ffc01c2f..13f112bd7b 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/with-allocations.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/with-allocations.yaml @@ -21,9 +21,9 @@ tests: # required but superfluous, is present content-type: /application/json/ response_json_paths: - $.resource_provider_generation: 4 - $.usages.DISK_GB: 1000 - $.usages.VCPU: 6 + $.resource_provider_generation: 5 + $.usages.DISK_GB: 1020 + $.usages.VCPU: 7 - name: fail to delete resource provider DELETE: /resource_providers/$ENVIRON['RP_UUID'] @@ -41,3 +41,30 @@ tests: content-type: /application/json/ response_strings: - Unable to delete inventory for resource provider $ENVIRON['RP_UUID'] because the inventory is in use. + +- name: get total usages by project + GET: /usages?project_id=$ENVIRON['PROJECT_ID'] + request_headers: + openstack-api-version: placement 1.9 + status: 200 + response_json_paths: + $.usages.DISK_GB: 1020 + $.usages.VCPU: 7 + +- name: get total usages by project and user + GET: /usages?project_id=$ENVIRON['PROJECT_ID']&user_id=$ENVIRON['USER_ID'] + request_headers: + openstack-api-version: placement 1.9 + status: 200 + response_json_paths: + $.usages.DISK_GB: 1000 + $.usages.VCPU: 6 + +- name: get total usages by project and alt user + GET: /usages?project_id=$ENVIRON['PROJECT_ID']&user_id=$ENVIRON['ALT_USER_ID'] + request_headers: + openstack-api-version: placement 1.9 + status: 200 + response_json_paths: + $.usages.DISK_GB: 20 + $.usages.VCPU: 1 |