From f4addc552d711cd1a6fb52fe2d27a92f86f95410 Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Tue, 15 Dec 2020 17:48:03 +0100 Subject: [PATCH] outsource flexgrid constants import in functests Signed-off-by: guillaume.lambert Change-Id: Ibaac844844e7c2113b9f2ddde1e5879cedf862f1 --- .../transportpce_tests/1.2.1/test_end2end.py | 6 ++-- .../transportpce_tests/2.2.1/test_end2end.py | 4 +-- .../2.2.1/test_otn_end2end.py | 2 +- .../common/flexgrid_utils.py | 31 +++++++++++++++++++ tests/transportpce_tests/common/test_utils.py | 18 ----------- 5 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 tests/transportpce_tests/common/flexgrid_utils.py diff --git a/tests/transportpce_tests/1.2.1/test_end2end.py b/tests/transportpce_tests/1.2.1/test_end2end.py index 92032039e..759fdbaa0 100644 --- a/tests/transportpce_tests/1.2.1/test_end2end.py +++ b/tests/transportpce_tests/1.2.1/test_end2end.py @@ -17,7 +17,7 @@ import unittest import requests from common import test_utils -from common.test_utils import INDEX_1_USED_FREQ_MAP, INDEX_1_2_USED_FREQ_MAP, AVAILABLE_FREQ_MAP +from common.flexgrid_utils import INDEX_1_USED_FREQ_MAP, INDEX_1_2_USED_FREQ_MAP, AVAILABLE_FREQ_MAP, check_freq_map class TransportPCEFulltesting(unittest.TestCase): @@ -594,7 +594,7 @@ class TransportPCEFulltesting(unittest.TestCase): res = response.json() freq_map = base64.b64decode( res['node'][0]['org-openroadm-network-topology:srg-attributes']['avail-freq-maps'][0]['freq-map']) - self.assertTrue(test_utils.check_freq_map(freq_map), "Index 1 and 2 should be available") + self.assertTrue(check_freq_map(freq_map), "Index 1 and 2 should be available") liste_tp = res['node'][0]['ietf-network-topology:termination-point'] for ele in liste_tp: self.assertNotIn('org-openroadm-network-topology:pp-attributes', dict.keys(ele)) @@ -606,7 +606,7 @@ class TransportPCEFulltesting(unittest.TestCase): res = response.json() freq_map = base64.b64decode( res['node'][0]['org-openroadm-network-topology:degree-attributes']['avail-freq-maps'][0]['freq-map']) - self.assertTrue(test_utils.check_freq_map(freq_map), "Index 1 and 2 should be available") + self.assertTrue(check_freq_map(freq_map), "Index 1 and 2 should be available") liste_tp = res['node'][0]['ietf-network-topology:termination-point'] for ele in liste_tp: if ele['tp-id'] == 'DEG1-CTP-TXRX': diff --git a/tests/transportpce_tests/2.2.1/test_end2end.py b/tests/transportpce_tests/2.2.1/test_end2end.py index c20b0eba5..56f1e3632 100644 --- a/tests/transportpce_tests/2.2.1/test_end2end.py +++ b/tests/transportpce_tests/2.2.1/test_end2end.py @@ -15,7 +15,7 @@ import unittest import time import requests from common import test_utils -from common.test_utils import INDEX_1_USED_FREQ_MAP, INDEX_1_2_USED_FREQ_MAP, AVAILABLE_FREQ_MAP +from common.flexgrid_utils import INDEX_1_USED_FREQ_MAP, INDEX_1_2_USED_FREQ_MAP, AVAILABLE_FREQ_MAP, check_freq_map class TransportPCEFulltesting(unittest.TestCase): @@ -555,7 +555,7 @@ class TransportPCEFulltesting(unittest.TestCase): res = response.json() freq_map = base64.b64decode( res['node'][0]['org-openroadm-network-topology:degree-attributes']['avail-freq-maps'][0]['freq-map']) - self.assertTrue(test_utils.check_freq_map(freq_map), "Index 1 and 2 should be available") + self.assertTrue(check_freq_map(freq_map), "Index 1 and 2 should be available") liste_tp = res['node'][0]['ietf-network-topology:termination-point'] for ele in liste_tp: if ele['tp-id'] == 'DEG2-CTP-TXRX': diff --git a/tests/transportpce_tests/2.2.1/test_otn_end2end.py b/tests/transportpce_tests/2.2.1/test_otn_end2end.py index 35e2e379b..71091d284 100644 --- a/tests/transportpce_tests/2.2.1/test_otn_end2end.py +++ b/tests/transportpce_tests/2.2.1/test_otn_end2end.py @@ -17,7 +17,7 @@ import unittest import time import requests from common import test_utils -from common.test_utils import INDEX_1_USED_FREQ_MAP, INDEX_1_2_USED_FREQ_MAP, AVAILABLE_FREQ_MAP +from common.flexgrid_utils import INDEX_1_USED_FREQ_MAP, INDEX_1_2_USED_FREQ_MAP, AVAILABLE_FREQ_MAP class TransportPCEtesting(unittest.TestCase): diff --git a/tests/transportpce_tests/common/flexgrid_utils.py b/tests/transportpce_tests/common/flexgrid_utils.py new file mode 100644 index 000000000..f7cff9734 --- /dev/null +++ b/tests/transportpce_tests/common/flexgrid_utils.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +############################################################################## +# Copyright (c) 2020 Orange, Inc. and others. All rights reserved. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +# pylint: disable=no-member + +import base64 + +def check_freq_map(freq_map): + freq_map_array = [int(x) for x in freq_map] + return freq_map_array[0] == 255 and freq_map_array[1] == 255 + + +def set_used_index_for_freq_map(freq_map, index): + freq_map[index] = 0 + return freq_map + + +INDEX_1_USED_FREQ_MAP = base64.b64encode(set_used_index_for_freq_map(bytearray(b'\xFF' * 96), 0)).decode('UTF-8') + +INDEX_1_2_USED_FREQ_MAP = base64.b64encode(set_used_index_for_freq_map( + set_used_index_for_freq_map(bytearray(b'\xFF' * 96), 0), 1)).decode('utf-8') + +AVAILABLE_FREQ_MAP = base64.b64encode(bytearray(b'\xFF' * 96)).decode('UTF-8') diff --git a/tests/transportpce_tests/common/test_utils.py b/tests/transportpce_tests/common/test_utils.py index 9d3bfec3e..34238bcc5 100644 --- a/tests/transportpce_tests/common/test_utils.py +++ b/tests/transportpce_tests/common/test_utils.py @@ -11,7 +11,6 @@ # pylint: disable=no-member -import base64 import json import os import sys @@ -465,20 +464,3 @@ class TimeOut: # pylint: disable=W0622 signal.alarm(0) - -def check_freq_map(freq_map): - freq_map_array = [int(x) for x in freq_map] - return freq_map_array[0] == 255 and freq_map_array[1] == 255 - - -def set_used_index_for_freq_map(freq_map, index): - freq_map[index] = 0 - return freq_map - - -INDEX_1_USED_FREQ_MAP = base64.b64encode(set_used_index_for_freq_map(bytearray(b'\xFF' * 96), 0)).decode('UTF-8') - -INDEX_1_2_USED_FREQ_MAP = base64.b64encode(set_used_index_for_freq_map( - set_used_index_for_freq_map(bytearray(b'\xFF' * 96), 0), 1)).decode('utf-8') - -AVAILABLE_FREQ_MAP = base64.b64encode(bytearray(b'\xFF' * 96)).decode('UTF-8') -- 2.36.6