[placement] adjust resource provider links by microversion

The resource provider representation includes links to other related
resources. Those links should vary depending on microversion as some
of the related resources did not show up until a later microversion.

This change makes it so 'aggregates' show up at microverison 1.1 and
beyond and traits in microversion 1.6 and beyond. A new gabbit has
been added, resource-provider-links which exercises this. Only the
single resource provider representation is tested because the same
code is used for single and collection representations.

Change-Id: Ife64922ee91a775fabdcf718e6eb0e0c7ddfde7a
Closes-Bug: #1693353
This commit is contained in:
Chris Dent 2017-05-29 16:38:59 +00:00
parent bf34d5f25c
commit 72960a33e0
3 changed files with 99 additions and 9 deletions

View File

@ -144,7 +144,13 @@ def _normalize_resources_qs_param(qs):
def _serialize_links(environ, resource_provider):
url = util.resource_provider_url(environ, resource_provider)
links = [{'rel': 'self', 'href': url}]
for rel in ('aggregates', 'inventories', 'usages', 'traits'):
rel_types = ['inventories', 'usages']
want_version = environ[microversion.MICROVERSION_ENVIRON]
if want_version >= (1, 1):
rel_types.append('aggregates')
if want_version >= (1, 6):
rel_types.append('traits')
for rel in rel_types:
links.append({'rel': rel, 'href': '%s/%s' % (url, rel)})
return links

View File

@ -0,0 +1,92 @@
# Confirm that the links provided when getting one or more resources
# providers are correct. They vary across different microversions.
fixtures:
- APIFixture
defaults:
request_headers:
x-auth-token: admin
accept: application/json
tests:
- name: post new resource provider
POST: /resource_providers
request_headers:
content-type: application/json
data:
name: $ENVIRON['RP_NAME']
uuid: $ENVIRON['RP_UUID']
status: 201
- name: get rp latest
GET: /resource_providers/$ENVIRON['RP_UUID']
request_headers:
openstack-api-version: placement latest
response_json_paths:
$.links.`len`: 5
$.links[?rel = "self"].href: /resource_providers/$ENVIRON['RP_UUID']
$.links[?rel = "inventories"].href: /resource_providers/$ENVIRON['RP_UUID']/inventories
$.links[?rel = "aggregates"].href: /resource_providers/$ENVIRON['RP_UUID']/aggregates
$.links[?rel = "usages"].href: /resource_providers/$ENVIRON['RP_UUID']/usages
$.links[?rel = "traits"].href: /resource_providers/$ENVIRON['RP_UUID']/traits
- name: get rp 1.0
GET: /resource_providers/$ENVIRON['RP_UUID']
request_headers:
openstack-api-version: placement 1.0
response_json_paths:
$.links.`len`: 3
$.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 rp 1.1
desc: aggregates added in 1.1
GET: /resource_providers/$ENVIRON['RP_UUID']
request_headers:
openstack-api-version: placement 1.1
response_json_paths:
$.links.`len`: 4
$.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
$.links[?rel = "aggregates"].href: /resource_providers/$ENVIRON['RP_UUID']/aggregates
- name: get rp 1.5
desc: traits added after 1.5
GET: /resource_providers/$ENVIRON['RP_UUID']
request_headers:
openstack-api-version: placement 1.5
response_json_paths:
$.links.`len`: 4
$.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
$.links[?rel = "aggregates"].href: /resource_providers/$ENVIRON['RP_UUID']/aggregates
- name: get rp 1.6
desc: traits added in 1.6
GET: /resource_providers/$ENVIRON['RP_UUID']
request_headers:
openstack-api-version: placement 1.6
response_json_paths:
$.links.`len`: 5
$.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
$.links[?rel = "aggregates"].href: /resource_providers/$ENVIRON['RP_UUID']/aggregates
$.links[?rel = "traits"].href: /resource_providers/$ENVIRON['RP_UUID']/traits
- name: get rp 1.7
desc: nothing new in 1.7
GET: /resource_providers/$ENVIRON['RP_UUID']
request_headers:
openstack-api-version: placement 1.7
response_json_paths:
$.links.`len`: 5
$.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
$.links[?rel = "aggregates"].href: /resource_providers/$ENVIRON['RP_UUID']/aggregates
$.links[?rel = "traits"].href: /resource_providers/$ENVIRON['RP_UUID']/traits

View File

@ -81,9 +81,7 @@ tests:
$.generation: 0
$.links[?rel = "self"].href: /resource_providers/$ENVIRON['RP_UUID']
$.links[?rel = "inventories"].href: /resource_providers/$ENVIRON['RP_UUID']/inventories
$.links[?rel = "aggregates"].href: /resource_providers/$ENVIRON['RP_UUID']/aggregates
$.links[?rel = "usages"].href: /resource_providers/$ENVIRON['RP_UUID']/usages
$.links[?rel = "traits"].href: /resource_providers/$ENVIRON['RP_UUID']/traits
- name: get resource provider works with no accept
GET: /resource_providers/$ENVIRON['RP_UUID']
@ -109,9 +107,7 @@ tests:
$.resource_providers[0].generation: 0
$.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 = "aggregates"].href: /resource_providers/$ENVIRON['RP_UUID']/aggregates
$.resource_providers[0].links[?rel = "usages"].href: /resource_providers/$ENVIRON['RP_UUID']/usages
$.resource_providers[0].links[?rel = "traits"].href: /resource_providers/$ENVIRON['RP_UUID']/traits
- name: filter out all resource providers by name
GET: /resource_providers?name=flubblebubble
@ -131,9 +127,7 @@ tests:
$.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 = "aggregates"].href: /resource_providers/$ENVIRON['RP_UUID']/aggregates
$.resource_providers[0].links[?rel = "usages"].href: /resource_providers/$ENVIRON['RP_UUID']/usages
$.resource_providers[0].links[?rel = "traits"].href: /resource_providers/$ENVIRON['RP_UUID']/traits
- name: list resource providers filtering by invalid uuid
GET: /resource_providers?uuid=spameggs
@ -159,9 +153,7 @@ tests:
$.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 = "aggregates"].href: /resource_providers/$ENVIRON['RP_UUID']/aggregates
$.resource_providers[0].links[?rel = "usages"].href: /resource_providers/$ENVIRON['RP_UUID']/usages
$.resource_providers[0].links[?rel = "traits"].href: /resource_providers/$ENVIRON['RP_UUID']/traits
- name: update a resource provider
PUT: /resource_providers/$RESPONSE['$.resource_providers[0].uuid']