Skip to content

Commit

Permalink
Add CLI for configuring synchronous mode (sonic-net#1094)
Browse files Browse the repository at this point in the history
* Add CLI for configuring synchronous mode

* Integrate switch for sync mode as a config CLI

* Add unit test
  • Loading branch information
shi-su authored Sep 23, 2020
1 parent faba418 commit e26aeed
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
25 changes: 25 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,31 @@ def hostname(new_hostname):
raise
click.echo("Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`.")

#
# 'synchronous_mode' command ('config synchronous_mode ...')
#
@config.command('synchronous_mode')
@click.argument('sync_mode', metavar='<enable|disable>', required=True)
def synchronous_mode(sync_mode):
""" Enable or disable synchronous mode between orchagent and syncd \n
swss restart required to apply the configuration \n
Options to restart swss and apply the configuration: \n
1. config save -y \n
config reload -y \n
2. systemctl restart swss
"""

if sync_mode == 'enable' or sync_mode == 'disable':
config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry('DEVICE_METADATA' , 'localhost', {"synchronous_mode" : sync_mode})
click.echo("""Wrote %s synchronous mode into CONFIG_DB, swss restart required to apply the configuration: \n
Option 1. config save -y \n
config reload -y \n
Option 2. systemctl restart swss""" % sync_mode)
else:
raise click.BadParameter("Error: Invalid argument %s, expect either enable or disable" % sync_mode)

#
# 'portchannel' group ('config portchannel ...')
#
Expand Down
37 changes: 37 additions & 0 deletions tests/synchronous_mode_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from click.testing import CliRunner
import config.main as config

class TestSynchronousMode(object):
@classmethod
def setup_class(cls):
print("SETUP")

def __check_result(self, result_msg, mode):
if mode == "enable" or mode == "disable":
expected_msg = """Wrote %s synchronous mode into CONFIG_DB, swss restart required to apply the configuration: \n
Option 1. config save -y \n
config reload -y \n
Option 2. systemctl restart swss""" % mode
else:
expected_msg = "Error: Invalid argument %s, expect either enable or disable" % mode

return expected_msg in result_msg


def test_synchronous_mode(self):
runner = CliRunner()

result = runner.invoke(config.config.commands["synchronous_mode"], ["enable"])
print(result.output)
assert result.exit_code == 0
assert self.__check_result(result.output, "enable")

result = runner.invoke(config.config.commands["synchronous_mode"], ["disable"])
print(result.output)
assert result.exit_code == 0
assert self.__check_result(result.output, "disable")

result = runner.invoke(config.config.commands["synchronous_mode"], ["invalid-input"])
print(result.output)
assert result.exit_code != 0
assert self.__check_result(result.output, "invalid-input")

0 comments on commit e26aeed

Please sign in to comment.