Skip to content

Commit

Permalink
Add UT to check sonic installer does not depend on database (sonic-ne…
Browse files Browse the repository at this point in the history
…t#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?.
  • Loading branch information
liuh-80 authored Sep 29, 2022
1 parent 6bef652 commit 8760bbe
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/installer_dependency_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pytest
import sonic_installer.main as sonic_installer
import utilities_common.cli as clicommon

from click.testing import CliRunner
from unittest import mock

# mock load_db_config to throw exception
class MockSonicDBConfig:
def load_sonic_db_config():
raise RuntimeError("sonic installer 'list' command should not depends on database")

def load_sonic_global_db_config():
raise RuntimeError("sonic installer 'list' command should not depends on database")

def isInit():
return False

def isGlobalInit():
return False

@mock.patch("swsscommon.swsscommon.SonicDBConfig", MockSonicDBConfig)
def test_sonic_installer_not_depends_on_database_container():
runner = CliRunner()
result = runner.invoke(
sonic_installer.sonic_installer.commands['list']
)
assert result.exit_code == 1

# check InterfaceAliasConverter will break by the mock method, sonic installer use it to load db config.
exception_happen = False
try:
clicommon.InterfaceAliasConverter()
except RuntimeError:
exception_happen = True

assert exception_happen == True

0 comments on commit 8760bbe

Please sign in to comment.