replace dict.iteritems() with six.iteritems(dict)

According to https://wiki.openstack.org/wiki/Python3 dict.iteritems()
should be replaced with six.iteritems(dict).

Change-Id: I52cc0e89c030d7b6bfc735239638b513410933c5
use mock instead of try...finally

There are some test code use try...finally block to catch or ignore
the stdout message. The job can be done by mock too, and it is cleaner.

Change-Id: I0c29382e7bcd0b7f399565b26f27315f7e17a8fc
Merge "use mock instead of try...finally"
Merge "replace dict.iteritems() with six.iteritems(dict)"