Skip to content

Commit

Permalink
[MASIC] Make test_bgp_bounce.py support for multi-asic platforms (#5723)
Browse files Browse the repository at this point in the history
* Update bgp_helpers.py

To support multi-asic on test_bgp_bounce.py

* Update multi_asic.py

Move restart_bgp() from bgp_helpers.py to multi_asic.py, to make it work for multi-asic device.

* Update bgp_helpers.py

* Update multi_asic.py

* Update bgp_helpers.py

* Move restart_bgp(asic_index) back to bgp_helpers

* Update multi_asic.py

* Add back header for restart_bgp(asic_id)

* Move restart_bgp on an asic to restart_bgp_on_asic

* Add restart_bgp_on_asic call for per asic

* Add import for wait_until in multi_asic.py

* Add back reset_service same as original design

* Change restart_bgp_on_asic

Change restart_bgp_on_asic to restart_service_on_asic to make it more flexible to call

* Change restart_bgp_on_asic

Change restart_bgp_on_asic to restart_service_on_asic

* Fix LGMT - unused import

* Fix typo

* Update multi_asic.py

* Refine assertion message in multi_asic.py

* Update assert message in bgp_helpers.py

* Remove pyassert in bgp_helpers.py

* Add is_service_fully_started_per_asic_or_host

* Call is_service_fully_started_per_asic_or_host

Call is_service_fully_started_per_asic_or_host in pyassert

* Add comment

* Fix LGMT - unused import
  • Loading branch information
wenyiz2021 authored Jun 3, 2022
1 parent cb8e51e commit 0b86347
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
39 changes: 14 additions & 25 deletions tests/bgp/bgp_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import re
import time
import json
from tests.common.helpers.constants import DEFAULT_ASIC_ID
from tests.common.helpers.assertions import pytest_assert
from tests.common.utilities import wait_until

Expand All @@ -12,7 +11,7 @@
BGP_PLAIN_TEMPLATE = 'bgp_plain.j2'
BGP_NO_EXPORT_TEMPLATE = 'bgp_no_export.j2'
BGP_CONFIG_BACKUP = 'backup_bgpd.conf.j2'
DEFAULT_BGP_CONFIG = 'bgp:/usr/share/sonic/templates/bgpd/bgpd.conf.j2'
DEFAULT_BGP_CONFIG = '/usr/share/sonic/templates/bgpd/bgpd.conf.j2'
DUMP_FILE = "/tmp/bgp_monitor_dump.log"
CUSTOM_DUMP_SCRIPT = "bgp/bgp_monitor_dump.py"
CUSTOM_DUMP_SCRIPT_DEST = "/usr/share/exabgp/bgp_monitor_dump.py"
Expand All @@ -30,22 +29,9 @@ def apply_bgp_config(duthost, template_name):
duthost: DUT host object
template_name: pathname of the bgp config on the DUT
"""
duthost.shell('docker cp {} {}'.format(template_name, DEFAULT_BGP_CONFIG))
restart_bgp(duthost)


def restart_bgp(duthost, asic_index=DEFAULT_ASIC_ID):
"""
Restart bgp services on the DUT
Args:
duthost: DUT host object
"""
duthost.asic_instance(asic_index).reset_service("bgp")
duthost.asic_instance(asic_index).restart_service("bgp")
docker_name = duthost.asic_instance(asic_index).get_docker_name("bgp")
pytest_assert(wait_until(100, 10, 0, duthost.is_service_fully_started, docker_name), "BGP not started.")

duthost.docker_copy_to_all_asics('bgp', template_name, DEFAULT_BGP_CONFIG)
duthost.restart_service("bgp")
pytest_assert(wait_until(100, 10, 0, duthost.is_service_fully_started_per_asic_or_host, "bgp"), "BGP not started.")

def define_config(duthost, template_src_path, template_dst_path):
"""
Expand All @@ -58,7 +44,7 @@ def define_config(duthost, template_src_path, template_dst_path):
"""
duthost.shell("mkdir -p {}".format(DUT_TMP_DIR))
duthost.copy(src=template_src_path, dest=template_dst_path)


def get_no_export_output(vm_host):
"""
Expand All @@ -81,12 +67,13 @@ def apply_default_bgp_config(duthost, copy=False):
"""
bgp_config_backup = os.path.join(DUT_TMP_DIR, BGP_CONFIG_BACKUP)
if copy:
duthost.shell('docker cp {} {}'.format(DEFAULT_BGP_CONFIG, bgp_config_backup))
duthost.docker_copy_from_asic('bgp', DEFAULT_BGP_CONFIG, bgp_config_backup)
else:
duthost.shell('docker cp {} {}'.format(bgp_config_backup, DEFAULT_BGP_CONFIG))
duthost.docker_copy_to_all_asics('bgp', bgp_config_backup, DEFAULT_BGP_CONFIG)
# Skip 'start-limit-hit' threshold
duthost.shell('systemctl reset-failed bgp')
restart_bgp(duthost)
duthost.reset_service("bgp")
duthost.restart_service("bgp")
pytest_assert(wait_until(100, 10, 0, duthost.is_service_fully_started_per_asic_or_host, "bgp"), "BGP not started.")

def parse_exabgp_dump(host):
"""
Expand Down Expand Up @@ -149,7 +136,8 @@ def remove_bgp_neighbors(duthost, asic_index):
duthost.shell(cmd)

# Restart BGP instance on that asic
restart_bgp(duthost, asic_index)
duthost.restart_service_on_asic("bgp", asic_index)
pytest_assert(wait_until(100, 10, 0, duthost.is_service_fully_started_per_asic_or_host, "bgp"), "BGP not started.")

return bgp_neighbors

Expand All @@ -166,4 +154,5 @@ def restore_bgp_neighbors(duthost, asic_index, bgp_neighbors):
duthost.shell("sudo sonic-cfggen {} -a '{}' --write-to-db".format(namespace_prefix, bgp_neigh_json))

# Restart BGP instance on that asic
restart_bgp(duthost, asic_index)
duthost.restart_service_on_asic("bgp", asic_index)
pytest_assert(wait_until(100, 10, 0, duthost.is_service_fully_started_per_asic_or_host, "bgp"), "BGP not started.")
24 changes: 24 additions & 0 deletions tests/common/devices/multi_asic.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,14 @@ def stop_service(self, service):

for asic in self.asics:
asic.stop_service(service)

def reset_service(self, service):
if service in self._DEFAULT_SERVICES:
return self.sonichost.reset_service(service, service)

for asic in self.asics:
asic.reset_service(service)

def restart_service(self, service):
if service in self._DEFAULT_SERVICES:
return self.sonichost.restart_service(service, service)
Expand Down Expand Up @@ -614,3 +621,20 @@ def docker_copy_from_asic(self, container_name, src, dst, asic_id = 0):
if duthost.is_multi_asic:
container_name += str(asic_id)
self.shell("sudo docker cp {}:{} {}".format(container_name, src, dst))

def is_service_fully_started_per_asic_or_host(self, service):
"""This function tell if service is fully started base on multi-asic/single-asic"""
duthost = self.sonichost
if duthost.is_multi_asic:
for asic_index in range(duthost.facts["num_asic"]):
docker_name = self.asic_instance(asic_index).get_docker_name(service)
if not duthost.is_service_fully_started(docker_name):
return False
return True
else:
return duthost.is_service_fully_started(service)

def restart_service_on_asic(self, service, asic_index=DEFAULT_ASIC_ID):
"""Restart service on an asic passed or None(DEFAULT_ASIC_ID)"""
self.asic_instance(asic_index).restart_service(service)

0 comments on commit 0b86347

Please sign in to comment.