
fixtures:
    - APIFixture

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

tests:

- name: what is at resource providers
  GET: /resource_providers
  request_headers:
      # microversion 1.15 for cache headers
      openstack-api-version: placement 1.15
  response_json_paths:
      $.resource_providers: []
  response_headers:
      cache-control: no-cache
      # Does last-modified look like a legit timestamp?
      last-modified:  /^\w+, \d+ \w+ \d{4} [\d:]+ GMT$/

- name: non admin forbidden
  GET: /resource_providers
  request_headers:
      x-auth-token: user
      accept: application/json
  status: 403
  response_json_paths:
      $.errors[0].title: Forbidden

- name: route not found non json
  GET: /moo
  request_headers:
      accept: text/plain
  status: 404
  response_strings:
      - The resource could not be found

- name: post new resource provider - old microversion
  POST: /resource_providers
  request_headers:
    content-type: application/json
    openstack-api-version: placement 1.19
  data:
      name: $ENVIRON['RP_NAME']
      uuid: $ENVIRON['RP_UUID']
  status: 201
  response_headers:
      location: //resource_providers/[a-f0-9-]+/
  response_forbidden_headers:
      - content-type

- name: delete it
  DELETE: $LOCATION
  status: 204

- name: post new resource provider - new microversion
  POST: /resource_providers
  request_headers:
      content-type: application/json
  data:
      name: $ENVIRON['RP_NAME']
      uuid: $ENVIRON['RP_UUID']
  status: 200
  response_headers:
      location: //resource_providers/[a-f0-9-]+/
  response_json_paths:
      $.uuid: $ENVIRON['RP_UUID']
      $.name: $ENVIRON['RP_NAME']
      $.parent_provider_uuid: null
      $.generation: 0
      $.links[?rel = "self"].href: /resource_providers/$ENVIRON['RP_UUID']
      $.links[?rel = "inventories"].href: /resource_providers/$ENVIRON['RP_UUID']/inventories
      $.links[?rel = "usages"].href: /resource_providers/$ENVIRON['RP_UUID']/usages

# On this one, don't test for which field was a duplicate because
# that depends on how the database reports columns.
- name: try to create same all again
  POST: /resource_providers
  request_headers:
    content-type: application/json
  data:
      name: $ENVIRON['RP_NAME']
      uuid: $ENVIRON['RP_UUID']
  status: 409
  response_strings:
      - Conflicting resource provider
  response_json_paths:
      $.errors[0].title: Conflict

- name: try to create same name again
  POST: /resource_providers
  request_headers:
    content-type: application/json
  data:
      name: $ENVIRON['RP_NAME']
      uuid: ada30fb5-566d-4fe1-b43b-28a9e988790c
  status: 409
  response_strings:
      - "Conflicting resource provider name: $ENVIRON['RP_NAME'] already exists"
  response_json_paths:
      $.errors[0].title: Conflict
      $.errors[0].code: placement.duplicate_name

- name: confirm the correct post
  GET: /resource_providers/$ENVIRON['RP_UUID']
  request_headers:
      content-type: application/json
      openstack-api-version: placement 1.15
  response_headers:
      content-type: application/json
      cache-control: no-cache
      # Does last-modified look like a legit timestamp?
      last-modified:  /^\w+, \d+ \w+ \d{4} [\d:]+ GMT$/
  response_json_paths:
      $.uuid: $ENVIRON['RP_UUID']
      $.name: $ENVIRON['RP_NAME']
      $.parent_provider_uuid: null
      $.generation: 0
      $.links[?rel = "self"].href: /resource_providers/$ENVIRON['RP_UUID']
      $.links[?rel = "inventories"].href: /resource_providers/$ENVIRON['RP_UUID']/inventories
      $.links[?rel = "usages"].href: /resource_providers/$ENVIRON['RP_UUID']/usages

- name: get resource provider works with no accept
  GET: /resource_providers/$ENVIRON['RP_UUID']
  response_headers:
      content-type: /application/json/
  response_json_paths:
      $.uuid: $ENVIRON['RP_UUID']

- name: get non-existing resource provider
  GET: /resource_providers/d67370b5-4dc0-470d-a4fa-85e8e89abc6c
  status: 404
  response_strings:
      - No resource provider with uuid d67370b5-4dc0-470d-a4fa-85e8e89abc6c found
  response_json_paths:
      $.errors[0].title: Not Found

- name: list one resource providers
  GET: /resource_providers
  request_headers:
      openstack-api-version: placement 1.15
  response_json_paths:
      $.resource_providers.`len`: 1
      $.resource_providers[0].uuid: $ENVIRON['RP_UUID']
      $.resource_providers[0].name: $ENVIRON['RP_NAME']
      $.resource_providers[0].generation: 0
      $.resource_providers[0].parent_provider_uuid: null
      $.resource_providers[0].links[?rel = "self"].href: /resource_providers/$ENVIRON['RP_UUID']
      $.resource_providers[0].links[?rel = "inventories"].href: /resource_providers/$ENVIRON['RP_UUID']/inventories
      $.resource_providers[0].links[?rel = "usages"].href: /resource_providers/$ENVIRON['RP_UUID']/usages
  response_headers:
      cache-control: no-cache
      # Does last-modified look like a legit timestamp?
      last-modified:  /^\w+, \d+ \w+ \d{4} [\d:]+ GMT$/

- name: filter out all resource providers by name
  GET: /resource_providers?name=flubblebubble
  response_json_paths:
      $.resource_providers.`len`: 0

- name: filter out all resource providers by uuid
  GET: /resource_providers?uuid=d67370b5-4dc0-470d-a4fa-85e8e89abc6c
  response_json_paths:
      $.resource_providers.`len`: 0

- name: list one resource provider filtering by name
  GET: /resource_providers?name=$ENVIRON['RP_NAME']
  response_json_paths:
      $.resource_providers.`len`: 1
      $.resource_providers[0].uuid: $ENVIRON['RP_UUID']
      $.resource_providers[0].name: $ENVIRON['RP_NAME']
      $.resource_providers[0].links[?rel = "self"].href: /resource_providers/$ENVIRON['RP_UUID']
      $.resource_providers[0].links[?rel = "inventories"].href: /resource_providers/$ENVIRON['RP_UUID']/inventories
      $.resource_providers[0].links[?rel = "usages"].href: /resource_providers/$ENVIRON['RP_UUID']/usages

- name: list resource providers filtering by invalid uuid
  GET: /resource_providers?uuid=spameggs
  status: 400
  response_strings:
      - 'Invalid query string parameters'
  response_json_paths:
      $.errors[0].title: Bad Request

- name: list resource providers providing an invalid filter
  GET: /resource_providers?spam=eggs
  status: 400
  response_strings:
      - 'Invalid query string parameters'
  response_json_paths:
      $.errors[0].title: Bad Request

- name: list one resource provider filtering by uuid with allocations link
  GET: /resource_providers?uuid=$ENVIRON['RP_UUID']
  request_headers:
      openstack-api-version: placement 1.11
  response_json_paths:
      $.resource_providers.`len`: 1
      $.resource_providers[0].uuid: $ENVIRON['RP_UUID']
      $.resource_providers[0].name: $ENVIRON['RP_NAME']
      $.resource_providers[0].links.`len`: 6
      $.resource_providers[0].links[?rel = "self"].href: /resource_providers/$ENVIRON['RP_UUID']
      $.resource_providers[0].links[?rel = "inventories"].href: /resource_providers/$ENVIRON['RP_UUID']/inventories
      $.resource_providers[0].links[?rel = "usages"].href: /resource_providers/$ENVIRON['RP_UUID']/usages
      $.resource_providers[0].links[?rel = "allocations"].href: /resource_providers/$ENVIRON['RP_UUID']/allocations

- name: list one resource provider filtering by uuid no allocations link
  GET: /resource_providers?uuid=$ENVIRON['RP_UUID']
  request_headers:
      openstack-api-version: placement 1.10
  response_json_paths:
      $.resource_providers.`len`: 1
      $.resource_providers[0].uuid: $ENVIRON['RP_UUID']
      $.resource_providers[0].name: $ENVIRON['RP_NAME']
      $.resource_providers[0].links.`len`: 5
      $.resource_providers[0].links[?rel = "self"].href: /resource_providers/$ENVIRON['RP_UUID']
      $.resource_providers[0].links[?rel = "inventories"].href: /resource_providers/$ENVIRON['RP_UUID']/inventories
      $.resource_providers[0].links[?rel = "usages"].href: /resource_providers/$ENVIRON['RP_UUID']/usages

- name: update a resource provider's name
  PUT: /resource_providers/$RESPONSE['$.resource_providers[0].uuid']
  request_headers:
      content-type: application/json
      openstack-api-version: placement 1.15
  data:
      name: new name
  status: 200
  response_headers:
      content-type: /application/json/
      cache-control: no-cache
      # Does last-modified look like a legit timestamp?
      last-modified:  /^\w+, \d+ \w+ \d{4} [\d:]+ GMT$/
  response_forbidden_headers:
      - location
  response_json_paths:
      $.generation: 0
      $.name: new name
      $.uuid: $ENVIRON['RP_UUID']
      $.links[?rel = "self"].href: /resource_providers/$ENVIRON['RP_UUID']

- name: check the name from that update
  GET: $LAST_URL
  response_json_paths:
      $.name: new name

- name: update a provider poorly
  PUT: $LAST_URL
  request_headers:
      content-type: application/json
  data:
      badfield: new name
  status: 400
  response_strings:
      - 'JSON does not validate'
  response_json_paths:
      $.errors[0].title: Bad Request

# This section of tests validate nested resource provider relationships and
# constraints. We attempt to set the parent provider UUID for the primary
# resource provider to a UUID value of a provider we have not yet created and
# expect a failure. We then create that parent provider record and attempt to
# set the same parent provider UUID without also setting the root provider UUID
# to the same value, with an expected failure. Finally, we set the primary
# provider's root AND parent to the new provider UUID and verify success.

- name: test POST microversion limits nested providers
  POST: /resource_providers
  request_headers:
      openstack-api-version: placement 1.13
      content-type: application/json
  data:
      name: child
      parent_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']
  status: 400
  response_strings:
      - 'JSON does not validate'

- name: test PUT microversion limits nested providers
  PUT: /resource_providers/$ENVIRON['RP_UUID']
  request_headers:
      openstack-api-version: placement 1.13
      content-type: application/json
  data:
      name: child
      parent_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']
  status: 400
  response_strings:
      - 'JSON does not validate'

- name: fail trying to set a root provider UUID
  PUT: /resource_providers/$ENVIRON['RP_UUID']
  request_headers:
      content-type: application/json
  data:
      root_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']
  status: 400
  response_strings:
      - 'JSON does not validate'

- name: fail trying to self-parent
  POST: /resource_providers
  request_headers:
      content-type: application/json
  data:
      name: child
      uuid: $ENVIRON['ALT_PARENT_PROVIDER_UUID']
      parent_provider_uuid: $ENVIRON['ALT_PARENT_PROVIDER_UUID']
  status: 400
  response_strings:
      - 'parent provider UUID cannot be same as UUID'
      - 'Unable to create resource provider \"child\", $ENVIRON["ALT_PARENT_PROVIDER_UUID"]:'

- name: update a parent provider UUID to non-existing provider
  PUT: /resource_providers/$ENVIRON['RP_UUID']
  request_headers:
      content-type: application/json
  data:
      name: parent
      parent_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']
  status: 400
  response_strings:
      - 'parent provider UUID does not exist'

- name: now create the parent provider
  POST: /resource_providers
  request_headers:
      content-type: application/json
  data:
      name: parent
      uuid: $ENVIRON['PARENT_PROVIDER_UUID']
  status: 200
  response_json_paths:
      $.uuid: $ENVIRON['PARENT_PROVIDER_UUID']
      $.name: parent
      $.parent_provider_uuid: null
      $.generation: 0

- name: get provider with old microversion no root provider UUID field
  GET: /resource_providers/$ENVIRON['PARENT_PROVIDER_UUID']
  request_headers:
      openstack-api-version: placement 1.13
      content-type: application/json
  response_json_paths:
      $.`len`: 4
      name: parent
  status: 200

- name: get provider has root provider UUID field
  GET: /resource_providers/$ENVIRON['PARENT_PROVIDER_UUID']
  request_headers:
      content-type: application/json
  response_json_paths:
      $.`len`: 6
      name: parent
      root_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']
      parent_provider_uuid: null
  status: 200

- name: update a parent
  PUT: /resource_providers/$ENVIRON['RP_UUID']
  request_headers:
      content-type: application/json
  data:
      name: child
      parent_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']
  status: 200

- name: get provider has new parent and root provider UUID field
  GET: /resource_providers/$ENVIRON['RP_UUID']
  request_headers:
      content-type: application/json
  response_json_paths:
      name: child
      root_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']
      parent_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']
  status: 200

- name: fail trying to un-parent with old microversion
  PUT: /resource_providers/$ENVIRON['RP_UUID']
  request_headers:
      content-type: application/json
      openstack-api-version: placement 1.36
  data:
      name: child
      parent_provider_uuid: null
  status: 400
  response_strings:
      - 'un-parenting a provider is not currently allowed'

- name: un-parent provider
  PUT: /resource_providers/$ENVIRON['RP_UUID']
  request_headers:
      content-type: application/json
      openstack-api-version: placement 1.37
  data:
      name: child
      parent_provider_uuid: null
  status: 200
  response_json_paths:
    $.uuid: $ENVIRON['RP_UUID']
    $.name: 'child'
    $.parent_provider_uuid: null
    $.root_provider_uuid: $ENVIRON['RP_UUID']

- name: re-parent back to its original parent after un-parent
  PUT: /resource_providers/$ENVIRON['RP_UUID']
  request_headers:
      content-type: application/json
      openstack-api-version: placement 1.37
  data:
      name: child
      parent_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']
  status: 200
  response_json_paths:
    $.uuid: $ENVIRON['RP_UUID']
    $.name: child
    $.parent_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']
    $.root_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']

- name: 409 conflict while trying to delete parent with existing child
  DELETE: /resource_providers/$ENVIRON['PARENT_PROVIDER_UUID']
  status: 409
  response_strings:
      - "Unable to delete parent resource provider
       $ENVIRON['PARENT_PROVIDER_UUID']: It has child resource providers."
  response_json_paths:
      $.errors[0].code: placement.resource_provider.cannot_delete_parent

- name: list all resource providers in a tree that does not exist
  GET: /resource_providers?in_tree=$ENVIRON['ALT_PARENT_PROVIDER_UUID']
  response_json_paths:
      $.resource_providers.`len`: 0

- name: list all resource providers in a tree with multiple providers in tree
  GET: /resource_providers?in_tree=$ENVIRON['RP_UUID']
  response_json_paths:
      $.resource_providers.`len`: 2
      # Verify that we have both the parent and child in the list
      $.resource_providers[?uuid="$ENVIRON['PARENT_PROVIDER_UUID']"].root_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']
      $.resource_providers[?uuid="$ENVIRON['RP_UUID']"].root_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']

- name: create a new parent provider
  POST: /resource_providers
  request_headers:
    content-type: application/json
  data:
      name: altwparent
      uuid: $ENVIRON['ALT_PARENT_PROVIDER_UUID']
  status: 200
  response_headers:
      location: //resource_providers/[a-f0-9-]+/
  response_json_paths:
      $.uuid: $ENVIRON['ALT_PARENT_PROVIDER_UUID']
      $.name: altwparent

- name: list all resource providers in a tree
  GET: /resource_providers?in_tree=$ENVIRON['ALT_PARENT_PROVIDER_UUID']
  response_json_paths:
      $.resource_providers.`len`: 1
      $.resource_providers[?uuid="$ENVIRON['ALT_PARENT_PROVIDER_UUID']"].root_provider_uuid: $ENVIRON['ALT_PARENT_PROVIDER_UUID']

- name: filter providers by traits none of them have
  GET: /resource_providers?required=HW_CPU_X86_SGX,HW_CPU_X86_SHA
  response_json_paths:
      $.resource_providers.`len`: 0

- name: add traits to a provider
  PUT: /resource_providers/$ENVIRON['RP_UUID']/traits
  request_headers:
    content-type: application/json
  data:
      resource_provider_generation: 0
      traits: ['HW_CPU_X86_SGX', 'STORAGE_DISK_SSD']

- name: add traits to another provider
  PUT: /resource_providers/$ENVIRON['ALT_PARENT_PROVIDER_UUID']/traits
  request_headers:
    content-type: application/json
  data:
      resource_provider_generation: 0
      traits: ['MISC_SHARES_VIA_AGGREGATE', 'STORAGE_DISK_SSD']

- name: filter providers with multiple traits where no provider has all of them
  GET: /resource_providers?required=HW_CPU_X86_SGX,MISC_SHARES_VIA_AGGREGATE
  response_json_paths:
      $.resource_providers.`len`: 0

- name: filter providers with a trait some of them have
  GET: /resource_providers?required=STORAGE_DISK_SSD
  response_json_paths:
      $.resource_providers.`len`: 2
      # Don't really care about the root UUID - just validating that the providers present are the ones we expected
      $.resource_providers[?uuid="$ENVIRON['ALT_PARENT_PROVIDER_UUID']"].root_provider_uuid: $ENVIRON['ALT_PARENT_PROVIDER_UUID']
      $.resource_providers[?uuid="$ENVIRON['RP_UUID']"].root_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']

- name: list providers with 'required' parameter filters cumulatively with in_tree
  GET: /resource_providers?required=STORAGE_DISK_SSD&in_tree=$ENVIRON['RP_UUID']
  response_json_paths:
      $.resource_providers.`len`: 1
      # Only RP_UUID satisfies both the tree and trait constraint
      $.resource_providers[?uuid="$ENVIRON['RP_UUID']"].root_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']

- name: list providers for full count
  GET: /resource_providers
  response_json_paths:
      $.resource_providers.`len`: 3

- name: list providers forbidden 1.22
  GET: /resource_providers?required=!STORAGE_DISK_SSD
  response_json_paths:
      $.resource_providers.`len`: 1

- name: confirm forbidden trait not there
  GET: /resource_providers/$RESPONSE['$.resource_providers[0].uuid']/traits
  response_json_paths:
      $.traits: []

- name: list providers forbidden 1.21
  GET: /resource_providers?required=!STORAGE_DISK_SSD
  request_headers:
      openstack-api-version: placement 1.21
  status: 400
  response_strings:
      - "Invalid query string parameters: Expected 'required' parameter value of the form: HW_CPU_X86_VMX,CUSTOM_MAGIC. Got: !STORAGE_DISK_SSD"

- name: list providers forbidden again
  GET: /resource_providers?required=!MISC_SHARES_VIA_AGGREGATE
  response_json_paths:
      $.resource_providers.`len`: 2

- name: mixed required and forbidden
  GET: /resource_providers?required=!HW_CPU_X86_SGX,STORAGE_DISK_SSD
  response_json_paths:
      $.resource_providers.`len`: 1

- name: confirm mixed required and forbidden
  GET: /resource_providers/$RESPONSE['$.resource_providers[0].uuid']/traits
  response_json_paths:
      $.traits.`sorted`: ['MISC_SHARES_VIA_AGGREGATE', 'STORAGE_DISK_SSD']

- name: multiple forbidden
  GET: /resource_providers?required=!MISC_SHARES_VIA_AGGREGATE,!HW_CPU_X86_SGX
  response_json_paths:
      $.resource_providers.`len`: 1

- name: confirm multiple forbidden
  GET: /resource_providers/$RESPONSE['$.resource_providers[0].uuid']/traits
  response_json_paths:
      $.traits: []

- name: forbidden no apply
  GET: /resource_providers?required=!HW_CPU_X86_VMX
  response_json_paths:
      $.resource_providers.`len`: 3

- name: create some inventory
  PUT: /resource_providers/$ENVIRON['ALT_PARENT_PROVIDER_UUID']/inventories
  request_headers:
      content-type: application/json
  data:
      resource_provider_generation: 1
      inventories:
        IPV4_ADDRESS:
          total: 253
        DISK_GB:
          total: 1024
  status: 200
  response_json_paths:
      $.resource_provider_generation: 2
      $.inventories.IPV4_ADDRESS.total: 253
      $.inventories.IPV4_ADDRESS.reserved: 0
      $.inventories.DISK_GB.total: 1024
      $.inventories.DISK_GB.allocation_ratio: 1.0

- name: list providers with 'required' parameter filters cumulatively with resources
  GET: /resource_providers?required=STORAGE_DISK_SSD&resources=IPV4_ADDRESS:10
  response_json_paths:
      $.resource_providers.`len`: 1
      # Only ALT_PARENT_PROVIDER_UUID satisfies both the tree and trait constraint
      $.resource_providers[?uuid="$ENVIRON['ALT_PARENT_PROVIDER_UUID']"].root_provider_uuid: $ENVIRON['ALT_PARENT_PROVIDER_UUID']

- name: invalid 'required' parameter - blank
  GET: /resource_providers?required=
  status: 400
  response_strings:
      - "Invalid query string parameters: Expected 'required' parameter value of the form: HW_CPU_X86_VMX,!CUSTOM_MAGIC."
  response_json_paths:
      $.errors[0].title: Bad Request

- name: invalid 'required' parameter 1.21
  GET: /resource_providers?required=
  request_headers:
      openstack-api-version: placement 1.21
  status: 400
  response_strings:
      - "Invalid query string parameters: Expected 'required' parameter value of the form: HW_CPU_X86_VMX,CUSTOM_MAGIC."
  response_json_paths:
      $.errors[0].title: Bad Request

- name: invalid 'required' parameter - contains an empty trait name
  GET: /resource_providers?required=STORAGE_DISK_SSD,,MISC_SHARES_VIA_AGGREGATE
  status: 400
  response_strings:
      - "Invalid query string parameters: Expected 'required' parameter value of the form: HW_CPU_X86_VMX,!CUSTOM_MAGIC."
  response_json_paths:
      $.errors[0].title: Bad Request

- name: invalid 'required' parameter - contains a nonexistent trait
  GET: /resource_providers?required=STORAGE_DISK_SSD,BOGUS_TRAIT,MISC_SHARES_VIA_AGGREGATE
  status: 400
  response_strings:
      - "No such trait(s): BOGUS_TRAIT."
  response_json_paths:
      $.errors[0].title: Bad Request

- name: schema validation fails with 'required' parameter on old microversion
  request_headers:
      openstack-api-version: placement 1.17
  GET: /resource_providers?required=HW_CPU_X86_SGX,MISC_SHARES_VIA_AGGREGATE
  status: 400
  response_strings:
      - Additional properties are not allowed
  response_json_paths:
      $.errors[0].title: Bad Request

- name: fail trying to re-parent to a different provider with old microversion
  PUT: /resource_providers/$ENVIRON['RP_UUID']
  request_headers:
      content-type: application/json
      openstack-api-version: placement 1.36
  data:
      name: child
      parent_provider_uuid: $ENVIRON['ALT_PARENT_PROVIDER_UUID']
  status: 400
  response_strings:
      - 're-parenting a provider is not currently allowed'

- name: re-parent to a different provider
  PUT: /resource_providers/$ENVIRON['RP_UUID']
  request_headers:
      content-type: application/json
      openstack-api-version: placement 1.37
  data:
      name: child
      parent_provider_uuid: $ENVIRON['ALT_PARENT_PROVIDER_UUID']
  status: 200
  response_json_paths:
    $.uuid: $ENVIRON['RP_UUID']
    $.name: 'child'
    $.parent_provider_uuid: $ENVIRON['ALT_PARENT_PROVIDER_UUID']
    $.root_provider_uuid: $ENVIRON['ALT_PARENT_PROVIDER_UUID']

- name: re-parent back to its original parent
  PUT: /resource_providers/$ENVIRON['RP_UUID']
  request_headers:
      content-type: application/json
      openstack-api-version: placement 1.37
  data:
      name: child
      parent_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']
  status: 200
  response_json_paths:
    $.uuid: $ENVIRON['RP_UUID']
    $.name: child
    $.parent_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']
    $.root_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']

- name: create a new provider
  POST: /resource_providers
  request_headers:
      content-type: application/json
  data:
      name: cow
  status: 200

- name: try to rename that provider to existing name
  PUT: $LOCATION
  request_headers:
      content-type: application/json
  data:
      name: child
  status: 409
  response_json_paths:
      $.errors[0].title: Conflict
      $.errors[0].code: placement.duplicate_name

- name: fail to put that provider with uuid
  PUT: $LAST_URL
  request_headers:
      content-type: application/json
  data:
      name: second new name
      uuid: 7d4275fc-8b40-4995-85e2-74fcec2cb3b6
  status: 400
  response_strings:
      - Additional properties are not allowed
  response_json_paths:
      $.errors[0].title: Bad Request

- name: delete resource provider
  DELETE: $LAST_URL
  status: 204

- name: 404 on deleted provider
  DELETE: $LAST_URL
  status: 404
  response_json_paths:
      $.errors[0].title: Not Found

- name: fail to get a provider
  GET: /resource_providers/random_sauce
  status: 404
  response_json_paths:
      $.errors[0].title: Not Found

- name: delete non-existing resource provider
  DELETE: /resource_providers/d67370b5-4dc0-470d-a4fa-85e8e89abc6c
  status: 404
  response_strings:
      - No resource provider with uuid d67370b5-4dc0-470d-a4fa-85e8e89abc6c found for delete
  response_json_paths:
      $.errors[0].title: Not Found

- name: post resource provider no uuid
  POST: /resource_providers
  request_headers:
    content-type: application/json
  data:
      name: a name
  status: 200
  response_headers:
      location: //resource_providers/[a-f0-9-]+/

- name: post malformed json as json
  POST: /resource_providers
  request_headers:
      content-type: application/json
  data: '{"foo": }'
  status: 400
  response_strings:
      - 'Malformed JSON:'
  response_json_paths:
      $.errors[0].title: Bad Request

- name: post bad uuid in resource provider
  POST: /resource_providers
  request_headers:
      content-type: application/json
  data:
      name: my bad rp
      uuid: this is not a uuid
  status: 400
  response_strings:
      - "Failed validating 'format'"
  response_json_paths:
      $.errors[0].title: Bad Request

- name: try to create resource provider with name exceed max characters
  POST: /resource_providers
  request_headers:
      content-type: application/json
  data:
      name: &name_exceeds_max_length_check This is a long text of 201 charactersssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
  status: 400
  response_strings:
      - "Failed validating 'maxLength'"
  response_json_paths:
      $.errors[0].title: Bad Request

- name: try to update resource provider with name exceed max characters
  PUT: /resource_providers/$ENVIRON['RP_UUID']
  request_headers:
      content-type: application/json
  data:
      name: *name_exceeds_max_length_check
  status: 400
  response_strings:
      - "Failed validating 'maxLength'"
  response_json_paths:
      $.errors[0].title: Bad Request

- name: confirm no cache-control headers before 1.15
  GET: /resource_providers
  request_headers:
      openstack-api-version: placement 1.14
  response_forbidden_headers:
      - cache-control
      - last-modified

- name: fail updating a parent to itself
  PUT: /resource_providers/$ENVIRON['PARENT_PROVIDER_UUID']
  request_headers:
      content-type: application/json
  data:
      name: parent
      parent_provider_uuid: $ENVIRON['PARENT_PROVIDER_UUID']
  status: 400
  response_strings:
      - 'creating loop in the provider tree is not allowed.'

- name: fail updating the parent to point to its child
  PUT: /resource_providers/$ENVIRON['PARENT_PROVIDER_UUID']
  request_headers:
      content-type: application/json
  data:
      name: parent
      parent_provider_uuid: $ENVIRON['RP_UUID']
  status: 400
  response_strings:
      - 'creating loop in the provider tree is not allowed.'

- name: create a resource provider with dashed uuid
  POST: /resource_providers
  request_headers:
    content-type: application/json
  data:
      name: rp with dashed uuid
      uuid: 2290d4af-9e6e-400b-9d65-1ee01376f71a
  status: 200
  response_headers:
      location: //resource_providers/[a-f0-9-]+/

- name: try to create with the same uuid but without dashes
  POST: /resource_providers
  request_headers:
    content-type: application/json
  data:
      name: rp with dashless uuid
      uuid: 2290d4af9e6e400b9d651ee01376f71a
  status: 409
  response_strings:
      - "Conflicting resource provider uuid: 2290d4af-9e6e-400b-9d65-1ee01376f71a already exists"
  response_json_paths:
      $.errors[0].title: Conflict
