Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
abdosi committed Jun 27, 2023
2 parents 501698b + 1069b22 commit e7b6504
Show file tree
Hide file tree
Showing 1,901 changed files with 168,878 additions and 36,723 deletions.
171 changes: 171 additions & 0 deletions .azure-pipelines/get_dut_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import argparse
import logging
import os
import sys
import json
import yaml

_self_dir = os.path.dirname(os.path.abspath(__file__))
base_path = os.path.realpath(os.path.join(_self_dir, ".."))
if base_path not in sys.path:
sys.path.append(base_path)
ansible_path = os.path.realpath(os.path.join(_self_dir, "../ansible"))
if ansible_path not in sys.path:
sys.path.append(ansible_path)

from devutil.devices import init_localhost, init_testbed_sonichosts # noqa E402

logger = logging.getLogger(__name__)

RC_INIT_FAILED = 1
RC_GET_DUT_VERSION_FAILED = 2

ASIC_NAME_PATH = '../ansible/group_vars/sonic/variables'


def read_asic_name(hwsku):
asic_name_file = os.path.join(os.path.dirname(__file__), ASIC_NAME_PATH)
try:
with open(asic_name_file) as f:
asic_name = yaml.safe_load(f)

asic_name_dict = {}
for key, value in asic_name.items():
if "hwskus" in key:
asic_name_dict[key] = value

for name, hw in asic_name_dict.items():
if hwsku in hw:
return name.split('_')[1]

return "unknown"

except IOError:
return None


def get_duts_version(sonichosts, output=None):
try:
ret = {}
duts_version = sonichosts.command("show version")
for dut, version in duts_version.items():
ret[dut] = {}
dut_version = version["stdout_lines"]

for line in dut_version:
if ":" in line:
line_splitted = line.split(":", 1)
key = line_splitted[0].strip()
value = line_splitted[1].strip()
if key == "Docker images":
ret[dut]["Docker images"] = []
continue
elif key == "ASIC":
ret[dut]["ASIC TYPE"] = value
continue
elif key == "HwSKU":
ret[dut]["ASIC"] = read_asic_name(value)
ret[dut][key] = value
elif "docker" in line:
line_splitted = line.split()
ret[dut]["Docker images"].append({"REPOSITORY": line_splitted[0],
"TAG": line_splitted[1],
"IMAGE ID": line_splitted[2],
"SIZE": line_splitted[3]})

if output:
with open(output, "w") as f:
f.write(json.dumps(ret))
f.close()
else:
print(ret)
except Exception as e:
logger.error("Failed to get DUT version: {}".format(e))
sys.exit(RC_GET_DUT_VERSION_FAILED)


def validate_args(args):
_log_level_map = {
"debug": logging.DEBUG,
"info": logging.INFO,
"warning": logging.WARNING,
"error": logging.ERROR,
"critical": logging.CRITICAL
}
logging.basicConfig(
stream=sys.stdout,
level=_log_level_map[args.log_level],
format="%(asctime)s %(filename)s#%(lineno)d %(levelname)s - %(message)s"
)


def main(args):
logger.info("Validating arguments")
validate_args(args)

logger.info("Initializing hosts")
localhost = init_localhost(args.inventory, options={"verbosity": args.verbosity})
sonichosts = init_testbed_sonichosts(
args.inventory, args.testbed_name, testbed_file=args.tbfile, options={"verbosity": args.verbosity}
)

if not localhost or not sonichosts:
sys.exit(RC_INIT_FAILED)

get_duts_version(sonichosts, args.output)


if __name__ == "__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description="Tool for getting sonic device version.")

parser.add_argument(
"-i", "--inventory",
dest="inventory",
nargs="+",
help="Ansible inventory file")

parser.add_argument(
"-t", "--testbed-name",
type=str,
required=True,
dest="testbed_name",
help="Testbed name."
)

parser.add_argument(
"--tbfile",
type=str,
dest="tbfile",
default="testbed.yaml",
help="Testbed definition file."
)

parser.add_argument(
"-v", "--verbosity",
type=int,
dest="verbosity",
default=2,
help="Log verbosity (0-3)."
)

parser.add_argument(
"--log-level",
type=str,
dest="log_level",
choices=["debug", "info", "warning", "error", "critical"],
default="debug",
help="Loglevel"
)

parser.add_argument(
"-o", "--output",
type=str,
dest="output",
required=False,
help="Output duts version to the specified file."
)

args = parser.parse_args()
main(args)
163 changes: 163 additions & 0 deletions .azure-pipelines/pr_test_scripts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
t0:
- arp/test_arp_extended.py
- arp/test_neighbor_mac.py
- arp/test_neighbor_mac_noptf.py
- bgp/test_bgp_dual_asn.py
- bgp/test_bgp_fact.py
- bgp/test_bgp_gr_helper.py::test_bgp_gr_helper_routes_perserved
- bgp/test_bgp_speaker.py
- bgp/test_bgpmon.py
- bgp/test_bgp_update_timer.py
- container_checker/test_container_checker.py
- cacl/test_cacl_application.py
- cacl/test_cacl_function.py
- dhcp_relay/test_dhcp_relay.py
- dhcp_relay/test_dhcpv6_relay.py
- dns/test_dns_resolv_conf.py
- generic_config_updater/test_aaa.py
- generic_config_updater/test_bgpl.py
- generic_config_updater/test_bgp_prefix.py
- generic_config_updater/test_bgp_speaker.py
- generic_config_updater/test_cacl.py
- generic_config_updater/test_dhcp_relay.py
- generic_config_updater/test_eth_interface.py
- generic_config_updater/test_ipv6.py
- generic_config_updater/test_lo_interface.py
- generic_config_updater/test_monitor_config.py
- generic_config_updater/test_ntp.py
- generic_config_updater/test_portchannel_interface.py
- generic_config_updater/test_syslog.py
- generic_config_updater/test_vlan_interface.py
- generic_config_updater/test_mmu_dynamic_threshold_config_update.py
- generic_config_updater/test_ecn_config_update.py
- iface_namingmode/test_iface_namingmode.py
- lldp/test_lldp.py
- minigraph/test_masked_services.py
- monit/test_monit_status.py
- ntp/test_ntp.py
- override_config_table/test_override_config_table.py
- pc/test_po_cleanup.py
- pc/test_po_update.py
# - platform_tests/test_advanced_reboot.py::test_warm_reboot
- platform_tests/test_cpu_memory_usage.py
- process_monitoring/test_critical_process_monitoring.py
- radv/test_radv_ipv6_ra.py
- route/test_default_route.py
- route/test_static_route.py
- show_techsupport/test_techsupport_no_secret.py
- snmp/test_snmp_cpu.py
- snmp/test_snmp_default_route.py
- snmp/test_snmp_interfaces.py
- snmp/test_snmp_lldp.py
- snmp/test_snmp_loopback.py
- snmp/test_snmp_pfc_counters.py
- snmp/test_snmp_queue.py
- ssh/test_ssh_ciphers.py
- ssh/test_ssh_limit.py
- syslog/test_syslog.py
- system_health/test_system_status.py
- tacacs/test_accounting.py
- tacacs/test_authorization.py
- tacacs/test_jit_user.py
- tacacs/test_ro_disk.py
- tacacs/test_ro_user.py
- tacacs/test_rw_user.py
- telemetry/test_telemetry.py
- test_features.py
- test_interfaces.py
- test_procdockerstatsd.py
- database/test_db_scripts.py
- system_health/test_watchdog.py

t0-2vlans:
- dhcp_relay/test_dhcp_relay.py
- dhcp_relay/test_dhcpv6_relay.py

t0-sonic:
- bgp/test_bgp_fact.py
- macsec/test_controlplane.py
- macsec/test_dataplane.py
- macsec/test_deployment.py
- macsec/test_fault_handling.py
- macsec/test_interop_protocol.py
- pc/test_retry_count.py
# - platform_tests/test_advanced_reboot.py::test_warm_reboot

dualtor:
- arp/test_arp_extended.py

t1-lag:
- bgp/test_bgp_allow_list.py
- bgp/test_bgp_bbr.py
- bgp/test_bgp_bounce.py
- bgp/test_bgp_fact.py
- bgp/test_bgp_multipath_relax.py
- bgp/test_bgp_update_timer.py
- bgp/test_bgpmon.py
- bgp/test_traffic_shift.py
- configlet/test_add_rack.py
- container_checker/test_container_checker.py
- generic_config_updater/test_mmu_dynamic_threshold_config_update.py
- http/test_http_copy.py
- iface_namingmode/test_iface_namingmode.py
- ipfwd/test_mtu.py
- lldp/test_lldp.py
- monit/test_monit_status.py
- override_config_table/test_override_config_table.py
- pc/test_lag_2.py
- platform_tests/test_cpu_memory_usage.py
- process_monitoring/test_critical_process_monitoring.py
- route/test_default_route.py
- scp/test_scp_copy.py
- test_interfaces.py

multi-asic-t1-lag:
- bgp/test_bgp_bbr.py
- bgp/test_bgp_fact.py
- bgp/test_bgp_update_timer.py
- snmp/test_snmp_default_route.py
- snmp/test_snmp_loopback.py
- snmp/test_snmp_pfc_counters.py
- snmp/test_snmp_queue.py
- tacacs/test_accounting.py
- tacacs/test_authorization.py
- tacacs/test_jit_user.py
- tacacs/test_ro_user.py
- tacacs/test_rw_user.py
- cacl/test_cacl_function.py
- monit/test_monit_status.py
- iface_namingmode/test_iface_namingmode.py
- scp/test_scp_copy.py
- test_interfaces.py
- process_monitoring/test_critical_process_monitoring.py
- container_checker/test_container_checker.py
- http/test_http_copy.py

t2:
- test_vs_chassis_setup.py
- voq/test_voq_init.py

wan-pub:
- system_health/test_system_status.py
- snmp/test_snmp_cpu.py
- snmp/test_snmp_interfaces.py
- snmp/test_snmp_lldp.py
- snmp/test_snmp_pfc_counters.py
- snmp/test_snmp_queue.py
- snmp/test_snmp_v2mib.py
- arp/test_arpall.py
- telemetry/test_telemetry.py
- tacacs/test_jit_user.py
- tacacs/test_ro_user.py
- tacacs/test_rw_user.py
- tacacs/test_ro_disk.py
- tacacs/test_authorization.py
- tacacs/test_accounting.py

specific_param:
t0-sonic:
- name: bgp/test_bgp_fact.py
param: "--neighbor_type=sonic --enable_macsec --macsec_profile=128_SCI,256_XPN_SCI"
# all the test modules under macsec directory
- name: macsec
param: "--neighbor_type=sonic --enable_macsec --macsec_profile=128_SCI,256_XPN_SCI"
Loading

0 comments on commit e7b6504

Please sign in to comment.