The exit_function is only for testing exit and quit command in virsh interactive mode, it's specified. 

If we direct use command('exit'), as I explained, test will fail as shell session closed unexpected, but functionally it's expected. So We need to bypass command() and use another way to solve this.

The exit_session in ShellSession can accept exit and quit command and close session without fail the case, the close_session in virsh.py just decrease session id which kill the process use close() in ShellSession, exit and quit command not executed in virsh, which will lead us miss the test coverage. 

(Note: close function is in ShellSession, so for close an open virsh shell session, it all goes back to ShellSession, that's why exit_session also in ShellSession)

I'll update the code use VirshPersistent in last comment, for exit_session pls offer more suggestion, thx.