Skip to content

Commit 8760bbe

Browse files
authored
Add UT to check sonic installer does not depend on database (sonic-net#2401)
### Description of PR Add new test cases to test sonic-installer does not depends on database docker. ### Type of change - [ ] Bug fix - [ ] Testbed and Framework(new/improvement) - [x] Test case(new/improvement) ### Back port request ### Approach #### What is the motivation for this PR? Add new test cases to test sonic-installer does not depends on database docker. #### How did you do it? Add new test case to cover user scenarios. #### How did you verify/test it? Run new UT make sure they are all pass. Make sure all current UT not break during merge validation. #### Any platform specific information? N/A #### Supported testbed topology if it's a new test case?.
1 parent 6bef652 commit 8760bbe

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/installer_dependency_test.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pytest
2+
import sonic_installer.main as sonic_installer
3+
import utilities_common.cli as clicommon
4+
5+
from click.testing import CliRunner
6+
from unittest import mock
7+
8+
# mock load_db_config to throw exception
9+
class MockSonicDBConfig:
10+
def load_sonic_db_config():
11+
raise RuntimeError("sonic installer 'list' command should not depends on database")
12+
13+
def load_sonic_global_db_config():
14+
raise RuntimeError("sonic installer 'list' command should not depends on database")
15+
16+
def isInit():
17+
return False
18+
19+
def isGlobalInit():
20+
return False
21+
22+
@mock.patch("swsscommon.swsscommon.SonicDBConfig", MockSonicDBConfig)
23+
def test_sonic_installer_not_depends_on_database_container():
24+
runner = CliRunner()
25+
result = runner.invoke(
26+
sonic_installer.sonic_installer.commands['list']
27+
)
28+
assert result.exit_code == 1
29+
30+
# check InterfaceAliasConverter will break by the mock method, sonic installer use it to load db config.
31+
exception_happen = False
32+
try:
33+
clicommon.InterfaceAliasConverter()
34+
except RuntimeError:
35+
exception_happen = True
36+
37+
assert exception_happen == True

0 commit comments

Comments
 (0)