Fixes bug 904971
Scheduler error handler was looking for instance_id when it may or may
not exist. Added the proper code for it to determine whether the
instance was actually created in the DB or not and how to find its ID.
Note: there's some pretty nasty stuff in here, but unavoidable without
larger changes. I'd like to hold off on these larger changes, because
the problem should be solved with some of the scalability work coming.
Tests included.
Change-Id: Ief5fde8128437c9dc257af9c4d0c2950d0962ce5