KeyError cause the command "module list --all" failed,
fix it, and do refactor to filter private modules and
reduce the loop times, add related unit tests and
functional tests.
Change-Id: Icd77739502e05b5f763a04a92547497bf82d5d63
Closes-Bug: #1661814