def _do_update_node(self, node_id, values): with _session_for_write(): query = model_query(models.Node) query = add_identity_filter(query, node_id) try: ref = query.with_lockmode('update').one() except NoResultFound: raise exception.NodeNotFound(node=node_id) # Prevent instance_uuid overwriting if values.get("instance_uuid") and ref.instance_uuid: raise exception.NodeAssociated(node=ref.uuid, instance=ref.instance_uuid) if 'provision_state' in values: values['provision_updated_at'] = timeutils.utcnow() if values['provision_state'] == states.INSPECTING: values['inspection_started_at'] = timeutils.utcnow() values['inspection_finished_at'] = None elif (ref.provision_state == states.INSPECTING and values['provision_state'] == states.MANAGEABLE): values['inspection_finished_at'] = timeutils.utcnow() values['inspection_started_at'] = None elif (ref.provision_state == states.INSPECTING and values['provision_state'] == states.INSPECTFAIL): values['inspection_started_at'] = None ref.update(values) return ref
def destroy_node(self, context, node_id): """Delete a node. :param context: request context. :param node_id: node id or uuid. :raises: NodeLocked if node is locked by another conductor. :raises: NodeAssociated if the node contains an instance associated with it. :raises: NodeInWrongPowerState if the node is not powered off. """ with task_manager.acquire(context, node_id) as task: node = task.node if node.instance_uuid is not None: raise exception.NodeAssociated(node=node.uuid, instance=node.instance_uuid) if node.power_state not in [states.POWER_OFF, states.NOSTATE]: msg = (_("Node %s can't be deleted because it's not " "powered off") % node.uuid) raise exception.NodeInWrongPowerState(msg) # FIXME(comstud): Remove context argument after we ensure # every instantiation of Node includes the context node.destroy(context) LOG.info(_LI('Successfully deleted node %(node)s.'), {'node': node.uuid})
def test_delete_associated(self, mock_dn): ndict = dbutils.get_test_node( instance_uuid='aaaaaaaa-1111-bbbb-2222-cccccccccccc') node = self.dbapi.create_node(ndict) mock_dn.side_effect = exception.NodeAssociated(node=node.uuid, instance=node.instance_uuid) response = self.delete('/nodes/%s' % ndict['uuid'], expect_errors=True) self.assertEqual(409, response.status_int) mock_dn.assert_called_once_with(mock.ANY, node.uuid, 'test-topic')
def destroy_node(self, context, node_id): """Delete a node. :param context: request context. :param node_id: node id or uuid. :raises: NodeLocked if node is locked by another conductor. :raises: NodeAssociated if the node contains an instance associated with it. """ with task_manager.acquire(context, node_id) as task: node = task.node if node.instance_uuid is not None: raise exception.NodeAssociated(node=node.uuid, instance=node.instance_uuid) self.dbapi.destroy_node(node_id)
def _do_update_node(self, node_id, values): session = get_session() with session.begin(): query = model_query(models.Node, session=session) query = add_identity_filter(query, node_id) try: ref = query.with_lockmode('update').one() except NoResultFound: raise exception.NodeNotFound(node=node_id) # Prevent instance_uuid overwriting if values.get("instance_uuid") and ref.instance_uuid: raise exception.NodeAssociated(node=node_id, instance=ref.instance_uuid) if 'provision_state' in values: values['provision_updated_at'] = timeutils.utcnow() ref.update(values) return ref
def destroy_node(self, context, node_id): """Delete a node. :param context: request context. :param node_id: node id or uuid. :raises: NodeLocked if node is locked by another conductor. :raises: NodeAssociated if the node contains an instance associated with it. :raises: NodeInWrongPowerState if the node is not powered off. """ with task_manager.acquire(context, node_id) as task: node = task.node if node.instance_uuid is not None: raise exception.NodeAssociated(node=node.uuid, instance=node.instance_uuid) if node.power_state not in [states.POWER_OFF, states.NOSTATE]: msg = (_("Node %s can't be deleted because it's not " "powered off") % node.uuid) raise exception.NodeInWrongPowerState(msg) self.dbapi.destroy_node(node_id)