I’m not a lawyer, but since Petraeus no longer has any official position in the U.S. government I don’t think anyone can do anything to keep him from testifying.
It’s more like he’s in the Cosa Nostra. Once you’re in at that level, you can never get out. You might get moved aside, but trying to get out, makes you a target. He won’t lose his pension, because nobody in power would want him to work elsewhere using his resources or skill sets.