Skip to content

Commit

Permalink
[thermalctld] [psud] [chassisd] Fix crash with undefined environment …
Browse files Browse the repository at this point in the history
…variable (#120)

When  `PSUD_UNIT_TESTING` and  `THERMALCTLD_UNIT_TESTING` variables don`t set we have the next problems:
```
 psud Traceback (most recent call last):
 psud File "/usr/local/bin/psud", line 21, in <module>
 psud if os.environ["PSUD_UNIT_TESTING"] == "1":
 psud File "/usr/lib/python2.7/UserDict.py", line 40, in __getitem__
 psud raise KeyError(key)
 psud KeyError: 'PSUD_UNIT_TESTING'
```

```
 thermalctld Traceback (most recent call last):
 thermalctld File "/usr/local/bin/thermalctld", line 19, in <module>
 thermalctld if os.environ["THERMALCTLD_UNIT_TESTING"] == "1":
 thermalctld File "/usr/lib/python2.7/UserDict.py", line 40, in __getitem__
 thermalctld raise KeyError(key)
 thermalctld KeyError: 'THERMALCTLD_UNIT_TESTING'
```

Also fixed the same issue in `chassisd`.

Signed-off-by: Petro Bratash <[email protected]>
  • Loading branch information
bratashX authored Nov 17, 2020
1 parent ef15ff5 commit f63ec30
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sonic-chassisd/scripts/chassisd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ try:
from sonic_py_common.task_base import ProcessTaskBase

# If unit testing is occurring, mock swsscommon and module_base
if os.environ["CHASSISD_UNIT_TESTING"] == "1":
if os.getenv("CHASSISD_UNIT_TESTING") == "1":
from tests import mock_swsscommon as swsscommon
from tests.mock_module_base import ModuleBase
else:
Expand Down
2 changes: 1 addition & 1 deletion sonic-psud/scripts/psud
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ try:
from sonic_py_common import daemon_base, logger

# If unit testing is occurring, mock swsscommon and module_base
if os.environ["PSUD_UNIT_TESTING"] == "1":
if os.getenv("PSUD_UNIT_TESTING") == "1":
from tests import mock_swsscommon as swsscommon
from tests.mock_device_base import DeviceBase
else:
Expand Down
2 changes: 1 addition & 1 deletion sonic-thermalctld/scripts/thermalctld
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ try:
from sonic_py_common.task_base import ProcessTaskBase

# If unit testing is occurring, mock swsscommon
if os.environ["THERMALCTLD_UNIT_TESTING"] == "1":
if os.getenv("THERMALCTLD_UNIT_TESTING") == "1":
from tests import mock_swsscommon as swsscommon
else:
from swsscommon import swsscommon
Expand Down

0 comments on commit f63ec30

Please sign in to comment.