AMBARI-8687. Fix ignored unit tests for AMBARI-8661 and few production code fixes/improvements (Dmitri Lisnichenko via ncole)