Fix dict.keys() PY3 compatible

The dict.keys()[0] will raise a TypeError in PY3,
as dict.keys() doesn't return a list any more in PY3
but a view of list.

Change-Id: I99514d57cb21bf65a59eb36b556248b9494246c7
Closes-Bug: #1583419
This commit is contained in:
qinchunhua 2016-07-05 02:01:20 -04:00
parent 44b2182597
commit df7c0dad5b
2 changed files with 2 additions and 2 deletions

2
tacker/tests/unit/vm/test_monitor.py Normal file → Executable file
View File

@ -85,7 +85,7 @@ class TestVNFMonitor(testtools.TestCase):
test_boot_wait = 30
test_vnfmonitor = VNFMonitor(test_boot_wait)
test_vnfmonitor.add_hosting_vnf(test_device_dict)
test_device_id = test_vnfmonitor._hosting_vnfs.keys()[0]
test_device_id = list(test_vnfmonitor._hosting_vnfs.keys())[0]
self.assertEqual(test_device_id, MOCK_DEVICE_ID)
@mock.patch('tacker.vm.monitor.VNFMonitor.__run__')

2
tacker/wsgi.py Normal file → Executable file
View File

@ -438,7 +438,7 @@ class XMLDictSerializer(DictSerializer):
links = data.pop(link_keys[0], None)
has_atom = True
root_key = (len(data) == 1 and
data.keys()[0] or constants.VIRTUAL_ROOT_KEY)
list(data.keys())[0] or constants.VIRTUAL_ROOT_KEY)
root_value = data.get(root_key, data)
doc = etree.Element("_temp_root")
used_prefixes = []