py3: Fix iterator index operator usage

In Python3 accessing dict.values(), dict.items() and dict.keys()
return an iterator instead of list. Iterators do not support the
index operator.

Wrap dict iterator in list().

Story: 2006796
Task: 42800
Signed-off-by: Dan Voiculeasa <dan.voiculeasa@windriver.com>
Change-Id: Ia6b672da5635c0ba16cf094662bb7dd1ca7e178a
(cherry picked from commit 67ca539acc)
This commit is contained in:
Dan Voiculeasa 2021-07-08 19:24:23 +03:00 committed by Chuck Short
parent 75081afa1f
commit 4925f27aa5
3 changed files with 4 additions and 4 deletions

View File

@ -270,7 +270,7 @@ class HostStatesController(rest.RestController):
specified_cpulist))
for specified_socket in specified_sockets:
socket, value = specified_socket.items()[0]
socket, value = list(specified_socket.items())[0]
if int(socket) >= num_nodes:
raise wsme.exc.ClientSideError(
_('There is no Processor (Socket) '
@ -309,7 +309,7 @@ class HostStatesController(rest.RestController):
for numa_node in cpu_counts:
cpu_counts[numa_node][function] = 0
for numa in sockets:
numa_node, value = numa.items()[0]
numa_node, value = list(numa.items())[0]
numa_node = int(numa_node)
value = int(value)
if ihost.hyperthreading:

View File

@ -12758,7 +12758,7 @@ class ConductorManager(service.PeriodicService):
# the evaluation
for filter_ in trigger_filters:
# Each filter is a single entry dict
k = filter_.keys()[0]
k = list(filter_.keys())[0]
if k not in target_for_filters:
LOG.info("Evaluate reapply for {} rejected: "
"trigger field {} absent".format(app.name, k))

View File

@ -96,7 +96,7 @@ class Database(fixtures.Fixture):
"'reserve2', 'edgeworker'))"
results = self.engine.execute("SELECT sql FROM sqlite_master \
WHERE type='table' AND name='i_host'")
create_i_host = results.first().values()[0]
create_i_host = list(results.first().values())[0]
create_i_host = create_i_host.replace(personality_check_old,
personality_check_new)
self.engine.execute("ALTER TABLE i_host RENAME TO i_host_bak")