From ce4c60cf4be532f9665d3db237e53cc0bddfa986 Mon Sep 17 00:00:00 2001 From: Dustin Cowles Date: Fri, 10 May 2019 11:55:00 -0700 Subject: [PATCH] Use SDK for setting instance id We would like nova not to use ironicclient, but instead to invoke the ironic API directly through an openstacksdk connection. The parent commits set up the framework, and this commit uses it for the _set_instance_id function. Blueprint: openstacksdk-in-nova Change-Id: I95f3414d29a5ff5cc49994bac1cda917edc4f292 --- nova/tests/unit/virt/ironic/test_driver.py | 27 +++++++++------------- nova/virt/ironic/driver.py | 17 ++++++-------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/nova/tests/unit/virt/ironic/test_driver.py b/nova/tests/unit/virt/ironic/test_driver.py index 93b457baae..7ce7258b4c 100644 --- a/nova/tests/unit/virt/ironic/test_driver.py +++ b/nova/tests/unit/virt/ironic/test_driver.py @@ -2563,28 +2563,24 @@ class IronicDriverTestCase(test.NoDBTestCase): instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) self.driver.prepare_for_spawn(instance) - expected_patch = [{'path': '/instance_uuid', 'op': 'add', - 'value': instance.uuid}] self.mock_conn.get_node.assert_called_once_with( node.uuid, fields=('uuid', 'power_state', 'target_power_state', 'provision_state', 'target_provision_state', 'last_error', 'maintenance', 'properties', 'instance_uuid', 'traits', 'resource_class')) - mock_call.assert_called_once_with( - 'node.update', node.uuid, expected_patch, retry_on_conflict=False) + self.mock_conn.update_node.assert_called_once_with( + node, retry_on_conflict=False, instance_id=instance.uuid) - @mock.patch.object(cw.IronicClientWrapper, 'call') - def test__set_instance_uuid(self, mock_call): + def test__set_instance_id(self): node = ironic_utils.get_test_node(driver='fake') instance = fake_instance.fake_instance_obj(self.ctx, - node=node.uuid) - expected_patch = [{'path': '/instance_uuid', 'op': 'add', - 'value': instance.uuid}] - self.driver._set_instance_uuid(node, instance) - mock_call.assert_called_once_with('node.update', node.uuid, - expected_patch, - retry_on_conflict=False) + node=node.id) + + self.driver._set_instance_id(node, instance) + + self.mock_conn.update_node.assert_called_once_with( + node, retry_on_conflict=False, instance_id=instance.uuid) def test_prepare_for_spawn_invalid_instance(self): instance = fake_instance.fake_instance_obj(self.ctx, @@ -2593,11 +2589,10 @@ class IronicDriverTestCase(test.NoDBTestCase): self.driver.prepare_for_spawn, instance) - @mock.patch.object(cw.IronicClientWrapper, 'call') - def test_prepare_for_spawn_conflict(self, mock_call): + def test_prepare_for_spawn_conflict(self): node = ironic_utils.get_test_node(driver='fake') self.mock_conn.get_node.return_value = node - mock_call.side_effect = ironic_exception.BadRequest + self.mock_conn.update_node.side_effect = sdk_exc.ConflictException instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.assertRaises(exception.InstanceDeployFailure, self.driver.prepare_for_spawn, diff --git a/nova/virt/ironic/driver.py b/nova/virt/ironic/driver.py index 1b30aa9ab1..353f89b9ab 100644 --- a/nova/virt/ironic/driver.py +++ b/nova/virt/ironic/driver.py @@ -380,20 +380,17 @@ class IronicDriver(virt_driver.ComputeDriver): def _stop_firewall(self, instance, network_info): self.firewall_driver.unfilter_instance(instance, network_info) - def _set_instance_uuid(self, node, instance): - - patch = [{'path': '/instance_uuid', 'op': 'add', - 'value': instance.uuid}] + def _set_instance_id(self, node, instance): try: - # NOTE(TheJulia): Assert an instance UUID to lock the node + # NOTE(TheJulia): Assert an instance ID to lock the node # from other deployment attempts while configuration is # being set. - self.ironicclient.call('node.update', node.uuid, patch, - retry_on_conflict=False) - except ironic.exc.BadRequest: + self.ironic_connection.update_node(node, retry_on_conflict=False, + instance_id=instance.uuid) + except sdk_exc.SDKException: msg = (_("Failed to reserve node %(node)s " "when provisioning the instance %(instance)s") - % {'node': node.uuid, 'instance': instance.uuid}) + % {'node': node.id, 'instance': instance.uuid}) LOG.error(msg) raise exception.InstanceDeployFailure(msg) @@ -405,7 +402,7 @@ class IronicDriver(virt_driver.ComputeDriver): _("Ironic node uuid not supplied to " "driver for instance %s.") % instance.uuid) node = self._get_node(node_uuid) - self._set_instance_uuid(node, instance) + self._set_instance_id(node, instance) def failed_spawn_cleanup(self, instance): LOG.debug('Failed spawn cleanup called for instance',