From 1dccf255ada5d1ab6d354f56d4219d1e04b6be4a Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Fri, 2 Dec 2022 13:37:34 +0000 Subject: [PATCH] Remove unnecessary aliasing Now that all Ironic operations have been migrated to SDK, we no longer need to retain the aliasing that was in place for these opts. Change-Id: I9fb5a385487f601329bccc9efde325d86be397b6 Signed-off-by: Stephen Finucane --- nova/tests/unit/virt/ironic/test_driver.py | 361 ++++++++++----------- nova/tests/unit/virt/ironic/utils.py | 91 +++--- nova/virt/ironic/driver.py | 250 +++++++------- 3 files changed, 335 insertions(+), 367 deletions(-) diff --git a/nova/tests/unit/virt/ironic/test_driver.py b/nova/tests/unit/virt/ironic/test_driver.py index 6fda8e0a27..5c8054de2a 100644 --- a/nova/tests/unit/virt/ironic/test_driver.py +++ b/nova/tests/unit/virt/ironic/test_driver.py @@ -173,7 +173,7 @@ class IronicDriverTestCase(test.NoDBTestCase): uuid=self.instance_id) self.mock_conn.nodes.return_value = iter([node]) result = self.driver._validate_instance_and_node(instance) - self.assertEqual(result.uuid, node_id) + self.assertEqual(result.id, node_id) self.mock_conn.nodes.assert_called_once_with( instance_id=instance.uuid, fields=ironic_driver._NODE_FIELDS) @@ -308,7 +308,7 @@ class IronicDriverTestCase(test.NoDBTestCase): props = _get_properties() stats = _get_stats() node = _get_cached_node( - uuid=node_uuid, instance_uuid=self.instance_uuid, + id=node_uuid, instance_id=self.instance_uuid, properties=props, resource_class='foo') result = self.driver._node_resource(node) @@ -342,7 +342,7 @@ class IronicDriverTestCase(test.NoDBTestCase): node_uuid = uuidutils.generate_uuid() props = _get_properties() props['cpu_arch'] = 'i386' - node = _get_cached_node(uuid=node_uuid, properties=props) + node = _get_cached_node(id=node_uuid, properties=props) result = self.driver._node_resource(node) self.assertEqual('i686', result['supported_instances'][0][0]) @@ -352,7 +352,7 @@ class IronicDriverTestCase(test.NoDBTestCase): node_uuid = uuidutils.generate_uuid() props = _get_properties() del props['cpu_arch'] - node = _get_cached_node(uuid=node_uuid, properties=props) + node = _get_cached_node(id=node_uuid, properties=props) result = self.driver._node_resource(node) self.assertEqual([], result['supported_instances']) @@ -387,8 +387,8 @@ class IronicDriverTestCase(test.NoDBTestCase): props = _get_properties() stats = _get_stats() node = _get_cached_node( - uuid=node_uuid, - instance_uuid=None, + id=node_uuid, + instance_id=None, power_state=ironic_states.POWER_OFF, properties=props, provision_state=ironic_states.AVAILABLE) @@ -411,7 +411,10 @@ class IronicDriverTestCase(test.NoDBTestCase): props = _get_properties() stats = _get_stats() node = _get_cached_node( - uuid=node_uuid, instance_uuid=None, properties=props) + id=node_uuid, + instance_id=None, + properties=props, + ) result = self.driver._node_resource(node) self.assertEqual(0, result['vcpus']) @@ -432,8 +435,8 @@ class IronicDriverTestCase(test.NoDBTestCase): stats = _get_stats() instance_info = _get_instance_info() node = _get_cached_node( - uuid=node_uuid, - instance_uuid=uuidutils.generate_uuid(), + id=node_uuid, + instance_id=uuidutils.generate_uuid(), provision_state=ironic_states.ACTIVE, properties=props, instance_info=instance_info) @@ -452,7 +455,7 @@ class IronicDriverTestCase(test.NoDBTestCase): def test__parse_node_properties(self, mock_warning): props = _get_properties() node = _get_cached_node( - uuid=uuidutils.generate_uuid(), + id=uuidutils.generate_uuid(), properties=props) # raw_cpu_arch is included because extra_specs filters do not # canonicalized the arch @@ -472,7 +475,7 @@ class IronicDriverTestCase(test.NoDBTestCase): props['local_gb'] = 'bad-value' props['cpu_arch'] = 'bad-value' node = _get_cached_node( - uuid=uuidutils.generate_uuid(), + id=uuidutils.generate_uuid(), properties=props) # raw_cpu_arch is included because extra_specs filters do not # canonicalized the arch @@ -492,7 +495,7 @@ class IronicDriverTestCase(test.NoDBTestCase): props = _get_properties() props['cpu_arch'] = 'amd64' node = _get_cached_node( - uuid=uuidutils.generate_uuid(), + id=uuidutils.generate_uuid(), properties=props) # raw_cpu_arch is included because extra_specs filters do not # canonicalized the arch @@ -577,14 +580,14 @@ class IronicDriverTestCase(test.NoDBTestCase): id=i, uuid=uuid)) nodes.append(ironic_utils.get_test_node(instance_id=uuid, - fields=['instance_id'])) + fields=('instance_id',))) mock_inst_by_uuid.side_effect = instances self.mock_conn.nodes.return_value = iter(nodes) response = self.driver.list_instances() self.mock_conn.nodes.assert_called_with(associated=True, - fields=['instance_uuid']) + fields=('instance_uuid',)) expected_calls = [mock.call(mock.ANY, instances[0].uuid), mock.call(mock.ANY, instances[1].uuid)] mock_inst_by_uuid.assert_has_calls(expected_calls) @@ -598,7 +601,7 @@ class IronicDriverTestCase(test.NoDBTestCase): self.driver.list_instances() self.mock_conn.nodes.assert_called_with(associated=True, - fields=['instance_uuid']) + fields=('instance_uuid',)) @mock.patch.object(objects.Instance, 'get_by_uuid') def test_list_instances_fail(self, mock_inst_by_uuid): @@ -607,7 +610,7 @@ class IronicDriverTestCase(test.NoDBTestCase): self.assertRaises(exception.VirtDriverNotReady, self.driver.list_instances) self.mock_conn.nodes.assert_called_with(associated=True, - fields=['instance_uuid']) + fields=('instance_uuid',)) self.assertFalse(mock_inst_by_uuid.called) def test_list_instance_uuids(self): @@ -616,13 +619,13 @@ class IronicDriverTestCase(test.NoDBTestCase): for n in range(num_nodes): nodes.append(ironic_utils.get_test_node( instance_id=uuidutils.generate_uuid(), - fields=['instance_id'])) + fields=('instance_id',))) self.mock_conn.nodes.return_value = iter(nodes) uuids = self.driver.list_instance_uuids() self.mock_conn.nodes.assert_called_with(associated=True, - fields=['instance_uuid']) + fields=('instance_uuid',)) expected = [n.instance_id for n in nodes] self.assertEqual(sorted(expected), sorted(uuids)) @@ -633,7 +636,7 @@ class IronicDriverTestCase(test.NoDBTestCase): self.driver.list_instance_uuids() self.mock_conn.nodes.assert_called_with(associated=True, - fields=['instance_uuid']) + fields=('instance_uuid',)) @mock.patch.object(objects.InstanceList, 'get_uuids_by_host') @mock.patch.object(objects.ServiceList, 'get_all_computes_by_hv_type') @@ -660,7 +663,7 @@ class IronicDriverTestCase(test.NoDBTestCase): self.mock_conn.get_node.return_value = node self.mock_conn.nodes.return_value = iter([node]) - result = self.driver.node_is_available(node.uuid) + result = self.driver.node_is_available(node.id) self.assertTrue(result) self.mock_conn.nodes.assert_called_with( @@ -681,7 +684,7 @@ class IronicDriverTestCase(test.NoDBTestCase): ) self.mock_conn.nodes.reset_mock() - result = self.driver.node_is_available(node.uuid) + result = self.driver.node_is_available(node.id) self.assertTrue(result) self.mock_conn.nodes.assert_not_called() @@ -689,37 +692,37 @@ class IronicDriverTestCase(test.NoDBTestCase): def test__node_resources_unavailable(self): node_dicts = [ # a node in maintenance /w no instance and power OFF - {'uuid': uuidutils.generate_uuid(), - 'maintenance': True, + {'id': uuidutils.generate_uuid(), + 'is_maintenance': True, 'power_state': ironic_states.POWER_OFF, 'provision_state': ironic_states.AVAILABLE}, # a node in maintenance /w no instance and ERROR power state - {'uuid': uuidutils.generate_uuid(), - 'maintenance': True, + {'id': uuidutils.generate_uuid(), + 'is_maintenance': True, 'power_state': ironic_states.ERROR, 'provision_state': ironic_states.AVAILABLE}, # a node not in maintenance /w no instance and bad power state - {'uuid': uuidutils.generate_uuid(), + {'id': uuidutils.generate_uuid(), 'power_state': ironic_states.NOSTATE, 'provision_state': ironic_states.AVAILABLE}, # a node not in maintenance or bad power state, bad provision state - {'uuid': uuidutils.generate_uuid(), + {'id': uuidutils.generate_uuid(), 'power_state': ironic_states.POWER_ON, 'provision_state': ironic_states.MANAGEABLE}, # a node in cleaning - {'uuid': uuidutils.generate_uuid(), + {'id': uuidutils.generate_uuid(), 'power_state': ironic_states.POWER_ON, 'provision_state': ironic_states.CLEANING}, # a node in cleaning, waiting for a clean step to finish - {'uuid': uuidutils.generate_uuid(), + {'id': uuidutils.generate_uuid(), 'power_state': ironic_states.POWER_ON, 'provision_state': ironic_states.CLEANWAIT}, # a node in deleting - {'uuid': uuidutils.generate_uuid(), + {'id': uuidutils.generate_uuid(), 'power_state': ironic_states.POWER_ON, 'provision_state': ironic_states.DELETING}, # a node in deleted - {'uuid': uuidutils.generate_uuid(), + {'id': uuidutils.generate_uuid(), 'power_state': ironic_states.POWER_ON, 'provision_state': ironic_states.DELETED}, ] @@ -739,8 +742,8 @@ class IronicDriverTestCase(test.NoDBTestCase): def test__node_resources_used(self): node_dicts = [ # a node in maintenance /w instance and active - {'uuid': uuidutils.generate_uuid(), - 'instance_uuid': uuidutils.generate_uuid(), + {'id': uuidutils.generate_uuid(), + 'instance_id': uuidutils.generate_uuid(), 'provision_state': ironic_states.ACTIVE}, ] for n in node_dicts: @@ -748,7 +751,7 @@ class IronicDriverTestCase(test.NoDBTestCase): self.assertTrue(self.driver._node_resources_used(node)) unused_node = _get_cached_node( - instance_uuid=None, + instance_id=None, provision_state=ironic_states.AVAILABLE) self.assertFalse(self.driver._node_resources_used(unused_node)) @@ -760,31 +763,30 @@ class IronicDriverTestCase(test.NoDBTestCase): mock_gi.return_value = [instance.uuid] node_dicts = [ # a node in maintenance /w no instance and power OFF - {'uuid': uuidutils.generate_uuid(), - 'maintenance': True, + {'id': uuidutils.generate_uuid(), + 'is_maintenance': True, 'power_state': ironic_states.POWER_OFF, 'expected': True}, # a node /w instance on this compute daemon and power ON - {'uuid': uuidutils.generate_uuid(), - 'instance_uuid': self.instance_uuid, + {'id': uuidutils.generate_uuid(), + 'instance_id': self.instance_uuid, 'power_state': ironic_states.POWER_ON, 'expected': True}, # a node /w instance on another compute daemon and power ON - {'uuid': uuidutils.generate_uuid(), - 'instance_uuid': uuidutils.generate_uuid(), + {'id': uuidutils.generate_uuid(), + 'instance_id': uuidutils.generate_uuid(), 'power_state': ironic_states.POWER_ON, 'expected': False}, # a node not in maintenance /w no instance and bad power state - {'uuid': uuidutils.generate_uuid(), + {'id': uuidutils.generate_uuid(), 'power_state': ironic_states.ERROR, 'expected': True}, ] - nodes = [_get_cached_node(**n) - for n in node_dicts] + nodes = [_get_cached_node(**n) for n in node_dicts] self.mock_conn.nodes.return_value = iter(nodes) available_nodes = self.driver.get_available_nodes() mock_gi.assert_called_once_with(mock.ANY, CONF.host) - expected_uuids = [n['uuid'] for n in node_dicts if n['expected']] + expected_uuids = [n['id'] for n in node_dicts if n['expected']] self.assertEqual(sorted(expected_uuids), sorted(available_nodes)) @mock.patch.object(ironic_driver.IronicDriver, @@ -1042,7 +1044,7 @@ class IronicDriverTestCase(test.NoDBTestCase): 'resource_class': 'iron-nfv', } - mock_nfc.return_value = _get_cached_node(uuid=mock.sentinel.nodename) + mock_nfc.return_value = _get_cached_node(id=mock.sentinel.nodename) self.driver.update_provider_tree(self.ptree, mock.sentinel.nodename) @@ -1074,7 +1076,7 @@ class IronicDriverTestCase(test.NoDBTestCase): traits = ['trait1', 'trait2'] mock_nfc.return_value = _get_cached_node( - uuid=mock.sentinel.nodename, traits=traits) + id=mock.sentinel.nodename, traits=traits) self.driver.update_provider_tree(self.ptree, mock.sentinel.nodename) @@ -1088,7 +1090,7 @@ class IronicDriverTestCase(test.NoDBTestCase): # A different set of traits - we should replace (for now). traits = ['trait1', 'trait7', 'trait42'] mock_nfc.return_value = _get_cached_node( - uuid=mock.sentinel.nodename, traits=traits) + id=mock.sentinel.nodename, traits=traits) self.driver.update_provider_tree(self.ptree, mock.sentinel.nodename) result = self.ptree.data(mock.sentinel.nodename).traits self.assertEqual(set(traits), result) @@ -1127,7 +1129,7 @@ class IronicDriverTestCase(test.NoDBTestCase): self.driver.get_available_nodes(refresh=True) self.mock_conn.nodes.reset_mock() - result = self.driver.get_available_resource(node.uuid) + result = self.driver.get_available_resource(node.id) self.assertEqual(fake_resource, result) self.assertEqual(0, self.mock_conn.nodes.call_count) self.assertEqual(0, self.mock_conn.get_node.call_count) @@ -1141,7 +1143,7 @@ class IronicDriverTestCase(test.NoDBTestCase): properties = {'memory_mb': 512, 'cpus': 2} power_state = ironic_states.POWER_ON node = _get_cached_node( - instance_uuid=self.instance_uuid, properties=properties, + instance_id=self.instance_uuid, properties=properties, power_state=power_state) self.mock_conn.nodes.return_value = iter([node]) @@ -1168,7 +1170,7 @@ class IronicDriverTestCase(test.NoDBTestCase): properties = {'memory_mb': 512, 'cpus': 2} power_state = ironic_states.POWER_ON node = _get_cached_node( - instance_uuid=self.instance_uuid, properties=properties, + instance_id=self.instance_uuid, properties=properties, power_state=power_state) mock_svc_by_hv.return_value = [] @@ -1192,7 +1194,7 @@ class IronicDriverTestCase(test.NoDBTestCase): properties = {'memory_mb': 512, 'cpus': 2} power_state = ironic_states.POWER_ON node = _get_cached_node( - instance_uuid=self.instance_uuid, properties=properties, + instance_id=self.instance_uuid, properties=properties, power_state=power_state) node2 = _get_cached_node() @@ -1220,7 +1222,7 @@ class IronicDriverTestCase(test.NoDBTestCase): properties = {'memory_mb': 512, 'cpus': 2} power_state = ironic_states.POWER_ON node = _get_cached_node( - instance_uuid=self.instance_uuid, properties=properties, + instance_id=self.instance_uuid, properties=properties, power_state=power_state) self.mock_conn.nodes.return_value = iter([node]) @@ -1355,7 +1357,7 @@ class IronicDriverTestCase(test.NoDBTestCase): mock_looping, mock_required_by): mock_required_by.return_value = False node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' - node = _get_cached_node(driver='fake', uuid=node_uuid) + node = _get_cached_node(driver='fake', id=node_uuid) fake_flavor = objects.Flavor(ephemeral_gb=0) instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid) instance.flavor = fake_flavor @@ -1376,8 +1378,7 @@ class IronicDriverTestCase(test.NoDBTestCase): def test__add_instance_info_to_node(self): node = _get_cached_node(driver='fake') - instance = fake_instance.fake_instance_obj(self.ctx, - node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) image_meta = ironic_utils.get_test_image_meta() flavor = ironic_utils.get_test_flavor() instance.flavor = flavor @@ -1433,7 +1434,7 @@ class IronicDriverTestCase(test.NoDBTestCase): def test__add_volume_target_info(self): node = ironic_utils.get_test_node(driver='fake') - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) block_device_info = self._create_fake_block_device_info() self.driver._add_volume_target_info(self.ctx, instance, @@ -1453,7 +1454,7 @@ class IronicDriverTestCase(test.NoDBTestCase): def test__add_volume_target_info_empty_bdms(self): node = ironic_utils.get_test_node(driver='fake') - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.driver._add_volume_target_info(self.ctx, instance, None) @@ -1461,7 +1462,7 @@ class IronicDriverTestCase(test.NoDBTestCase): def test__add_volume_target_info_failures(self): node = ironic_utils.get_test_node(driver='fake') - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) block_device_info = self._create_fake_block_device_info() @@ -1481,9 +1482,9 @@ class IronicDriverTestCase(test.NoDBTestCase): def test__cleanup_volume_target_info(self): node = ironic_utils.get_test_node(driver='fake') - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.mock_conn.volume_targets.return_value = [ - ironic_utils.get_test_volume_target(uuid='fake_uuid'), + ironic_utils.get_test_volume_target(id='fake_uuid'), ] self.driver._cleanup_volume_target_info(instance) @@ -1496,7 +1497,7 @@ class IronicDriverTestCase(test.NoDBTestCase): def test__cleanup_volume_target_info_empty_targets(self): node = ironic_utils.get_test_node(driver='fake') - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.mock_conn.volume_targets.return_value = [] self.driver._cleanup_volume_target_info(instance) @@ -1505,10 +1506,10 @@ class IronicDriverTestCase(test.NoDBTestCase): def test__cleanup_volume_target_info_not_found(self): node = ironic_utils.get_test_node(driver='fake') - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.mock_conn.volume_targets.return_value = [ - ironic_utils.get_test_volume_target(uuid='fake_uuid1'), - ironic_utils.get_test_volume_target(uuid='fake_uuid2'), + ironic_utils.get_test_volume_target(id='fake_uuid1'), + ironic_utils.get_test_volume_target(id='fake_uuid2'), ] self.mock_conn.delete_volume_target.side_effect = [ sdk_exc.NotFoundException('not found'), @@ -1526,10 +1527,10 @@ class IronicDriverTestCase(test.NoDBTestCase): def test__cleanup_volume_target_info_bad_request(self): node = ironic_utils.get_test_node(driver='fake') - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.mock_conn.volume_targets.return_value = [ - ironic_utils.get_test_volume_target(uuid='fake_uuid1'), - ironic_utils.get_test_volume_target(uuid='fake_uuid2'), + ironic_utils.get_test_volume_target(id='fake_uuid1'), + ironic_utils.get_test_volume_target(id='fake_uuid2'), ] self.mock_conn.delete_volume_target.side_effect = [ sdk_exc.BadRequestException('error'), @@ -1669,7 +1670,7 @@ class IronicDriverTestCase(test.NoDBTestCase): network_info = 'foo' node = _get_cached_node( - driver='fake', uuid=node_id, provision_state=state) + driver='fake', id=node_id, provision_state=state) instance = fake_instance.fake_instance_obj(self.ctx, node=node_id) def fake_set_node_provision_state(*_): @@ -1712,7 +1713,7 @@ class IronicDriverTestCase(test.NoDBTestCase): node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' node = _get_cached_node( driver='fake', - uuid=node_uuid, + id=node_uuid, provision_state=ironic_states.ACTIVE, ) fake_validate.return_value = node @@ -1735,7 +1736,7 @@ class IronicDriverTestCase(test.NoDBTestCase): def test_destroy_trigger_remove_info_fail(self, mock_clean, fake_validate): node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' node = ironic_utils.get_test_node( - driver='fake', uuid=node_uuid, + driver='fake', id=node_uuid, provision_state=ironic_states.AVAILABLE) fake_validate.return_value = node instance = fake_instance.fake_instance_obj(self.ctx, @@ -1751,15 +1752,15 @@ class IronicDriverTestCase(test.NoDBTestCase): '_validate_instance_and_node') def _test__unprovision_instance(self, mock_validate_inst, state=None): node = _get_cached_node(driver='fake', provision_state=state) - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) mock_validate_inst.return_value = node with mock.patch.object(self.driver, 'node_cache') as cache_mock: self.driver._unprovision(instance, node) mock_validate_inst.assert_called_once_with(instance) self.mock_conn.set_node_provision_state.assert_called_once_with( - node.uuid, "deleted", + node.id, "deleted", ) - cache_mock.pop.assert_called_once_with(node.uuid, None) + cache_mock.pop.assert_called_once_with(node.id, None) def test__unprovision_cleaning(self): self._test__unprovision_instance(state=ironic_states.CLEANING) @@ -1773,7 +1774,7 @@ class IronicDriverTestCase(test.NoDBTestCase): CONF.set_default('api_max_retries', default=2, group='ironic') node = _get_cached_node( driver='fake', provision_state=ironic_states.ACTIVE) - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) mock_validate_inst.return_value = node self.assertRaises(exception.NovaException, self.driver._unprovision, @@ -1782,7 +1783,7 @@ class IronicDriverTestCase(test.NoDBTestCase): mock.call(instance)) mock_validate_inst.assert_has_calls(expected_calls) self.mock_conn.set_node_provision_state.assert_called_once_with( - node.uuid, "deleted", + node.id, "deleted", ) @mock.patch.object(ironic_driver.IronicDriver, @@ -1790,14 +1791,14 @@ class IronicDriverTestCase(test.NoDBTestCase): def test__unprovision_instance_not_found(self, mock_validate_inst): node = _get_cached_node( driver='fake', provision_state=ironic_states.DELETING) - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) mock_validate_inst.side_effect = exception.InstanceNotFound( instance_id='fake') self.driver._unprovision(instance, node) mock_validate_inst.assert_called_once_with(instance) self.mock_conn.set_node_provision_state.assert_called_once_with( - node.uuid, "deleted", + node.id, "deleted", ) def test_destroy_unassociate_fail(self): @@ -1832,11 +1833,10 @@ class IronicDriverTestCase(test.NoDBTestCase): fake_looping_call = FakeLoopingCall() mock_looping.return_value = fake_looping_call - instance = fake_instance.fake_instance_obj(self.ctx, - node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.driver.reboot(self.ctx, instance, None, 'HARD') self.mock_conn.set_node_power_state.assert_called_once_with( - node.uuid, 'reboot', + node.id, 'reboot', ) @mock.patch.object(ironic_driver.IronicDriver, @@ -1844,10 +1844,9 @@ class IronicDriverTestCase(test.NoDBTestCase): def test_trigger_crash_dump(self, fake_validate): node = _get_cached_node() fake_validate.return_value = node - instance = fake_instance.fake_instance_obj(self.ctx, - node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.driver.trigger_crash_dump(instance) - self.mock_conn.inject_nmi_to_node.assert_called_once_with(node.uuid) + self.mock_conn.inject_nmi_to_node.assert_called_once_with(node.id) @mock.patch.object(ironic_driver.IronicDriver, '_validate_instance_and_node') @@ -1856,8 +1855,7 @@ class IronicDriverTestCase(test.NoDBTestCase): fake_validate.return_value = node self.mock_conn.inject_nmi_to_node.side_effect = \ sdk_exc.BadRequestException() - instance = fake_instance.fake_instance_obj(self.ctx, - node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.assertRaises(sdk_exc.BadRequestException, self.driver.trigger_crash_dump, instance) @@ -1870,11 +1868,10 @@ class IronicDriverTestCase(test.NoDBTestCase): fake_looping_call = FakeLoopingCall() mock_looping.return_value = fake_looping_call - instance = fake_instance.fake_instance_obj(self.ctx, - node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.driver.reboot(self.ctx, instance, None, 'SOFT') self.mock_conn.set_node_power_state.assert_called_once_with( - node.uuid, 'soft reboot', + node.id, 'soft reboot', ) @mock.patch.object(loopingcall, 'FixedIntervalLoopingCall') @@ -1890,13 +1887,12 @@ class IronicDriverTestCase(test.NoDBTestCase): fake_looping_call = FakeLoopingCall() mock_looping.return_value = fake_looping_call - instance = fake_instance.fake_instance_obj(self.ctx, - node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.driver.reboot(self.ctx, instance, None, 'SOFT') self.mock_conn.set_node_power_state.assert_has_calls( [ - mock.call(node.uuid, 'soft reboot'), - mock.call(node.uuid, 'reboot'), + mock.call(node.id, 'soft reboot'), + mock.call(node.id, 'reboot'), ] ) @@ -1933,7 +1929,7 @@ class IronicDriverTestCase(test.NoDBTestCase): ) self.mock_conn.set_node_power_state.assert_called_once_with( - node.uuid, 'power on', + node.id, 'power on', ) @mock.patch.object(loopingcall, 'FixedIntervalLoopingCall') @@ -1954,7 +1950,7 @@ class IronicDriverTestCase(test.NoDBTestCase): self._test_power_off() self.mock_conn.set_node_power_state.assert_called_once_with( - node.uuid, 'power off', + node.id, 'power off', ) @mock.patch.object(ironic_driver.IronicDriver, @@ -1967,7 +1963,7 @@ class IronicDriverTestCase(test.NoDBTestCase): self._test_power_off(timeout=30) self.mock_conn.set_node_power_state.assert_called_once_with( - node.uuid, 'soft power off', timeout=30, + node.id, 'soft power off', timeout=30, ) @mock.patch.object(ironic_driver.IronicDriver, @@ -1982,8 +1978,8 @@ class IronicDriverTestCase(test.NoDBTestCase): self._test_power_off(timeout=30) expected_calls = [ - mock.call(node.uuid, 'soft power off', timeout=30), - mock.call(node.uuid, 'power off'), + mock.call(node.id, 'soft power off', timeout=30), + mock.call(node.id, 'power off'), ] self.assertEqual( len(expected_calls), @@ -2000,8 +1996,8 @@ class IronicDriverTestCase(test.NoDBTestCase): self._test_power_off(timeout=30) expected_calls = [ - mock.call(node.uuid, 'soft power off', timeout=30), - mock.call(node.uuid, 'power off'), + mock.call(node.id, 'soft power off', timeout=30), + mock.call(node.id, 'power off'), ] self.assertEqual( len(expected_calls), @@ -2011,7 +2007,7 @@ class IronicDriverTestCase(test.NoDBTestCase): def test_plug_vifs_with_port(self): node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' - node = _get_cached_node(uuid=node_uuid) + node = _get_cached_node(id=node_uuid) instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid) @@ -2022,7 +2018,7 @@ class IronicDriverTestCase(test.NoDBTestCase): # asserts self.mock_conn.attach_vif_to_node( - node.uuid, vif_id, retry_on_conflict=False, + node.id, vif_id, retry_on_conflict=False, ) @mock.patch.object(ironic_driver.IronicDriver, '_plug_vifs') @@ -2037,9 +2033,8 @@ class IronicDriverTestCase(test.NoDBTestCase): def test_plug_vifs_multiple_ports(self): node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' - node = _get_cached_node(uuid=node_uuid) - instance = fake_instance.fake_instance_obj(self.ctx, - node=node_uuid) + node = _get_cached_node(id=node_uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid) first_vif_id = 'aaaaaaaa-vv11-cccc-dddd-eeeeeeeeeeee' second_vif_id = 'aaaaaaaa-vv22-cccc-dddd-eeeeeeeeeeee' first_vif = ironic_utils.get_test_vif(address='22:FF:FF:FF:FF:FF', @@ -2051,8 +2046,8 @@ class IronicDriverTestCase(test.NoDBTestCase): # asserts calls = ( - mock.call(node.uuid, first_vif_id, retry_on_conflict=False), - mock.call(node.uuid, second_vif_id, retry_on_conflict=False), + mock.call(node.id, first_vif_id, retry_on_conflict=False), + mock.call(node.id, second_vif_id, retry_on_conflict=False), ) self.mock_conn.attach_vif_to_node.assert_has_calls( calls, any_order=True, @@ -2060,9 +2055,8 @@ class IronicDriverTestCase(test.NoDBTestCase): def test_plug_vifs_failure(self): node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' - node = _get_cached_node(uuid=node_uuid) - instance = fake_instance.fake_instance_obj(self.ctx, - node=node_uuid) + node = _get_cached_node(id=node_uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid) first_vif_id = 'aaaaaaaa-vv11-cccc-dddd-eeeeeeeeeeee' second_vif_id = 'aaaaaaaa-vv22-cccc-dddd-eeeeeeeeeeee' first_vif = ironic_utils.get_test_vif(address='22:FF:FF:FF:FF:FF', @@ -2083,7 +2077,7 @@ class IronicDriverTestCase(test.NoDBTestCase): def test_plug_vifs_already_attached(self): node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' - node = _get_cached_node(uuid=node_uuid) + node = _get_cached_node(id=node_uuid) instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid) first_vif_id = 'aaaaaaaa-vv11-cccc-dddd-eeeeeeeeeeee' @@ -2101,7 +2095,7 @@ class IronicDriverTestCase(test.NoDBTestCase): def test_plug_vifs_no_network_info(self): node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' - node = _get_cached_node(uuid=node_uuid) + node = _get_cached_node(id=node_uuid) instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid) @@ -2152,7 +2146,7 @@ class IronicDriverTestCase(test.NoDBTestCase): @mock.patch.object(ironic_driver.IronicDriver, '_plug_vifs') def test_attach_interface(self, mock_pv): node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' - node = _get_cached_node(uuid=node_uuid) + node = _get_cached_node(id=node_uuid) instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid) self.mock_conn.get_node.return_value = node @@ -2244,7 +2238,7 @@ class IronicDriverTestCase(test.NoDBTestCase): mock_configdrive): node_uuid = uuidutils.generate_uuid() node = _get_cached_node( - uuid=node_uuid, instance_uuid=self.instance_uuid) + id=node_uuid, instance_id=self.instance_uuid) self.mock_conn.get_node.return_value = node mock_required_by.return_value = True mock_configdrive.side_effect = exception.NovaException() @@ -2272,7 +2266,7 @@ class IronicDriverTestCase(test.NoDBTestCase): mock_required_by, mock_configdrive): node_uuid = uuidutils.generate_uuid() node = _get_cached_node( - uuid=node_uuid, instance_uuid=self.instance_uuid) + id=node_uuid, instance_id=self.instance_uuid) self.mock_conn.get_node.return_value = node mock_required_by.return_value = False @@ -2298,8 +2292,8 @@ class IronicDriverTestCase(test.NoDBTestCase): instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid, host=hostname) - node = ironic_utils.get_test_node(uuid=node_uuid, - instance_uuid=self.instance_uuid, + node = ironic_utils.get_test_node(id=node_uuid, + instance_id=self.instance_uuid, network_interface='flat') self.mock_conn.get_node.return_value = node host_id = self.driver.network_binding_host_id(self.ctx, instance) @@ -2308,22 +2302,22 @@ class IronicDriverTestCase(test.NoDBTestCase): def test_get_volume_connector(self): node_uuid = uuids.node_uuid node_props = {'cpu_arch': 'x86_64'} - node = ironic_utils.get_test_node(uuid=node_uuid, + node = ironic_utils.get_test_node(id=node_uuid, properties=node_props) connectors = [ironic_utils.get_test_volume_connector( - node_uuid=node_uuid, type='iqn', + node_id=node_uuid, type='iqn', connector_id='iqn.test'), ironic_utils.get_test_volume_connector( - node_uuid=node_uuid, type='ip', + node_id=node_uuid, type='ip', connector_id='1.2.3.4'), ironic_utils.get_test_volume_connector( - node_uuid=node_uuid, type='wwnn', + node_id=node_uuid, type='wwnn', connector_id='200010601'), ironic_utils.get_test_volume_connector( - node_uuid=node_uuid, type='wwpn', + node_id=node_uuid, type='wwpn', connector_id='200010605'), ironic_utils.get_test_volume_connector( - node_uuid=node_uuid, type='wwpn', + node_id=node_uuid, type='wwpn', connector_id='200010606')] expected_props = {'initiator': 'iqn.test', @@ -2356,14 +2350,14 @@ class IronicDriverTestCase(test.NoDBTestCase): ): node_uuid = uuids.node_uuid node_props = {'cpu_arch': 'x86_64'} - node = ironic_utils.get_test_node(uuid=node_uuid, + node = ironic_utils.get_test_node(id=node_uuid, properties=node_props) connectors = [ironic_utils.get_test_volume_connector( - node_uuid=node_uuid, type='iqn', + node_id=node_uuid, type='iqn', connector_id='iqn.test')] if mac_specified: connectors.append(ironic_utils.get_test_volume_connector( - node_uuid=node_uuid, type='mac', + node_id=node_uuid, type='mac', connector_id='11:22:33:44:55:66')) fixed_ip = network_model.FixedIP(address='1.2.3.4', version=4) subnet = network_model.Subnet(ips=[fixed_ip]) @@ -2382,7 +2376,7 @@ class IronicDriverTestCase(test.NoDBTestCase): self.mock_conn.volume_connectors.return_value = connectors instance = fake_instance.fake_instance_obj(self.ctx, node=node_uuid) port = ironic_utils.get_test_port( - node_uuid=node_uuid, address='11:22:33:44:55:66', + node_id=node_uuid, address='11:22:33:44:55:66', internal_info={'tenant_vif_port_id': vif['id']}) self.mock_conn.ports.return_value = [port] if no_fixed_ip: @@ -2393,7 +2387,7 @@ class IronicDriverTestCase(test.NoDBTestCase): mock_nw_info.return_value = [vif] if portgroup_exist: portgroup = ironic_utils.get_test_portgroup( - node_uuid=node_uuid, address='11:22:33:44:55:66', + node_id=node_uuid, address='11:22:33:44:55:66', extra={'vif_port_id': vif['id']}) self.mock_conn.port_groups.return_value = [portgroup] else: @@ -2433,7 +2427,7 @@ class IronicDriverTestCase(test.NoDBTestCase): @mock.patch.object(ironic_driver.IronicDriver, '_plug_vifs') def test_prepare_networks_before_block_device_mapping(self, mock_pvifs): node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' - node = _get_cached_node(uuid=node_uuid) + node = _get_cached_node(id=node_uuid) self.mock_conn.get_node.return_value = node instance = fake_instance.fake_instance_obj(self.ctx) network_info = utils.get_test_network_info() @@ -2445,7 +2439,7 @@ class IronicDriverTestCase(test.NoDBTestCase): def test_prepare_networks_before_block_device_mapping_error(self, mock_pvifs): node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' - node = _get_cached_node(uuid=node_uuid) + node = _get_cached_node(id=node_uuid) self.mock_conn.get_node.return_value = node instance = fake_instance.fake_instance_obj(self.ctx) network_info = utils.get_test_network_info() @@ -2473,15 +2467,14 @@ class IronicDriverTestCase(test.NoDBTestCase): def test_prepare_for_spawn(self): node = ironic_utils.get_test_node( - driver='fake', instance_uuid=None, + driver='fake', instance_id=None, provision_state=ironic_states.AVAILABLE, power_state=ironic_states.POWER_OFF) self.mock_conn.get_node.return_value = node - instance = fake_instance.fake_instance_obj(self.ctx, - node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.driver.prepare_for_spawn(instance) self.mock_conn.get_node.assert_called_once_with( - node.uuid, + node.id, fields=('uuid', 'power_state', 'target_power_state', 'provision_state', 'target_provision_state', 'last_error', 'maintenance', 'properties', 'instance_uuid', 'traits', @@ -2508,7 +2501,7 @@ class IronicDriverTestCase(test.NoDBTestCase): def test_prepare_for_spawn_conflict(self): node = ironic_utils.get_test_node( - driver='fake', instance_uuid=None, + driver='fake', instance_id=None, provision_state=ironic_states.AVAILABLE, power_state=ironic_states.POWER_OFF) self.mock_conn.get_node.return_value = node @@ -2520,7 +2513,7 @@ class IronicDriverTestCase(test.NoDBTestCase): def test_prepare_for_spawn_not_available(self): node = ironic_utils.get_test_node( - driver='fake', instance_uuid=None, + driver='fake', instance_id=None, provision_state=ironic_states.CLEANWAIT, power_state=ironic_states.POWER_OFF) self.mock_conn.get_node.return_value = node @@ -2533,8 +2526,7 @@ class IronicDriverTestCase(test.NoDBTestCase): @mock.patch.object(ironic_driver.IronicDriver, '_cleanup_deploy') def test_failed_spawn_cleanup(self, mock_cleanup): node = ironic_utils.get_test_node(driver='fake') - instance = fake_instance.fake_instance_obj(self.ctx, - node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.mock_conn.nodes.return_value = iter([node]) self.driver.failed_spawn_cleanup(instance) @@ -2553,8 +2545,7 @@ class IronicDriverTestCase(test.NoDBTestCase): # TODO(TheJulia): This REALLY should be updated to cover all of the # calls that take place. node = ironic_utils.get_test_node(driver='fake') - instance = fake_instance.fake_instance_obj(self.ctx, - node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.driver._cleanup_deploy(node, instance) mock_vol.assert_called_once_with(instance) mock_unvif.assert_called_once_with(node, instance, None) @@ -2567,8 +2558,7 @@ class IronicDriverTestCase(test.NoDBTestCase): # TODO(TheJulia): This REALLY should be updated to cover all of the # calls that take place. node = ironic_utils.get_test_node(driver='fake') - instance = fake_instance.fake_instance_obj(self.ctx, - node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.driver._cleanup_deploy(node, instance, remove_instance_info=False) mock_vol.assert_called_once_with(instance) mock_unvif.assert_called_once_with(node, instance, None) @@ -2589,12 +2579,11 @@ class IronicDriverSyncTestCase(IronicDriverTestCase): fake_looping_call = FakeLoopingCall() mock_looping.return_value = fake_looping_call - instance = fake_instance.fake_instance_obj(self.ctx, - node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.driver.rescue(self.ctx, instance, None, None, 'xyz', None) self.mock_conn.set_node_provision_state.assert_called_once_with( - node.uuid, 'rescue', rescue_password='xyz', + node.id, 'rescue', rescue_password='xyz', ) @mock.patch.object(loopingcall, 'FixedIntervalLoopingCall') @@ -2605,7 +2594,7 @@ class IronicDriverSyncTestCase(IronicDriverTestCase): mock_looping.return_value = fake_looping_call self.mock_conn.set_node_provision_state.side_effect = \ sdk_exc.BadRequestException() - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.assertRaises( exception.InstanceRescueFailure, @@ -2613,7 +2602,7 @@ class IronicDriverSyncTestCase(IronicDriverTestCase): self.ctx, instance, None, None, 'xyz', None, ) self.mock_conn.set_node_provision_state.assert_called_once_with( - node.uuid, 'rescue', rescue_password='xyz', + node.id, 'rescue', rescue_password='xyz', ) @mock.patch.object(ironic_driver.IronicDriver, @@ -2621,7 +2610,7 @@ class IronicDriverSyncTestCase(IronicDriverTestCase): def test_rescue_instance_not_found(self, fake_validate): node = ironic_utils.get_test_node(driver='fake') - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) fake_validate.side_effect = exception.InstanceNotFound( instance_id='fake', ) @@ -2640,7 +2629,7 @@ class IronicDriverSyncTestCase(IronicDriverTestCase): last_error='rescue failed') fake_validate.return_value = node - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.assertRaises( exception.InstanceRescueFailure, @@ -2654,11 +2643,11 @@ class IronicDriverSyncTestCase(IronicDriverTestCase): fake_looping_call = FakeLoopingCall() mock_looping.return_value = fake_looping_call - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.driver.unrescue(self.ctx, instance) self.mock_conn.set_node_provision_state.assert_called_once_with( - node.uuid, 'unrescue', + node.id, 'unrescue', ) @mock.patch.object(loopingcall, 'FixedIntervalLoopingCall') @@ -2670,7 +2659,7 @@ class IronicDriverSyncTestCase(IronicDriverTestCase): self.mock_conn.set_node_provision_state.side_effect = \ sdk_exc.BadRequestException() - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.assertRaises( exception.InstanceUnRescueFailure, self.driver.unrescue, self.ctx, instance, @@ -2681,7 +2670,7 @@ class IronicDriverSyncTestCase(IronicDriverTestCase): def test_unrescue_instance_not_found(self, fake_validate): node = ironic_utils.get_test_node(driver='fake') - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) fake_validate.side_effect = exception.InstanceNotFound( instance_id='fake') @@ -2697,7 +2686,7 @@ class IronicDriverSyncTestCase(IronicDriverTestCase): last_error='unrescue failed') fake_validate.return_value = node - instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid) + instance = fake_instance.fake_instance_obj(self.ctx, node=node.id) self.assertRaises( exception.InstanceUnRescueFailure, @@ -3070,17 +3059,17 @@ class NodeCacheTestCase(test.NoDBTestCase): instances = [] nodes = [ _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), ] hosts = ['host1', 'host1', 'host1'] self._test__refresh_cache(instances, nodes, hosts) - expected_cache = {n.uuid: n for n in nodes} + expected_cache = {n.id: n for n in nodes} self.assertEqual(expected_cache, self.driver.node_cache) def test__refresh_cache(self): @@ -3088,17 +3077,17 @@ class NodeCacheTestCase(test.NoDBTestCase): instances = [] nodes = [ _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), ] hosts = [self.host, self.host, self.host] self._test__refresh_cache(instances, nodes, hosts) - expected_cache = {n.uuid: n for n in nodes} + expected_cache = {n.id: n for n in nodes} self.assertEqual(expected_cache, self.driver.node_cache) def test__refresh_cache_partition_key(self): @@ -3106,11 +3095,11 @@ class NodeCacheTestCase(test.NoDBTestCase): instances = [] nodes = [ _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), ] hosts = [self.host, self.host, self.host] partition_key = 'some-group' @@ -3119,7 +3108,7 @@ class NodeCacheTestCase(test.NoDBTestCase): self._test__refresh_cache(instances, nodes, hosts, partition_key=partition_key) - expected_cache = {n.uuid: n for n in nodes} + expected_cache = {n.id: n for n in nodes} self.assertEqual(expected_cache, self.driver.node_cache) def test__refresh_cache_partition_key_old_api(self): @@ -3127,11 +3116,11 @@ class NodeCacheTestCase(test.NoDBTestCase): instances = [] nodes = [ _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), ] hosts = [self.host, self.host, self.host] partition_key = 'some-group' @@ -3141,7 +3130,7 @@ class NodeCacheTestCase(test.NoDBTestCase): partition_key=partition_key, can_send_146=False) - expected_cache = {n.uuid: n for n in nodes} + expected_cache = {n.id: n for n in nodes} self.assertEqual(expected_cache, self.driver.node_cache) def test__refresh_cache_multiple_services(self): @@ -3149,17 +3138,17 @@ class NodeCacheTestCase(test.NoDBTestCase): instances = [] nodes = [ _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), ] hosts = [self.host, 'host2', 'host3'] self._test__refresh_cache(instances, nodes, hosts) - expected_cache = {n.uuid: n for n in nodes[0:1]} + expected_cache = {n.id: n for n in nodes[0:1]} self.assertEqual(expected_cache, self.driver.node_cache) def test__refresh_cache_our_instances(self): @@ -3168,18 +3157,18 @@ class NodeCacheTestCase(test.NoDBTestCase): instances = [uuidutils.generate_uuid()] nodes = [ _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=instances[0]), + id=uuidutils.generate_uuid(), instance_id=instances[0]), _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), ] # only two calls, having the instance will short-circuit the first node hosts = [{self.host}, {self.host}] self._test__refresh_cache(instances, nodes, hosts) - expected_cache = {n.uuid: n for n in nodes} + expected_cache = {n.id: n for n in nodes} self.assertEqual(expected_cache, self.driver.node_cache) def test__refresh_cache_their_instances(self): @@ -3188,19 +3177,19 @@ class NodeCacheTestCase(test.NoDBTestCase): instances = [] nodes = [ _get_cached_node( - uuid=uuidutils.generate_uuid(), - instance_uuid=uuidutils.generate_uuid()), + id=uuidutils.generate_uuid(), + instance_id=uuidutils.generate_uuid()), _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), _get_cached_node( - uuid=uuidutils.generate_uuid(), instance_uuid=None), + id=uuidutils.generate_uuid(), instance_id=None), ] hosts = [self.host, self.host] # only two calls, having the instance will short-circuit the first node self._test__refresh_cache(instances, nodes, hosts) - expected_cache = {n.uuid: n for n in nodes[1:]} + expected_cache = {n.id: n for n in nodes[1:]} self.assertEqual(expected_cache, self.driver.node_cache) @@ -3259,7 +3248,7 @@ class IronicDriverConsoleTestCase(test.NoDBTestCase): self.assertGreater(self.mock_conn.get_node_console.call_count, 1) self.assertEqual(2, self.mock_conn.set_node_console_mode.call_count) - self.assertEqual(self.node.uuid, result['node'].uuid) + self.assertEqual(self.node.id, result['node'].id) self.assertThat(result['console_info'], nova_matchers.DictMatches(expected)) @@ -3277,7 +3266,7 @@ class IronicDriverConsoleTestCase(test.NoDBTestCase): self.driver._get_node_console_with_reset, self.instance) - self.mock_conn.get_node_console.assert_called_once_with(self.node.uuid) + self.mock_conn.get_node_console.assert_called_once_with(self.node.id) self.mock_conn.set_node_console_mode.assert_not_called() self.assertTrue(mock_log.debug.called) @@ -3297,7 +3286,7 @@ class IronicDriverConsoleTestCase(test.NoDBTestCase): self.driver._get_node_console_with_reset, self.instance) - self.mock_conn.get_node_console.assert_called_once_with(self.node.uuid) + self.mock_conn.get_node_console.assert_called_once_with(self.node.id) self.assertEqual(2, self.mock_conn.set_node_console_mode.call_count) self.assertTrue(mock_log.error.called) @@ -3392,7 +3381,7 @@ class IronicDriverConsoleTestCase(test.NoDBTestCase): self.assertRaises(exception.ConsoleTypeUnavailable, self.driver.get_serial_console, self.ctx, self.instance) - self.mock_conn.get_node_console.assert_called_once_with(self.node.uuid) + self.mock_conn.get_node_console.assert_called_once_with(self.node.id) self.mock_conn.set_node_console_mode.assert_not_called() @mock.patch.object(ironic_driver, 'LOG', autospec=True) diff --git a/nova/tests/unit/virt/ironic/utils.py b/nova/tests/unit/virt/ironic/utils.py index 6cd652d177..beda048900 100644 --- a/nova/tests/unit/virt/ironic/utils.py +++ b/nova/tests/unit/virt/ironic/utils.py @@ -32,17 +32,13 @@ def get_test_validation(**kw): def get_test_node(fields=None, **kw): - # TODO(dustinc): Once the usages of id/uuid, maintenance/is_maintenance, - # and portgroup/port_group are normalized, the duplicates can be removed - _id = kw.get('id') or kw.get('uuid', - 'eeeeeeee-dddd-cccc-bbbb-aaaaaaaaaaaa') - _instance_id = kw.get('instance_id') or kw.get('instance_uuid') - _is_maintenance = kw.get('is_maintenance') or kw.get('maintenance', False) - node = {'uuid': _id, - 'id': _id, + # NOTE(stephenfin): Prevent invalid properties making their way through + if 'uuid' in kw or 'instance_uuid' in kw or 'maintenance' in kw: + raise Exception('Invalid property provided') + + node = {'id': kw.get('id', 'eeeeeeee-dddd-cccc-bbbb-aaaaaaaaaaaa'), 'chassis_uuid': kw.get('chassis_uuid'), - 'power_state': kw.get('power_state', - ironic_states.NOSTATE), + 'power_state': kw.get('power_state', ironic_states.NOSTATE), 'target_power_state': kw.get('target_power_state', ironic_states.NOSTATE), 'provision_state': kw.get('provision_state', @@ -50,58 +46,50 @@ def get_test_node(fields=None, **kw): 'target_provision_state': kw.get('target_provision_state', ironic_states.NOSTATE), 'last_error': kw.get('last_error'), - 'instance_uuid': _instance_id, - 'instance_id': _instance_id, + 'instance_id': kw.get('instance_id'), 'instance_info': kw.get('instance_info'), 'driver': kw.get('driver', 'fake'), 'driver_info': kw.get('driver_info', {}), 'properties': kw.get('properties', {}), 'reservation': kw.get('reservation'), - 'maintenance': _is_maintenance, - 'is_maintenance': _is_maintenance, + 'is_maintenance': kw.get('is_maintenance'), 'network_interface': kw.get('network_interface'), 'resource_class': kw.get('resource_class'), 'traits': kw.get('traits', []), 'extra': kw.get('extra', {}), 'updated_at': kw.get('created_at'), 'created_at': kw.get('updated_at')} + if fields is not None: node = {key: value for key, value in node.items() if key in fields} + return type('node', (object,), node)() def get_test_port(**kw): - # TODO(dustinc): Once the usages of id/uuid, maintenance/is_maintenance, - # and portgroup/port_group are normalized, the duplicates can be removed - _id = kw.get('id') or kw.get('uuid', - 'gggggggg-uuuu-qqqq-ffff-llllllllllll') - _node_id = kw.get('node_uuid') or kw.get('node_id', get_test_node().id) - _port_group_id = kw.get('port_group_id') or kw.get('portgroup_uuid') + # NOTE(stephenfin): Prevent invalid properties making their way through + if 'uuid' in kw or 'node_uuid' in kw or 'portgroup_uuid' in kw: + raise Exception('Invalid property provided') + return type('port', (object,), - {'uuid': _id, - 'id': _id, - 'node_uuid': _node_id, - 'node_id': _node_id, + {'id': kw.get('id', 'gggggggg-uuuu-qqqq-ffff-llllllllllll'), + 'node_id': kw.get('node_id', get_test_node().id), 'address': kw.get('address', 'FF:FF:FF:FF:FF:FF'), 'extra': kw.get('extra', {}), 'internal_info': kw.get('internal_info', {}), - 'portgroup_uuid': _port_group_id, - 'port_group_id': _port_group_id, + 'port_group_id': kw.get('port_group_id'), 'created_at': kw.get('created_at'), 'updated_at': kw.get('updated_at')})() def get_test_portgroup(**kw): - # TODO(dustinc): Once the usages of id/uuid, maintenance/is_maintenance, - # and portgroup/port_group are normalized, the duplicates can be removed - _id = kw.get('id') or kw.get('uuid', - 'deaffeed-1234-5678-9012-fedcbafedcba') - _node_id = kw.get('node_id') or kw.get('node_uuid', get_test_node().id) + # NOTE(stephenfin): Prevent invalid properties making their way through + if 'uuid' in kw or 'node_uuid' in kw: + raise Exception('Invalid property provided') + return type('portgroup', (object,), - {'uuid': _id, - 'id': _id, - 'node_uuid': _node_id, - 'node_id': _node_id, + {'id': kw.get('id', 'deaffeed-1234-5678-9012-fedcbafedcba'), + 'node_id': kw.get('node_id', get_test_node().id), 'address': kw.get('address', 'EE:EE:EE:EE:EE:EE'), 'extra': kw.get('extra', {}), 'internal_info': kw.get('internal_info', {}), @@ -109,7 +97,8 @@ def get_test_portgroup(**kw): 'mode': kw.get('mode', 'active-backup'), 'name': kw.get('name'), 'standalone_ports_supported': kw.get( - 'standalone_ports_supported', True), + 'standalone_ports_supported', True, + ), 'created_at': kw.get('created_at'), 'updated_at': kw.get('updated_at')})() @@ -133,16 +122,13 @@ def get_test_vif(**kw): def get_test_volume_connector(**kw): - # TODO(dustinc): Once the usages of id/uuid, maintenance/is_maintenance, - # and portgroup/port_group are normalized, the duplicates can be removed - _id = kw.get('id') or kw.get('uuid', - 'hhhhhhhh-qqqq-uuuu-mmmm-bbbbbbbbbbbb') - _node_id = kw.get('node_id') or kw.get('node_uuid', get_test_node().id) + # NOTE(stephenfin): Prevent invalid properties making their way through + if 'uuid' in kw or 'node_uuid' in kw: + raise Exception('Invalid property provided') + return type('volume_connector', (object,), - {'uuid': _id, - 'id': _id, - 'node_uuid': _node_id, - 'node_id': _node_id, + {'id': kw.get('id', 'hhhhhhhh-qqqq-uuuu-mmmm-bbbbbbbbbbbb'), + 'node_id': kw.get('node_id', get_test_node().id), 'type': kw.get('type', 'iqn'), 'connector_id': kw.get('connector_id', 'iqn.test'), 'extra': kw.get('extra', {}), @@ -151,16 +137,13 @@ def get_test_volume_connector(**kw): def get_test_volume_target(**kw): - # TODO(dustinc): Once the usages of id/uuid, maintenance/is_maintenance, - # and portgroup/port_group are normalized, the duplicates can be removed - _id = kw.get('id') or kw.get('uuid', - 'aaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee') - _node_id = kw.get('node_id') or kw.get('node_uuid', get_test_node().id) + # NOTE(stephenfin): Prevent invalid properties making their way through + if 'uuid' in kw or 'node_uuid' in kw: + raise Exception('Invalid property provided') + return type('volume_target', (object,), - {'uuid': _id, - 'id': _id, - 'node_uuid': _node_id, - 'node_id': _node_id, + {'id': kw.get('id', 'aaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'), + 'node_id': kw.get('node_id', get_test_node().id), 'volume_type': kw.get('volume_type', 'iscsi'), 'properties': kw.get('properties', {}), 'boot_index': kw.get('boot_index', 0), diff --git a/nova/virt/ironic/driver.py b/nova/virt/ironic/driver.py index 78eb4fd77d..4f55f6cacd 100644 --- a/nova/virt/ironic/driver.py +++ b/nova/virt/ironic/driver.py @@ -119,7 +119,7 @@ def _log_ironic_polling(what, node, instance): 'provision_state=%(prov_state)s, ' 'target_provision_state=%(tgt_prov_state)s', dict(what=what, - node=node.uuid, + node=node.id, power_state=power_state, tgt_power_state=tgt_power_state, prov_state=prov_state, @@ -205,12 +205,7 @@ class IronicDriver(virt_driver.ComputeDriver): Some methods pass in variables named nodename, but are actually UUID's. """ - node = self.ironic_connection.get_node(node_id, fields=_NODE_FIELDS) - # TODO(dustinc): Make consumers use the right fields and remove this - node.uuid = node.id - node.instance_uuid = node.instance_id - node.maintenance = node.is_maintenance - return node + return self.ironic_connection.get_node(node_id, fields=_NODE_FIELDS) def _validate_instance_and_node(self, instance): """Get the node associated with the instance. @@ -229,13 +224,6 @@ class IronicDriver(virt_driver.ComputeDriver): 'that can only return zero or one: %s') % nodes) node = nodes[0] - # TODO(dustinc): Make consumers use the right fields and remove - if hasattr(node, "id"): - node.uuid = node.id - if hasattr(node, "instance_id"): - node.instance_uuid = node.instance_id - if hasattr(node, "is_maintenance"): - node.maintenance = node.is_maintenance return node def _node_resources_unavailable(self, node_obj): @@ -252,7 +240,7 @@ class IronicDriver(virt_driver.ComputeDriver): # keep NOSTATE around for compatibility good_provision_states = [ ironic_states.AVAILABLE, ironic_states.NOSTATE] - return (node_obj.maintenance or + return (node_obj.is_maintenance or node_obj.power_state in bad_power_states or node_obj.provision_state not in good_provision_states) @@ -270,7 +258,7 @@ class IronicDriver(virt_driver.ComputeDriver): consuming resources and try to correct us. So only nodes with an instance attached should report as consumed here. """ - return node_obj.instance_uuid is not None + return node_obj.instance_id is not None def _parse_node_properties(self, node): """Helper method to parse the node's properties.""" @@ -282,7 +270,7 @@ class IronicDriver(virt_driver.ComputeDriver): except (TypeError, ValueError): LOG.warning('Node %(uuid)s has a malformed "%(prop)s". ' 'It should be an integer.', - {'uuid': node.uuid, 'prop': prop}) + {'uuid': node.id, 'prop': prop}) properties[prop] = 0 raw_cpu_arch = node.properties.get('cpu_arch', None) @@ -291,7 +279,7 @@ class IronicDriver(virt_driver.ComputeDriver): except exception.InvalidArchitectureName: cpu_arch = None if not cpu_arch: - LOG.warning("cpu_arch not defined for node '%s'", node.uuid) + LOG.warning("cpu_arch not defined for node '%s'", node.id) properties['cpu_arch'] = cpu_arch properties['raw_cpu_arch'] = raw_cpu_arch @@ -339,8 +327,8 @@ class IronicDriver(virt_driver.ComputeDriver): local_gb = local_gb_used = 0 dic = { - 'uuid': str(node.uuid), - 'hypervisor_hostname': str(node.uuid), + 'uuid': str(node.id), + 'hypervisor_hostname': str(node.id), 'hypervisor_type': self._get_hypervisor_type(), 'hypervisor_version': self._get_hypervisor_version(), 'resource_class': node.resource_class, @@ -378,23 +366,25 @@ class IronicDriver(virt_driver.ComputeDriver): def prepare_for_spawn(self, instance): LOG.debug('Preparing to spawn instance %s.', instance.uuid) - node_uuid = instance.get('node') - if not node_uuid: + node_id = instance.get('node') + if not node_id: msg = _( "Ironic node uuid not supplied to " "driver for instance %s." - ) % instance.uuid + ) % instance.id raise exception.NovaException(msg) - node = self._get_node(node_uuid) + node = self._get_node(node_id) # Its possible this node has just moved from deleting # to cleaning. Placement will update the inventory # as all reserved, but this instance might have got here # before that happened, but after the previous allocation # got deleted. We trigger a re-schedule to another node. - if (self._node_resources_used(node) or - self._node_resources_unavailable(node)): - msg = "Chosen ironic node %s is not available" % node_uuid + if ( + self._node_resources_used(node) or + self._node_resources_unavailable(node) + ): + msg = "Chosen ironic node %s is not available" % node_id LOG.info(msg, instance=instance) raise exception.ComputeResourcesUnavailable(reason=msg) @@ -530,7 +520,7 @@ class IronicDriver(virt_driver.ComputeDriver): if node.provision_state == ironic_states.ACTIVE: # job is done LOG.debug("Ironic node %(node)s is now ACTIVE", - dict(node=node.uuid), instance=instance) + dict(node=node.id), instance=instance) raise loopingcall.LoopingCallDone() if node.target_provision_state in (ironic_states.DELETED, @@ -600,6 +590,20 @@ class IronicDriver(virt_driver.ComputeDriver): :returns: a list or generator of raw nodes from ironic :raises: VirtDriverNotReady """ + # NOTE(stephenfin): The SDK renames some node properties but it doesn't + # do this for 'fields'. The Ironic API expects the original names so we + # must rename them manually here. + if 'fields' in kwargs: + fields = [] + for field in kwargs['fields']: + if field == 'id': + fields.append('uuid') + elif field == 'instance_id': + fields.append('instance_uuid') + else: + fields.append(field) + kwargs['fields'] = tuple(fields) + try: # NOTE(dustinc): The generator returned by the SDK can only be # interated once. Since there are cases where it needs to be @@ -619,20 +623,7 @@ class IronicDriver(virt_driver.ComputeDriver): if return_generator: return node_generator else: - node_list = [] - # TODO(dustinc): Update all usages to use SDK attributes then stop - # copying values to PythonClient attributes. - for node in node_generator: - # NOTE(dustinc): There are usages that filter out these fields - # which forces us to check for the attributes. - if hasattr(node, "id"): - node.uuid = node.id - if hasattr(node, "instance_id"): - node.instance_uuid = node.instance_id - if hasattr(node, "is_maintenance"): - node.maintenance = node.is_maintenance - node_list.append(node) - return node_list + return list(node_generator) def list_instances(self): """Return the names of all the instances provisioned. @@ -641,13 +632,15 @@ class IronicDriver(virt_driver.ComputeDriver): :raises: VirtDriverNotReady """ - # NOTE(dustinc): The SDK returns an object with instance_id, - # but the Ironic API expects instance_uuid in query. context = nova_context.get_admin_context() - return [objects.Instance.get_by_uuid(context, i.instance_id).name - for i in self._get_node_list(return_generator=True, - associated=True, - fields=['instance_uuid'])] + return [ + objects.Instance.get_by_uuid(context, i.instance_id).name + for i in self._get_node_list( + return_generator=True, + associated=True, + fields=('instance_id',), + ) + ] def list_instance_uuids(self): """Return the IDs of all the instances provisioned. @@ -656,10 +649,13 @@ class IronicDriver(virt_driver.ComputeDriver): :raises: VirtDriverNotReady """ - # NOTE(dustinc): The SDK returns an object with instance_id, - # but the Ironic API expects instance_uuid in query. - return [node.instance_id for node in self._get_node_list( - return_generator=True, associated=True, fields=['instance_uuid'])] + return [ + node.instance_id for node in self._get_node_list( + return_generator=True, + associated=True, + fields=('instance_id',), + ) + ] def node_is_available(self, nodename): """Confirms a Nova hypervisor node exists in the Ironic inventory. @@ -789,19 +785,19 @@ class IronicDriver(virt_driver.ComputeDriver): for node in nodes: # NOTE(jroll): we always manage the nodes for instances we manage - if node.instance_uuid in instances: - node_cache[node.uuid] = node + if node.instance_id in instances: + node_cache[node.id] = node # NOTE(jroll): check if the node matches us in the hash ring, and - # does not have an instance_uuid (which would imply the node has + # does not have an instance_id (which would imply the node has # an instance managed by another compute service). # Note that this means nodes with an instance that was deleted in # nova while the service was down, and not yet reaped, will not be # reported until the periodic task cleans it up. - elif (node.instance_uuid is None and + elif (node.instance_id is None and CONF.host.lower() in - self.hash_ring.get_nodes(node.uuid.encode('utf-8'))): - node_cache[node.uuid] = node + self.hash_ring.get_nodes(node.id.encode('utf-8'))): + node_cache[node.id] = node self.node_cache = node_cache self.node_cache_time = time.time() @@ -833,11 +829,11 @@ class IronicDriver(virt_driver.ComputeDriver): # unfortunately. self._refresh_cache() - node_uuids = list(self.node_cache.keys()) + node_ids = list(self.node_cache.keys()) LOG.debug("Returning %(num_nodes)s available node(s)", - dict(num_nodes=len(node_uuids))) + dict(num_nodes=len(node_ids))) - return node_uuids + return node_ids def get_nodenames_by_uuid(self, refresh=False): nodes = self.get_available_nodes(refresh=refresh) @@ -960,24 +956,24 @@ class IronicDriver(virt_driver.ComputeDriver): node = self._node_from_cache(nodename) return self._node_resource(node) - def _node_from_cache(self, node_uuid): + def _node_from_cache(self, node_id): """Returns a node from the cache, retrieving the node from Ironic API if the node doesn't yet exist in the cache. """ # NOTE(vdrok): node_cache might also be modified during instance # _unprovision call, hence this function is synchronized - @utils.synchronized('ironic-node-%s' % node_uuid) + @utils.synchronized('ironic-node-%s' % node_id) def _sync_node_from_cache(): cache_age = time.time() - self.node_cache_time - if node_uuid in self.node_cache: + if node_id in self.node_cache: LOG.debug("Using cache for node %(node)s, age: %(age)s", - {'node': node_uuid, 'age': cache_age}) - return self.node_cache[node_uuid] + {'node': node_id, 'age': cache_age}) + return self.node_cache[node_id] else: LOG.debug("Node %(node)s not found in cache, age: %(age)s", - {'node': node_uuid, 'age': cache_age}) - node = self._get_node(node_uuid) - self.node_cache[node_uuid] = node + {'node': node_id, 'age': cache_age}) + node = self._get_node(node_id) + self.node_cache[node_id] = node return node return _sync_node_from_cache() @@ -1012,7 +1008,7 @@ class IronicDriver(virt_driver.ComputeDriver): self._refresh_cache() for node in self.node_cache.values(): - if instance.uuid == node.instance_uuid: + if instance.uuid == node.instance_id: break else: # if we can't find the instance, fall back to ironic @@ -1145,14 +1141,14 @@ class IronicDriver(virt_driver.ComputeDriver): # The compute manager is meant to know the node uuid, so missing uuid # is a significant issue. It may mean we've been passed the wrong data. - node_uuid = instance.get('node') - if not node_uuid: + node_id = instance.get('node') + if not node_id: raise exception.NovaException( _("Ironic node uuid not supplied to " "driver for instance %s.") % instance.uuid ) - node = self._get_node(node_uuid) + node = self._get_node(node_id) flavor = instance.flavor self._add_instance_info_to_node(node, instance, image_meta, flavor, @@ -1164,7 +1160,7 @@ class IronicDriver(virt_driver.ComputeDriver): with excutils.save_and_reraise_exception(): LOG.error("Error preparing deploy for instance " "on baremetal node %(node)s.", - {'node': node_uuid}, + {'node': node_id}, instance=instance) self._cleanup_deploy(node, instance, network_info) @@ -1179,7 +1175,7 @@ class IronicDriver(virt_driver.ComputeDriver): # NOTE(stephenfin): we don't pass required since we have to do our own # validation validate_chk = self.ironic_connection.validate_node( - node_uuid, + node_id, required=None, ) if ( @@ -1193,7 +1189,7 @@ class IronicDriver(virt_driver.ComputeDriver): "Ironic node: %(id)s failed to validate. " "(deploy: %(deploy)s, power: %(power)s, " "storage: %(storage)s)") - % {'id': node.uuid, + % {'id': node.id, 'deploy': validate_chk['deploy'], 'power': validate_chk['power'], 'storage': validate_chk['storage']}) @@ -1217,12 +1213,12 @@ class IronicDriver(virt_driver.ComputeDriver): LOG.info("Config drive for instance %(instance)s on " "baremetal node %(node)s created.", - {'instance': instance['uuid'], 'node': node_uuid}) + {'instance': instance['uuid'], 'node': node_id}) # trigger the node deploy try: self.ironic_connection.set_node_provision_state( - node_uuid, + node_id, ironic_states.ACTIVE, config_drive=configdrive_value, ) @@ -1239,13 +1235,13 @@ class IronicDriver(virt_driver.ComputeDriver): try: timer.start(interval=CONF.ironic.api_retry_interval).wait() LOG.info('Successfully provisioned Ironic node %s', - node.uuid, instance=instance) + node.id, instance=instance) except Exception: with excutils.save_and_reraise_exception(): LOG.error("Error deploying instance %(instance)s on " "baremetal node %(node)s.", {'instance': instance.uuid, - 'node': node_uuid}) + 'node': node_id}) def _unprovision(self, instance, node): """This method is called from destroy() to unprovision @@ -1253,7 +1249,7 @@ class IronicDriver(virt_driver.ComputeDriver): """ try: self.ironic_connection.set_node_provision_state( - node.uuid, + node.id, 'deleted', ) except Exception as e: @@ -1281,7 +1277,7 @@ class IronicDriver(virt_driver.ComputeDriver): # can consider the instance unprovisioned. LOG.debug("Ironic node %(node)s is in state %(state)s, " "instance is now unprovisioned.", - dict(node=node.uuid, state=node.provision_state), + dict(node=node.id, state=node.provision_state), instance=instance) raise loopingcall.LoopingCallDone() @@ -1289,7 +1285,7 @@ class IronicDriver(virt_driver.ComputeDriver): msg = (_("Error destroying the instance on node %(node)s. " "Provision state still '%(state)s'.") % {'state': node.provision_state, - 'node': node.uuid}) + 'node': node.id}) LOG.error(msg) raise exception.NovaException(msg) else: @@ -1303,14 +1299,14 @@ class IronicDriver(virt_driver.ComputeDriver): # NOTE(vdrok): synchronize this function so that get_available_resource # has up-to-date view of node_cache. - @utils.synchronized('ironic-node-%s' % node.uuid) + @utils.synchronized('ironic-node-%s' % node.id) def _sync_remove_cache_entry(): # NOTE(vdrok): Force the cache update, so that # update_usages resource tracker call that will happen next # has the up-to-date node view. - self.node_cache.pop(node.uuid, None) - LOG.debug('Removed node %(uuid)s from node cache.', - {'uuid': node.uuid}) + self.node_cache.pop(node.id, None) + LOG.debug('Removed node %(id)s from node cache.', + {'id': node.id}) _sync_remove_cache_entry() def destroy(self, context, instance, network_info, @@ -1357,7 +1353,7 @@ class IronicDriver(virt_driver.ComputeDriver): remove_instance_info=False) LOG.info('Successfully unprovisioned Ironic node %s', - node.uuid, instance=instance) + node.id, instance=instance) def reboot(self, context, instance, network_info, reboot_type, block_device_info=None, bad_volumes_callback=None, @@ -1387,7 +1383,7 @@ class IronicDriver(virt_driver.ComputeDriver): if reboot_type == 'SOFT': try: self.ironic_connection.set_node_power_state( - node.uuid, + node.id, 'soft reboot', ) hard = False @@ -1398,14 +1394,14 @@ class IronicDriver(virt_driver.ComputeDriver): instance=instance) if hard: - self.ironic_connection.set_node_power_state(node.uuid, 'reboot') + self.ironic_connection.set_node_power_state(node.id, 'reboot') timer = loopingcall.FixedIntervalLoopingCall( self._wait_for_power_state, instance, 'reboot') timer.start(interval=CONF.ironic.api_retry_interval).wait() LOG.info('Successfully rebooted(type %(type)s) Ironic node %(node)s', {'type': ('HARD' if hard else 'SOFT'), - 'node': node.uuid}, + 'node': node.id}, instance=instance) def power_off(self, instance, timeout=0, retry_interval=0): @@ -1429,7 +1425,7 @@ class IronicDriver(virt_driver.ComputeDriver): # we don't pass 'wait=True' since we want a configurable # polling interval self.ironic_connection.set_node_power_state( - node.uuid, + node.id, 'soft power off', timeout=timeout, ) @@ -1440,7 +1436,7 @@ class IronicDriver(virt_driver.ComputeDriver): node = self._validate_instance_and_node(instance) if node.power_state == ironic_states.POWER_OFF: LOG.info('Successfully soft powered off Ironic node %s', - node.uuid, instance=instance) + node.id, instance=instance) return LOG.info("Failed to soft power off instance " "%(instance)s on baremetal node %(node)s " @@ -1449,7 +1445,7 @@ class IronicDriver(virt_driver.ComputeDriver): "Attempting hard power off.", {'instance': instance.uuid, 'timeout': timeout, - 'node': node.uuid, + 'node': node.id, 'reason': node.last_error}, instance=instance) except sdk_exc.SDKException as e: @@ -1458,16 +1454,16 @@ class IronicDriver(virt_driver.ComputeDriver): "due to error: %(reason)s. " "Attempting hard power off.", {'instance': instance.uuid, - 'node': node.uuid, + 'node': node.id, 'reason': e}, instance=instance) - self.ironic_connection.set_node_power_state(node.uuid, 'power off') + self.ironic_connection.set_node_power_state(node.id, 'power off') timer = loopingcall.FixedIntervalLoopingCall( self._wait_for_power_state, instance, 'power off') timer.start(interval=CONF.ironic.api_retry_interval).wait() LOG.info('Successfully hard powered off Ironic node %s', - node.uuid, instance=instance) + node.id, instance=instance) def power_on(self, context, instance, network_info, block_device_info=None, accel_info=None): @@ -1487,13 +1483,13 @@ class IronicDriver(virt_driver.ComputeDriver): """ LOG.debug('Power on called for instance', instance=instance) node = self._validate_instance_and_node(instance) - self.ironic_connection.set_node_power_state(node.uuid, 'power on') + self.ironic_connection.set_node_power_state(node.id, 'power on') timer = loopingcall.FixedIntervalLoopingCall( self._wait_for_power_state, instance, 'power on') timer.start(interval=CONF.ironic.api_retry_interval).wait() LOG.info('Successfully powered on Ironic node %s', - node.uuid, instance=instance) + node.id, instance=instance) def power_update_event(self, instance, target_power_state): """Update power, vm and task states of the specified instance in @@ -1528,17 +1524,17 @@ class IronicDriver(virt_driver.ComputeDriver): LOG.debug('Trigger crash dump called for instance', instance=instance) node = self._validate_instance_and_node(instance) - self.ironic_connection.inject_nmi_to_node(node.uuid) + self.ironic_connection.inject_nmi_to_node(node.id) LOG.info('Successfully triggered crash dump into Ironic node %s', - node.uuid, instance=instance) + node.id, instance=instance) def _plug_vif(self, node, port_id): last_attempt = 5 for attempt in range(0, last_attempt + 1): try: self.ironic_connection.attach_vif_to_node( - node.uuid, + node.id, port_id, retry_on_conflict=False, ) @@ -1546,7 +1542,7 @@ class IronicDriver(virt_driver.ComputeDriver): msg = (_("Cannot attach VIF %(vif)s to the node %(node)s " "due to error: %(err)s") % { 'vif': port_id, - 'node': node.uuid, 'err': e}) + 'node': node.id, 'err': e}) LOG.error(msg) raise exception.VirtualInterfacePlugException(msg) except sdk_exc.ConflictException: @@ -1581,10 +1577,10 @@ class IronicDriver(virt_driver.ComputeDriver): for vif in network_info: port_id = str(vif['id']) try: - self.ironic_connection.detach_vif_from_node(node.uuid, port_id) + self.ironic_connection.detach_vif_from_node(node.id, port_id) except sdk_exc.BadRequestException: LOG.debug("VIF %(vif)s isn't attached to Ironic node %(node)s", - {'vif': port_id, 'node': node.uuid}) + {'vif': port_id, 'node': node.id}) def plug_vifs(self, instance, network_info): """Plug VIFs into networks. @@ -1713,8 +1709,8 @@ class IronicDriver(virt_driver.ComputeDriver): instance.task_state = task_states.REBUILD_SPAWNING instance.save(expected_task_state=[task_states.REBUILDING]) - node_uuid = instance.node - node = self._get_node(node_uuid) + node_id = instance.node + node = self._get_node(node_id) self._add_instance_info_to_node(node, instance, image_meta, instance.flavor, preserve_ephemeral) @@ -1738,12 +1734,12 @@ class IronicDriver(virt_driver.ComputeDriver): LOG.info("Config drive for instance %(instance)s on " "baremetal node %(node)s created.", - {'instance': instance['uuid'], 'node': node_uuid}) + {'instance': instance['uuid'], 'node': node_id}) # Trigger the node rebuild/redeploy. try: self.ironic_connection.set_node_provision_state( - node_uuid, + node_id, ironic_states.REBUILD, config_drive=configdrive_value, ) @@ -1805,12 +1801,12 @@ class IronicDriver(virt_driver.ComputeDriver): for the instance """ node = self._validate_instance_and_node(instance) - node_uuid = node.uuid + node_id = node.id def _get_console(): """Request to acquire node console.""" try: - return self.ironic_connection.get_node_console(node_uuid) + return self.ironic_connection.get_node_console(node_id) except sdk_exc.SDKException as e: LOG.error('Failed to acquire console information for ' 'instance %(inst)s: %(reason)s', @@ -1831,7 +1827,7 @@ class IronicDriver(virt_driver.ComputeDriver): def _enable_console(mode): """Request to enable/disable node console.""" try: - self.ironic_connection.set_node_console_mode(node_uuid, mode) + self.ironic_connection.set_node_console_mode(node_id, mode) except sdk_exc.SDKException as e: LOG.error('Failed to set console mode to "%(mode)s" ' 'for instance %(inst)s: %(reason)s', @@ -1851,7 +1847,7 @@ class IronicDriver(virt_driver.ComputeDriver): LOG.error('Timeout while waiting for console mode to be ' 'set to "%(mode)s" on node %(node)s', {'mode': mode, - 'node': node_uuid}) + 'node': node_id}) raise exception.ConsoleNotAvailable() # Acquire the console @@ -1905,7 +1901,7 @@ class IronicDriver(virt_driver.ComputeDriver): LOG.warning('Console type "%(type)s" (of ironic node ' '%(node)s) does not support Nova serial console', {'type': console_info["type"], - 'node': node.uuid}, + 'node': node.id}, instance=instance) raise exception.ConsoleTypeUnavailable(console_type='serial') @@ -1921,7 +1917,7 @@ class IronicDriver(virt_driver.ComputeDriver): LOG.error('Invalid Socat console URL "%(url)s" ' '(ironic node %(node)s)', {'url': console_info["url"], - 'node': node.uuid}, + 'node': node.id}, instance=instance) raise exception.ConsoleTypeUnavailable(console_type='serial') @@ -1932,7 +1928,7 @@ class IronicDriver(virt_driver.ComputeDriver): LOG.warning('Socat serial console only supports "tcp". ' 'This URL is "%(url)s" (ironic node %(node)s).', {'url': console_info["url"], - 'node': node.uuid}, + 'node': node.id}, instance=instance) raise exception.ConsoleTypeUnavailable(console_type='serial') @@ -2015,7 +2011,7 @@ class IronicDriver(virt_driver.ComputeDriver): if ip: LOG.debug('Volume connector IP address for node %(node)s is ' '%(ip)s.', - {'node': node.uuid, 'ip': ip}, + {'node': node.id, 'ip': ip}, instance=instance) props['ip'] = props['host'] = ip if values.get('iqn'): @@ -2040,7 +2036,7 @@ class IronicDriver(virt_driver.ComputeDriver): def _get_volume_connector_ip(self, instance, node, values): if values.get('ip'): LOG.debug('Node %s has an IP address for volume connector', - node.uuid, instance=instance) + node.id, instance=instance) return values['ip'][0] vif_id = self._get_vif_from_macs(node, values.get('mac', []), instance) @@ -2081,7 +2077,7 @@ class IronicDriver(virt_driver.ComputeDriver): { 'vif': vif_id, 'mac': mac, - 'node': node.uuid, + 'node': node.id, }, instance=instance, ) @@ -2089,7 +2085,7 @@ class IronicDriver(virt_driver.ComputeDriver): for mac in macs: port_groups = self.ironic_connection.port_groups( - node=node.uuid, + node=node.id, address=mac, details=True, ) @@ -2098,7 +2094,7 @@ class IronicDriver(virt_driver.ComputeDriver): return vif_id ports = self.ironic_connection.ports( - node=node.uuid, + node=node.id, address=mac, details=True, ) @@ -2136,7 +2132,7 @@ class IronicDriver(virt_driver.ComputeDriver): """ LOG.debug('Rescue called for instance', instance=instance) - node_uuid = instance.node + node_id = instance.node def _wait_for_rescue(): try: @@ -2153,7 +2149,7 @@ class IronicDriver(virt_driver.ComputeDriver): try: self.ironic_connection.set_node_provision_state( - node_uuid, + node_id, ironic_states.RESCUE, rescue_password=rescue_password, ) @@ -2163,7 +2159,7 @@ class IronicDriver(virt_driver.ComputeDriver): timer = loopingcall.FixedIntervalLoopingCall(_wait_for_rescue) timer.start(interval=CONF.ironic.api_retry_interval).wait() LOG.info('Successfully rescued Ironic node %(node)s', - {'node': node_uuid}, instance=instance) + {'node': node_id}, instance=instance) def unrescue( self, @@ -2177,7 +2173,7 @@ class IronicDriver(virt_driver.ComputeDriver): """ LOG.debug('Unrescue called for instance', instance=instance) - node_uuid = instance.node + node_id = instance.node def _wait_for_unrescue(): try: @@ -2194,7 +2190,7 @@ class IronicDriver(virt_driver.ComputeDriver): try: self.ironic_connection.set_node_provision_state( - node_uuid, + node_id, ironic_states.UNRESCUE, ) except Exception as e: @@ -2203,7 +2199,7 @@ class IronicDriver(virt_driver.ComputeDriver): timer = loopingcall.FixedIntervalLoopingCall(_wait_for_unrescue) timer.start(interval=CONF.ironic.api_retry_interval).wait() LOG.info('Successfully unrescued Ironic node %(node)s', - {'node': node_uuid}, instance=instance) + {'node': node_id}, instance=instance) def manages_network_binding_host_id(self): """IronicDriver manages port bindings for baremetal instances.