# Tests of the ensure consumer behaviour for versions of the API before 1.8;
# starting with 1.8, project_id and user_id are required by the
# PUT: /allocations/{consumer_uuid} API.
fixtures:
    - AllocationFixture

defaults:
    request_headers:
        x-auth-token: admin
        accept: application/json
        openstack-api-version: placement 1.7

vars:
- &default_incomplete_id 00000000-0000-0000-0000-000000000000
tests:

- name: put an allocation without project/user (1.7)
  PUT: /allocations/$ENVIRON['CONSUMER_UUID']
  request_headers:
      content-type: application/json
      openstack-api-version: placement 1.7
  data:
      allocations:
          - resource_provider:
                uuid: $ENVIRON['RP_UUID']
            resources:
                DISK_GB: 10
  status: 204

# We now ALWAYS create a consumer record, and if project or user isn't
# specified (as was the case in 1.7) we should get the project/user
# corresponding to the CONF option for incomplete consumers when asking for the
# allocation information at a microversion that shows project/user information
# (1.12+)
- name: get with 1.12 microversion and check project and user are filled
  GET: /allocations/$ENVIRON['CONSUMER_UUID']
  request_headers:
      openstack-api-version: placement 1.12
  response_json_paths:
      $.project_id: *default_incomplete_id
      $.user_id: *default_incomplete_id
