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
Avoid unnecessary stderr message when run test

Currently, if we run `tox -epy27`, we will get an useless stderr
message 'HTTPUnauthorized (HTTP 401)', which is triggered on purpose
by a test. It should be mocked because it provides no such useful message.

Change-Id: I009310257741a34fe966d6d745de3c6cf58e0feb
Closes-Bug: #1323480
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 "Avoid unnecessary stderr message when run test"
Merge "use mock instead of try...finally"
Merge "replace dict.iteritems() with six.iteritems(dict)"