Skip to content
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

[config]config reload should generate sysinfo if missing #2778

Merged
merged 4 commits into from
May 1, 2023
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
13 changes: 13 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,19 @@ def reload(db, filename, yes, load_sysinfo, no_service_restart, force, file_form
click.echo("The config file {} doesn't exist".format(file))
continue

if file_format == 'config_db':
Copy link
Contributor

@qiluo-msft qiluo-msft Apr 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this feature already implement by argument load_sysinfo? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The purpose of the PR is to keep the CLI cmd identical for Golden Config reload.
From NDM team's knowledge, they don't have such info from their side.

file_input = read_json_file(file)

platform = file_input.get("DEVICE_METADATA", {}).\
get("localhost", {}).get("platform")
mac = file_input.get("DEVICE_METADATA", {}).\
get("localhost", {}).get("mac")

if not platform or not mac:
wen587 marked this conversation as resolved.
Show resolved Hide resolved
log.log_warning("Input file does't have platform or mac. platform: {}, mac: {}"
.format(None if platform is None else platform, None if mac is None else mac))
load_sysinfo = True

if load_sysinfo:
try:
command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, file)
Expand Down
61 changes: 60 additions & 1 deletion tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,66 @@ def setup_class(cls):
print("SETUP")
import config.main
importlib.reload(config.main)
open(cls.dummy_cfg_file, 'w').close()

def add_sysinfo_to_cfg_file(self):
with open(self.dummy_cfg_file, 'w') as f:
device_metadata = {
"DEVICE_METADATA": {
"localhost": {
"platform": "some_platform",
"mac": "02:42:f0:7f:01:05"
}
}
}
f.write(json.dumps(device_metadata))

def test_reload_config_invalid_input(self, get_cmd_module, setup_single_broadcom_asic):
open(self.dummy_cfg_file, 'w').close()
with mock.patch(
"utilities_common.cli.run_command",
mock.MagicMock(side_effect=mock_run_command_side_effect)
) as mock_run_command:
(config, show) = get_cmd_module
runner = CliRunner()

result = runner.invoke(
config.config.commands["reload"],
[self.dummy_cfg_file, '-y', '-f'])

print(result.exit_code)
print(result.output)
traceback.print_tb(result.exc_info[2])
assert result.exit_code != 0

def test_reload_config_no_sysinfo(self, get_cmd_module, setup_single_broadcom_asic):
with open(self.dummy_cfg_file, 'w') as f:
device_metadata = {
"DEVICE_METADATA": {
"localhost": {
"hwsku": "some_hwsku"
}
}
}
f.write(json.dumps(device_metadata))

with mock.patch(
"utilities_common.cli.run_command",
mock.MagicMock(side_effect=mock_run_command_side_effect)
) as mock_run_command:
(config, show) = get_cmd_module
runner = CliRunner()

result = runner.invoke(
config.config.commands["reload"],
[self.dummy_cfg_file, '-y', '-f'])

print(result.exit_code)
print(result.output)
traceback.print_tb(result.exc_info[2])
assert result.exit_code == 0

def test_reload_config(self, get_cmd_module, setup_single_broadcom_asic):
self.add_sysinfo_to_cfg_file()
with mock.patch(
"utilities_common.cli.run_command",
mock.MagicMock(side_effect=mock_run_command_side_effect)
Expand All @@ -466,6 +523,7 @@ def test_reload_config(self, get_cmd_module, setup_single_broadcom_asic):
== RELOAD_CONFIG_DB_OUTPUT

def test_config_reload_disabled_service(self, get_cmd_module, setup_single_broadcom_asic):
self.add_sysinfo_to_cfg_file()
with mock.patch(
"utilities_common.cli.run_command",
mock.MagicMock(side_effect=mock_run_command_side_effect_disabled_timer)
Expand All @@ -485,6 +543,7 @@ def test_config_reload_disabled_service(self, get_cmd_module, setup_single_broad
assert "\n".join([l.rstrip() for l in result.output.split('\n')]) == reload_config_with_disabled_service_output

def test_reload_config_masic(self, get_cmd_module, setup_multi_broadcom_masic):
self.add_sysinfo_to_cfg_file()
with mock.patch(
"utilities_common.cli.run_command",
mock.MagicMock(side_effect=mock_run_command_side_effect)
Expand Down