-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sonic-cfggen] Allow cfggen to work on system without ports #7999
Changes from all commits
dd95237
e662e65
db76a6f
fd1f5ce
668db75
95abadd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -317,7 +317,7 @@ def main(): | |
if args.port_config is None: | ||
args.port_config = device_info.get_path_to_port_config_file(hwsku) | ||
(ports, _, _) = get_port_config(hwsku, platform, args.port_config, asic_id) | ||
if not ports: | ||
if ports is None: | ||
print('Failed to get port config', file=sys.stderr) | ||
sys.exit(1) | ||
deep_update(data, {'PORT': ports}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @qiluo-msft The code I deleted, verified both conditions:
Since now (in modular chassis without linecards), ports dictionary can be empty, we just need to verify it is not None. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,17 @@ | |
import json | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
import tests.common_utils as utils | ||
|
||
from unittest import TestCase | ||
from portconfig import get_port_config, INTF_KEY | ||
|
||
if sys.version_info.major == 3: | ||
from unittest import mock | ||
else: | ||
import mock | ||
|
||
# Global Variable | ||
PLATFORM_OUTPUT_FILE = "platform_output.json" | ||
|
@@ -85,3 +91,10 @@ def test_platform_json_all_ethernet_interfaces(self): | |
output_dict = ast.literal_eval(output.strip()) | ||
expected = ast.literal_eval(json.dumps(fh_data)) | ||
self.assertDictEqual(output_dict, expected) | ||
|
||
@mock.patch('portconfig.readJson', mock.MagicMock(return_value={INTF_KEY:{}})) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure what this file is? Can you please elaborate? Additionally, can you confirm if the format readJson is correct? |
||
@mock.patch('os.path.isfile', mock.MagicMock(return_value=True)) | ||
def test_platform_json_no_interfaces(self): | ||
(ports, _, _) = get_port_config(port_config_file=self.platform_json) | ||
self.assertNotEqual(ports, None) | ||
self.assertEqual(ports, {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a new feature or significant fix. Could you add new testcase to protect it? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still applicable. Could you help add a positive testcase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qiluo-msft
While I implemented the unittest I noticed a bug.
I handled the flow of reading the ports from port_config.ini but not the flow of reading the ports from platrfom.json+hwsku.json. Now it is fixed and I added unittest as well.
Appreciate your review.