py33: safe_encode() returns bytes in Python 3

Python 2:
str.encode = encode(...)
    S.encode([encoding[,errors]]) -> object

Python 3:
str.encode = encode(...)
    S.encode(encoding='utf-8', errors='strict') -> bytes

In Python 3, strings are always Unicode.  safe_encode() returns
"bytes", the "\n" will be printed literally, it is not expected.

bytes.decode() will transform bytes to str, which will be printed
properly.

Close-bug: #1229150
Change-Id: If926d3f7837673b4608ae667d34cea3c78e82e5d
py33: don't encode security_group

In Python 3, str and bytes can not be mixed. str.encode() will
return bytes in py33, which will induce the mismatch.

Bypass the s.name.encode() in py33.

Change-Id: Iee8d69aab9df4af126e94e4363f79e32fdd70fcd
Close-bug: #1231868
py33: align the order of parameters for urlencode()

In Python 3.3, hash randomization is enabled by default. It causes the
iteration order of dicts and sets to be unpredictable and differ across
Python runs.

In the test case, the fixed expecting string will not match the test
result, it is relying on the dict order.

This change transforms the input dict to a sequence of two-element list,
with fixed order, and update the related expecitng string in test case.

Close-Bug #1234438

Change-Id: Ic7846279a9f508a856cd4ee70408d537088792f2
py33: unify the input of request to json format

In novaclient.client.HTTPClient.request, json.dumps() process the
body of "POST":
kwargs['data'] = json.dumps(kwargs['body'])

So, in test case, we should pass the same forat for mock.call().

Also, transform the "data" variable to json format.

Close-Bug #1234067

Change-Id: I3a0abaa8064b4360cb94b7b205454e26bddef8e4
py33: sort hosts while treeize AvailabilityZone

In Python 3.3, hash randomization is enabled by default. It causes the
iteration order of dicts and sets to be unpredictable and differ across
Python runs.

sort the hosts while treeize AvailabiltyZone.

Test cmd
--------
for i in {1..100}; do echo $i; \
tox -e py33 |grep test_detail_availability_zone; done

Change-Id: I9ab25ef52d6d19b45a39f04cbcde864ee225b4cc
Close-Bug: #1235067
py33: sort the files parameters of "--files"

In Python 3.3, hash randomization is enabled by default. It causes the
iteration order of dicts and sets to be unpredictable and differ across
Python runs.

Sort the files parameters when multiple files are designated.

Close-Bug #1235096

Change-Id: I0db645b3fb92408bd8c6780bfabe7ce8265a65a8
Merge "py33: safe_encode() returns bytes in Python 3"
Merge "py33: align the order of parameters for urlencode()"
Merge "py33: unify the input of request to json format"
Merge "py33: sort hosts while treeize AvailabilityZone"
py33: use six.StringIO() to mock stdout/stderr

six.StringIO() is the right way to keep Python2/3 compatibiliby
while mocking stdout/stderr.

Close-Bug #1235086

Change-Id: I33d9223b2202896331d24339056d57d4ca9acdc5
Merge "py33: don't encode security_group"
Merge "py33: use six.StringIO() to mock stdout/stderr"