Skip to content

Commit

Permalink
Change to use asic_instance() API in all test cases (#3118)
Browse files Browse the repository at this point in the history
With this PR made following changes:

Use asic_instance() to always return ASIC object

Rename get_asic() to get_asic_or_sonic_host() which will return sonic host if asic_index is None else return asic host object. This API is useful if we want to execute/run something on host as well on asic in multi-asic platforms

Updated all the testcases to use correct set of API's.

Fix the issue
#3103
  • Loading branch information
abdosi authored Mar 10, 2021
1 parent 986592b commit 57b0b83
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 20 deletions.
8 changes: 4 additions & 4 deletions tests/cacl/test_cacl_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def verify_cacl(duthost, localhost, creds, docker_network, asic_index = None):
expected_iptables_rules, expected_ip6tables_rules = generate_expected_rules(duthost, docker_network, asic_index)


stdout = duthost.get_asic(asic_index).command("iptables -S")["stdout"]
stdout = duthost.get_asic_or_sonic_host(asic_index).command("iptables -S")["stdout"]
actual_iptables_rules = stdout.strip().split("\n")

# Ensure all expected iptables rules are present on the DuT
Expand All @@ -422,7 +422,7 @@ def verify_cacl(duthost, localhost, creds, docker_network, asic_index = None):
#for i in range(len(expected_iptables_rules)):
# pytest_assert(actual_iptables_rules[i] == expected_iptables_rules[i], "iptables rules not in expected order")

stdout = duthost.get_asic(asic_index).command("ip6tables -S")["stdout"]
stdout = duthost.get_asic_or_sonic_host(asic_index).command("ip6tables -S")["stdout"]
actual_ip6tables_rules = stdout.strip().split("\n")

# Ensure all expected ip6tables rules are present on the DuT
Expand All @@ -444,7 +444,7 @@ def verify_cacl(duthost, localhost, creds, docker_network, asic_index = None):
def verify_nat_cacl(duthost, localhost, creds, docker_network, asic_index):
expected_iptables_rules, expected_ip6tables_rules = generate_nat_expected_rules(duthost, docker_network, asic_index)

stdout = duthost.get_asic(asic_index).command("iptables -t nat -S")["stdout"]
stdout = duthost.get_asic_or_sonic_host(asic_index).command("iptables -t nat -S")["stdout"]
actual_iptables_rules = stdout.strip().split("\n")

# Ensure all expected iptables rules are present on the DuT
Expand All @@ -455,7 +455,7 @@ def verify_nat_cacl(duthost, localhost, creds, docker_network, asic_index):
unexpected_iptables_rules = set(actual_iptables_rules) - set(expected_iptables_rules)
pytest_assert(len(unexpected_iptables_rules) == 0, "Unexpected iptables nat rules: {}".format(repr(unexpected_iptables_rules)))

stdout = duthost.get_asic(asic_index).command("ip6tables -t nat -S")["stdout"]
stdout = duthost.get_asic_or_sonic_host(asic_index).command("ip6tables -t nat -S")["stdout"]
actual_ip6tables_rules = stdout.strip().split("\n")

# Ensure all expected ip6tables rules are present on the DuT
Expand Down
2 changes: 1 addition & 1 deletion tests/common/devices/multi_asic.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def __getattr__(self, attr):
else:
return getattr(self.sonichost, attr) # For backward compatibility

def get_asic(self, asic_id):
def get_asic_or_sonic_host(self, asic_id):
if asic_id == DEFAULT_ASIC_ID:
return self.sonichost
return self.asics[asic_id]
Expand Down
4 changes: 0 additions & 4 deletions tests/common/devices/sonic_asic.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ def get_critical_services(self):
service, self.asic_index if self.sonichost.is_multi_asic else ""))
return a_service

def get_service_name(self, service):
service_name = "{}{}".format(service, "@{}".format(self.asic_index) if self.sonichost.is_multi_asic else "")
return service_name

def is_it_frontend(self):
if self.sonichost.is_multi_asic:
sub_role_cmd = 'sudo sonic-cfggen -d -v DEVICE_METADATA.localhost.sub_role -n {}'.format(self.namespace)
Expand Down
2 changes: 1 addition & 1 deletion tests/common/platform/interface_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def check_interface_status(dut, asic_index, interfaces, xcvr_skip_list):
@param dut: The AnsibleHost object of DUT. For interacting with DUT.
@param interfaces: List of interfaces that need to be checked.
"""
asichost = dut.get_asic(asic_index)
asichost = dut.asic_instance(asic_index)
namespace = asichost.get_asic_namespace()
logging.info("Check interface status using cmd 'show interface'")
#TODO Remove this logic when minigraph facts supports namespace in multi_asic
Expand Down
10 changes: 5 additions & 5 deletions tests/common/platform/transceiver_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def all_transceivers_detected(dut, asic_index, interfaces, xcvr_skip_list):
Check if transceiver information of all the specified interfaces have been detected.
"""
cmd = "redis-cli --raw -n 6 keys TRANSCEIVER_INFO\*"
asichost = dut.get_asic(asic_index)
asichost = dut.asic_instance(asic_index)
docker_cmd = asichost.get_docker_cmd(cmd, "database")
db_output = dut.command(docker_cmd)["stdout_lines"]
not_detected_interfaces = [intf for intf in interfaces if "TRANSCEIVER_INFO|%s" % intf not in db_output]
Expand All @@ -60,7 +60,7 @@ def check_transceiver_basic(dut, asic_index, interfaces, xcvr_skip_list):
"""
logging.info("Check whether transceiver information of all ports are in redis")
cmd = "redis-cli -n 6 keys TRANSCEIVER_INFO*"
asichost = dut.get_asic(asic_index)
asichost = dut.asic_instance(asic_index)
docker_cmd = asichost.get_docker_cmd(cmd, "database")
xcvr_info = dut.command(docker_cmd)
parsed_xcvr_info = parse_transceiver_info(xcvr_info["stdout_lines"])
Expand All @@ -75,7 +75,7 @@ def check_transceiver_details(dut, asic_index, interfaces, xcvr_skip_list):
@param dut: The AnsibleHost object of DUT. For interacting with DUT.
@param interfaces: List of interfaces that need to be checked.
"""
asichost = dut.get_asic(asic_index)
asichost = dut.asic_instance(asic_index)
logging.info("Check detailed transceiver information of each connected port")
expected_fields = ["type", "hardware_rev", "serial", "manufacturer", "model"]
for intf in interfaces:
Expand All @@ -96,7 +96,7 @@ def check_transceiver_dom_sensor_basic(dut, asic_index, interfaces, xcvr_skip_li
"""
logging.info("Check whether TRANSCEIVER_DOM_SENSOR of all ports in redis")
cmd = "redis-cli -n 6 keys TRANSCEIVER_DOM_SENSOR*"
asichost = dut.get_asic(asic_index)
asichost = dut.asic_instance(asic_index)
docker_cmd = asichost.get_docker_cmd(cmd, "database")
xcvr_dom_sensor = dut.command(docker_cmd)
parsed_xcvr_dom_sensor = parse_transceiver_dom_sensor(xcvr_dom_sensor["stdout_lines"])
Expand All @@ -112,7 +112,7 @@ def check_transceiver_dom_sensor_details(dut, asic_index, interfaces, xcvr_skip_
@param interfaces: List of interfaces that need to be checked.
"""
logging.info("Check detailed TRANSCEIVER_DOM_SENSOR information of each connected ports")
asichost = dut.get_asic(asic_index)
asichost = dut.asic_instance(asic_index)
expected_fields = ["temperature", "voltage", "rx1power", "rx2power", "rx3power", "rx4power", "tx1bias",
"tx2bias", "tx3bias", "tx4bias", "tx1power", "tx2power", "tx3power", "tx4power"]
for intf in interfaces:
Expand Down
2 changes: 1 addition & 1 deletion tests/platform_tests/sfp/test_sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_check_sfputil_low_power_mode(duthosts, enum_rand_one_per_hwsku_frontend
* sfputil lpmode on
"""
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
asichost = duthost.get_asic(enum_frontend_asic_index)
asichost = duthost.asic_instance(enum_frontend_asic_index)

# Get the interface pertaining to that asic
portmap, dev_conn = get_dev_conn(duthost, conn_graph_facts, enum_frontend_asic_index)
Expand Down
4 changes: 2 additions & 2 deletions tests/platform_tests/test_sequential_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def restart_service_and_check(localhost, dut, enum_frontend_asic_index, service,
"""
logging.info("Restart the %s service on asic %s" %(service, enum_frontend_asic_index))

asichost = dut.get_asic(enum_frontend_asic_index)
service_name = asichost.get_service_name(service)
asichost = dut.asic_instance(enum_frontend_asic_index)
service_name = asichost.get_docker_name(service)
dut.command("sudo systemctl restart {}".format(service_name))

for container in dut.get_default_critical_services_list():
Expand Down
4 changes: 2 additions & 2 deletions tests/route/test_default_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_default_route_set_src(duthosts, enum_rand_one_per_hwsku_frontend_hostna
"""
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
asichost = duthost.get_asic(enum_asic_index)
asichost = duthost.asic_instance(enum_asic_index)

config_facts = asichost.config_facts(host=duthost.hostname, source="running")['ansible_facts']

Expand Down Expand Up @@ -52,7 +52,7 @@ def test_default_ipv6_route_next_hop_global_address(duthosts, enum_rand_one_per_
"""
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
asichost = duthost.get_asic(enum_asic_index)
asichost = duthost.asic_instance(enum_asic_index)

rtinfo = asichost.get_ip_route_info(ipaddress.ip_network(u"::/0"))
pytest_assert(rtinfo['nexthops'] > 0, "cannot find ipv6 nexthop for default route")
Expand Down

0 comments on commit 57b0b83

Please sign in to comment.