From a630d5d72f0d8aadd134f4d810a413263118c6a9 Mon Sep 17 00:00:00 2001 From: Stepan Blyschak Date: Wed, 9 Nov 2022 12:19:13 +0000 Subject: [PATCH 1/4] [config/show] Add command to control pending FIB suppression Signed-off-by: Stepan Blyschak --- config/main.py | 21 +++++++++++++++-- doc/Command-Reference.md | 37 ++++++++++++++++++++++++++++++ show/main.py | 11 +++++++++ tests/suppress_pending_fib_test.py | 34 +++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 tests/suppress_pending_fib_test.py diff --git a/config/main.py b/config/main.py index 20739fc932..020fd602d1 100644 --- a/config/main.py +++ b/config/main.py @@ -1792,7 +1792,7 @@ def load_minigraph(db, no_service_restart, traffic_shift_away, golden_config_pat cfggen_namespace_option = " -n {}".format(namespace) clicommon.run_command(db_migrator + ' -o set_version' + cfggen_namespace_option) - # Keep device isolated with TSA + # Keep device isolated with TSA if traffic_shift_away: clicommon.run_command("TSA", display_cmd=True) if golden_config_path or not golden_config_path and os.path.isfile(DEFAULT_GOLDEN_CONFIG_DB_FILE): @@ -1997,9 +1997,26 @@ def synchronous_mode(sync_mode): else: raise click.BadParameter("Error: Invalid argument %s, expect either enable or disable" % sync_mode) +# +# 'suppress-pending-fib' command ('config suppress-pending-fib ...') +# +@config.command('suppress-pending-fib') +@click.argument('state', metavar='', required=True) +@clicommon.pass_db +def suppress_pending_fib(db, state): + ''' Enable or disable pending FIB suppression. Once enabled, BGP will not advertise routes that are not yet installed in the hardware ''' + + if state not in ('enabled', 'disabled'): + raise click.BadParameter(f'Error: Invalid argument {state}, expect either enabled or disabled') + + config_db = db.cfgdb + sync_mode = config_db.get_entry('DEVICE_METADATA', 'localhost').get('synchronous_mode') + + config_db.mod_entry('DEVICE_METADATA' , 'localhost', {"suppress-pending-fib" : state}) + # # 'yang_config_validation' command ('config yang_config_validation ...') -# +# @config.command('yang_config_validation') @click.argument('yang_config_validation', metavar='', required=True) def yang_config_validation(yang_config_validation): diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 5f188e7a78..746f5d7c09 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -1987,6 +1987,25 @@ This command displays the routing policy that takes precedence over the other ro Exit routemap ``` +**show suppress-pending-fib** + +This command is used to show the status of suppress pending FIB feature. +When enabled, BGP will not advertise routes which aren't yet offloaded. + +- Usage: + ``` + show suppress-pending-fib + ``` + +- Examples: + ``` + admin@sonic:~$ show suppress-pending-fib + Enabled + ``` + ``` + admin@sonic:~$ show suppress-pending-fib + Disabled + ``` ### BGP config commands @@ -2078,6 +2097,24 @@ This command is used to remove particular IPv4 or IPv6 BGP neighbor configuratio admin@sonic:~$ sudo config bgp remove neighbor SONIC02SPINE ``` +**config suppress-pending-fib** + +This command is used to enable or disable announcements of routes not yet installed in the HW. +Once enabled, BGP will not advertise routes which aren't yet offloaded. + +- Usage: + ``` + config suppress-pending-fib + ``` + +- Examples: + ``` + admin@sonic:~$ sudo config suppress-pending-fib enabled + ``` + ``` + admin@sonic:~$ sudo config suppress-pending-fib enabled + ``` + Go Back To [Beginning of the document](#) or [Beginning of this section](#bgp) ## Console diff --git a/show/main.py b/show/main.py index 9c07d92080..602349b72b 100755 --- a/show/main.py +++ b/show/main.py @@ -2000,6 +2000,17 @@ def peer(db, peer_ip): click.echo(tabulate(bfd_body, bfd_headers)) +# 'suppress-pending-fib' subcommand ("show suppress-pending-fib") +@cli.command('suppress-pending-fib') +@clicommon.pass_db +def suppress_pending_fib(db): + """ Show the status of suppress pending FIB feature """ + + field_values = db.cfgdb.get_entry('DEVICE_METADATA', 'localhost') + state = field_values.get('suppress-pending-fib', 'disabled').title() + click.echo(state) + + # Load plugins and register them helper = util_base.UtilHelper() helper.load_and_register_plugins(plugins, cli) diff --git a/tests/suppress_pending_fib_test.py b/tests/suppress_pending_fib_test.py new file mode 100644 index 0000000000..1ce4126752 --- /dev/null +++ b/tests/suppress_pending_fib_test.py @@ -0,0 +1,34 @@ +from click.testing import CliRunner + +import config.main as config +import show.main as show +from utilities_common.db import Db + + +class TestSuppressFibPending: + def test_synchronous_mode(self): + runner = CliRunner() + + db = Db() + + result = runner.invoke(config.config.commands['suppress-pending-fib'], ['enabled'], obj=db) + print(result.output) + assert result.exit_code == 0 + assert db.cfgdb.get_entry('DEVICE_METADATA' , 'localhost')['suppress-pending-fib'] == 'enabled' + + result = runner.invoke(show.cli.commands['suppress-pending-fib'], obj=db) + assert result.exit_code == 0 + assert result.output == 'Enabled\n' + + result = runner.invoke(config.config.commands['suppress-pending-fib'], ['disabled'], obj=db) + print(result.output) + assert result.exit_code == 0 + assert db.cfgdb.get_entry('DEVICE_METADATA' , 'localhost')['suppress-pending-fib'] == 'disabled' + + result = runner.invoke(show.cli.commands['suppress-pending-fib'], obj=db) + assert result.exit_code == 0 + assert result.output == 'Disabled\n' + + result = runner.invoke(config.config.commands['suppress-pending-fib'], ['invalid-input'], obj=db) + print(result.output) + assert result.exit_code != 0 From 7e1462bb771c168445abb1c0ea144618c907f7ef Mon Sep 17 00:00:00 2001 From: Stepan Blyschak Date: Thu, 10 Nov 2022 11:50:58 +0000 Subject: [PATCH 2/4] use click.Choice Signed-off-by: Stepan Blyschak --- config/main.py | 7 +------ doc/Command-Reference.md | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/config/main.py b/config/main.py index 020fd602d1..2235776a38 100644 --- a/config/main.py +++ b/config/main.py @@ -2001,17 +2001,12 @@ def synchronous_mode(sync_mode): # 'suppress-pending-fib' command ('config suppress-pending-fib ...') # @config.command('suppress-pending-fib') -@click.argument('state', metavar='', required=True) +@click.argument('state', metavar='', required=True, type=click.Choice(['enabled', 'disabled'])) @clicommon.pass_db def suppress_pending_fib(db, state): ''' Enable or disable pending FIB suppression. Once enabled, BGP will not advertise routes that are not yet installed in the hardware ''' - if state not in ('enabled', 'disabled'): - raise click.BadParameter(f'Error: Invalid argument {state}, expect either enabled or disabled') - config_db = db.cfgdb - sync_mode = config_db.get_entry('DEVICE_METADATA', 'localhost').get('synchronous_mode') - config_db.mod_entry('DEVICE_METADATA' , 'localhost', {"suppress-pending-fib" : state}) # diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 746f5d7c09..d294117765 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -2112,7 +2112,7 @@ Once enabled, BGP will not advertise routes which aren't yet offloaded. admin@sonic:~$ sudo config suppress-pending-fib enabled ``` ``` - admin@sonic:~$ sudo config suppress-pending-fib enabled + admin@sonic:~$ sudo config suppress-pending-fib disabled ``` Go Back To [Beginning of the document](#) or [Beginning of this section](#bgp) From 6e50b20a9087ac37df0f80e261e671c8818c2d4d Mon Sep 17 00:00:00 2001 From: Stepan Blyshchak <38952541+stepanblyschak@users.noreply.github.com> Date: Fri, 11 Nov 2022 15:54:39 +0200 Subject: [PATCH 3/4] Update Command-Reference.md --- doc/Command-Reference.md | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 5dc32e5a4f..27dcede1b7 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -2007,7 +2007,6 @@ When enabled, BGP will not advertise routes which aren't yet offloaded. Disabled ``` - Go Back To [Beginning of the document](#) or [Beginning of this section](#bgp) ### BGP config commands From 33e3821cd5f2a26f17f44960380bddee81ab7d6f Mon Sep 17 00:00:00 2001 From: Stepan Blyschak Date: Fri, 25 Nov 2022 13:39:50 +0000 Subject: [PATCH 4/4] change field name Signed-off-by: Stepan Blyschak --- config/main.py | 6 +++--- doc/Command-Reference.md | 16 ++++++++-------- show/main.py | 6 +++--- tests/suppress_pending_fib_test.py | 14 +++++++------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/config/main.py b/config/main.py index 2235776a38..75b733b2af 100644 --- a/config/main.py +++ b/config/main.py @@ -1998,16 +1998,16 @@ def synchronous_mode(sync_mode): raise click.BadParameter("Error: Invalid argument %s, expect either enable or disable" % sync_mode) # -# 'suppress-pending-fib' command ('config suppress-pending-fib ...') +# 'suppress-fib-pending' command ('config suppress-fib-pending ...') # -@config.command('suppress-pending-fib') +@config.command('suppress-fib-pending') @click.argument('state', metavar='', required=True, type=click.Choice(['enabled', 'disabled'])) @clicommon.pass_db def suppress_pending_fib(db, state): ''' Enable or disable pending FIB suppression. Once enabled, BGP will not advertise routes that are not yet installed in the hardware ''' config_db = db.cfgdb - config_db.mod_entry('DEVICE_METADATA' , 'localhost', {"suppress-pending-fib" : state}) + config_db.mod_entry('DEVICE_METADATA' , 'localhost', {"suppress-fib-pending" : state}) # # 'yang_config_validation' command ('config yang_config_validation ...') diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index d294117765..75f5642c93 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -1987,23 +1987,23 @@ This command displays the routing policy that takes precedence over the other ro Exit routemap ``` -**show suppress-pending-fib** +**show suppress-fib-pending** This command is used to show the status of suppress pending FIB feature. When enabled, BGP will not advertise routes which aren't yet offloaded. - Usage: ``` - show suppress-pending-fib + show suppress-fib-pending ``` - Examples: ``` - admin@sonic:~$ show suppress-pending-fib + admin@sonic:~$ show suppress-fib-pending Enabled ``` ``` - admin@sonic:~$ show suppress-pending-fib + admin@sonic:~$ show suppress-fib-pending Disabled ``` @@ -2097,22 +2097,22 @@ This command is used to remove particular IPv4 or IPv6 BGP neighbor configuratio admin@sonic:~$ sudo config bgp remove neighbor SONIC02SPINE ``` -**config suppress-pending-fib** +**config suppress-fib-pending** This command is used to enable or disable announcements of routes not yet installed in the HW. Once enabled, BGP will not advertise routes which aren't yet offloaded. - Usage: ``` - config suppress-pending-fib + config suppress-fib-pending ``` - Examples: ``` - admin@sonic:~$ sudo config suppress-pending-fib enabled + admin@sonic:~$ sudo config suppress-fib-pending enabled ``` ``` - admin@sonic:~$ sudo config suppress-pending-fib disabled + admin@sonic:~$ sudo config suppress-fib-pending disabled ``` Go Back To [Beginning of the document](#) or [Beginning of this section](#bgp) diff --git a/show/main.py b/show/main.py index 602349b72b..3d4c9b48fe 100755 --- a/show/main.py +++ b/show/main.py @@ -2000,14 +2000,14 @@ def peer(db, peer_ip): click.echo(tabulate(bfd_body, bfd_headers)) -# 'suppress-pending-fib' subcommand ("show suppress-pending-fib") -@cli.command('suppress-pending-fib') +# 'suppress-fib-pending' subcommand ("show suppress-fib-pending") +@cli.command('suppress-fib-pending') @clicommon.pass_db def suppress_pending_fib(db): """ Show the status of suppress pending FIB feature """ field_values = db.cfgdb.get_entry('DEVICE_METADATA', 'localhost') - state = field_values.get('suppress-pending-fib', 'disabled').title() + state = field_values.get('suppress-fib-pending', 'disabled').title() click.echo(state) diff --git a/tests/suppress_pending_fib_test.py b/tests/suppress_pending_fib_test.py index 1ce4126752..04064d306e 100644 --- a/tests/suppress_pending_fib_test.py +++ b/tests/suppress_pending_fib_test.py @@ -11,24 +11,24 @@ def test_synchronous_mode(self): db = Db() - result = runner.invoke(config.config.commands['suppress-pending-fib'], ['enabled'], obj=db) + result = runner.invoke(config.config.commands['suppress-fib-pending'], ['enabled'], obj=db) print(result.output) assert result.exit_code == 0 - assert db.cfgdb.get_entry('DEVICE_METADATA' , 'localhost')['suppress-pending-fib'] == 'enabled' + assert db.cfgdb.get_entry('DEVICE_METADATA' , 'localhost')['suppress-fib-pending'] == 'enabled' - result = runner.invoke(show.cli.commands['suppress-pending-fib'], obj=db) + result = runner.invoke(show.cli.commands['suppress-fib-pending'], obj=db) assert result.exit_code == 0 assert result.output == 'Enabled\n' - result = runner.invoke(config.config.commands['suppress-pending-fib'], ['disabled'], obj=db) + result = runner.invoke(config.config.commands['suppress-fib-pending'], ['disabled'], obj=db) print(result.output) assert result.exit_code == 0 - assert db.cfgdb.get_entry('DEVICE_METADATA' , 'localhost')['suppress-pending-fib'] == 'disabled' + assert db.cfgdb.get_entry('DEVICE_METADATA' , 'localhost')['suppress-fib-pending'] == 'disabled' - result = runner.invoke(show.cli.commands['suppress-pending-fib'], obj=db) + result = runner.invoke(show.cli.commands['suppress-fib-pending'], obj=db) assert result.exit_code == 0 assert result.output == 'Disabled\n' - result = runner.invoke(config.config.commands['suppress-pending-fib'], ['invalid-input'], obj=db) + result = runner.invoke(config.config.commands['suppress-fib-pending'], ['invalid-input'], obj=db) print(result.output) assert result.exit_code != 0