Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions sonic-chassisd/scripts/chassisd
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@ try:

from sonic_py_common import daemon_base, logger
from sonic_py_common.task_base import ProcessTaskBase
except ImportError as e:
raise ImportError (str(e) + " - required module not found")

try:
from swsscommon import swsscommon
# If unit testing is occurring, mock swsscommon and module_base
if os.environ["CHASSISD_UNIT_TESTING"] == "1":
from tests import mock_swsscommon as swsscommon
from tests.mock_module_base import ModuleBase
else:
from swsscommon import swsscommon
from sonic_platform_base.module_base import ModuleBase
except ImportError as e:
from tests import mock_swsscommon as swsscommon

try:
from sonic_platform_base.module_base import ModuleBase
except ImportError as e:
from tests.mock_module_base import ModuleBase
raise ImportError (str(e) + " - required module not found")

#
# Constants ====================================================================
Expand Down
10 changes: 7 additions & 3 deletions sonic-chassisd/tests/test_chassisd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
from imp import load_source

from mock import Mock, MagicMock, patch
from sonic_py_common import daemon_base
Expand All @@ -17,10 +18,7 @@
scripts_path = os.path.join(modules_path, "scripts")
sys.path.insert(0, modules_path)

from imp import load_source

load_source('chassisd', scripts_path + '/chassisd')
from chassisd import *

CHASSIS_MODULE_INFO_NAME_FIELD = 'name'
CHASSIS_MODULE_INFO_DESC_FIELD = 'desc'
Expand All @@ -31,13 +29,19 @@
CHASSIS_INFO_CARD_NUM_FIELD = 'module_num'

def setup_function():
os.environ["CHASSISD_UNIT_TESTING"] = "1"

load_source('chassisd', scripts_path + '/chassisd')
from chassisd import *

ModuleUpdater.log_notice = MagicMock()
ModuleUpdater.log_warning = MagicMock()


def teardown_function():
ModuleUpdater.log_notice.reset()
ModuleUpdater.log_warning.reset()
os.environ["CHASSISD_UNIT_TESTING"] = "0"


def test_moduleupdater_check_valid_fields():
Expand Down
10 changes: 6 additions & 4 deletions sonic-thermalctld/scripts/thermalctld
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ try:

from sonic_py_common import daemon_base, logger
from sonic_py_common.task_base import ProcessTaskBase

# If unit testing is occurring, mock swsscommon
if os.environ["THERMALCTLD_UNIT_TESTING"] == "1":
from tests import mock_swsscommon as swsscommon
else:
from swsscommon import swsscommon
except ImportError as e:
raise ImportError(repr(e) + " - required module not found")

try:
from swsscommon import swsscommon
except ImportError as e:
from tests import mock_swsscommon as swsscommon

SYSLOG_IDENTIFIER = 'thermalctld'
NOT_AVAILABLE = 'N/A'
Expand Down
11 changes: 7 additions & 4 deletions sonic-thermalctld/tests/test_thermalctld.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
from imp import load_source

from mock import Mock, MagicMock, patch
from sonic_py_common import daemon_base
Expand All @@ -16,14 +17,15 @@
scripts_path = os.path.join(modules_path, "scripts")
sys.path.insert(0, modules_path)

from imp import load_source

load_source('thermalctld', scripts_path + '/thermalctld')
from thermalctld import *

TEMPER_INFO_TABLE_NAME = 'TEMPERATURE_INFO'

def setup_function():
os.environ["THERMALCTLD_UNIT_TESTING"] = "1"

load_source('thermalctld', scripts_path + '/thermalctld')
from thermalctld import *

FanStatus.log_notice = MagicMock()
FanStatus.log_warning = MagicMock()
FanUpdater.log_notice = MagicMock()
Expand All @@ -43,6 +45,7 @@ def teardown_function():
TemperatureStatus.log_warning.reset()
TemperatureUpdater.log_warning.reset()
TemperatureUpdater.log_warning.reset()
os.environ["THERMALCTLD_UNIT_TESTING"] = "0"


def test_fanstatus_set_presence():
Expand Down