Skip to content

Prevent output_watts KeyError#16772

Merged
yejianquan merged 1 commit intosonic-net:masterfrom
Javier-Tan:output_watts_changes
Feb 4, 2025
Merged

Prevent output_watts KeyError#16772
yejianquan merged 1 commit intosonic-net:masterfrom
Javier-Tan:output_watts_changes

Conversation

@Javier-Tan
Copy link
Contributor

Description of PR

Summary:
Fixes #16771

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • New Test case
    • Skipped for non-supported platforms
  • Test case improvement

Back port request

  • 202012
  • 202205
  • 202305
  • 202311
  • 202405
  • 202411

Approach

What is the motivation for this PR?

Prevent test failures due to KeyError when retrieving PDU["output_watts"]

How did you do it?

Use .get function to provide default value for PDUs that don't have output_watts as an attribute

How did you verify/test it?

Tested on T2 device with PDUs that don't provide output_watts (thanks @auspham)

Any platform specific information?

N/A

Supported testbed topology if it's a new test case?

N/A

Documentation

…rror

* Use .get to get output_watts with a default value if the key doesn't exist

Signed-off-by: Javier Tan [email protected]
@Javier-Tan Javier-Tan requested a review from prgeor as a code owner February 4, 2025 04:29
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Javier-Tan Javier-Tan requested a review from auspham February 4, 2025 04:30
Copy link
Contributor

@auspham auspham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for taking care of this.

@auspham
Copy link
Contributor

auspham commented Feb 4, 2025

@yejianquan for viz

Copy link
Collaborator

@yejianquan yejianquan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yejianquan yejianquan merged commit 69c37c9 into sonic-net:master Feb 4, 2025
12 checks passed
@mssonicbld
Copy link
Collaborator

Cherry-pick PR to msft-202405: Azure/sonic-mgmt.msft#54

yejianquan pushed a commit that referenced this pull request Feb 4, 2025
Description of PR
Summary:

When executing show reboot-cause history, swss needs to access /var/run/redis/sonic-db/database_config.json we're dependent on the database service to boot up.

Without waiting for this service to boot up we might run into runtime error:

/usr/local/lib/python3.8/dist-packages/_pytest/main.py:305: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
Plugin: terminalreporter, Hook: pytest_sessionfinish
KeyboardInterrupt: 
For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning
  config.hook.pytest_sessionfinish(
Traceback (most recent call last):
  File "/var/src/sonic-mgmt-int/tests/platform_tests/test_power_off_reboot.py", line 118, in test_power_off_reboot
    reboot_and_check(
  File "/var/src/sonic-mgmt-int/tests/platform_tests/test_reboot.py", line 86, in reboot_and_check
    reboot(dut, localhost, reboot_type=reboot_type,
  File "/var/src/sonic-mgmt-int/tests/common/plugins/loganalyzer/utils.py", line 24, in decorated
    res = func(*args, **kwargs)
  File "/var/src/sonic-mgmt-int/tests/common/reboot.py", line 341, in reboot
    curr_reboot_cause_history = duthost.show_and_parse("show reboot-cause history")
  File "/var/src/sonic-mgmt-int/tests/common/devices/multi_asic.py", line 136, in _run_on_asics
    return getattr(self.sonichost, self.multi_asic_attr)(*module_args, **complex_args)
  File "/var/src/sonic-mgmt-int/tests/common/devices/sonic.py", line 1687, in show_and_parse
    output = self.shell(show_cmd, **kwargs)["stdout_lines"]
  File "/var/src/sonic-mgmt-int/tests/common/devices/base.py", line 131, in _run
    raise RunAnsibleModuleFail("run module {} failed".format(self.module_name), res)
tests.common.errors.RunAnsibleModuleFail: run module shell failed, Ansible Results =>
failed = True
changed = True
rc = 1
cmd = show reboot-cause history
start = 2025-02-04 03:50:33.469088
end = 2025-02-04 03:50:33.934749
delta = 0:00:00.465661
msg = non-zero return code
invocation = {'module_args': {'_raw_params': 'show reboot-cause history', '_uses_shell': True, 'warn': False, 'stdin_add_newline': True, 'strip_empty_ends': True, 'argv': None, 'chdir': None, 'executable': None, 'creates': None, 'removes': None, 'stdin': None}}
_ansible_no_log = None
stdout =
stderr =
Traceback (most recent call last):
  File "/usr/local/bin/show", line 5, in <module>
    from show.main import cli
  File "/usr/local/lib/python3.11/dist-packages/show/main.py", line 325, in <module>
    if is_gearbox_configured():
       ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/show/main.py", line 265, in is_gearbox_configured
    app_db = SonicV2Connector()
             ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 2066, in __init__
    for db_name in self.get_db_list():
                   ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 2003, in get_db_list
    return _swsscommon.SonicV2Connector_Native_get_db_list(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Sonic database config file doesn't exist at /var/run/redis/sonic-db/database_config.json
Fixes # (issue)31217914


Approach
What is the motivation for this PR?
Explained above

How did you do it?
Simply wait for database service is ready before executing the command

How did you verify/test it?
Verified on T2 testbed together with #16772

image

Signed-off-by: Austin Pham <[email protected]>
@auspham auspham mentioned this pull request Feb 4, 2025
11 tasks
yejianquan pushed a commit that referenced this pull request Feb 6, 2025
Description of PR
Summary: Cherry-pick #16773 conflict

Summary:

When executing show reboot-cause history, swss needs to access /var/run/redis/sonic-db/database_config.json we're dependent on the database service to boot up.

Without waiting for this service to boot up we might run into runtime error:

/usr/local/lib/python3.8/dist-packages/_pytest/main.py:305: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
Plugin: terminalreporter, Hook: pytest_sessionfinish
KeyboardInterrupt: 
For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning
  config.hook.pytest_sessionfinish(
Traceback (most recent call last):
  File "/var/src/sonic-mgmt-int/tests/platform_tests/test_power_off_reboot.py", line 118, in test_power_off_reboot
    reboot_and_check(
  File "/var/src/sonic-mgmt-int/tests/platform_tests/test_reboot.py", line 86, in reboot_and_check
    reboot(dut, localhost, reboot_type=reboot_type,
  File "/var/src/sonic-mgmt-int/tests/common/plugins/loganalyzer/utils.py", line 24, in decorated
    res = func(*args, **kwargs)
  File "/var/src/sonic-mgmt-int/tests/common/reboot.py", line 341, in reboot
    curr_reboot_cause_history = duthost.show_and_parse("show reboot-cause history")
  File "/var/src/sonic-mgmt-int/tests/common/devices/multi_asic.py", line 136, in _run_on_asics
    return getattr(self.sonichost, self.multi_asic_attr)(*module_args, **complex_args)
  File "/var/src/sonic-mgmt-int/tests/common/devices/sonic.py", line 1687, in show_and_parse
    output = self.shell(show_cmd, **kwargs)["stdout_lines"]
  File "/var/src/sonic-mgmt-int/tests/common/devices/base.py", line 131, in _run
    raise RunAnsibleModuleFail("run module {} failed".format(self.module_name), res)
tests.common.errors.RunAnsibleModuleFail: run module shell failed, Ansible Results =>
failed = True
changed = True
rc = 1
cmd = show reboot-cause history
start = 2025-02-04 03:50:33.469088
end = 2025-02-04 03:50:33.934749
delta = 0:00:00.465661
msg = non-zero return code
invocation = {'module_args': {'_raw_params': 'show reboot-cause history', '_uses_shell': True, 'warn': False, 'stdin_add_newline': True, 'strip_empty_ends': True, 'argv': None, 'chdir': None, 'executable': None, 'creates': None, 'removes': None, 'stdin': None}}
_ansible_no_log = None
stdout =
stderr =
Traceback (most recent call last):
  File "/usr/local/bin/show", line 5, in <module>
    from show.main import cli
  File "/usr/local/lib/python3.11/dist-packages/show/main.py", line 325, in <module>
    if is_gearbox_configured():
       ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/show/main.py", line 265, in is_gearbox_configured
    app_db = SonicV2Connector()
             ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 2066, in __init__
    for db_name in self.get_db_list():
                   ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 2003, in get_db_list
    return _swsscommon.SonicV2Connector_Native_get_db_list(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Sonic database config file doesn't exist at /var/run/redis/sonic-db/database_config.json
Fixes # (issue)31217914

Approach
What is the motivation for this PR?
Explained above

How did you do it?
Simply wait for database service is ready before executing the command

How did you verify/test it?
Verified on T2 testbed together with #16772

image

Signed-off-by: Austin Pham <[email protected]>
wangxin pushed a commit to wangxin/sonic-mgmt that referenced this pull request Feb 21, 2025
<!--
Please make sure you've read and understood our contributing guidelines;
https://github.com/sonic-net/SONiC/blob/gh-pages/CONTRIBUTING.md

Please provide following information to help code review process a bit easier:
-->
### Description of PR
<!--
- Please include a summary of the change and which issue is fixed.
- Please also include relevant motivation and context. Where should reviewer start? background context?
- List any dependencies that are required for this change.
-->

Summary:

When executing `show reboot-cause history`, swss needs to access `/var/run/redis/sonic-db/database_config.json` we're dependent on the database service to boot up.

Without waiting for this service to boot up we might run into runtime error:

```
/usr/local/lib/python3.8/dist-packages/_pytest/main.py:305: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
Plugin: terminalreporter, Hook: pytest_sessionfinish
KeyboardInterrupt:
For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning
  config.hook.pytest_sessionfinish(
Traceback (most recent call last):
  File "/var/src/sonic-mgmt-int/tests/platform_tests/test_power_off_reboot.py", line 118, in test_power_off_reboot
    reboot_and_check(
  File "/var/src/sonic-mgmt-int/tests/platform_tests/test_reboot.py", line 86, in reboot_and_check
    reboot(dut, localhost, reboot_type=reboot_type,
  File "/var/src/sonic-mgmt-int/tests/common/plugins/loganalyzer/utils.py", line 24, in decorated
    res = func(*args, **kwargs)
  File "/var/src/sonic-mgmt-int/tests/common/reboot.py", line 341, in reboot
    curr_reboot_cause_history = duthost.show_and_parse("show reboot-cause history")
  File "/var/src/sonic-mgmt-int/tests/common/devices/multi_asic.py", line 136, in _run_on_asics
    return getattr(self.sonichost, self.multi_asic_attr)(*module_args, **complex_args)
  File "/var/src/sonic-mgmt-int/tests/common/devices/sonic.py", line 1687, in show_and_parse
    output = self.shell(show_cmd, **kwargs)["stdout_lines"]
  File "/var/src/sonic-mgmt-int/tests/common/devices/base.py", line 131, in _run
    raise RunAnsibleModuleFail("run module {} failed".format(self.module_name), res)
tests.common.errors.RunAnsibleModuleFail: run module shell failed, Ansible Results =>
failed = True
changed = True
rc = 1
cmd = show reboot-cause history
start = 2025-02-04 03:50:33.469088
end = 2025-02-04 03:50:33.934749
delta = 0:00:00.465661
msg = non-zero return code
invocation = {'module_args': {'_raw_params': 'show reboot-cause history', '_uses_shell': True, 'warn': False, 'stdin_add_newline': True, 'strip_empty_ends': True, 'argv': None, 'chdir': None, 'executable': None, 'creates': None, 'removes': None, 'stdin': None}}
_ansible_no_log = None
stdout =
stderr =
Traceback (most recent call last):
  File "/usr/local/bin/show", line 5, in <module>
    from show.main import cli
  File "/usr/local/lib/python3.11/dist-packages/show/main.py", line 325, in <module>
    if is_gearbox_configured():
       ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/show/main.py", line 265, in is_gearbox_configured
    app_db = SonicV2Connector()
             ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 2066, in __init__
    for db_name in self.get_db_list():
                   ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 2003, in get_db_list
    return _swsscommon.SonicV2Connector_Native_get_db_list(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Sonic database config file doesn't exist at /var/run/redis/sonic-db/database_config.json
```

Fixes # (issue)31217914

### Type of change

<!--
- Fill x for your type of change.
- e.g.
- [x] Bug fix
-->

- [ ] Bug fix
- [ ] Testbed and Framework(new/improvement)
- [ ] New Test case
    - [ ] Skipped for non-supported platforms
- [ ] Test case improvement

### Back port request
- [ ] 202012
- [ ] 202205
- [ ] 202305
- [ ] 202311
- [ ] 202405
- [ ] 202411

### Approach
#### What is the motivation for this PR?

Explained above

#### How did you do it?

Simply wait for database service is ready before executing the command

#### How did you verify/test it?

Verified on T2 testbed together with sonic-net#16772

![image](https://github.com/user-attachments/assets/60a385a7-6cd3-428d-82b6-991dbe3faa81)

#### Any platform specific information?

#### Supported testbed topology if it's a new test case?

### Documentation
<!--
(If it's a new feature, new test case)
Did you update documentation/Wiki relevant to your implementation?
Link to the wiki page?
-->
wangxin pushed a commit to wangxin/sonic-mgmt that referenced this pull request Feb 21, 2025
[action] [PR:16773] fix: fix show reboot-cause history error

Description of PR
Summary:

When executing show reboot-cause history, swss needs to access /var/run/redis/sonic-db/database_config.json we're dependent on the database service to boot up.

Without waiting for this service to boot up we might run into runtime error:

/usr/local/lib/python3.8/dist-packages/_pytest/main.py:305: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
Plugin: terminalreporter, Hook: pytest_sessionfinish
KeyboardInterrupt:
For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning
  config.hook.pytest_sessionfinish(
Traceback (most recent call last):
  File "/var/src/sonic-mgmt-int/tests/platform_tests/test_power_off_reboot.py", line 118, in test_power_off_reboot
    reboot_and_check(
  File "/var/src/sonic-mgmt-int/tests/platform_tests/test_reboot.py", line 86, in reboot_and_check
    reboot(dut, localhost, reboot_type=reboot_type,
  File "/var/src/sonic-mgmt-int/tests/common/plugins/loganalyzer/utils.py", line 24, in decorated
    res = func(*args, **kwargs)
  File "/var/src/sonic-mgmt-int/tests/common/reboot.py", line 341, in reboot
    curr_reboot_cause_history = duthost.show_and_parse("show reboot-cause history")
  File "/var/src/sonic-mgmt-int/tests/common/devices/multi_asic.py", line 136, in _run_on_asics
    return getattr(self.sonichost, self.multi_asic_attr)(*module_args, **complex_args)
  File "/var/src/sonic-mgmt-int/tests/common/devices/sonic.py", line 1687, in show_and_parse
    output = self.shell(show_cmd, **kwargs)["stdout_lines"]
  File "/var/src/sonic-mgmt-int/tests/common/devices/base.py", line 131, in _run
    raise RunAnsibleModuleFail("run module {} failed".format(self.module_name), res)
tests.common.errors.RunAnsibleModuleFail: run module shell failed, Ansible Results =>
failed = True
changed = True
rc = 1
cmd = show reboot-cause history
start = 2025-02-04 03:50:33.469088
end = 2025-02-04 03:50:33.934749
delta = 0:00:00.465661
msg = non-zero return code
invocation = {'module_args': {'_raw_params': 'show reboot-cause history', '_uses_shell': True, 'warn': False, 'stdin_add_newline': True, 'strip_empty_ends': True, 'argv': None, 'chdir': None, 'executable': None, 'creates': None, 'removes': None, 'stdin': None}}
_ansible_no_log = None
stdout =
stderr =
Traceback (most recent call last):
  File "/usr/local/bin/show", line 5, in <module>
    from show.main import cli
  File "/usr/local/lib/python3.11/dist-packages/show/main.py", line 325, in <module>
    if is_gearbox_configured():
       ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/show/main.py", line 265, in is_gearbox_configured
    app_db = SonicV2Connector()
             ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 2066, in __init__
    for db_name in self.get_db_list():
                   ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 2003, in get_db_list
    return _swsscommon.SonicV2Connector_Native_get_db_list(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Sonic database config file doesn't exist at /var/run/redis/sonic-db/database_config.json
Fixes # (issue)31217914

Approach
What is the motivation for this PR?
Explained above

How did you do it?
Simply wait for database service is ready before executing the command

How did you verify/test it?
Verified on T2 testbed together with sonic-net#16772

image
nnelluri-cisco pushed a commit to nnelluri-cisco/sonic-mgmt that referenced this pull request Mar 15, 2025
…rror (sonic-net#16772)

Description of PR
Summary:
Fixes sonic-net#16771


Approach
What is the motivation for this PR?
Prevent test failures due to KeyError when retrieving PDU["output_watts"]

How did you do it?
Use .get function to provide default value for PDUs that don't have output_watts as an attribute

How did you verify/test it?
Tested on T2 device with PDUs that don't provide output_watts (thanks @auspham)

Signed-off-by: Javier Tan [email protected]
nnelluri-cisco pushed a commit to nnelluri-cisco/sonic-mgmt that referenced this pull request Mar 15, 2025
Description of PR
Summary:

When executing show reboot-cause history, swss needs to access /var/run/redis/sonic-db/database_config.json we're dependent on the database service to boot up.

Without waiting for this service to boot up we might run into runtime error:

/usr/local/lib/python3.8/dist-packages/_pytest/main.py:305: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
Plugin: terminalreporter, Hook: pytest_sessionfinish
KeyboardInterrupt: 
For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning
  config.hook.pytest_sessionfinish(
Traceback (most recent call last):
  File "/var/src/sonic-mgmt-int/tests/platform_tests/test_power_off_reboot.py", line 118, in test_power_off_reboot
    reboot_and_check(
  File "/var/src/sonic-mgmt-int/tests/platform_tests/test_reboot.py", line 86, in reboot_and_check
    reboot(dut, localhost, reboot_type=reboot_type,
  File "/var/src/sonic-mgmt-int/tests/common/plugins/loganalyzer/utils.py", line 24, in decorated
    res = func(*args, **kwargs)
  File "/var/src/sonic-mgmt-int/tests/common/reboot.py", line 341, in reboot
    curr_reboot_cause_history = duthost.show_and_parse("show reboot-cause history")
  File "/var/src/sonic-mgmt-int/tests/common/devices/multi_asic.py", line 136, in _run_on_asics
    return getattr(self.sonichost, self.multi_asic_attr)(*module_args, **complex_args)
  File "/var/src/sonic-mgmt-int/tests/common/devices/sonic.py", line 1687, in show_and_parse
    output = self.shell(show_cmd, **kwargs)["stdout_lines"]
  File "/var/src/sonic-mgmt-int/tests/common/devices/base.py", line 131, in _run
    raise RunAnsibleModuleFail("run module {} failed".format(self.module_name), res)
tests.common.errors.RunAnsibleModuleFail: run module shell failed, Ansible Results =>
failed = True
changed = True
rc = 1
cmd = show reboot-cause history
start = 2025-02-04 03:50:33.469088
end = 2025-02-04 03:50:33.934749
delta = 0:00:00.465661
msg = non-zero return code
invocation = {'module_args': {'_raw_params': 'show reboot-cause history', '_uses_shell': True, 'warn': False, 'stdin_add_newline': True, 'strip_empty_ends': True, 'argv': None, 'chdir': None, 'executable': None, 'creates': None, 'removes': None, 'stdin': None}}
_ansible_no_log = None
stdout =
stderr =
Traceback (most recent call last):
  File "/usr/local/bin/show", line 5, in <module>
    from show.main import cli
  File "/usr/local/lib/python3.11/dist-packages/show/main.py", line 325, in <module>
    if is_gearbox_configured():
       ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/show/main.py", line 265, in is_gearbox_configured
    app_db = SonicV2Connector()
             ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 2066, in __init__
    for db_name in self.get_db_list():
                   ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 2003, in get_db_list
    return _swsscommon.SonicV2Connector_Native_get_db_list(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Sonic database config file doesn't exist at /var/run/redis/sonic-db/database_config.json
Fixes # (issue)31217914


Approach
What is the motivation for this PR?
Explained above

How did you do it?
Simply wait for database service is ready before executing the command

How did you verify/test it?
Verified on T2 testbed together with sonic-net#16772

image

Signed-off-by: Austin Pham <[email protected]>
@Javier-Tan Javier-Tan deleted the output_watts_changes branch June 27, 2025 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Not all PDUs return output_watts

4 participants