# Tests of allocation candidates API

fixtures:
    - SharedStorageFixture

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

tests:

- name: list traits
  GET: /traits
  status: 200
  response_strings:
    # We at least want to make sure that this trait is supported.
    - MISC_SHARES_VIA_AGGREGATE

- name: get allocation candidates before microversion
  GET: /allocation_candidates?resources=VCPU:1
  request_headers:
      openstack-api-version: placement 1.8
  status: 404

- name: get allocation candidates empty resources
  GET: /allocation_candidates?resources=
  status: 400
  response_strings:
      - Badly formed resources parameter. Expected resources query string parameter in form
      - 'Got: empty string.'

- name: get allocation candidates no resources
  GET: /allocation_candidates
  status: 400
  response_strings:
      - "'resources' is a required property"

- name: get bad resource class
  GET: /allocation_candidates?resources=MCPU:99
  status: 400
  response_strings:
      - Invalid resource class in resources parameter

- name: get bad limit microversion
  GET: /allocation_candidates?resources=VCPU:1&limit=5
  request_headers:
      openstack-api-version: placement 1.15
  status: 400
  response_strings:
      - Invalid query string parameters
      - "'limit' was unexpected"

- name: get bad limit type
  GET: /allocation_candidates?resources=VCPU:1&limit=cow
  request_headers:
      openstack-api-version: placement 1.16
  status: 400
  response_strings:
      - Invalid query string parameters
      - "Failed validating 'pattern'"

- name: get bad limit value negative
  GET: /allocation_candidates?resources=VCPU:1&limit=-99
  request_headers:
      openstack-api-version: placement 1.16
  status: 400
  response_strings:
      - Invalid query string parameters
      - "Failed validating 'pattern'"

- name: get bad limit value zero
  GET: /allocation_candidates?resources=VCPU:1&limit=0
  request_headers:
      openstack-api-version: placement 1.16
  status: 400
  response_strings:
      - Invalid query string parameters
      - "Failed validating 'pattern'"

- name: get allocation candidates no allocations yet
  GET: /allocation_candidates?resources=VCPU:1,MEMORY_MB:1024,DISK_GB:100
  status: 200
  response_json_paths:
      # There are 4 providers involved. 2 compute nodes, 2 shared storage
      # providers
      $.provider_summaries.`len`: 4
      # There are 5 allocation requests, one combination for each compute
      # node that provides the VCPU/MEMORY_MB and DISK_GB provided by each
      # shared storage provider, plus compute node #2 alone
      $.allocation_requests.`len`: 5
      # Verify that compute node #1 only has VCPU and MEMORY_MB listed in the
      # resource requests. This validates the entire resources key.
      $.allocation_requests..allocations[?resource_provider.uuid="$ENVIRON['CN1_UUID']"].resources:
        - VCPU: 1
          MEMORY_MB: 1024
        - VCPU: 1
          MEMORY_MB: 1024
      # Verify that compute node #2 has VCPU and MEMORY_MB listed in the
      # resource requests thrice and DISK_GB once
      $.allocation_requests..allocations[?resource_provider.uuid="$ENVIRON['CN2_UUID']"].resources[VCPU]: [1, 1, 1]
      $.allocation_requests..allocations[?resource_provider.uuid="$ENVIRON['CN2_UUID']"].resources[MEMORY_MB]: [1024, 1024, 1024]
      $.allocation_requests..allocations[?resource_provider.uuid="$ENVIRON['CN2_UUID']"].resources[DISK_GB]: 100
      # Verify that shared storage providers only have DISK_GB listed in the
      # resource requests, but each is listed twice
      $.allocation_requests..allocations[?resource_provider.uuid="$ENVIRON['SS_UUID']"].resources[DISK_GB]: [100, 100]
      $.allocation_requests..allocations[?resource_provider.uuid="$ENVIRON['SS2_UUID']"].resources[DISK_GB]: [100, 100]
      # Verify that the resources listed in the provider summary for compute
      # node #1 show correct capacity and usage
      $.provider_summaries["$ENVIRON['CN1_UUID']"].resources[VCPU].capacity: 384 # 16.0 * 24
      $.provider_summaries["$ENVIRON['CN1_UUID']"].resources[VCPU].used: 0
      $.provider_summaries["$ENVIRON['CN1_UUID']"].resources[MEMORY_MB].capacity: 196608 # 1.5 * 128G
      $.provider_summaries["$ENVIRON['CN1_UUID']"].resources[MEMORY_MB].used: 0
      # Verify that the resources listed in the provider summary for compute
      # node #2 show correct capacity and usage
      $.provider_summaries["$ENVIRON['CN2_UUID']"].resources[VCPU].capacity: 384 # 16.0 * 24
      $.provider_summaries["$ENVIRON['CN2_UUID']"].resources[VCPU].used: 0
      $.provider_summaries["$ENVIRON['CN2_UUID']"].resources[MEMORY_MB].capacity: 196608 # 1.5 * 128G
      $.provider_summaries["$ENVIRON['CN2_UUID']"].resources[MEMORY_MB].used: 0
      $.provider_summaries["$ENVIRON['CN2_UUID']"].resources[DISK_GB].capacity: 1900 # 1.0 * 2000 - 100G
      $.provider_summaries["$ENVIRON['CN2_UUID']"].resources[DISK_GB].used: 0
      # Verify that the resources listed in the provider summary for shared
      # storage show correct capacity and usage
      $.provider_summaries["$ENVIRON['SS_UUID']"].resources[DISK_GB].capacity: 1900 # 1.0 * 2000 - 100G
      $.provider_summaries["$ENVIRON['SS_UUID']"].resources[DISK_GB].used: 0
      $.provider_summaries["$ENVIRON['SS2_UUID']"].resources[DISK_GB].capacity: 1900 # 1.0 * 2000 - 100G
      $.provider_summaries["$ENVIRON['SS2_UUID']"].resources[DISK_GB].used: 0
  response_forbidden_headers:
      # In the default microversion in this file (1.10) the cache headers
      # are not preset.
      - cache-control
      - last-modified

# Verify the 1.12 format of the allocation_requests sub object which
# changes from a list-list to dict-ish format.
- name: get allocation candidates 1.12 dictish
  GET: /allocation_candidates?resources=VCPU:1,MEMORY_MB:1024,DISK_GB:100
  request_headers:
      openstack-api-version: placement 1.12
  response_json_paths:
      # There are 4 providers involved. 2 compute nodes, 2 shared storage
      # providers
      $.provider_summaries.`len`: 4
      # There are 5 allocation requests, one combination for each compute
      # node that provides the VCPU/MEMORY_MB and DISK_GB provided by each
      # shared storage provider, plus compute node #2 alone
      $.allocation_requests.`len`: 5
      # Verify that compute node #1 only has VCPU and MEMORY_MB listed in the
      # resource requests. This validates the entire resources key.
      $.allocation_requests..allocations["$ENVIRON['CN1_UUID']"].resources:
        - VCPU: 1
          MEMORY_MB: 1024
        - VCPU: 1
          MEMORY_MB: 1024
      # Verify that compute node #2 has VCPU and MEMORY_MB listed in the
      # resource requests thrice and DISK_GB once
      $.allocation_requests..allocations["$ENVIRON['CN2_UUID']"].resources[VCPU]: [1, 1, 1]
      $.allocation_requests..allocations["$ENVIRON['CN2_UUID']"].resources[MEMORY_MB]: [1024, 1024, 1024]
      $.allocation_requests..allocations["$ENVIRON['CN2_UUID']"].resources[DISK_GB]: 100
      # Verify that shared storage providers only have DISK_GB listed in the
      # resource requests, but each is listed twice
      $.allocation_requests..allocations["$ENVIRON['SS_UUID']"].resources[DISK_GB]: [100, 100]
      $.allocation_requests..allocations["$ENVIRON['SS2_UUID']"].resources[DISK_GB]: [100, 100]

- name: get allocation candidates cache headers
  GET: /allocation_candidates?resources=VCPU:1,MEMORY_MB:1024,DISK_GB:100
  request_headers:
      # microversion 1.15 to cause cache headers
      openstack-api-version: placement 1.15
  response_headers:
      cache-control: no-cache
      # Does last-modified look like a legit timestamp?
      last-modified:  /^\w+, \d+ \w+ \d{4} [\d:]+ GMT$/

- name: get allocation candidates with limit
  GET: /allocation_candidates?resources=VCPU:1,MEMORY_MB:1024,DISK_GB:100&limit=1
  status: 200
  request_headers:
      openstack-api-version: placement 1.16
  response_json_paths:
      $.allocation_requests.`len`: 1

- name: get allocation candidates with multiple limits picks the first one
  GET: /allocation_candidates?resources=VCPU:1,MEMORY_MB:1024,DISK_GB:100&limit=10&limit=1
  status: 200
  request_headers:
      openstack-api-version: placement 1.16
  response_json_paths:
      $.allocation_requests.`len`: 5

- name: get allocation candidates with required traits in old version
  GET: /allocation_candidates?resources=VCPU:1,MEMORY_MB:1024,DISK_GB:100&required=HW_CPU_X86_SSE
  status: 400
  request_headers:
      openstack-api-version: placement 1.16
  response_strings:
      - Invalid query string parameters
      - "'required' was unexpected"

- name: get allocation candidates without traits summary in old version
  GET: /allocation_candidates?resources=VCPU:1,MEMORY_MB:1024,DISK_GB:100
  status: 200
  request_headers:
      openstack-api-version: placement 1.16
  response_json_paths:
       $.provider_summaries["$ENVIRON['CN1_UUID']"].`len`: 1
       $.provider_summaries["$ENVIRON['CN2_UUID']"].`len`: 1

- name: get allocation candidates with invalid trait
  GET: /allocation_candidates?resources=VCPU:1,MEMORY_MB:1024,DISK_GB:100&required=INVALID_TRAIT
  status: 400
  request_headers:
      openstack-api-version: placement 1.17
  response_strings:
      - No such trait(s)

- name: get allocation candidates with empty required value
  GET: /allocation_candidates?resources=VCPU:1,MEMORY_MB:1024,DISK_GB:100&required=
  status: 400
  request_headers:
      openstack-api-version: placement 1.17
  response_strings:
      - "Invalid query string parameters: Expected 'required' parameter value of the form: HW_CPU_X86_VMX,CUSTOM_MAGIC."

- name: get allocation candidates with empty required value 1.22
  GET: /allocation_candidates?resources=VCPU:1,MEMORY_MB:1024,DISK_GB:100&required=
  status: 400
  request_headers:
      openstack-api-version: placement 1.22
  response_strings:
      - "Invalid query string parameters: Expected 'required' parameter value of the form: HW_CPU_X86_VMX,!CUSTOM_MAGIC."

- name: get allocation candidates with invalid required value
  GET: /allocation_candidates?resources=VCPU:1,MEMORY_MB:1024,DISK_GB:100&required=,,
  status: 400
  request_headers:
      openstack-api-version: placement 1.17
  response_strings:
      - "Invalid query string parameters: Expected 'required' parameter value of the form: HW_CPU_X86_VMX,CUSTOM_MAGIC."

- name: get allocation candidates with forbidden trait pre-forbidden
  GET: /allocation_candidates?resources=VCPU:1,MEMORY_MB:1024,DISK_GB:100&required=!CUSTOM_MAGIC
  status: 400
  request_headers:
      openstack-api-version: placement 1.17
  response_strings:
      - "Invalid query string parameters: Expected 'required' parameter value of the form: HW_CPU_X86_VMX,CUSTOM_MAGIC."

- name: get allocation candidates with required trait
  GET: /allocation_candidates?resources=VCPU:1,MEMORY_MB:1024,DISK_GB:100&required=HW_CPU_X86_SSE
  status: 200
  request_headers:
      openstack-api-version: placement 1.17
  response_json_paths:
      $.allocation_requests.`len`: 2
      $.provider_summaries.`len`: 3
      $.provider_summaries["$ENVIRON['CN1_UUID']"].`len`: 2
      $.provider_summaries["$ENVIRON['CN1_UUID']"].traits.`sorted`:
          - HW_CPU_X86_SSE
          - HW_CPU_X86_SSE2

- name: get allocation candidates with forbidden trait
  GET: /allocation_candidates?resources=VCPU:1,MEMORY_MB:1024,DISK_GB:100&required=!HW_CPU_X86_SSE
  status: 200
  request_headers:
      openstack-api-version: placement 1.22
  response_json_paths:
      # There are no allocation requests for CN1. CN2 always satisfies the VCPU/MEMORY_MB.
      # The disk comes from CN2 or one of the shared storage providers.
      $.allocation_requests.`len`: 3
      $.allocation_requests..allocations["$ENVIRON['CN2_UUID']"].resources[VCPU]: [1, 1, 1]
      $.allocation_requests..allocations["$ENVIRON['CN2_UUID']"].resources[MEMORY_MB]: [1024, 1024, 1024]
      $.allocation_requests..allocations["$ENVIRON['CN2_UUID']"].resources[DISK_GB]: 100
      $.allocation_requests..allocations["$ENVIRON['SS_UUID']"].resources[DISK_GB]: 100
      $.allocation_requests..allocations["$ENVIRON['SS2_UUID']"].resources.DISK_GB: 100

- name: get allocation candidates with multiple required traits
  GET: /allocation_candidates?resources=VCPU:1,MEMORY_MB:1024,DISK_GB:100&required=HW_CPU_X86_SSE,HW_CPU_X86_SSE2
  status: 200
  request_headers:
      openstack-api-version: placement 1.17
  response_json_paths:
      $.allocation_requests.`len`: 2
      $.provider_summaries.`len`: 3
      $.provider_summaries["$ENVIRON['CN1_UUID']"].`len`: 2
      $.provider_summaries["$ENVIRON['CN1_UUID']"].traits.`sorted`:
          - HW_CPU_X86_SSE
          - HW_CPU_X86_SSE2

- name: get allocation candidates with required trait and no matching
  GET: /allocation_candidates?resources=VCPU:1,MEMORY_MB:1024,DISK_GB:100&required=HW_CPU_X86_SSE3
  status: 200
  request_headers:
      openstack-api-version: placement 1.17
  response_json_paths:
      $.allocation_requests.`len`: 0
      $.provider_summaries.`len`: 0

# Before microversion 1.27, the ``provider_summaries`` field in the response
# of the ``GET /allocation_candidates`` API included inventories of resource
# classes that are requested.
- name: get allocation candidates provider summaries with requested resource
  GET: /allocation_candidates?resources=VCPU:1
  status: 200
  request_headers:
      openstack-api-version: placement 1.26
  response_json_paths:
      $.allocation_requests.`len`: 2
      $.provider_summaries.`len`: 2
      $.provider_summaries["$ENVIRON['CN1_UUID']"].resources.`len`: 1
      $.provider_summaries["$ENVIRON['CN1_UUID']"].resources:
        VCPU:
          capacity: 384 # 16.0 * 24
          used: 0
      $.provider_summaries["$ENVIRON['CN2_UUID']"].resources.`len`: 1
      $.provider_summaries["$ENVIRON['CN2_UUID']"].resources:
        VCPU:
          capacity: 384 # 16.0 * 24
          used: 0

# From microversion 1.27, the ``provider_summaries`` field includes
# all the resource class inventories regardless of whether it is requested.
- name: get allocation candidates provider summaries with all resources
  GET: /allocation_candidates?resources=VCPU:1
  status: 200
  request_headers:
      openstack-api-version: placement 1.27
  response_json_paths:
      $.allocation_requests.`len`: 2
      $.provider_summaries.`len`: 2
      $.provider_summaries["$ENVIRON['CN1_UUID']"].resources.`len`: 2
      $.provider_summaries["$ENVIRON['CN1_UUID']"].resources:
        VCPU:
          capacity: 384 # 16.0 * 24
          used: 0
        MEMORY_MB:
          capacity: 196608 # 1.5 * 128G
          used: 0
      $.provider_summaries["$ENVIRON['CN2_UUID']"].resources.`len`: 3
      $.provider_summaries["$ENVIRON['CN2_UUID']"].resources:
        VCPU:
          capacity: 384 # 16.0 * 24
          used: 0
        MEMORY_MB:
          capacity: 196608 # 1.5 * 128G
          used: 0
        DISK_GB:
          capacity: 1900 # 1.0 * 2000 - 100G
          used: 0

# Before microversion 1.29, no root/parent uuid is included
- name: get allocation candidates no root or parent uuid
  GET: /allocation_candidates?resources=VCPU:1
  status: 200
  request_headers:
      openstack-api-version: placement 1.28
  response_json_paths:
      $.allocation_requests.`len`: 2
      $.provider_summaries.`len`: 2
      $.provider_summaries.["$ENVIRON['CN1_UUID']"].`len`: 2
      $.provider_summaries.["$ENVIRON['CN2_UUID']"].`len`: 2

- name: get allocation candidates with root and parent uuid
  GET: /allocation_candidates?resources=VCPU:1
  status: 200
  request_headers:
      openstack-api-version: placement 1.29
  response_json_paths:
      $.allocation_requests.`len`: 2
      $.provider_summaries.`len`: 10
      $.provider_summaries.["$ENVIRON['CN1_UUID']"].`len`: 4
      $.provider_summaries.["$ENVIRON['CN2_UUID']"].`len`: 4
      $.provider_summaries.["$ENVIRON['CN1_UUID']"].parent_provider_uuid: null
      $.provider_summaries.["$ENVIRON['CN1_UUID']"].root_provider_uuid: "$ENVIRON['CN1_UUID']"
      $.provider_summaries.["$ENVIRON['NUMA1_1_UUID']"].parent_provider_uuid: "$ENVIRON['CN1_UUID']"
      $.provider_summaries.["$ENVIRON['NUMA1_1_UUID']"].root_provider_uuid: "$ENVIRON['CN1_UUID']"
      $.provider_summaries.["$ENVIRON['NUMA1_2_UUID']"].parent_provider_uuid: "$ENVIRON['CN1_UUID']"
      $.provider_summaries.["$ENVIRON['NUMA1_2_UUID']"].root_provider_uuid: "$ENVIRON['CN1_UUID']"
      $.provider_summaries.["$ENVIRON['PF1_1_UUID']"].parent_provider_uuid: "$ENVIRON['NUMA1_1_UUID']"
      $.provider_summaries.["$ENVIRON['PF1_1_UUID']"].root_provider_uuid: "$ENVIRON['CN1_UUID']"
      $.provider_summaries.["$ENVIRON['PF1_2_UUID']"].parent_provider_uuid: "$ENVIRON['NUMA1_2_UUID']"
      $.provider_summaries.["$ENVIRON['PF1_2_UUID']"].root_provider_uuid: "$ENVIRON['CN1_UUID']"

# Before microversion 1.29, it isn't aware of nested providers.
# Namely, it can return non-root providers for allocation candidates,
- name: get allocation candidates only nested provider old microversion
  GET: /allocation_candidates?resources=SRIOV_NET_VF:4
  status: 200
  request_headers:
      openstack-api-version: placement 1.28
  response_json_paths:
      $.allocation_requests.`len`: 4
      $.provider_summaries.`len`: 4

- name: get allocation candidates only nested provider new microversion
  GET: /allocation_candidates?resources=SRIOV_NET_VF:4
  status: 200
  request_headers:
      openstack-api-version: placement 1.29
  response_json_paths:
      $.allocation_requests.`len`: 4
      $.provider_summaries.`len`: 10

# ...but it can't return combinations of providers in a tree.
- name: get allocation candidates root and nested old microversion
  GET: /allocation_candidates?resources=VCPU:1,SRIOV_NET_VF:4
  status: 200
  request_headers:
      openstack-api-version: placement 1.28
  response_json_paths:
      $.allocation_requests.`len`: 0
      $.provider_summaries.`len`: 0

- name: get allocation candidates root and nested new microversion
  GET: /allocation_candidates?resources=VCPU:1,SRIOV_NET_VF:4
  status: 200
  request_headers:
      openstack-api-version: placement 1.29
  response_json_paths:
      $.allocation_requests.`len`: 4
      $.provider_summaries.`len`: 10
      $.allocation_requests..allocations["$ENVIRON['CN1_UUID']"].resources.VCPU: [1, 1]
      $.allocation_requests..allocations["$ENVIRON['PF1_1_UUID']"].resources.SRIOV_NET_VF: 4
      $.allocation_requests..allocations["$ENVIRON['PF1_2_UUID']"].resources.SRIOV_NET_VF: 4
      $.allocation_requests..allocations["$ENVIRON['CN2_UUID']"].resources.VCPU: [1, 1]
      $.allocation_requests..allocations["$ENVIRON['PF2_1_UUID']"].resources.SRIOV_NET_VF: 4
      $.allocation_requests..allocations["$ENVIRON['PF2_2_UUID']"].resources.SRIOV_NET_VF: 4

- name: get allocation candidates nested limit
  desc: confirm provider summaries are complete, fixes story/2005859
  GET: /allocation_candidates?resources=VCPU:1,SRIOV_NET_VF:4&limit=1
  status: 200
  request_headers:
      openstack-api-version: placement 1.29
  response_json_paths:
      $.allocation_requests.`len`: 1
      $.allocation_requests[0].allocations.`len`: 2
      # We expect all the providers that share roots with the allocations.
      # In this case it the compute node, its two numa nodes and its two pfs.
      $.provider_summaries.`len`: 5

# Make sure that old microversions can return combinations where
# sharing providers are involved
- name: get allocation candidates shared and nested old microversion
  GET: /allocation_candidates?resources=DISK_GB:10,SRIOV_NET_VF:4
  status: 200
  request_headers:
      openstack-api-version: placement 1.28
  response_json_paths:
      $.allocation_requests.`len`: 8
      $.provider_summaries.`len`: 6

- name: get allocation candidates in tree old microversion
  GET: /allocation_candidates?resources=VCPU:1,SRIOV_NET_VF:4&in_tree=$ENVIRON['CN1_UUID']
  status: 400
  request_headers:
      openstack-api-version: placement 1.30
  response_strings:
    - "Invalid query string parameters"

- name: get allocation candidates in tree with invalid uuid
  GET: /allocation_candidates?resources=VCPU:1,SRIOV_NET_VF:4&in_tree=life-is-beautiful
  status: 400
  request_headers:
      openstack-api-version: placement 1.31
  response_strings:
    - "Expected 'in_tree' parameter to be a format of uuid"

- name: get allocation candidates in tree with root
  GET: /allocation_candidates?resources=VCPU:1,SRIOV_NET_VF:4&in_tree=$ENVIRON['CN1_UUID']
  status: 200
  request_headers:
      openstack-api-version: placement 1.31
  response_json_paths:
      $.allocation_requests.`len`: 2
      $.provider_summaries.`len`: 5
      $.allocation_requests..allocations["$ENVIRON['CN1_UUID']"].resources.VCPU: [1, 1]
      $.allocation_requests..allocations["$ENVIRON['PF1_1_UUID']"].resources.SRIOV_NET_VF: 4
      $.allocation_requests..allocations["$ENVIRON['PF1_2_UUID']"].resources.SRIOV_NET_VF: 4

- name: get allocation candidates in tree with child
  GET: /allocation_candidates?resources=VCPU:1,SRIOV_NET_VF:4&in_tree=$ENVIRON['PF1_2_UUID']
  status: 200
  request_headers:
      openstack-api-version: placement 1.31
  response_json_paths:
    $.allocation_requests.`len`: 2
    $.provider_summaries.`len`: 5
    $.allocation_requests..allocations["$ENVIRON['CN1_UUID']"].resources.VCPU: [1, 1]
    $.allocation_requests..allocations["$ENVIRON['PF1_1_UUID']"].resources.SRIOV_NET_VF: 4
    $.allocation_requests..allocations["$ENVIRON['PF1_2_UUID']"].resources.SRIOV_NET_VF: 4

- name: get allocation candidates in tree with shared 1
  GET: /allocation_candidates?resources=VCPU:1,DISK_GB:10&in_tree=$ENVIRON['CN1_UUID']
  status: 200
  request_headers:
      openstack-api-version: placement 1.31
  response_json_paths:
    # CN1 has no local disk. SS can't be used since it's out of the CN1 tree.
    $.allocation_requests.`len`: 0

- name: get allocation candidates in tree with shared 2
  GET: /allocation_candidates?resources=VCPU:1,DISK_GB:10&in_tree=$ENVIRON['CN2_UUID']
  status: 200
  request_headers:
      openstack-api-version: placement 1.31
  response_json_paths:
    # CN2 has local disk, but we don't get disk from the sharing providers
    # because they're not in_tree with CN2.
    $.allocation_requests.`len`: 1
    $.allocation_requests..allocations["$ENVIRON['CN2_UUID']"].resources.VCPU: 1
    $.allocation_requests..allocations["$ENVIRON['CN2_UUID']"].resources.DISK_GB: 10

- name: get allocation candidates in tree with shared 3
  GET: /allocation_candidates?resources=VCPU:1,DISK_GB:10&in_tree=$ENVIRON['SS_UUID']
  status: 200
  request_headers:
      openstack-api-version: placement 1.31
  response_json_paths:
    # SS doesn't have VCPU.
    $.allocation_requests.`len`: 0

# Test granular scenarios with `in_tree<N>`
- name: get allocation candidates in tree granular error orphaned
  GET: /allocation_candidates?resources=VCPU:1&in_tree1=$ENVIRON['CN1_UUID']
  status: 400
  request_headers:
      openstack-api-version: placement 1.31
  response_strings:
    - "All request groups must specify resources."

- name: get allocation candidates in_tree root granular root resource
  GET: /allocation_candidates?resources1=VCPU:1&in_tree1=$ENVIRON['CN1_UUID']
  status: 200
  request_headers:
      openstack-api-version: placement 1.31
  response_json_paths:
    $.allocation_requests.`len`: 1
    $.allocation_requests..allocations["$ENVIRON['CN1_UUID']"].resources.VCPU: 1

- name: get allocation candidates in_tree child granular root resource
  GET: /allocation_candidates?resources1=VCPU:1&in_tree1=$ENVIRON['PF1_1_UUID']
  status: 200
  request_headers:
      openstack-api-version: placement 1.31
  response_json_paths:
    $.allocation_requests.`len`: 1
    $.allocation_requests..allocations["$ENVIRON['CN1_UUID']"].resources.VCPU: 1

- name: get allocation candidates in_tree root granular child resource
  GET: /allocation_candidates?resources1=SRIOV_NET_VF:4&in_tree1=$ENVIRON['CN1_UUID']
  status: 200
  request_headers:
      openstack-api-version: placement 1.31
  response_json_paths:
    $.allocation_requests.`len`: 2
    $.allocation_requests..allocations["$ENVIRON['PF1_1_UUID']"].resources.SRIOV_NET_VF: 4
    $.allocation_requests..allocations["$ENVIRON['PF1_2_UUID']"].resources.SRIOV_NET_VF: 4

- name: get allocation candidates in_tree child granular child resource
  GET: /allocation_candidates?resources1=SRIOV_NET_VF:4&in_tree1=$ENVIRON['PF1_1_UUID']
  status: 200
  request_headers:
      openstack-api-version: placement 1.31
  response_json_paths:
    $.allocation_requests.`len`: 2
    $.allocation_requests..allocations["$ENVIRON['PF1_1_UUID']"].resources.SRIOV_NET_VF: 4
    $.allocation_requests..allocations["$ENVIRON['PF1_2_UUID']"].resources.SRIOV_NET_VF: 4

- name: get allocation candidates in tree granular local storage nonexistent
  GET: /allocation_candidates?resources=VCPU:1&resources1=DISK_GB:10&in_tree1=$ENVIRON['CN1_UUID']
  status: 200
  request_headers:
      openstack-api-version: placement 1.31
  response_json_paths:
    # CN1 has no local storage
    $.allocation_requests.`len`: 0

- name: get allocation candidates in tree granular local storage exists
  GET: /allocation_candidates?resources=VCPU:1&resources1=DISK_GB:10&in_tree1=$ENVIRON['CN2_UUID']
  status: 200
  request_headers:
      openstack-api-version: placement 1.31
  response_json_paths:
    $.allocation_requests.`len`: 1
    $.allocation_requests..allocations["$ENVIRON['CN2_UUID']"].resources.VCPU: 1
    $.allocation_requests..allocations["$ENVIRON['CN2_UUID']"].resources.DISK_GB: 10

# Practical usage for "Give me DISK_GB from SS and VCPU from I-don't-care-where"
- name: get allocation candidates in tree granular shared storage
  GET: /allocation_candidates?resources=VCPU:1&resources1=DISK_GB:10&in_tree1=$ENVIRON['SS_UUID']
  status: 200
  request_headers:
      openstack-api-version: placement 1.31
  response_json_paths:
    $.allocation_requests.`len`: 2
    $.allocation_requests..allocations["$ENVIRON['CN1_UUID']"].resources.VCPU: 1
    $.allocation_requests..allocations["$ENVIRON['CN2_UUID']"].resources.VCPU: 1
    $.allocation_requests..allocations["$ENVIRON['SS_UUID']"].resources.DISK_GB: [10, 10]

# Practical usage for "Give me VCPU from CN1 and DISK_GB from I-don't-care-where"
- name: get allocation candidates in tree unnumbered compute granular disk from shared storage only
  GET: /allocation_candidates?resources=VCPU:1&in_tree=$ENVIRON['CN1_UUID']&resources1=DISK_GB:10
  status: 200
  request_headers:
      openstack-api-version: placement 1.31
  response_json_paths:
    # CN1 has no local storage
    $.allocation_requests.`len`: 2
    $.allocation_requests..allocations["$ENVIRON['CN1_UUID']"].resources.VCPU: [1, 1]
    $.allocation_requests..allocations["$ENVIRON['SS_UUID']"].resources.DISK_GB: 10
    $.allocation_requests..allocations["$ENVIRON['SS2_UUID']"].resources.DISK_GB: 10

- name: get allocation candidates in tree unnumbered compute granular disk from shared or local
  GET: /allocation_candidates?resources=VCPU:1&in_tree=$ENVIRON['CN2_UUID']&resources1=DISK_GB:10
  status: 200
  request_headers:
      openstack-api-version: placement 1.31
  response_json_paths:
    # CN2 has local storage
    $.allocation_requests.`len`: 3
    $.allocation_requests..allocations["$ENVIRON['CN2_UUID']"].resources.VCPU: [1, 1, 1]
    $.allocation_requests..allocations["$ENVIRON['CN2_UUID']"].resources.DISK_GB: 10
    $.allocation_requests..allocations["$ENVIRON['SS_UUID']"].resources.DISK_GB: 10
    $.allocation_requests..allocations["$ENVIRON['SS2_UUID']"].resources.DISK_GB: 10

# Practical usage for "Give me VCPU from CN1 and DISK_GB from SS"
- name: get allocation candidates in tree granular compute and granular shared storage
  GET: /allocation_candidates?resources1=VCPU:1&in_tree1=$ENVIRON['CN1_UUID']&resources2=DISK_GB:10&in_tree2=$ENVIRON['SS_UUID']&group_policy=none
  status: 200
  request_headers:
      openstack-api-version: placement 1.31
  response_json_paths:
    $.allocation_requests.`len`: 1
    $.allocation_requests..allocations["$ENVIRON['CN1_UUID']"].resources.VCPU: 1
    $.allocation_requests..allocations["$ENVIRON['SS_UUID']"].resources.DISK_GB: 10
