Record Virt Test version on test logs

This is a drop in replacement of pull request #288 by @zhouqt. This version is more thorough, and also implements caching, to avoid running git subprocesses too frequently.