Merge "baremetal: use proxy methods in unregister_machine"
This commit is contained in:
commit
467779f581
|
@ -325,7 +325,7 @@ class BaremetalCloudMixin(_normalize.Normalizer):
|
||||||
else:
|
else:
|
||||||
return machine
|
return machine
|
||||||
|
|
||||||
def unregister_machine(self, nics, uuid, wait=False, timeout=600):
|
def unregister_machine(self, nics, uuid, wait=None, timeout=600):
|
||||||
"""Unregister Baremetal from Ironic
|
"""Unregister Baremetal from Ironic
|
||||||
|
|
||||||
Removes entries for Network Interfaces and baremetal nodes
|
Removes entries for Network Interfaces and baremetal nodes
|
||||||
|
@ -335,15 +335,17 @@ class BaremetalCloudMixin(_normalize.Normalizer):
|
||||||
to be removed.
|
to be removed.
|
||||||
:param string uuid: The UUID of the node to be deleted.
|
:param string uuid: The UUID of the node to be deleted.
|
||||||
|
|
||||||
:param wait: Boolean value, defaults to false, if to block the method
|
:param wait: DEPRECATED, do not use.
|
||||||
upon the final step of unregistering the machine.
|
|
||||||
|
|
||||||
:param timeout: Integer value, representing seconds with a default
|
:param timeout: Integer value, representing seconds with a default
|
||||||
value of 600, which controls the maximum amount of
|
value of 600, which controls the maximum amount of
|
||||||
time to block the method's completion on.
|
time to block until a lock is released on machine.
|
||||||
|
|
||||||
:raises: OpenStackCloudException on operation failure.
|
:raises: OpenStackCloudException on operation failure.
|
||||||
"""
|
"""
|
||||||
|
if wait is not None:
|
||||||
|
warnings.warn("wait argument is deprecated and has no effect",
|
||||||
|
DeprecationWarning)
|
||||||
|
|
||||||
machine = self.get_machine(uuid)
|
machine = self.get_machine(uuid)
|
||||||
invalid_states = ['active', 'cleaning', 'clean wait', 'clean failed']
|
invalid_states = ['active', 'cleaning', 'clean wait', 'clean failed']
|
||||||
|
@ -357,47 +359,20 @@ class BaremetalCloudMixin(_normalize.Normalizer):
|
||||||
# previously concealed by exception retry logic that detected the
|
# previously concealed by exception retry logic that detected the
|
||||||
# failure, and resubitted the request in python-ironicclient.
|
# failure, and resubitted the request in python-ironicclient.
|
||||||
try:
|
try:
|
||||||
self.wait_for_baremetal_node_lock(machine, timeout=timeout)
|
self.baremetal.wait_for_node_reservation(machine, timeout)
|
||||||
except exc.OpenStackCloudException as e:
|
except exc.OpenStackCloudException as e:
|
||||||
raise exc.OpenStackCloudException(
|
raise exc.OpenStackCloudException(
|
||||||
"Error unregistering node '%s': Exception occured while"
|
"Error unregistering node '%s': Exception occured while"
|
||||||
" waiting to be able to proceed: %s" % (machine['uuid'], e))
|
" waiting to be able to proceed: %s" % (machine['uuid'], e))
|
||||||
|
|
||||||
for nic in nics:
|
for nic in nics:
|
||||||
port_msg = ("Error removing NIC {nic} from baremetal API for "
|
try:
|
||||||
"node {uuid}").format(nic=nic, uuid=uuid)
|
port = next(self.baremetal.ports(address=nic['mac']))
|
||||||
port_url = '/ports/detail?address={mac}'.format(mac=nic['mac'])
|
except StopIteration:
|
||||||
port = self._baremetal_client.get(port_url, microversion=1.6,
|
continue
|
||||||
error_message=port_msg)
|
self.baremetal.delete_port(port.id)
|
||||||
port_url = '/ports/{uuid}'.format(uuid=port['ports'][0]['uuid'])
|
|
||||||
_utils._call_client_and_retry(self._baremetal_client.delete,
|
|
||||||
port_url, retry_on=[409, 503],
|
|
||||||
error_message=port_msg)
|
|
||||||
|
|
||||||
with _utils.shade_exceptions(
|
self.baremetal.delete_node(uuid)
|
||||||
"Error unregistering machine {node_id} from the baremetal "
|
|
||||||
"API".format(node_id=uuid)):
|
|
||||||
|
|
||||||
# NOTE(TheJulia): While this should not matter microversion wise,
|
|
||||||
# ironic assumes all calls without an explicit microversion to be
|
|
||||||
# version 1.0. Ironic expects to deprecate support for older
|
|
||||||
# microversions in future releases, as such, we explicitly set
|
|
||||||
# the version to what we have been using with the client library..
|
|
||||||
version = "1.6"
|
|
||||||
msg = "Baremetal machine failed to be deleted"
|
|
||||||
url = '/nodes/{node_id}'.format(
|
|
||||||
node_id=uuid)
|
|
||||||
_utils._call_client_and_retry(self._baremetal_client.delete,
|
|
||||||
url, retry_on=[409, 503],
|
|
||||||
error_message=msg,
|
|
||||||
microversion=version)
|
|
||||||
|
|
||||||
if wait:
|
|
||||||
for count in utils.iterate_timeout(
|
|
||||||
timeout,
|
|
||||||
"Timeout waiting for machine to be deleted"):
|
|
||||||
if not self.get_machine(uuid):
|
|
||||||
break
|
|
||||||
|
|
||||||
def patch_machine(self, name_or_id, patch):
|
def patch_machine(self, name_or_id, patch):
|
||||||
"""Patch Machine Information
|
"""Patch Machine Information
|
||||||
|
|
|
@ -1482,7 +1482,6 @@ class TestBaremetalNode(base.IronicTestCase):
|
||||||
port_uuid = self.fake_baremetal_port['uuid']
|
port_uuid = self.fake_baremetal_port['uuid']
|
||||||
# NOTE(TheJulia): The two values below should be the same.
|
# NOTE(TheJulia): The two values below should be the same.
|
||||||
port_node_uuid = self.fake_baremetal_port['node_uuid']
|
port_node_uuid = self.fake_baremetal_port['node_uuid']
|
||||||
port_url_address = 'detail?address=%s' % mac_address
|
|
||||||
self.fake_baremetal_node['provision_state'] = 'available'
|
self.fake_baremetal_node['provision_state'] = 'available'
|
||||||
self.register_uris([
|
self.register_uris([
|
||||||
dict(
|
dict(
|
||||||
|
@ -1495,7 +1494,7 @@ class TestBaremetalNode(base.IronicTestCase):
|
||||||
method='GET',
|
method='GET',
|
||||||
uri=self.get_mock_url(
|
uri=self.get_mock_url(
|
||||||
resource='ports',
|
resource='ports',
|
||||||
append=[port_url_address]),
|
qs_elements=['address=%s' % mac_address]),
|
||||||
json={'ports': [{'address': mac_address,
|
json={'ports': [{'address': mac_address,
|
||||||
'node_uuid': port_node_uuid,
|
'node_uuid': port_node_uuid,
|
||||||
'uuid': port_uuid}]}),
|
'uuid': port_uuid}]}),
|
||||||
|
@ -1516,55 +1515,6 @@ class TestBaremetalNode(base.IronicTestCase):
|
||||||
|
|
||||||
self.assert_calls()
|
self.assert_calls()
|
||||||
|
|
||||||
def test_unregister_machine_timeout(self):
|
|
||||||
mac_address = self.fake_baremetal_port['address']
|
|
||||||
nics = [{'mac': mac_address}]
|
|
||||||
port_uuid = self.fake_baremetal_port['uuid']
|
|
||||||
port_node_uuid = self.fake_baremetal_port['node_uuid']
|
|
||||||
port_url_address = 'detail?address=%s' % mac_address
|
|
||||||
self.fake_baremetal_node['provision_state'] = 'available'
|
|
||||||
self.register_uris([
|
|
||||||
dict(
|
|
||||||
method='GET',
|
|
||||||
uri=self.get_mock_url(
|
|
||||||
resource='nodes',
|
|
||||||
append=[self.fake_baremetal_node['uuid']]),
|
|
||||||
json=self.fake_baremetal_node),
|
|
||||||
dict(
|
|
||||||
method='GET',
|
|
||||||
uri=self.get_mock_url(
|
|
||||||
resource='ports',
|
|
||||||
append=[port_url_address]),
|
|
||||||
json={'ports': [{'address': mac_address,
|
|
||||||
'node_uuid': port_node_uuid,
|
|
||||||
'uuid': port_uuid}]}),
|
|
||||||
dict(
|
|
||||||
method='DELETE',
|
|
||||||
uri=self.get_mock_url(
|
|
||||||
resource='ports',
|
|
||||||
append=[self.fake_baremetal_port['uuid']])),
|
|
||||||
dict(
|
|
||||||
method='DELETE',
|
|
||||||
uri=self.get_mock_url(
|
|
||||||
resource='nodes',
|
|
||||||
append=[self.fake_baremetal_node['uuid']])),
|
|
||||||
dict(
|
|
||||||
method='GET',
|
|
||||||
uri=self.get_mock_url(
|
|
||||||
resource='nodes',
|
|
||||||
append=[self.fake_baremetal_node['uuid']]),
|
|
||||||
json=self.fake_baremetal_node),
|
|
||||||
])
|
|
||||||
self.assertRaises(
|
|
||||||
exc.OpenStackCloudException,
|
|
||||||
self.cloud.unregister_machine,
|
|
||||||
nics,
|
|
||||||
self.fake_baremetal_node['uuid'],
|
|
||||||
wait=True,
|
|
||||||
timeout=0.001)
|
|
||||||
|
|
||||||
self.assert_calls()
|
|
||||||
|
|
||||||
def test_unregister_machine_locked_timeout(self):
|
def test_unregister_machine_locked_timeout(self):
|
||||||
mac_address = self.fake_baremetal_port['address']
|
mac_address = self.fake_baremetal_port['address']
|
||||||
nics = [{'mac': mac_address}]
|
nics = [{'mac': mac_address}]
|
||||||
|
@ -1598,7 +1548,6 @@ class TestBaremetalNode(base.IronicTestCase):
|
||||||
port_uuid = self.fake_baremetal_port['uuid']
|
port_uuid = self.fake_baremetal_port['uuid']
|
||||||
# NOTE(TheJulia): The two values below should be the same.
|
# NOTE(TheJulia): The two values below should be the same.
|
||||||
port_node_uuid = self.fake_baremetal_port['node_uuid']
|
port_node_uuid = self.fake_baremetal_port['node_uuid']
|
||||||
port_url_address = 'detail?address=%s' % mac_address
|
|
||||||
self.fake_baremetal_node['provision_state'] = 'available'
|
self.fake_baremetal_node['provision_state'] = 'available'
|
||||||
self.register_uris([
|
self.register_uris([
|
||||||
dict(
|
dict(
|
||||||
|
@ -1611,7 +1560,7 @@ class TestBaremetalNode(base.IronicTestCase):
|
||||||
method='GET',
|
method='GET',
|
||||||
uri=self.get_mock_url(
|
uri=self.get_mock_url(
|
||||||
resource='ports',
|
resource='ports',
|
||||||
append=[port_url_address]),
|
qs_elements=['address=%s' % mac_address]),
|
||||||
json={'ports': [{'address': mac_address,
|
json={'ports': [{'address': mac_address,
|
||||||
'node_uuid': port_node_uuid,
|
'node_uuid': port_node_uuid,
|
||||||
'uuid': port_uuid}]}),
|
'uuid': port_uuid}]}),
|
||||||
|
|
Loading…
Reference in New Issue