Merge "placement: Add GET /usages to placement API"

This commit is contained in:
Jenkins
2017-06-24 01:30:23 +00:00
committed by Gerrit Code Review
10 changed files with 196 additions and 23 deletions

View File

@@ -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

View File

@@ -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: /

View File

@@ -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'"

View File

@@ -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

View File

@@ -74,7 +74,7 @@ class TestMicroversionIntersection(test.NoDBTestCase):
# if you add two different versions of method 'foobar' the
# number only goes up by one if no other version foobar yet
# exists. This operates as a simple sanity check.
TOTAL_VERSIONED_METHODS = 13
TOTAL_VERSIONED_METHODS = 14
def test_methods_versioned(self):
methods_data = microversion.VERSIONED_METHODS