def revert(self, result, flow_failures, **kwargs): # Only reverts failed rebuilds, because the revert # for a failed build is handled in the manager. if self.instance.task_state == task_states.REBUILD_SPAWNING: LOG.info( 'Rebuild of instance failed. Deleting instance from ' 'destination.', instance=self.instance) vm.delete_lpar(self.adapter, self.instance)
def execute(self): vm.delete_lpar(self.adapter, self.instance)
def test_dlt_lpar(self, mock_vterm, mock_pvm_uuid): """Performs a delete LPAR test.""" mock_pvm_uuid.return_value = 'pvm_uuid' vm.delete_lpar(self.apt, 'inst') mock_pvm_uuid.assert_called_once_with('inst') mock_vterm.assert_called_once_with(self.apt, 'pvm_uuid') self.apt.delete.assert_called_once_with('LogicalPartition', root_id='pvm_uuid') # Test Failure Path # build a mock response body with the expected HSCL msg resp = mock.Mock(body='error msg: HSCL151B more text') self.apt.delete.side_effect = pvm_exc.Error('Mock Error Message', response=resp) # Reset counters mock_pvm_uuid.reset_mock() self.apt.reset_mock() mock_vterm.reset_mock() self.assertRaises(pvm_exc.Error, vm.delete_lpar, self.apt, 'inst') mock_pvm_uuid.assert_called_once_with('inst') mock_vterm.assert_called_once_with(self.apt, 'pvm_uuid') self.apt.delete.assert_called_once_with('LogicalPartition', root_id='pvm_uuid') # Test HttpNotFound - exception not raised mock_pvm_uuid.reset_mock() self.apt.reset_mock() mock_vterm.reset_mock() resp.status = 404 self.apt.delete.side_effect = pvm_exc.HttpNotFound(resp=resp) vm.delete_lpar(self.apt, 'inst') mock_pvm_uuid.assert_called_once_with('inst') mock_vterm.assert_called_once_with(self.apt, 'pvm_uuid') self.apt.delete.assert_called_once_with('LogicalPartition', root_id='pvm_uuid') # Test Other HttpError mock_pvm_uuid.reset_mock() self.apt.reset_mock() mock_vterm.reset_mock() resp.status = 111 self.apt.delete.side_effect = pvm_exc.HttpError(resp=resp) self.assertRaises(pvm_exc.HttpError, vm.delete_lpar, self.apt, 'inst') mock_pvm_uuid.assert_called_once_with('inst') mock_vterm.assert_called_once_with(self.apt, 'pvm_uuid') self.apt.delete.assert_called_once_with('LogicalPartition', root_id='pvm_uuid') # Test HttpNotFound closing vterm mock_pvm_uuid.reset_mock() self.apt.reset_mock() mock_vterm.reset_mock() resp.status = 404 mock_vterm.side_effect = pvm_exc.HttpNotFound(resp=resp) vm.delete_lpar(self.apt, 'inst') mock_pvm_uuid.assert_called_once_with('inst') mock_vterm.assert_called_once_with(self.apt, 'pvm_uuid') self.apt.delete.assert_not_called() # Test Other HttpError closing vterm mock_pvm_uuid.reset_mock() self.apt.reset_mock() mock_vterm.reset_mock() resp.status = 111 mock_vterm.side_effect = pvm_exc.HttpError(resp=resp) self.assertRaises(pvm_exc.HttpError, vm.delete_lpar, self.apt, 'inst') mock_pvm_uuid.assert_called_once_with('inst') mock_vterm.assert_called_once_with(self.apt, 'pvm_uuid') self.apt.delete.assert_not_called()