From 543e960eb7cb5379d306035539c9e3d526655e47 Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Thu, 26 May 2016 10:42:01 +0200 Subject: [PATCH] tests: guarantee unique networks in get_list_of_random_networks The function generates a list of random networks, but so far did not guarantee their uniqueness. In rare cases, it breaks test_subnetpool_prefixes unit test in gate that relies on those networks to be unique. Now, the function will regenerate the result several times if duplicates are detected. Change-Id: Ia300e36ad7a25dd156ac8b5f27dcdeeaa5339ab8 Closes-Bug: #1585941 --- neutron/tests/unit/objects/test_base.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/neutron/tests/unit/objects/test_base.py b/neutron/tests/unit/objects/test_base.py index 23155cae795..1cc11ff2cfc 100644 --- a/neutron/tests/unit/objects/test_base.py +++ b/neutron/tests/unit/objects/test_base.py @@ -225,7 +225,12 @@ def get_random_dscp_mark(): def get_list_of_random_networks(num=10): - return [tools.get_random_ip_network() for i in range(num)] + for i in range(5): + res = [tools.get_random_ip_network() for i in range(num)] + # make sure there are no duplicates + if len(set(res)) == num: + return res + raise Exception('Failed to generate unique networks') FIELD_TYPE_VALUE_GENERATOR_MAP = {