Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/acl/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pytest


@pytest.fixture(scope='module')
def get_function_conpleteness_level(pytestconfig):
return pytestconfig.getoption("--completeness_level")
13 changes: 13 additions & 0 deletions tests/acl/templates/acltb_test_stress_acl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
loop_times=1000
finished_times=0
while [[ ${loop_times} > 0 ]]; do
acl-loader update full /tmp/ip_stress_acl.json
acl-loader delete
let finished_times+=1
let loop_times-=1
echo "Finished ${finished_times} times, ${loop_times} times remaining"
done
show acl rule
show acl table
echo "End"
88 changes: 88 additions & 0 deletions tests/acl/test_stress_acl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import json
import logging
import pytest

pytestmark = [
pytest.mark.topology("any"),
pytest.mark.device_type('vs')
]

logger = logging.getLogger(__name__)

LOOP_TIMES_LEVEL_MAP = {
'debug': 10,
'basic': 1000,
'confident': 10000
}

# Template json file used to test scale rules
IP_ACL_FILE = "/tmp/acltb_test_stress_acl.json"
IP_ACL_BASH_TEMPLATE = "acl/templates/acltb_test_stress_acl.sh"
IP_ACL_BASH_FILE = "/tmp/acltb_test_stress_acl.sh"
IP_ACL_BASH_LOG_FILE = "/tmp/acltb_test_stress_acl.log"


def generate_acl_rule(duthost, ip_type):
"""
Generate acl rule with template json file
"""
rules_data = {}
ip_acl_entry = {}

ip_type == "ipv4"
acl_entry = {}
acl_entry[1] = {
"actions": {
"config": {
"forwarding-action": "ACCEPT"
}
},
"config": {
"sequence-id": 1
},
"ip": {
"config": {
"source-ip-address": "20.0.0.1/32"
}
}
}
ip_acl_entry.update(acl_entry)
rules_data['acl'] = {
"acl-sets": {
"acl-set": {
"IP_STRESS_ACL": {
"acl-entries": {
"acl-entry": ip_acl_entry
}
}
}
}
}

duthost.copy(content=json.dumps(rules_data, indent=4), dest=IP_ACL_FILE)


def test_acl_add_del_stress(duthosts, rand_one_dut_hostname, get_function_conpleteness_level):
duthost = duthosts[rand_one_dut_hostname]
generate_acl_rule(duthost, "ipv4")
duthost.shell("config acl add table -p PortChannel101,PortChannel102,PortChannel103,PortChannel104 \
IP_STRESS_ACL L3")
normalized_level = get_function_conpleteness_level
if normalized_level is None:
normalized_level = 'basic'
loop_time = LOOP_TIMES_LEVEL_MAP[normalized_level]

with open(IP_ACL_BASH_TEMPLATE, 'r') as f:
file_data = ""
for line in f:
if "loop_times=" in line:
line = "loop_times={}\n".format(loop_time)
file_data += line
with open(IP_ACL_BASH_TEMPLATE, 'w') as f:
f.write(file_data)

duthost.template(src=IP_ACL_BASH_TEMPLATE, dest=IP_ACL_BASH_FILE)
duthost.shell("bash {} > {}".format(IP_ACL_BASH_FILE, IP_ACL_BASH_LOG_FILE))
duthost.fetch(src=IP_ACL_BASH_LOG_FILE, dest="logs/")

logger.info("End")