baremetal: allow updating name and extra fields of an allocation
Support for this was introduced in Bare Metal API 1.57 (Train). Change-Id: I4885d9a710cd6697c241bb1962dbbe2741a049a1 Story: #2005126 Task: #29798
This commit is contained in:
parent
4f276064a8
commit
e4205085b3
@ -87,6 +87,8 @@ Allocation Operations
|
||||
.. autoclass:: openstack.baremetal.v1._proxy.Proxy
|
||||
|
||||
.. automethod:: openstack.baremetal.v1._proxy.Proxy.create_allocation
|
||||
.. automethod:: openstack.baremetal.v1._proxy.Proxy.update_allocation
|
||||
.. automethod:: openstack.baremetal.v1._proxy.Proxy.patch_allocation
|
||||
.. automethod:: openstack.baremetal.v1._proxy.Proxy.delete_allocation
|
||||
.. automethod:: openstack.baremetal.v1._proxy.Proxy.get_allocation
|
||||
.. automethod:: openstack.baremetal.v1._proxy.Proxy.allocations
|
||||
|
@ -838,6 +838,32 @@ class Proxy(proxy.Proxy):
|
||||
"""
|
||||
return self._get(_allocation.Allocation, allocation)
|
||||
|
||||
def update_allocation(self, allocation, **attrs):
|
||||
"""Update an allocation.
|
||||
|
||||
:param allocation: The value can be the name or ID of an allocation or
|
||||
a :class:`~openstack.baremetal.v1.allocation.Allocation` instance.
|
||||
:param dict attrs: The attributes to update on the allocation
|
||||
represented by the ``allocation`` parameter.
|
||||
|
||||
:returns: The updated allocation.
|
||||
:rtype: :class:`~openstack.baremetal.v1.allocation.Allocation`
|
||||
"""
|
||||
return self._update(_allocation.Allocation, allocation, **attrs)
|
||||
|
||||
def patch_allocation(self, allocation, patch):
|
||||
"""Apply a JSON patch to the allocation.
|
||||
|
||||
:param allocation: The value can be the name or ID of an allocation or
|
||||
a :class:`~openstack.baremetal.v1.allocation.Allocation` instance.
|
||||
:param patch: JSON patch to apply.
|
||||
|
||||
:returns: The updated allocation.
|
||||
:rtype: :class:`~openstack.baremetal.v1.allocation.Allocation`
|
||||
"""
|
||||
return self._get_resource(_allocation.Allocation,
|
||||
allocation).patch(self, patch)
|
||||
|
||||
def delete_allocation(self, allocation, ignore_missing=True):
|
||||
"""Delete an allocation.
|
||||
|
||||
|
@ -24,17 +24,20 @@ class Allocation(_common.ListMixin, resource.Resource):
|
||||
# capabilities
|
||||
allow_create = True
|
||||
allow_fetch = True
|
||||
allow_commit = False
|
||||
allow_commit = True
|
||||
allow_delete = True
|
||||
allow_list = True
|
||||
allow_patch = True
|
||||
commit_method = 'PATCH'
|
||||
commit_jsonpatch = True
|
||||
|
||||
_query_mapping = resource.QueryParameters(
|
||||
'node', 'resource_class', 'state',
|
||||
fields={'name': 'fields', 'type': _common.comma_separated_list},
|
||||
)
|
||||
|
||||
# The allocation API introduced in 1.52.
|
||||
_max_microversion = '1.52'
|
||||
# Allocation update is available since 1.57
|
||||
_max_microversion = '1.57'
|
||||
|
||||
#: The candidate nodes for this allocation.
|
||||
candidate_nodes = resource.Body('candidate_nodes', type=list)
|
||||
|
@ -16,12 +16,10 @@ from openstack import exceptions
|
||||
from openstack.tests.functional.baremetal import base
|
||||
|
||||
|
||||
class TestBareMetalAllocation(base.BaseBaremetalTest):
|
||||
|
||||
min_microversion = '1.52'
|
||||
class Base(base.BaseBaremetalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestBareMetalAllocation, self).setUp()
|
||||
super(Base, self).setUp()
|
||||
# NOTE(dtantsur): generate a unique resource class to prevent parallel
|
||||
# tests from clashing.
|
||||
self.resource_class = 'baremetal-%d' % random.randrange(1024)
|
||||
@ -40,6 +38,11 @@ class TestBareMetalAllocation(base.BaseBaremetalTest):
|
||||
instance_id=None))
|
||||
return node
|
||||
|
||||
|
||||
class TestBareMetalAllocation(Base):
|
||||
|
||||
min_microversion = '1.52'
|
||||
|
||||
def test_allocation_create_get_delete(self):
|
||||
allocation = self.create_allocation(resource_class=self.resource_class)
|
||||
self.assertEqual('allocating', allocation.state)
|
||||
@ -108,3 +111,65 @@ class TestBareMetalAllocation(base.BaseBaremetalTest):
|
||||
for item in result:
|
||||
self.assertIsNotNone(item.id)
|
||||
self.assertIsNone(item.resource_class)
|
||||
|
||||
|
||||
class TestBareMetalAllocationUpdate(Base):
|
||||
|
||||
min_microversion = '1.57'
|
||||
|
||||
def test_allocation_update(self):
|
||||
name = 'ossdk-name1'
|
||||
|
||||
allocation = self.create_allocation(resource_class=self.resource_class)
|
||||
allocation = self.conn.baremetal.wait_for_allocation(allocation)
|
||||
self.assertEqual('active', allocation.state)
|
||||
self.assertIsNone(allocation.last_error)
|
||||
self.assertIsNone(allocation.name)
|
||||
self.assertEqual({}, allocation.extra)
|
||||
|
||||
allocation = self.conn.baremetal.update_allocation(
|
||||
allocation, name=name, extra={'answer': 42})
|
||||
self.assertEqual(name, allocation.name)
|
||||
self.assertEqual({'answer': 42}, allocation.extra)
|
||||
|
||||
allocation = self.conn.baremetal.get_allocation(name)
|
||||
self.assertEqual(name, allocation.name)
|
||||
self.assertEqual({'answer': 42}, allocation.extra)
|
||||
|
||||
self.conn.baremetal.delete_allocation(allocation, ignore_missing=False)
|
||||
self.assertRaises(exceptions.ResourceNotFound,
|
||||
self.conn.baremetal.get_allocation, allocation.id)
|
||||
|
||||
def test_allocation_patch(self):
|
||||
name = 'ossdk-name2'
|
||||
|
||||
allocation = self.create_allocation(resource_class=self.resource_class)
|
||||
allocation = self.conn.baremetal.wait_for_allocation(allocation)
|
||||
self.assertEqual('active', allocation.state)
|
||||
self.assertIsNone(allocation.last_error)
|
||||
self.assertIsNone(allocation.name)
|
||||
self.assertEqual({}, allocation.extra)
|
||||
|
||||
allocation = self.conn.baremetal.patch_allocation(
|
||||
allocation, [{'op': 'replace', 'path': '/name', 'value': name},
|
||||
{'op': 'add', 'path': '/extra/answer', 'value': 42}])
|
||||
self.assertEqual(name, allocation.name)
|
||||
self.assertEqual({'answer': 42}, allocation.extra)
|
||||
|
||||
allocation = self.conn.baremetal.get_allocation(name)
|
||||
self.assertEqual(name, allocation.name)
|
||||
self.assertEqual({'answer': 42}, allocation.extra)
|
||||
|
||||
allocation = self.conn.baremetal.patch_allocation(
|
||||
allocation, [{'op': 'remove', 'path': '/name'},
|
||||
{'op': 'remove', 'path': '/extra/answer'}])
|
||||
self.assertIsNone(allocation.name)
|
||||
self.assertEqual({}, allocation.extra)
|
||||
|
||||
allocation = self.conn.baremetal.get_allocation(allocation.id)
|
||||
self.assertIsNone(allocation.name)
|
||||
self.assertEqual({}, allocation.extra)
|
||||
|
||||
self.conn.baremetal.delete_allocation(allocation, ignore_missing=False)
|
||||
self.assertRaises(exceptions.ResourceNotFound,
|
||||
self.conn.baremetal.get_allocation, allocation.id)
|
||||
|
@ -51,7 +51,7 @@ class TestAllocation(base.TestCase):
|
||||
self.assertEqual('/allocations', sot.base_path)
|
||||
self.assertTrue(sot.allow_create)
|
||||
self.assertTrue(sot.allow_fetch)
|
||||
self.assertFalse(sot.allow_commit)
|
||||
self.assertTrue(sot.allow_commit)
|
||||
self.assertTrue(sot.allow_delete)
|
||||
self.assertTrue(sot.allow_list)
|
||||
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Allows updating ``name`` and ``extra`` fields of a baremetal allocation.
|
Loading…
Reference in New Issue
Block a user