Add more checks and database cleanup in yum

Change-Id: I5ecb28ba6bd3e18070718de1031e83d994449b48
Closes-Bug: #1323999
(cherry picked from commit 1bb717b4555defc6a3e2412ac2911373c7f6e92a)