'Validates PowerVM destroy.'

@mock.patch('nova.virt.powervm.vm.delete_lpar')
def test_destroy(self, mock_dlt_lpar):

    self.drv.disk_dvr = mock.create_autospec(ssp.SSPDiskAdapter, instance=True)
    self.drv.destroy('context', self.inst, [], block_device_info={})
    self.pwroff.assert_called_once_with(self.adp, self.inst, force_immediate=True)
    self.drv.disk_dvr.detach_disk.assert_called_once_with(self.inst)
    self.drv.disk_dvr.delete_disks.assert_called_once_with(self.drv.disk_dvr.detach_disk.return_value)
    mock_dlt_lpar.assert_called_once_with(self.adp, self.inst)
    self.pwroff.reset_mock()
    self.drv.disk_dvr.detach_disk.reset_mock()
    self.drv.disk_dvr.delete_disks.reset_mock()
    mock_dlt_lpar.reset_mock()
    self.pwroff.side_effect = exception.InstanceNotFound(instance_id='something')
    self.drv.destroy('context', self.inst, [], block_device_info={}, destroy_disks=False)
    self.pwroff.assert_called_once_with(self.adp, self.inst, force_immediate=False)
    self.drv.disk_dvr.detach_disk.assert_not_called()
    self.drv.disk_dvr.delete_disks.assert_not_called()
    mock_dlt_lpar.assert_not_called()
    self.pwroff.reset_mock()
    self.pwroff.side_effect = None
    mock_dlt_lpar.side_effect = pvm_exc.TimeoutError('Timed    out')
    self.assertRaises(exception.InstanceTerminationFailure, self.drv.destroy, 'context', self.inst, [], block_device_info={})
    self.pwroff.assert_called_once_with(self.adp, self.inst, force_immediate=True)
    self.drv.disk_dvr.detach_disk.assert_called_once_with(self.inst)
    self.drv.disk_dvr.delete_disks.assert_called_once_with(self.drv.disk_dvr.detach_disk.return_value)
    mock_dlt_lpar.assert_called_once_with(self.adp, self.inst)
    mock_dlt_lpar.side_effect = ValueError()
    self.assertRaises(ValueError, self.drv.destroy, 'context', self.inst, [], block_device_info={})
