From 0df4275ced5f963623f94599ace8c628395eed96 Mon Sep 17 00:00:00 2001 From: Vitaly Gavensky Date: Mon, 20 May 2024 10:13:59 +0300 Subject: [PATCH] Temp: test 1 --- .github/workflows/pdr_plugin_ci_workflow.yml | 14 +-- .../tests/exclude_list_tests.py | 119 ------------------ 2 files changed, 6 insertions(+), 127 deletions(-) delete mode 100644 plugins/pdr_deterministic_plugin/tests/exclude_list_tests.py diff --git a/.github/workflows/pdr_plugin_ci_workflow.yml b/.github/workflows/pdr_plugin_ci_workflow.yml index d5dda0725..39fac7457 100644 --- a/.github/workflows/pdr_plugin_ci_workflow.yml +++ b/.github/workflows/pdr_plugin_ci_workflow.yml @@ -29,6 +29,12 @@ jobs: - name: Run PyLint run: pylint --rcfile=plugins/pdr_deterministic_plugin/.pylintrc plugins/pdr_deterministic_plugin + - name: Run exclusion list class test + run: pytest plugins/pdr_deterministic_plugin/tests/exclude_list_class_tests.py + +# - name: Test exclusion list REST API of pytest +# run: pytest plugins/pdr_deterministic_plugin/tests/exclude_list_rest_api_tests.py + - name: Run full simulation test run: | sudo bash plugins/pdr_deterministic_plugin/.pytest/run_pdr_standalone_pytest.sh @@ -36,11 +42,3 @@ jobs: python plugins/pdr_deterministic_plugin/tests/simulation_telemetry.py echo "Terminating standalone PDR process" pkill -9 -f isolation_algo.py 2>/dev/null || true - -# - name: Test exclude list with pytest -# run: pytest plugins/pdr_deterministic_plugin/tests/exclude_list_tests.py #--doctest-modules --junitxml=junit/exclude_list_tests_results.xml --cov=com --cov-report=xml --cov-report=html - -# - name: Kill plugin process -# run: | -# pkill -9 -f isolation_algo.py 2>/dev/null || true -# sleep 10 diff --git a/plugins/pdr_deterministic_plugin/tests/exclude_list_tests.py b/plugins/pdr_deterministic_plugin/tests/exclude_list_tests.py deleted file mode 100644 index dab087bad..000000000 --- a/plugins/pdr_deterministic_plugin/tests/exclude_list_tests.py +++ /dev/null @@ -1,119 +0,0 @@ -# -# Copyright © 2013-2024 NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED. -# -# This software product is a proprietary product of Nvidia Corporation and its affiliates -# (the "Company") and all right, title, and interest in and to the software -# product, including all associated intellectual property rights, are and -# shall remain exclusively with the Company. -# -# This software product is governed by the End User License Agreement -# provided with the software product. -# - -import http -import json -import os -import tempfile -import time -import pytest -import requests -from constants import PDRConstants as Constants -from exclude_list import ExcludeList, ExcludeListItem -from isolation_algo import create_logger - -# Temp 4 - -def get_logger(): - """ - Return logger associated with log file in temporary directory - """ - log_name = os.path.basename(Constants.LOG_FILE) - log_path = os.path.join(tempfile.gettempdir(), log_name) - return create_logger(log_path) - -pytest.mark.run(order=0) -def test_exclude_list_class_methods(): - """ - Test exclude list class methods by direct calls - """ - excluded_ports = [ - ExcludeListItem("0123456789aaabbb_1", 0), # Add forever - ExcludeListItem("9876543210cccddd_2", 30), # Add for 30 seconds - ExcludeListItem("3456789012eeefff_3", 0) # Add forever - ] - - # Create exclude list and ensure it's empty - exclude_list = ExcludeList(get_logger()) - items = exclude_list.items() - assert not items - - # Add ports to excluded list - for port in excluded_ports: - exclude_list.add(port.port_name, port.ttl_seconds) - - # Test excluded list size - items = exclude_list.items() - assert items and len(items) == len(excluded_ports) - - # Test 'contains' method - for port in excluded_ports: - assert exclude_list.contains(port.port_name) - - # Test excluded list content - for (index, item) in enumerate(items): - assert item.port_name == excluded_ports[index].port_name - assert item.ttl_seconds == excluded_ports[index].ttl_seconds - - # Test auto-remove of second port after TTL is expired - auto_remove_port = excluded_ports[1] - time.sleep(auto_remove_port.ttl_seconds + 1) - assert not exclude_list.contains(auto_remove_port.port_name) - - # Test excluded list size - items = exclude_list.items() - assert items and len(items) == (len(excluded_ports) - 1) - - # Test excluded list content - for port in excluded_ports: - if port.port_name != auto_remove_port.port_name: - assert exclude_list.contains(port.port_name) - - # Test forced remove of third port - remove_port = excluded_ports[2] - exclude_list.remove(port.port_name) - assert not exclude_list.contains(remove_port.port_name) - - # Test excluded list size - items = exclude_list.items() - assert items and len(items) == (len(excluded_ports) - 2) - - # Test excluded list content - for port in excluded_ports: - if port.port_name != remove_port.port_name and port.port_name != auto_remove_port.port_name: - assert exclude_list.contains(port.port_name) - -#pytest.mark.run(order=1) -def no_test_exclude_list_rest_api(): - """ - Test exclude list inside plugin via REST API - """ - url = "http://127.0.0.1:8977/excluded" - - excluded_ports = [ - ExcludeListItem("0123456789aaabbb_1", 0), # Add forever - ExcludeListItem("9876543210cccddd_2", 30), # Add for 30 seconds - ExcludeListItem("3456789012eeefff_3", 0) # Add forever - ] - - # Prepare data for PUT HTTP request - data = [] - for port in excluded_ports: - data.append([port.port_name, port.ttl_seconds]) - - # Add ports to excluded list - response = requests.put(url, data=json.dumps(data), headers={'Content-Type': 'application/json'}, timeout=5, auth = None, verify = False) - assert response.status_code == http.client.OK - -if __name__ == '__main__': - test_exclude_list_class_methods() - #no_test_exclude_list_rest_api()