Add support for 1.18 microversion
The 1.18 microversion of placement adds support for the required parameter when requesting a list of resource providers. The values are traits which limit the results to only those providers that have those traits. The --required argument may be specified multiple times. Note the NOTE in the added test about raciness. There's not a ton we can do about that since the functional tests aren't actually functional tests, they are integration. Change-Id: If79b4d12c712fdeeafa5ea77ae3411d31c8cfe9b
This commit is contained in:
parent
fc563d37bc
commit
469381795d
|
@ -118,6 +118,16 @@ class ListResourceProvider(command.Lister, version.CheckerMixin):
|
|||
' This option requires at least'
|
||||
' ``--os-placement-api-version 1.14``.'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--required',
|
||||
metavar='<required>',
|
||||
action='append',
|
||||
default=[],
|
||||
help='A required trait. May be repeated. Resource providers '
|
||||
'must collectively contain all of the required traits. '
|
||||
'This option requires at least '
|
||||
'``--os-placement-api-version 1.18``.'
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
|
@ -140,6 +150,9 @@ class ListResourceProvider(command.Lister, version.CheckerMixin):
|
|||
if 'in_tree' in parsed_args and parsed_args.in_tree:
|
||||
self.check_version(version.ge('1.14'))
|
||||
filters['in_tree'] = parsed_args.in_tree
|
||||
if 'required' in parsed_args and parsed_args.required:
|
||||
self.check_version(version.ge('1.18'))
|
||||
filters['required'] = ','.join(parsed_args.required)
|
||||
|
||||
url = common.url_with_filters(BASE_URL, filters)
|
||||
resources = http.request('GET', url).json()['resource_providers']
|
||||
|
|
|
@ -123,7 +123,7 @@ class BaseTestCase(base.BaseTestCase):
|
|||
|
||||
def resource_provider_list(self, uuid=None, name=None,
|
||||
aggregate_uuids=None, resources=None,
|
||||
in_tree=None):
|
||||
in_tree=None, required=None):
|
||||
to_exec = 'resource provider list'
|
||||
if uuid:
|
||||
to_exec += ' --uuid ' + uuid
|
||||
|
@ -136,6 +136,8 @@ class BaseTestCase(base.BaseTestCase):
|
|||
to_exec += ' ' + ' '.join('--resource %s' % r for r in resources)
|
||||
if in_tree:
|
||||
to_exec += ' --in-tree ' + in_tree
|
||||
if required:
|
||||
to_exec += ' ' + ' '.join('--required %s' % t for t in required)
|
||||
|
||||
return self.openstack(to_exec, use_json=True)
|
||||
|
||||
|
|
|
@ -129,6 +129,10 @@ class TestAllocationCandidate116(base.BaseTestCase):
|
|||
class TestAllocationCandidate117(base.BaseTestCase):
|
||||
VERSION = '1.17'
|
||||
|
||||
# NOTE(cdent): The choice of traits here is important. We need to
|
||||
# make sure that we do not overlap with 'test_show_required_trait'
|
||||
# in TestResourceProvider118 which also creates some resource
|
||||
# providers. In a multi-process enviromment, the tests can race.
|
||||
def test_show_required_trait(self):
|
||||
rp1 = self.resource_provider_create()
|
||||
rp2 = self.resource_provider_create()
|
||||
|
|
|
@ -266,3 +266,41 @@ class TestResourceProvider114(base.BaseTestCase):
|
|||
self.resource_provider_delete,
|
||||
parent['uuid'])
|
||||
self.assertIn('HTTP 409', exc.output.decode('utf-8'))
|
||||
|
||||
|
||||
class TestResourceProvider118(base.BaseTestCase):
|
||||
VERSION = '1.18'
|
||||
|
||||
# NOTE(cdent): The choice of traits here is important. We need to
|
||||
# make sure that we do not overlap with 'test_show_required_trait'
|
||||
# in TestAllocationCandidate117 which also creates some resource
|
||||
# providers. In a multi-process enviromment, the tests can race.
|
||||
def test_show_required_trait(self):
|
||||
rp1 = self.resource_provider_create()
|
||||
rp2 = self.resource_provider_create()
|
||||
self.resource_inventory_set(
|
||||
rp1['uuid'], 'MEMORY_MB=8192', 'DISK_GB=512')
|
||||
self.resource_inventory_set(
|
||||
rp2['uuid'], 'MEMORY_MB=8192', 'DISK_GB=512')
|
||||
self.resource_provider_trait_set(
|
||||
rp1['uuid'], 'STORAGE_DISK_SSD', 'HW_NIC_SRIOV_MULTIQUEUE')
|
||||
self.resource_provider_trait_set(
|
||||
rp2['uuid'], 'STORAGE_DISK_HDD', 'HW_NIC_SRIOV_MULTIQUEUE')
|
||||
|
||||
rps = self.resource_provider_list(
|
||||
resources=('MEMORY_MB=1024', 'DISK_GB=80'),
|
||||
required=('HW_NIC_SRIOV_MULTIQUEUE',))
|
||||
|
||||
uuids = [rp['uuid'] for rp in rps]
|
||||
|
||||
self.assertEqual(2, len(rps))
|
||||
self.assertIn(rp1['uuid'], uuids)
|
||||
self.assertIn(rp2['uuid'], uuids)
|
||||
|
||||
# Narrow the results and check multiple args.
|
||||
rps = self.resource_provider_list(
|
||||
resources=('MEMORY_MB=1024', 'DISK_GB=80'),
|
||||
required=('STORAGE_DISK_HDD', 'HW_NIC_SRIOV_MULTIQUEUE',))
|
||||
|
||||
self.assertEqual(1, len(rps))
|
||||
self.assertEqual(rp2['uuid'], rps[0]['uuid'])
|
||||
|
|
|
@ -32,7 +32,8 @@ SUPPORTED_VERSIONS = [
|
|||
'1.14',
|
||||
'1.15', # unused
|
||||
'1.16',
|
||||
'1.17'
|
||||
'1.17',
|
||||
'1.18',
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
features:
|
||||
- |
|
||||
Support is added for the `1.18`_ placement API microversion by adding
|
||||
the ``--required`` option to the ``openstack resource provider list``
|
||||
command.
|
||||
|
||||
.. _1.18: https://docs.openstack.org/placement/latest/placement-api-microversion-history.html#support-required-traits-queryparam-on-get-resource-providers
|
Loading…
Reference in New Issue