def test_quota_reservation_task_with_update_flag(self, need_update, mock_get_vol_by_id, mock_type_get, mock_quota_reserve): volume_size = 1 fake_size = '2' fake_snap = fake_snapshot.fake_snapshot_obj(self.ctxt, volume_size=volume_size) fake_snap.save = mock.MagicMock() fake_vol = fake_volume.fake_volume_obj( self.ctxt, id=fake.VOLUME_ID, volume_type_id=fake.VOLUME_TYPE_ID) mock_get_vol_by_id.return_value = fake_vol mock_type_get.return_value = {'name': 'fake_type_name'} task = manager.QuotaReserveTask() task.execute(self.ctxt, fake_size, fake_snap, {'update_size': need_update}) reserve_opts = {'gigabytes': 1, 'gigabytes_fake_type_name': 1} if not need_update: reserve_opts.update({ 'snapshots': 1, 'snapshots_fake_type_name': 1 }) mock_quota_reserve.assert_called_once_with(self.ctxt, **reserve_opts)
def test_quota_reservation_revert_task(self, mock_quota_rollback): """Test checks that we can rollback the snapshot.""" mock_result = mock.MagicMock() optional_args = {} optional_args['is_quota_committed'] = False task = manager.QuotaReserveTask() task.revert(self.ctxt, mock_result, optional_args) mock_quota_rollback.assert_called_once_with( self.ctxt, mock_result['reservations'])
def test_quota_reservation_revert_already_been_committed( self, mock_quota_revert): """Test reservations can not be rolled back.""" mock_result = mock.MagicMock() optional_args = {} optional_args['is_quota_committed'] = True task = manager.QuotaReserveTask() task.revert(self.ctxt, mock_result, optional_args) mock_quota_revert.assert_called_once_with(self.ctxt, mock_result, optional_args)