Skip to content

Commit

Permalink
Rest API test (initial steps)
Browse files Browse the repository at this point in the history
  • Loading branch information
vg12345 committed May 20, 2024
1 parent dbf5eaa commit a0568c1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/pdr_plugin_ci_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ jobs:
- name: Run exclusion list class test
run: pytest -s 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: Test exclusion list REST API of pytest
run: |
sudo bash plugins/pdr_deterministic_plugin/.pytest/run_pdr_standalone_pytest.sh
echo "Test exclusion list REST API methods"
pytest plugins/pdr_deterministic_plugin/tests/exclude_list_rest_api_tests.py
echo "Terminating standalone PDR process"
pkill -9 -f isolation_algo.py 2>/dev/null || true
- name: Run full simulation test
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_exclude_list_class_methods():
exclude_list = ExcludeList(get_logger())
items = exclude_list.items()
assert not items
print(" - Create exclusion list and ensure it's empty -- PASS")
print(" - test: create exclusion list and ensure it's empty -- PASS")

# Add ports to excluded list
for port in excluded_ports:
Expand All @@ -54,24 +54,24 @@ def test_exclude_list_class_methods():
# Test exclusion list size
items = exclude_list.items()
assert items and len(items) == len(excluded_ports)
print(" - Add ports to exclusion list -- PASS")
print(" - test: add ports to exclusion list -- PASS")

# Test 'contains' method
for port in excluded_ports:
assert exclude_list.contains(port.port_name)
print(" - Test exclusion list 'contains' method -- PASS")
print(" - test: exclusion list 'contains' method -- PASS")

# Test exclusion 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
print(" - Test exclusion list content -- PASS")
print(" - test: exclusion list content -- PASS")

# 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)
print(" - Test auto-remove of port from exclusion list after TTL is expired -- PASS")
print(" - test: auto-remove of port from exclusion list after TTL is expired -- PASS")

# Test excluded list size
items = exclude_list.items()
Expand All @@ -81,13 +81,13 @@ def test_exclude_list_class_methods():
for port in excluded_ports:
if port.port_name != auto_remove_port.port_name:
assert exclude_list.contains(port.port_name)
print(" - Test exclusion list content -- PASS")
print(" - test: exclusion list content -- PASS")

# 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)
print(" - Test forced remove of port from exclusion list -- PASS")
print(" - test: forced remove of port from exclusion list -- PASS")

# Test excluded list size
items = exclude_list.items()
Expand All @@ -97,7 +97,7 @@ def test_exclude_list_class_methods():
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)
print(" - Test exclusion list content -- PASS")
print(" - test: exclusion list content -- PASS")


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,7 @@
import time
import pytest
import requests
from constants import PDRConstants as Constants
from exclude_list import ExcludeList, ExcludeListItem
from isolation_algo import create_logger


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)
from exclude_list import ExcludeListItem


pytest.mark.run(order=0)
Expand Down

0 comments on commit a0568c1

Please sign in to comment.