Skip to content

Commit

Permalink
Delete TRSNCEIVER tables while config reload (#3726)
Browse files Browse the repository at this point in the history
<!--
 Please make sure you've read and understood our contributing guidelines:
 https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

 failure_prs.log skip_prs.log Make sure all your commits include a signature generated with `git commit -s` **

 If this is a bug fix, make sure your description includes "closes #xxxx",
 "fixes #xxxx" or "resolves #xxxx" so that GitHub automatically closes the related
 issue when the PR is merged.

 If you are adding/modifying/removing any command or utility script, please also
 make sure to add/modify/remove any unit tests from the tests
 directory as appropriate.

 If you are modifying or removing an existing 'show', 'config' or 'sonic-clear'
 subcommand, or you are adding a new subcommand, please make sure you also
 update the Command Line Reference Guide (doc/Command-Reference.md) to reflect
 your changes.

 Please provide the following information:
-->

#### What I did
Removed TRANSCEIVER tables while config reload / load minigraph is executed.
This code adds the option to reserve TRANSCEIVER_INFO table if xcvrd is being restarted. - https://github.com/sonic-net/sonic-platform-daemons/blob/0cb36447ebfda390d999df6516beac4c17315a7b/sonic-xcvrd/xcvrd/xcvrd.py#L2199

The fix introduced here comes to fix the issue that the table remains also after config reload / load minigraph, which may cause config DB and TRANSCEIVER_INFO table have different ports keys.

#### How I did it
Update config reload command to delete TRANSCEIVER tables: ["TRANSCEIVER_INFO", "TRANSCEIVER_STATUS", "TRANSCEIVER_PM", "TRANSCEIVER_FIRMWARE_INFO", "TRANSCEIVER_DOM_SENSOR", "TRANSCEIVER_DOM_THRESHOLD"]
#### How to verify it
Execute config reload and make sure TRANSCEIVER tables are deleted

#### Previous command output (if the output of a command-line utility has changed)

#### New command output (if the output of a command-line utility has changed)
  • Loading branch information
mssonicbld authored Jan 21, 2025
1 parent 8adc564 commit 727f488
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,18 @@ def flush_configdb(namespace=DEFAULT_NAMESPACE):
return client, config_db


def delete_transceiver_tables():
tables = ["TRANSCEIVER_INFO", "TRANSCEIVER_STATUS", "TRANSCEIVER_PM",
"TRANSCEIVER_FIRMWARE_INFO", "TRANSCEIVER_DOM_SENSOR", "TRANSCEIVER_DOM_THRESHOLD"]
state_db_del_pattern = "|*"

# delete TRANSCEIVER tables from State DB
state_db = SonicV2Connector(use_unix_socket_path=True)
state_db.connect(state_db.STATE_DB, False)
for table in tables:
state_db.delete_all_by_pattern(state_db.STATE_DB, table + state_db_del_pattern)


def migrate_db_to_lastest(namespace=DEFAULT_NAMESPACE):
# Migrate DB contents to latest version
db_migrator = '/usr/local/bin/db_migrator.py'
Expand Down Expand Up @@ -1902,6 +1914,7 @@ def reload(db, filename, yes, load_sysinfo, no_service_restart, force, file_form
cfg_hwsku = output.strip()

client, config_db = flush_configdb(namespace)
delete_transceiver_tables()

if load_sysinfo:
if namespace is DEFAULT_NAMESPACE:
Expand Down Expand Up @@ -2037,6 +2050,7 @@ def load_minigraph(db, no_service_restart, traffic_shift_away, override_config,
#Stop services before config push
if not no_service_restart:
log.log_notice("'load_minigraph' stopping services...")
delete_transceiver_tables()
_stop_services()

# For Single Asic platform the namespace list has the empty string
Expand Down

0 comments on commit 727f488

Please sign in to comment.