LLDP保存配置后重启生效压力测试
1、拷机环境下验证将lldp status修改为rx_only/tx_only/rxtx/disabled几种模式,每种模式下shutdown/no shutdown端口查看邻居状态是否正确
2、反复拷机验证修改lldp status为rx_only/tx_only/rxtx/disabled后保存配置,重启仍然生效
test_TC_GN_LLDP.py
import logging
import pytest
import random
import re
import time
import os
import pprint
import json
import string
import ptf.testutils as testutils
import ptf.mask as mask
import ptf.packet as scapy
from datetime import datetime
from tests.common.helpers.assertions import pytest_assert
from tests.common import config_reload
from tests.conftest import duthost
from collections import defaultdict
from tests.common import reboot, port_toggle
from tests.common.helpers.assertions import pytest_require
from tests.common import testbed
from natsort import natsorted
import tests.common.utilities as utilities
from tests.common import reboot
pytestmark = [
pytest.mark.topology('t0')
]
logger = logging.getLogger(__name__)
@pytest.fixture(scope="module")
def cfg_facts(duthosts, rand_one_dut_hostname):
duthost = duthosts[rand_one_dut_hostname]
return get_cfg_facts(duthost)
def get_cfg_facts(duthost):
tmp_facts = json.loads(duthost.shell("sonic-cfggen -d --print-data")['stdout']) # return config db contents(running-con fig)
port_name_list_sorted = natsorted(tmp_facts['PORT'].keys())
port_index_map = {}
for idx, val in enumerate(port_name_list_sorted):
port_index_map[val] = idx
tmp_facts['config_port_indices'] = port_index_map
return tmp_facts
@pytest.fixture(scope='module', autouse=True)
def setup_dut(cfg_facts):
# dut port map ptf port
utilities.log_info("begin set params")
# set params
global portChannel1
global dutPortToVm
global newDutPortToVm
global ptfRecvPortMapVm
global ptfSendPortMapDut
global dutPortChannel1Ip
global vmPortChannel1Ip
global vmIps
global Vm1Ip
global randomEth
dutPortMapVm = 'Ethernet8'
dutPortChannel1Ip = '10.0.0.56/31'
vmPortChannel1Ip = '10.0.0.57/31'
vmIps = ['10.1.1.1', '10.1.2.1']
randomEth = str(random.randint(1,56))
portChannelList = natsorted(cfg_facts['PORTCHANNEL'].keys())
Vm1Ip = natsorted(cfg_facts['BGP_NEIGHBOR'].keys())[0].split("|")[1]
portChannel1 = portChannelList[0]
# Ethernet29
dutPortToVm = cfg_facts['PORTCHANNEL'][portChannel1]['members'][0]
pattern = "[0-9]"
# Ethernet 29
newDutPortToVm = re.sub(pattern, lambda x: " " + x.group(0), dutPortToVm, 1)
ptfRecvPortMapVm = cfg_facts['config_port_indices'][dutPortToVm]
ptfSendPortMapDut = cfg_facts['config_port_indices'][dutPortMapVm]
yield
utilities.log_info("End of the test")
@pytest.fixture(scope='function', autouse=True)
def check_config(duthost, nbrhosts):
utilities.log_info("Start checking the configuration, get the old configuration")
beforeConfigList = []
afterConfigList = []
torNeighbors = natsorted([neighbor for neighbor in nbrhosts.keys()])
tor = torNeighbors[0]
beforeConfigList = utilities.getConfigList(beforeConfigList, nbrhosts[tor]['host'], duthost)
yield
utilities.log_info("Start checking the configuration, get the new configuration")
afterConfigList = utilities.getConfigList(afterConfigList, nbrhosts[tor]['host'], duthost)
result = utilities.getConfigComp(beforeConfigList, afterConfigList)
utilities.log_info("End of configuration check, result is {}".format(str(result)))
if not result:
config_reload(duthost)
pytest_assert(result, "Configuration not cleared")
def scan_neighbor(randomEth,mode,duthost):
res_mode = cliecho(duthost, command = "sonic-cli -c 'configure terminal' -c 'interface Ethernet {0}' -c 'show lldp mode Ethernet{0}'".format(randomEth), mode = 'arr')
utilities.log_step("mode vertify")
if mode == 'rx':
pytest_assert("rx-only" in str(res_mode),"change mode rx error")
elif mode == 'tx':
pytest_assert("tx-only" in str(res_mode),"change mode tx error")
elif mode == 'rxtx':
pytest_assert("rx-and-tx" in str(res_mode),"change mode rxtx error")
elif mode == 'disable':
pytest_assert("disabled" in str(res_mode),"change mode disable error")
duthost.shell("sonic-cli -c 'configure terminal' -c 'interface Ethernet {}' -c 'shutdown'".format(randomEth))
if mode == 'tx' or mode == 'disable':
time.sleep(5)
res_neighbor = cliecho(duthost, command = "sonic-cli -c 'configure terminal' -c 'interface Ethernet {0}' -c 'show lldp n eighbor Ethernet{0}'".format(randomEth), mode = 'arr')
utilities.log_step("neighbor vertify after shutdown")
pytest_assert("Ethernet{}".format(randomEth) not in str(res_neighbor),"neighbor vertify after shutdown error")
res_table = cliecho(duthost, command = "sonic-cli -c 'configure terminal' -c 'interface Ethernet {0}' -c 'show lldp tabl e | grep Ethernet{0}'".format(randomEth), mode = 'arr')
utilities.log_step("table vertify after shutdown")
pytest_assert("Ethernet{} ".format(randomEth) not in str(res_table),"table vertify after shutdown error")
time.sleep(2)
duthost.shell("sonic-cli -c 'configure terminal' -c 'interface Ethernet {}' -c 'no shutdown'".format(randomEth))
time.sleep(2)
res_neighbor = cliecho(duthost, command = "sonic-cli -c 'configure terminal' -c 'interface Ethernet {0}' -c 'show lldp n eighbor Ethernet{0}'".format(randomEth), mode = 'arr')
utilities.log_step("neighbor vertify after no shutdown")
pytest_assert("Ethernet{}".format(randomEth) in str(res_neighbor),"neighbor vertify after no shutdown error")
res_table = cliecho(duthost, command = "sonic-cli -c 'configure terminal' -c 'interface Ethernet {0}' -c 'show lldp tabl e | grep Ethernet{0}'".format(randomEth), mode = 'arr')
utilities.log_step("table vertify after no shutdown")
pytest_assert("Ethernet{} ".format(randomEth) in str(res_table),"table vertify after no shutdown error")
def test_TC_GN_LLDP_031(duthosts, rand_one_dut_hostname, localhost):
duthost = duthosts[rand_one_dut_hostname]
try:
utilities.log_info("Test portchannel manual start")
utilities.log_info("DUT side configuration start")
for num in range(1,5):
mode = 'rx'
duthost.shell("sonic-cli -c 'configure terminal' -c 'interface Ethernet {}' -c 'lldp mode {}'".format(randomEth,mode))
time.sleep(2)
scan_neighbor(randomEth,mode,duthost)
mode = 'tx'
duthost.shell("sonic-cli -c 'configure terminal' -c 'interface Ethernet {}' -c 'lldp mode {}'".format(randomEth,mode))
time.sleep(2)
scan_neighbor(randomEth,mode,duthost)
mode = 'rxtx'
duthost.shell("sonic-cli -c 'configure terminal' -c 'interface Ethernet {}' -c 'lldp mode {}'".format(randomEth,mode))
time.sleep(2)
scan_neighbor(randomEth,mode,duthost)
mode = 'disable'
duthost.shell("sonic-cli -c 'configure terminal' -c 'interface Ethernet {}' -c 'lldp mode {}'".format(randomEth,mode))
time.sleep(2)
scan_neighbor(randomEth,mode,duthost)
reboot(duthost, localhost, reboot_type='cold', delay=10, \
timeout=0, wait=0, wait_for_ssh=True, reboot_helper=None, reboot_kwargs=None)
time.sleep(60)
scan_neighbor(randomEth,'disable',duthost)
finally:
duthost.shell("sonic-cli -c 'configure terminal' -c 'interface Ethernet {}' -c 'lldp mode rxtx'".format(randomEth))

浙公网安备 33010602011771号