forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[config load]: do not stop/reset/reload service if it is disabled (so…
…nic-net#1028) also introduce fixtures to setup the cmd as well as asic context Signed-off-by: Guohan Lu <lguohan@gmail.com>
- Loading branch information
Showing
5 changed files
with
209 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from click.testing import CliRunner | ||
|
||
load_minigraph_command_output="""\ | ||
Executing stop of service telemetry... | ||
Executing stop of service swss... | ||
Executing stop of service lldp... | ||
Executing stop of service pmon... | ||
Executing stop of service bgp... | ||
Executing stop of service hostcfgd... | ||
Executing stop of service nat... | ||
Running command: /usr/local/bin/sonic-cfggen -H -m --write-to-db | ||
Running command: pfcwd start_default | ||
Running command: config qos reload | ||
Executing reset-failed of service bgp... | ||
Executing reset-failed of service dhcp_relay... | ||
Executing reset-failed of service hostcfgd... | ||
Executing reset-failed of service hostname-config... | ||
Executing reset-failed of service interfaces-config... | ||
Executing reset-failed of service lldp... | ||
Executing reset-failed of service nat... | ||
Executing reset-failed of service ntp-config... | ||
Executing reset-failed of service pmon... | ||
Executing reset-failed of service radv... | ||
Executing reset-failed of service rsyslog-config... | ||
Executing reset-failed of service snmp... | ||
Executing reset-failed of service swss... | ||
Executing reset-failed of service syncd... | ||
Executing reset-failed of service teamd... | ||
Executing reset-failed of service telemetry... | ||
Executing restart of service hostname-config... | ||
Executing restart of service interfaces-config... | ||
Executing restart of service ntp-config... | ||
Executing restart of service rsyslog-config... | ||
Executing restart of service swss... | ||
Executing restart of service bgp... | ||
Executing restart of service pmon... | ||
Executing restart of service lldp... | ||
Executing restart of service hostcfgd... | ||
Executing restart of service nat... | ||
Executing restart of service telemetry... | ||
Please note setting loaded from minigraph will be lost after system reboot. To preserve setting, run `config save`. | ||
""" | ||
|
||
class TestLoadMinigraph(object): | ||
@classmethod | ||
def setup_class(cls): | ||
print("SETUP") | ||
|
||
def test_load_minigraph(self, get_cmd_module, setup_single_broacom_asic): | ||
(config, show) = get_cmd_module | ||
runner = CliRunner() | ||
result = runner.invoke(config.config.commands["load_minigraph"], ["-y"]) | ||
print result.exit_code | ||
print result.output | ||
assert result.exit_code == 0 | ||
assert "\n".join([ l.rstrip() for l in result.output.split('\n')]) == load_minigraph_command_output | ||
|
||
def test_load_minigraph_with_disabled_telemetry(self, get_cmd_module, setup_single_broacom_asic): | ||
(config, show) = get_cmd_module | ||
runner = CliRunner() | ||
runner.invoke(config.config.commands["feature"].commands["state"], ["telemetry", "disabled"]) | ||
result = runner.invoke(show.cli.commands["feature"].commands["status"], ["telemetry"]) | ||
print result.output | ||
result = runner.invoke(config.config.commands["load_minigraph"], ["-y"]) | ||
print result.exit_code | ||
print result.output | ||
assert result.exit_code == 0 | ||
assert "telemetry" not in result.output | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
print("TEARDOWN") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import os | ||
import sys | ||
|
||
import mock | ||
import click | ||
import pytest | ||
|
||
import mock_tables.dbconnector | ||
|
||
import sonic_device_util | ||
from swsssdk import ConfigDBConnector | ||
|
||
test_path = os.path.dirname(os.path.abspath(__file__)) | ||
modules_path = os.path.dirname(test_path) | ||
sys.path.insert(0, modules_path) | ||
|
||
generated_services_list = [ | ||
'ntp-config.service', | ||
'warmboot-finalizer.service', | ||
'watchdog-control.service', | ||
'rsyslog-config.service', | ||
'interfaces-config.service', | ||
'hostcfgd.service', | ||
'hostname-config.service', | ||
'topology.service', | ||
'updategraph.service', | ||
'config-setup.service', | ||
'caclmgrd.service', | ||
'procdockerstatsd.service', | ||
'pcie-check.service', | ||
'process-reboot-cause.service', | ||
'dhcp_relay.service', | ||
'snmp.service', | ||
'sflow.service', | ||
'bgp.service', | ||
'telemetry.service', | ||
'swss.service', | ||
'database.service', | ||
'database.service', | ||
'lldp.service', | ||
'lldp.service', | ||
'pmon.service', | ||
'radv.service', | ||
'mgmt-framework.service', | ||
'nat.service', | ||
'teamd.service', | ||
'syncd.service', | ||
'snmp.timer', | ||
'telemetry.timer'] | ||
|
||
|
||
def _dummy_run_command(command, display_cmd=False, return_cmd=False): | ||
if display_cmd == True: | ||
click.echo(click.style("Running command: ", fg='cyan') + click.style(command, fg='green')) | ||
|
||
@pytest.fixture | ||
def get_cmd_module(): | ||
import config.main as config | ||
import show.main as show | ||
|
||
config_db = ConfigDBConnector() | ||
config_db.connect() | ||
|
||
config.config_db = config_db | ||
show.config_db = config_db | ||
|
||
config.run_command = _dummy_run_command | ||
|
||
return (config, show) | ||
|
||
@pytest.fixture | ||
def setup_single_broacom_asic(): | ||
import config.main as config | ||
import show.main as show | ||
|
||
sonic_device_util.get_num_npus = mock.MagicMock(return_value = 1) | ||
config._get_sonic_generated_services = \ | ||
mock.MagicMock(return_value = (generated_services_list, [])) | ||
|
||
config.asic_type = mock.MagicMock(return_value = "broadcom") | ||
config._get_device_type = mock.MagicMock(return_value = "ToRRouter") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters