[sonic-utilities-tests/config_mgmt_test.py]: Unit Tests for config_mg… #947
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…mt.py library.
Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com
This is a dummy PR just for better description. Committed in [https://github.com//pull/765/commits/77e3734c66339f5b92be560c10f4d8a291ccb7e7]
Depend on #765.
Depend on sonic-net/sonic-buildimage#4798.
- What I did
Write Unit tests for Config_mgmt library introduced in PR #765.
- How I did it
Key Decisions:
-- Config_mgmt interaction with Redis DB:
These tests will be executed at build time, the entire interaction with Redis DB is mocked using:
import mock_tables.dbconnector
This mocks below classes used in config_mgmt
from swsssdk import ConfigDBConnector, SonicV2Connector, port_util
-- Mock sonic_yang or not:
Most of the functions in config_mgmt calls APIs from sonic_yang_mgmt (https://github.com/Azure/sonic-buildimage/tree/master/src/sonic-yang-mgmt) library. It is important to catch any compatibility issues during build time rather than run time. So it is decided not to mock sonic_yang but use real instance. Due to this sonic_utilities will have a build time dependency on sonic_yang_mgmt.
-- Unit Test each function or the functions exposed to caller:
1. To unit test each function, we need to mock sonic_yang, which is against the previous decision.
2. Also calling the functions which are exposed to the caller is sufficient to unit test all functions. Because functions like breakOutPort internally call every function in the library, and the expected result is not produced if internal functions are not working properly.
3. In the real scenario, the caller will use this library for config validation and to break out the port in a continuous manner. To emulate a real scenario it is decided to exercise only the functions exposed to the caller.
Check Result:
-- How to check expected result for breakout Command:
1. A successful call to breakOutPort API results in a call to writeConfigDB API twice.
One time with config to be deleted and second time with config to be added. Both calls are necessary and should be done in order. This is tested by mocking writeConfigDB API as below:
Then we can check result as below:
Note: it is important to check that both calls are done, rather than just checking final config.
Tests:
-- Create the configMgmt Class object and validate config.
-- Have a table without yang model in config, Check if this table is returned by tablesWithoutYang()
-- Test configWithKeys() to search ports in the config.
-- Important Test case, Test below sequence for port breakout:
Note: this is important to do this sequence in one test case, because it is good to test with continuous change in Config. Also this way, a new configuration for each test is not needed.
Expected Result:
All automated tests should pass.
Each breakout test is checked for expected result as below:
Have a hard coded value of expected dConfig and aConfig, where
dConfig: Config to be deleted.
aConfig: Config to be deleted.
And check if writeConfigDB is called using the above configurations.
Example:
Actual Result:
- How to verify it
Actual Result:
- Previous command output (if the output of a command-line utility has changed)
- New command output (if the output of a command-line utility has changed)