#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

# Tests that allocation request mappings can be sent back

fixtures:
    # See the layout diagram in this fixture's docstring in ../fixtures.py
    - NUMANetworkFixture

defaults:
    request_headers:
        x-auth-token: admin
        content-type: application/json
        accept: application/json
        # 1.34 is the microversion at which mappings are expected
        openstack-api-version: placement 1.34

tests:
- name: mappings request
  GET: /allocation_candidates
  query_parameters:
      required_NET1: CUSTOM_PHYSNET1
      resources_NET1: NET_BW_EGR_KILOBIT_PER_SEC:10
      required_NET2: CUSTOM_PHYSNET2
      resources_NET2: NET_BW_EGR_KILOBIT_PER_SEC:20
      resources: VCPU:1
      group_policy: isolate

- name: put allocation with results
  PUT: /allocations/254eea13-27e1-4305-b35f-5dedd9f58ba0
  data:
      allocations: $HISTORY['mappings request'].$RESPONSE['$.allocation_requests[0].allocations']
      mappings: $HISTORY['mappings request'].$RESPONSE['$.allocation_requests[0].mappings']
      consumer_generation: null
      user_id: 8c974f9a-f266-42f7-8613-a8017cbfb87F
      project_id: b2e599e0-ded8-47fd-b8ab-ceb7fca578bd
  status: 204

- name: put allocation wrong microversion
  PUT: /allocations/5662942e-497f-4a54-8257-dcbb3fa3e5f4
  request_headers:
      openstack-api-version: placement 1.33
  data:
      allocations: $HISTORY['mappings request'].$RESPONSE['$.allocation_requests[0].allocations']
      mappings: $HISTORY['mappings request'].$RESPONSE['$.allocation_requests[0].mappings']
      consumer_generation: null
      user_id: 8c974f9a-f266-42f7-8613-a8017cbfb87F
      project_id: b2e599e0-ded8-47fd-b8ab-ceb7fca578bd
  status: 400
  response_json_paths:
      $.errors[0].detail: /Additional properties are not allowed/

- name: put allocation mapping bad form
  PUT: /allocations/5f9588de-079d-462a-a459-408524ab9b60
  data:
      allocations: $HISTORY['mappings request'].$RESPONSE['$.allocation_requests[0].allocations']
      mappings:
          alpha: beta
      consumer_generation: null
      user_id: 8c974f9a-f266-42f7-8613-a8017cbfb87F
      project_id: b2e599e0-ded8-47fd-b8ab-ceb7fca578bd
  status: 400
  response_json_paths:
      $.errors[0].detail: "/JSON does not validate: 'beta' is not of type 'array'/"

- name: put allocation mapping empty
  PUT: /allocations/5f9588de-079d-462a-a459-408524ab9b60
  data:
      allocations: $HISTORY['mappings request'].$RESPONSE['$.allocation_requests[0].allocations']
      mappings: {}
      consumer_generation: null
      user_id: 8c974f9a-f266-42f7-8613-a8017cbfb87F
      project_id: b2e599e0-ded8-47fd-b8ab-ceb7fca578bd
  status: 400
  response_json_paths:
      $.errors[0].detail: "/JSON does not validate: {} does not have enough properties/"

- name: post allocation with results
  POST: /allocations
  data:
      '0b2c687e-89eb-47f6-bb68-2fc83e28032a':
          allocations: $HISTORY['mappings request'].$RESPONSE['$.allocation_requests[0].allocations']
          mappings: $HISTORY['mappings request'].$RESPONSE['$.allocation_requests[0].mappings']
          consumer_generation: null
          user_id: 8c974f9a-f266-42f7-8613-a8017cbfb87F
          project_id: b2e599e0-ded8-47fd-b8ab-ceb7fca578bd
  status: 204

- name: post allocation wrong microversion
  POST: /allocations
  request_headers:
      openstack-api-version: placement 1.33
  data:
      '0b2c687e-89eb-47f6-bb68-2fc83e28032a':
          allocations: $HISTORY['mappings request'].$RESPONSE['$.allocation_requests[0].allocations']
          mappings: $HISTORY['mappings request'].$RESPONSE['$.allocation_requests[0].mappings']
          consumer_generation: null
          user_id: 8c974f9a-f266-42f7-8613-a8017cbfb87F
          project_id: b2e599e0-ded8-47fd-b8ab-ceb7fca578bd
  status: 400
  response_json_paths:
      $.errors[0].detail: /Additional properties are not allowed/
