aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries
diff options
context:
space:
mode:
authorVratko Polak <vrpolak@cisco.com>2020-03-11 12:46:44 +0100
committerVratko Polak <vrpolak@cisco.com>2020-03-17 16:00:11 +0000
commit2ef3f094650a61f4f4bd50cb7b44145c1050f0ba (patch)
tree8c2e137e968075560e873628d098264dfbe04332 /resources/libraries
parent62f25d4d865c01ebcd18179b0abb98c54304f741 (diff)
NodePath: Make path computation deterministic
In Python3, set operations seem to result in indeterministic order. + Remove verbose logging from topology.py Change-Id: I47cc90637a0b2969e1686b4216b7d8fe4fe2aaab Signed-off-by: Vratko Polak <vrpolak@cisco.com> (cherry picked from commit 11e9514af6e6d9e993b469fae3ce6671c3d3e536)
Diffstat (limited to 'resources/libraries')
-rw-r--r--resources/libraries/python/NodePath.py11
-rw-r--r--resources/libraries/python/topology.py7
2 files changed, 10 insertions, 8 deletions
diff --git a/resources/libraries/python/NodePath.py b/resources/libraries/python/NodePath.py
index e97bde87ad..6f08be491b 100644
--- a/resources/libraries/python/NodePath.py
+++ b/resources/libraries/python/NodePath.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2019 Cisco and/or its affiliates.
+# Copyright (c) 2020 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
@@ -120,10 +120,11 @@ class NodePath:
f"No link between {node1[u'host']} and {node2[u'host']}"
)
+ # Not using set operations, as we need deterministic order.
if always_same_link:
- l_set = set(links).intersection(self._links)
+ l_set = [link for link in links if link in self._links]
else:
- l_set = set(links).difference(self._links)
+ l_set = [link for link in links if link not in self._links]
if not l_set:
raise RuntimeError(
f"No free link between {node1[u'host']} and "
@@ -131,9 +132,9 @@ class NodePath:
)
if not l_set:
- link = links.pop()
+ link = links[0]
else:
- link = l_set.pop()
+ link = l_set[0]
self._links.append(link)
interface1 = topo.get_interface_by_link_name(node1, link)
diff --git a/resources/libraries/python/topology.py b/resources/libraries/python/topology.py
index 7dec51619c..338ccb6b57 100644
--- a/resources/libraries/python/topology.py
+++ b/resources/libraries/python/topology.py
@@ -879,8 +879,6 @@ class Topology:
:rtype: list
"""
- logger.trace(f"node1: {str(node1)}")
- logger.trace(f"node2: {str(node2)}")
node1_links = self._get_node_active_link_names(
node1, filter_list=filter_list_node1
)
@@ -894,7 +892,10 @@ class Topology:
elif node2_links is None:
logger.error(u"Unable to find active links for node2")
else:
- connecting_links = list(set(node1_links).intersection(node2_links))
+ # Not using set operations, as we need deterministic order.
+ connecting_links = [
+ link for link in node1_links if link in node2_links
+ ]
return connecting_links