Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for running T2 applicable tests using vsonic(KVM) for n… #6022

Merged
merged 11 commits into from
Feb 27, 2024
65 changes: 32 additions & 33 deletions ansible/roles/test/files/tools/loganalyzer/loganalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

# ---------------------------------------------------------------------
# Global imports
# ---------------------------------------------------------------------

# ---------------------------------------------------------------------
from __future__ import print_function
import sys
import getopt
import re
Expand Down Expand Up @@ -110,7 +111,7 @@ def print_diagnostic_message(self, message):
if (not self.verbose):
return

print(('[LogAnalyzer][diagnostic]:%s' % message))
print('[LogAnalyzer][diagnostic]:%s' % message)
# ---------------------------------------------------------------------

def create_start_marker(self):
Expand Down Expand Up @@ -219,28 +220,30 @@ def wait_for_marker(self, marker, timeout=120, polling_interval=10):
last_check_pos = 0
syslog_file = "/var/log/syslog"
prev_syslog_file = "/var/log/syslog.1"
last_dt = prev_syslog_file
while wait_time <= timeout:
# look for marker in syslog file
if os.path.exists(syslog_file):
with open(syslog_file, 'r') as fp:
# resume from last search position
if last_check_pos:
fp.seek(last_check_pos)
# check if marker in the file
for logs in fp:
if marker in logs:
return True
# record last search position
last_check_pos = fp.tell()

# logs might get rotated while waiting for marker
# look for marker in syslog.1 file
if os.path.exists(prev_syslog_file):
with open(prev_syslog_file, 'r') as pfp:
# check if marker in the file
for logs in pfp:
if marker in logs:
return True
with open(syslog_file, 'r') as fp:
dt = os.path.getctime(syslog_file)
if last_dt != dt:
try:
with open(prev_syslog_file, 'r') as pfp:
pfp.seek(last_check_pos)
for log in fp:
if marker in log:
return True
except OSError:
mannytaheri marked this conversation as resolved.
Show resolved Hide resolved
print("cannot find file {}".format(prev_syslog_file))
last_check_pos = 0
last_dt = dt
# resume from last search position
if last_check_pos:
fp.seek(last_check_pos)
# check if marker in the file
for log in fp:
if marker in log:
return True
# record last search position
last_check_pos = fp.tell()
time.sleep(polling_interval)
wait_time += polling_interval

Expand Down Expand Up @@ -287,10 +290,8 @@ def error_to_regx(self, error_string):
# -- Replaces a digit number with the digit regular expression
error_string = re.sub(r"\b\d+\b", "\\\\d+", error_string)
# -- Replaces a hex number with the hex regular expression
error_string = re.sub(
r"0x[0-9a-fA-F]+", "0x[0-9a-fA-F]+", error_string)
self.print_diagnostic_message(
'Built error string: %s' % error_string)
error_string = re.sub(r"0x[0-9a-fA-F]+", "0x[0-9a-fA-F]+", error_string)
self.print_diagnostic_message('Built error string: %s' % error_string)

# -- If given a list, concatenate into one regx --#
else:
Expand Down Expand Up @@ -323,8 +324,7 @@ def create_msg_regex(self, file_lsit):

for index, row in enumerate(csvreader):
row = [item for item in row if item != ""]
self.print_diagnostic_message(
'[diagnostic]:processing row:%d' % index)
self.print_diagnostic_message('[diagnostic]:processing row:%d' % index)
self.print_diagnostic_message('row:%s' % row)
try:
# -- Ignore Empty Lines
Expand Down Expand Up @@ -767,10 +767,9 @@ def main(argv):
verbose = False

try:
opts, args = getopt.getopt(argv, "a:r:s:l:o:m:i:e:vh",
["action=", "run_id=", "start_marker=", "logs=",
"out_dir=", "match_files_in=", "ignore_files_in=",
"expect_files_in=", "verbose", "help"])
opts, args = getopt.getopt(argv, "a:r:s:l:o:m:i:e:vh", [
"action=", "run_id=", "start_marker=", "logs=", "out_dir=", "match_files_in=", "ignore_files_in=",
"expect_files_in=", "verbose", "help"])

except getopt.GetoptError:
print("Invalid option specified")
Expand Down
33 changes: 22 additions & 11 deletions tests/lldp/test_lldp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def lldp_setup(duthosts, enum_rand_one_per_hwsku_frontend_hostname, patch_lldpct


def test_lldp(duthosts, enum_rand_one_per_hwsku_frontend_hostname, localhost,
collect_techsupport_all_duts, enum_frontend_asic_index):
collect_techsupport_all_duts, enum_frontend_asic_index, request):
""" verify the LLDP message on DUT """
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]

Expand All @@ -33,11 +33,15 @@ def test_lldp(duthosts, enum_rand_one_per_hwsku_frontend_hostname, localhost,
# Compare the LLDP neighbor name with minigraph neigbhor name (exclude the management port)
assert v['chassis']['name'] == config_facts['DEVICE_NEIGHBOR'][k]['name']
# Compare the LLDP neighbor interface with minigraph neigbhor interface (exclude the management port)
assert v['port']['ifname'] == config_facts['DEVICE_NEIGHBOR'][k]['port']
if request.config.getoption("--neighbor_type") == 'eos':
mannytaheri marked this conversation as resolved.
Show resolved Hide resolved
assert v['port']['ifname'] == config_facts['DEVICE_NEIGHBOR'][k]['port']
else:
# Dealing with KVM that advertises port description
assert v['port']['descr'] == config_facts['DEVICE_NEIGHBOR'][k]['port']


def test_lldp_neighbor(duthosts, enum_rand_one_per_hwsku_frontend_hostname, localhost, eos,
collect_techsupport_all_duts, loganalyzer, enum_frontend_asic_index, tbinfo):
def test_lldp_neighbor(duthosts, enum_rand_one_per_hwsku_frontend_hostname, localhost, eos, sonic,
mannytaheri marked this conversation as resolved.
Show resolved Hide resolved
collect_techsupport_all_duts, loganalyzer, enum_frontend_asic_index, tbinfo, request):
""" verify LLDP information on neighbors """
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]

Expand Down Expand Up @@ -80,16 +84,23 @@ def test_lldp_neighbor(duthosts, enum_rand_one_per_hwsku_frontend_hostname, loca
logger.info("Neighbor device {} does not sent management IP via lldp".format(v['chassis']['name']))
hostip = nei_meta[v['chassis']['name']]['mgmt_addr']

nei_lldp_facts = localhost.lldp_facts(
host=hostip, version='v2c', community=eos['snmp_rocommunity'])['ansible_facts']
neighbor_interface = v['port']['ifname']
logger.info("lldp facts for interface {}:{}".format(neighbor_interface,
nei_lldp_facts['ansible_lldp_facts'][neighbor_interface]))
if request.config.getoption("--neighbor_type") == 'eos':
nei_lldp_facts = localhost.lldp_facts(host=hostip, version='v2c', community=eos['snmp_rocommunity'])[
'ansible_facts']
neighbor_interface = v['port']['ifname']
else:
nei_lldp_facts = localhost.lldp_facts(host=hostip, version='v2c', community=sonic['snmp_rocommunity'])[
'ansible_facts']
neighbor_interface = v['port']['local']
# Verify the published DUT system name field is correct
assert nei_lldp_facts['ansible_lldp_facts'][neighbor_interface]['neighbor_sys_name'] == duthost.hostname
# Verify the published DUT chassis id field is not empty
assert nei_lldp_facts['ansible_lldp_facts'][neighbor_interface]['neighbor_chassis_id'] == \
"0x%s" % (switch_mac.replace(':', ''))
if request.config.getoption("--neighbor_type") == 'eos':
assert nei_lldp_facts['ansible_lldp_facts'][neighbor_interface]['neighbor_chassis_id'] == \
"0x%s" % (switch_mac.replace(':', ''))
else:
assert nei_lldp_facts['ansible_lldp_facts'][neighbor_interface]['neighbor_chassis_id'] == switch_mac

# Verify the published DUT system description field is correct
assert nei_lldp_facts['ansible_lldp_facts'][neighbor_interface]['neighbor_sys_desc'] == dut_system_description
# Verify the published DUT port id field is correct
Expand Down
7 changes: 6 additions & 1 deletion tests/pc/test_lag_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,18 @@ def has_lags(dut):
"lacp_rate",
"fallback"])
def test_lag(common_setup_teardown, duthosts, tbinfo, nbrhosts, fanouthosts,
conn_graph_facts, enum_dut_portchannel_with_completeness_level, testcase): # noqa F811
conn_graph_facts, enum_dut_portchannel_with_completeness_level, testcase, request): # noqa F811
# We can't run single_lag test on vtestbed since there is no leaffanout
if testcase == "single_lag" and is_vtestbed(duthosts[0]):
pytest.skip("Skip single_lag test on vtestbed")
if 'PortChannel201' in enum_dut_portchannel_with_completeness_level:
pytest.skip("PortChannel201 is a specific configuration of t0-56-po2vlan topo, which is not supported by test")

# Skip lacp_rate testcases on KVM since setting lacp rate it is not supported on KVM
if testcase == "lacp_rate":
if request.config.getoption("--neighbor_type") == 'sonic':
pytest.skip("lacp_rate is not supported in vsonic")

ptfhost = common_setup_teardown

dut_name, dut_lag = decode_dut_port_name(enum_dut_portchannel_with_completeness_level)
Expand Down
115 changes: 71 additions & 44 deletions tests/voq/test_voq_nbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .voq_helpers import get_inband_info
from .voq_helpers import get_ptf_port
from .voq_helpers import get_vm_with_ip
from tests.common.devices.eos import EosHost

from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # noqa F401
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -127,16 +128,13 @@ def restore_bgp(duthosts, nbrhosts, all_cfg_facts):

for peer in nbr['conf']['bgp']['peers']:
for neighbor in nbr['conf']['bgp']['peers'][peer]:
nbr['host'].eos_config(
lines=["no neighbor %s shutdown" % neighbor],
parents=['router bgp {}'.format(nbr['conf']['bgp']['asn'])])

if ":" in address:
if isinstance(nbr['host'], EosHost):
nbr['host'].eos_config(
lines=["no ipv6 route ::/0 %s " % neighbor])
lines=["no neighbor %s shutdown" % neighbor],
parents=['router bgp {}'.format(nbr['conf']['bgp']['asn'])])
else:
nbr['host'].eos_config(
lines=["no ip route 0.0.0.0/0 %s " % neighbor])
nbr['host'].shell("sudo vtysh -c 'configure terminal' -c 'router bgp " + str(
nbr['conf']['bgp']['asn']) + "' -c 'no neighbor {} shutdown'".format(neighbor))


@pytest.fixture(scope="module", autouse=True)
Expand Down Expand Up @@ -219,21 +217,25 @@ def disable_nbr_bgp_neighs(node=None, results=None):
'disable neighbors {} on neighbor host {}'.format(node['conf']['bgp']['peers'], node['host'].hostname))
for peer in node['conf']['bgp']['peers']:
for neighbor in node['conf']['bgp']['peers'][peer]:
node_results.append(node['host'].eos_config(
lines=["neighbor %s shutdown" % neighbor],
parents=['router bgp {}'.format(node['conf']['bgp']['asn'])],
module_ignore_errors=True)
)
if ":" in neighbor:
if isinstance(node['host'], EosHost):
node_results.append(node['host'].eos_config(
lines=["ipv6 route ::/0 %s " % neighbor],
lines=["neighbor %s shutdown" % neighbor],
parents=['router bgp {}'.format(node['conf']['bgp']['asn'])],
module_ignore_errors=True)
)
if ":" in neighbor:
node_results.append(node['host'].eos_config(
lines=["ipv6 route ::/0 %s " % neighbor],
module_ignore_errors=True)
)
else:
node_results.append(node['host'].eos_config(
lines=["ip route 0.0.0.0/0 %s " % neighbor],
module_ignore_errors=True)
)
else:
node_results.append(node['host'].eos_config(
lines=["ip route 0.0.0.0/0 %s " % neighbor],
module_ignore_errors=True)
)
node_results.append(node['host'].shell("sudo vtysh -c 'configure terminal' -c 'router bgp " + str(
mannytaheri marked this conversation as resolved.
Show resolved Hide resolved
node['conf']['bgp']['asn']) + "' -c 'neighbor {} shutdown'".format(neighbor)))

results[node['host'].hostname] = node_results

Expand Down Expand Up @@ -310,36 +312,47 @@ def enable_nbr_bgp_neighs(node=None, results=None):
for peer in node['conf']['bgp']['peers']:
for neighbor in node['conf']['bgp']['peers'][peer]:
try:
node_results.append(node['host'].eos_config(
lines=["no neighbor %s shutdown" % neighbor],
parents=['router bgp {}'.format(node['conf']['bgp']['asn'])])
)
if ":" in neighbor:
if isinstance(node['host'], EosHost):
node_results.append(node['host'].eos_config(
lines=["no ipv6 route ::/0 %s " % neighbor])
lines=["no neighbor %s shutdown" % neighbor],
parents=['router bgp {}'.format(node['conf']['bgp']['asn'])])
)
if ":" in neighbor:
node_results.append(node['host'].eos_config(
lines=["no ipv6 route ::/0 %s " % neighbor])
)
else:
node_results.append(node['host'].eos_config(
lines=["no ip route 0.0.0.0/0 %s " % neighbor],
)
)
else:
node_results.append(node['host'].eos_config(
lines=["no ip route 0.0.0.0/0 %s " % neighbor],
)
)
node_results.append(node['host'].shell(
"sudo vtysh -c 'configure terminal' -c 'router bgp " + str(
node['conf']['bgp']['asn']) + "' -c 'no neighbor {} shutdown'".format(neighbor)))

except Exception:
logger.warning("Enable of neighbor on VM: %s failed, retrying", node['host'].hostname)
time.sleep(10)
node_results.append(node['host'].eos_config(
lines=["no neighbor %s shutdown" % neighbor],
parents=['router bgp {}'.format(node['conf']['bgp']['asn'])])
)
if ":" in neighbor:
if isinstance(node['host'], EosHost):
node_results.append(node['host'].eos_config(
lines=["no ipv6 route ::/0 %s " % neighbor],
)
lines=["no neighbor %s shutdown" % neighbor],
parents=['router bgp {}'.format(node['conf']['bgp']['asn'])])
)
if ":" in neighbor:
node_results.append(node['host'].eos_config(
lines=["no ipv6 route ::/0 %s " % neighbor],
)
)
else:
node_results.append(node['host'].eos_config(
lines=["no ip route 0.0.0.0/0 %s " % neighbor],
)
)
else:
node_results.append(node['host'].eos_config(
lines=["no ip route 0.0.0.0/0 %s " % neighbor],
)
)
node_results.append(node['host'].shell(
"sudo vtysh -c 'configure terminal' -c 'router bgp " + str(
node['conf']['bgp']['asn']) + "' -c 'no neighbor {} shutdown'".format(neighbor)))

results[node['host'].hostname] = node_results

Expand Down Expand Up @@ -435,12 +448,26 @@ def _change_vm_interface_on_vm(nbrhosts, state="up", node=None, results=None):
for eos_intf in list(nbr['conf']['interfaces'].keys()):
if "Loopback" in eos_intf:
continue

if state == "up":
logger.info("Startup EOS %s interface %s", node, eos_intf)
node_results.append(nbr['host'].eos_config(lines=["no shutdown"], parents=["interface %s" % eos_intf]))
logger.info("Startup Nbr %s interface %s", node, eos_intf)
mannytaheri marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(nbr['host'], EosHost):
node_results.append(
nbr['host'].eos_config(lines=["no shutdown"], parents=["interface %s" % eos_intf]))
else:
if "port-channel" in eos_intf.lower():
# convert PortChannel-1 to PortChannel1
eos_intf = "PortChannel" + eos_intf[-1]
node_results.append(nbr['host'].shell("config interface startup {}".format(eos_intf)))
else:
logger.info("Shutdown EOS %s interface %s", node, eos_intf)
node_results.append(nbr['host'].eos_config(lines=["shutdown"], parents=["interface %s" % eos_intf]))
logger.info("Shutdown Nbr %s interface %s", node, eos_intf)
if isinstance(nbr['host'], EosHost):
node_results.append(nbr['host'].eos_config(lines=["shutdown"], parents=["interface %s" % eos_intf]))
else:
if "port-channel" in eos_intf.lower():
# convert PortChannel-1 to PortChannel1
eos_intf = "PortChannel" + eos_intf[-1]
node_results.append(nbr['host'].shell("config interface shutdown {}".format(eos_intf)))

results[node] = node_results

Expand Down
Loading
Loading