def test_nvgre_tunnel_add_invalid(self): db = Db() runner = CliRunner() # add result = runner.invoke( config.config.commands["nvgre-tunnel"].commands["add"], ["tunnel_1", "--src-ip", INVALID_VALUE], obj=db) logger.debug("\n" + result.output) logger.debug(result.exit_code) assert result.exit_code == ERROR # verify self.verify_output(db, runner, "nvgre-tunnel", assert_show_output.show_nvgre_tunnel_empty)
def test_nvgre_tunnel_map_add_invalid_vlan(self): db = Db() runner = CliRunner() # add result = runner.invoke( config.config.commands["nvgre-tunnel-map"].commands["add"], ["tunnel_1", "Vlan5000", "--vlan-id", "5000", "--vsid", "5000"], obj=db) logger.debug("\n" + result.output) logger.debug(result.exit_code) assert result.exit_code == ERROR # verify self.verify_output(db, runner, "nvgre-tunnel-map", assert_show_output.show_nvgre_tunnel_map_empty)
def test_config_pbh_hash_field_add_none_ip_mask( self, hash_field_name, hash_field, ): db = Db() runner = CliRunner() result = runner.invoke( config.config.commands["pbh"].commands["hash-field"]. commands["add"], [hash_field_name, "--hash-field", hash_field, "--sequence-id", "2"], obj=db ) logger.debug("\n" + result.output) logger.debug(result.exit_code) assert result.exit_code == ERROR
def test_config_pbh_rule_add_invalid_flow_counter(self): dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'rule') db = Db() runner = CliRunner() result = runner.invoke( config.config.commands["pbh"].commands["rule"]. commands["add"], ["pbh_table1", "vxlan ", "--priority", "2", "--ip-protocol", "0x11", "--inner-ether-type", "0x0800", "--l4-dst-port", "0x12b5", "--hash", "inner_v6_hash", "--packet-action", "SET_ECMP_HASH", "--flow-counter", INVALID_VALUE], obj=db ) logger.debug("\n" + result.output) logger.debug(result.exit_code) assert result.exit_code == ERROR2
def test_config_snmp_feature_fallback(self, get_cmd_module): (config, show) = get_cmd_module db = Db() runner = CliRunner() result = runner.invoke( config.config.commands["feature"].commands["fallback"], ["snmp", "off"], obj=db) print(result.exit_code) print(result.output) assert result.exit_code == 0 result = runner.invoke(show.cli.commands["feature"].commands["config"], ["snmp"], obj=db) print(result.output) assert result.exit_code == 0 assert result.output == show_feature_snmp_config_fallback_output
def test_config_bgp_autorestart(self, get_cmd_module): (config, show) = get_cmd_module db = Db() runner = CliRunner() result = runner.invoke( config.config.commands["feature"].commands["autorestart"], ["bgp", "disabled"], obj=db) print(result.exit_code) print(result.output) assert result.exit_code == 0 result = runner.invoke( show.cli.commands["feature"].commands["autorestart"], ["bgp"], obj=db) print(result.output) assert result.exit_code == 0 assert result.output == show_feature_bgp_disabled_autorestart_output
def test_config_device_metadata(self): dbconnector.dedicated_dbs['CONFIG_DB'] = mock_db_path db = Db() runner = CliRunner() result = runner.invoke( config_main.config.commands['device-metadata'].commands['localhost'].commands['buffer-model'], ['dynamic'], obj=db ) result = runner.invoke( show_main.cli.commands['device-metadata'].commands['localhost'], [], obj=db ) logger.debug("\n" + result.output) logger.debug(result.exit_code) assert result.exit_code == SUCCESS assert result.output == show_cmd_output.show_device_metadata_localhost_changed_buffer_model
def test_config_loopback_action_on_subinterface(self): runner = CliRunner() db = Db() obj = {'config_db': db.cfgdb} action = 'forward' iface = 'Ethernet0.10' result = runner.invoke(config.config.commands['interface']. commands["ip"].commands['loopback-action'], [iface, action], obj=obj) table = db.cfgdb.get_table('VLAN_SUB_INTERFACE') assert (table[iface]['loopback_action'] == action) print(result.exit_code, result.output) assert result.exit_code == 0
def test_config_loopback_action_on_port_channel_interface(self): runner = CliRunner() db = Db() obj = {'config_db': db.cfgdb} action = 'forward' iface = 'PortChannel0002' result = runner.invoke(config.config.commands['interface']. commands["ip"].commands['loopback-action'], [iface, action], obj=obj) table = db.cfgdb.get_table('PORTCHANNEL_INTERFACE') assert (table[iface]['loopback_action'] == action) print(result.exit_code, result.output) assert result.exit_code == 0
def test_pfcwd_start_ports_invalid(self): # pfcwd start --action drop --restoration-time 200 Ethernet0 200 import pfcwd.main as pfcwd runner = CliRunner() db = Db() result = runner.invoke( pfcwd.cli.commands["start"], [ "--action", "forward", "--restoration-time", "101", "Ethernet1000", "102" ], obj=db ) print(result.output) assert result.exit_code == 0 assert result.output == pfcwd_show_start_config_output_fail
def test_show_pbh_statistics_on_empty_config(self): dbconnector.dedicated_dbs['CONFIG_DB'] = None dbconnector.dedicated_dbs['COUNTERS_DB'] = None self.remove_pbh_counters_file() db = Db() runner = CliRunner() result = runner.invoke(show.cli.commands["pbh"].commands["statistics"], [], obj=db) logger.debug("\n" + result.output) logger.debug(result.exit_code) assert result.exit_code == SUCCESS assert result.output == assert_show_output.show_pbh_statistics_empty
def test_config_vlan_proxy_arp_with_nonexist_vlan_intf_table(self): modes = ["enabled", "disabled"] runner = CliRunner() db = Db() db.cfgdb.delete_table("VLAN_INTERFACE") for mode in modes: result = runner.invoke( config.config.commands["vlan"].commands["proxy_arp"], ["1000", mode], obj=db) print(result.exit_code) print(result.output) assert result.exit_code != 0 assert "Interface Vlan1000 does not exist" in result.output
def test_config_add_del_vlan_and_vlan_member_in_alias_mode(self): runner = CliRunner() db = Db() os.environ['SONIC_CLI_IFACE_MODE'] = "alias" # add vlan 1001 result = runner.invoke(config.config.commands["vlan"].commands["add"], ["1001"], obj=db) print(result.exit_code) print(result.output) assert result.exit_code == 0 # add etp6 to vlan 1001 result = runner.invoke(config.config.commands["vlan"].commands["member"].commands["add"], ["1001", "etp6", "--untagged"], obj=db) print(result.exit_code) print(result.output) traceback.print_tb(result.exc_info[2]) assert result.exit_code == 0 # show output result = runner.invoke(show.cli.commands["vlan"].commands["brief"], [], obj=db) print(result.output) assert result.output == config_add_del_vlan_and_vlan_member_in_alias_mode_output # remove vlan member result = runner.invoke(config.config.commands["vlan"].commands["member"].commands["del"], ["1001", "etp6"], obj=db) print(result.exit_code) print(result.output) assert result.exit_code == 0 # add del 1001 result = runner.invoke(config.config.commands["vlan"].commands["del"], ["1001"], obj=db) print(result.exit_code) print(result.output) assert result.exit_code == 0 # show output result = runner.invoke(show.cli.commands["vlan"].commands["brief"], [], obj=db) print(result.exit_code) print(result.output) assert result.exit_code == 0 assert result.output == show_vlan_brief_in_alias_mode_output os.environ['SONIC_CLI_IFACE_MODE'] = ""
def test_config_pbh_table_add_invalid_port(self): dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join( mock_db_path, 'table') db = Db() runner = CliRunner() result = runner.invoke( config.config.commands["pbh"].commands["table"].commands["add"], [ "pbh_table3", "--interface-list", INVALID_VALUE, "--description", "VxLAN adn NVGRE" ], obj=db) logger.debug("\n" + result.output) logger.debug(result.exit_code) assert result.exit_code == ERROR2
def test_init_config_feature_migration(self): dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join( mock_db_path, 'config_db', 'feature-input') import db_migrator dbmgtr = db_migrator.DBMigrator(None) dbmgtr.migrate() dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join( mock_db_path, 'config_db', 'feature-expected') expected_db = Db() resulting_table = dbmgtr.configDB.get_table('FEATURE') expected_table = expected_db.cfgdb.get_table('FEATURE') diff = DeepDiff(resulting_table, expected_table, ignore_order=True) assert not diff assert not expected_db.cfgdb.get_table('CONTAINER_FEATURE')
def test_modify_mclag_domain(self): runner = CliRunner() db = Db() obj = {'db':db.cfgdb} # add mclag domain entry in db db.cfgdb.set_entry("MCLAG_DOMAIN", MCLAG_DOMAIN_ID, {"source_ip": MCLAG_SRC_IP}) result = runner.invoke(config.config.commands["mclag"].commands["add"], [MCLAG_DOMAIN_ID, MCLAG_SRC_IP, MCLAG_PEER_IP, MCLAG_PEER_LINK], obj=obj) assert result.exit_code != 0, "mclag add domain peer ip test caase with code {}:{} Output:{}".format(type(result.exit_code), result.exit_code, result.output) assert self.verify_mclag_domain_cfg(db, MCLAG_DOMAIN_ID, MCLAG_SRC_IP, MCLAG_PEER_IP, MCLAG_PEER_LINK) == True, "mclag config not found" # modify mclag config result = runner.invoke(config.config.commands["mclag"].commands["add"], [MCLAG_DOMAIN_ID, MCLAG_SRC_IP, MCLAG_PEER_IP, MCLAG_PEER_LINK], obj=obj) assert result.exit_code != 0, "test_mclag_domain_add_again with code {}:{} Output:{}".format(type(result.exit_code), result.exit_code, result.output) assert self.verify_mclag_domain_cfg(db, MCLAG_DOMAIN_ID, MCLAG_SRC_IP, MCLAG_PEER_IP, MCLAG_PEER_LINK2) == True, "mclag config not modified"
def test_show(self): runner = CliRunner() db = Db() db.cfgdb.set_entry("CONSOLE_PORT", 1, { "remote_device" : "switch1", "baud_rate" : "9600" }) db.cfgdb.set_entry("CONSOLE_PORT", 2, { "remote_device" : "switch2", "baud_rate" : "9600" }) db.cfgdb.set_entry("CONSOLE_PORT", 3, { "baud_rate" : "9600" }) db.db.set(db.db.STATE_DB, "CONSOLE_PORT|2", "state", "busy") db.db.set(db.db.STATE_DB, "CONSOLE_PORT|2", "pid", "223") db.db.set(db.db.STATE_DB, "CONSOLE_PORT|2", "start_time", "Wed Mar 6 08:31:35 2019") # use '--brief' option to avoid access system result = runner.invoke(consutil.consutil.commands["show"], ['--brief'], obj=db) print(result.exit_code) print(sys.stderr, result.output) assert result.exit_code == 0 assert result.output == TestConsutilShow.expect_show_output
def test_config_vlan_add_portchannel_member(self): runner = CliRunner() db = Db() result = runner.invoke(config.config.commands["vlan"].commands["member"].commands["add"], \ ["1000", "PortChannel1001", "--untagged"], obj=db) print(result.exit_code) print(result.output) assert result.exit_code == 0 # show output result = runner.invoke(show.cli.commands["vlan"].commands["brief"], [], obj=db) print(result.exit_code) print(result.output) assert result.exit_code == 0 assert result.output == show_vlan_brief_with_portchannel_output
def test_fail_autorestart(self, get_cmd_module): (config, show) = get_cmd_module runner = CliRunner() db = Db() # Try setting auto restart for non-existing feature result = runner.invoke(config.config.commands["feature"].commands["autorestart"], ["foo", "disabled"]) print(result.exit_code) assert result.exit_code == 1 # Delete Feature table db.cfgdb.delete_table("FEATURE") # Try setting auto restart when no FEATURE table result = runner.invoke(config.config.commands["feature"].commands["autorestart"], ["bgp", "disabled"], obj=db) print(result.exit_code) assert result.exit_code == 1
def test_vrf_static_route(self): db = Db() runner = CliRunner() obj = {'config_db':db.cfgdb} # config route add prefix vrf Vrf-BLUE 2.2.3.4/32 nexthop 30.0.0.6 result = runner.invoke(config.config.commands["route"].commands["add"], \ ["prefix", "vrf", "Vrf-BLUE", "2.2.3.4/32", "nexthop", "30.0.0.6"], obj=obj) print(result.exit_code, result.output) assert ('Vrf-BLUE', '2.2.3.4/32') in db.cfgdb.get_table('STATIC_ROUTE') assert db.cfgdb.get_entry('STATIC_ROUTE', 'Vrf-BLUE|2.2.3.4/32') == {'nexthop': '30.0.0.6', 'blackhole': 'false', 'distance': '0', 'ifname': '', 'nexthop-vrf': ''} # config route del prefix vrf Vrf-BLUE 2.2.3.4/32 nexthop 30.0.0.6 result = runner.invoke(config.config.commands["route"].commands["del"], \ ["prefix", "vrf", "Vrf-BLUE", "2.2.3.4/32", "nexthop", "30.0.0.6"], obj=obj) print(result.exit_code, result.output) assert not ('Vrf-BLUE', '2.2.3.4/32') in db.cfgdb.get_table('STATIC_ROUTE')
def test_config_pbh_table_add_port_and_portchannel(self): dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join( mock_db_path, 'table') db = Db() runner = CliRunner() result = runner.invoke( config.config.commands["pbh"].commands["table"].commands["add"], [ "pbh_table3", "--interface-list", "PortChannel0002,Ethernet8", "--description", "VxLAN adn NVGRE" ], obj=db) logger.debug("\n" + result.output) logger.debug(result.exit_code) assert result.exit_code == SUCCESS
def test_lacp_key_migrator(self): dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join( mock_db_path, 'config_db', 'portchannel-input') import db_migrator dbmgtr = db_migrator.DBMigrator(None) dbmgtr.migrate() dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join( mock_db_path, 'config_db', 'portchannel-expected') expected_db = Db() advance_version_for_expected_database(dbmgtr.configDB, expected_db.cfgdb, 'version_2_0_2') assert dbmgtr.configDB.get_table( 'PORTCHANNEL') == expected_db.cfgdb.get_table('PORTCHANNEL') assert dbmgtr.configDB.get_table( 'VERSIONS') == expected_db.cfgdb.get_table('VERSIONS')
def test_config_snmp_location_modify_with_same_location(self): db = Db() runner = CliRunner() with mock.patch('utilities_common.cli.run_command') as mock_run_command: result = runner.invoke(config.config.commands["snmp"].commands["location"].commands["add"], ["public"], obj=db) print(result.exit_code) print(result.output) assert result.exit_code == 0 assert result.output == config_snmp_location_add_new_location assert db.cfgdb.get_entry("SNMP", "LOCATION") == {"Location": "public"} result = runner.invoke(config.config.commands["snmp"].commands["location"].commands["modify"], ["public"], obj=db) print(result.exit_code) assert result.exit_code == 1 assert 'SNMP location public already exists' in result.output
def test_config_snmp_location_del_new_location_with_location_already_existing(self): db = Db() runner = CliRunner() with mock.patch('utilities_common.cli.run_command') as mock_run_command: result = runner.invoke(config.config.commands["snmp"].commands["location"].commands["add"], ["public"], obj=db) print(result.exit_code) print(result.output) assert result.exit_code == 0 assert result.output == config_snmp_location_add_new_location assert db.cfgdb.get_entry("SNMP", "LOCATION") == {"Location": "public"} result = runner.invoke(config.config.commands["snmp"].commands["location"].commands["del"], ["Mile High"], obj=db) print(result.exit_code) assert result.exit_code == 1 assert 'SNMP Location Mile High does not exist. The location is public' in result.output
def test_config_snmp_contact_modify_new_contact_with_invalid_email(self): db = Db() runner = CliRunner() with mock.patch('utilities_common.cli.run_command') as mock_run_command: result = runner.invoke(config.config.commands["snmp"].commands["contact"].commands["add"], ["testuser", "*****@*****.**"], obj=db) print(result.exit_code) print(result.output) assert result.exit_code == 0 assert result.output == config_snmp_contact_add_del_new_contact assert db.cfgdb.get_entry("SNMP", "CONTACT") == {"testuser": "******"} result = runner.invoke(config.config.commands["snmp"].commands["contact"].commands["modify"], ["blah", "blah@contoso@com"], obj=db) print(result.exit_code) assert result.exit_code == 2 assert 'Contact email blah@contoso@com is not valid' in result.output
def test_config_snmp_contact_modify_contact_and_email_with_existing_entry(self): db = Db() runner = CliRunner() with mock.patch('utilities_common.cli.run_command') as mock_run_command: result = runner.invoke(config.config.commands["snmp"].commands["contact"].commands["add"], ["testuser", "*****@*****.**"], obj=db) print(result.exit_code) print(result.output) assert result.exit_code == 0 assert result.output == config_snmp_contact_add_del_new_contact assert db.cfgdb.get_entry("SNMP", "CONTACT") == {"testuser": "******"} result = runner.invoke(config.config.commands["snmp"].commands["contact"].commands["modify"], ["testuser", "*****@*****.**"], obj=db) print(result.exit_code) assert result.exit_code == 1 assert 'SNMP contact testuser [email protected] already exists' in result.output
def test_show_pbh_statistics_after_rule_toggle(self): dbconnector.dedicated_dbs['COUNTERS_DB'] = os.path.join( mock_db_path, 'counters_db') dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join( mock_db_path, 'full_pbh_config') self.remove_pbh_counters_file() db = Db() runner = CliRunner() result = runner.invoke( clear.cli.commands["pbh"].commands["statistics"], [], obj=db) logger.debug("\n" + result.output) logger.debug(result.exit_code) result = runner.invoke( config.config.commands["pbh"].commands["rule"].commands["delete"], ["pbh_table2", "vxlan"], obj=db) logger.debug("\n" + result.output) logger.debug(result.exit_code) result = runner.invoke( config.config.commands["pbh"].commands["rule"].commands["add"], [ "pbh_table2", "vxlan", "--priority", "2", "--ip-protocol", "0x11", "--inner-ether-type", "0x0800", "--l4-dst-port", "0x12b5", "--hash", "inner_v4_hash", "--packet-action", "SET_LAG_HASH", "--flow-counter", "ENABLED" ], obj=db) logger.debug("\n" + result.output) logger.debug(result.exit_code) result = runner.invoke(show.cli.commands["pbh"].commands["statistics"], [], obj=db) logger.debug("\n" + result.output) logger.debug(result.exit_code) assert result.exit_code == SUCCESS assert result.output == assert_show_output.show_pbh_statistics_after_toggling_rule
def test_show_pbh_statistics_after_flow_counter_toggle(self): dbconnector.dedicated_dbs['COUNTERS_DB'] = os.path.join( mock_db_path, 'counters_db') dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join( mock_db_path, 'full_pbh_config') dbconnector.dedicated_dbs['STATE_DB'] = os.path.join( mock_db_path, 'state_db') self.remove_pbh_counters_file() db = Db() runner = CliRunner() result = runner.invoke( clear.cli.commands["pbh"].commands["statistics"], [], obj=db) logger.debug("\n" + result.output) logger.debug(result.exit_code) result = runner.invoke( config.config.commands["pbh"].commands["rule"].commands["update"]. commands["field"].commands["set"], ["pbh_table1", "nvgre", "--flow-counter", "DISABLED"], obj=db) logger.debug("\n" + result.output) logger.debug(result.exit_code) result = runner.invoke( config.config.commands["pbh"].commands["rule"].commands["update"]. commands["field"].commands["set"], ["pbh_table1", "nvgre", "--flow-counter", "ENABLED"], obj=db) logger.debug("\n" + result.output) logger.debug(result.exit_code) result = runner.invoke(show.cli.commands["pbh"].commands["statistics"], [], obj=db) logger.debug("\n" + result.output) logger.debug(result.exit_code) assert result.exit_code == SUCCESS assert result.output == assert_show_output.show_pbh_statistics_after_toggling_counter
def test_config_bgp_feature_inconsistent_autorestart(self, get_cmd_module): from .mock_tables import dbconnector from .mock_tables import mock_multi_asic_3_asics reload(mock_multi_asic_3_asics) dbconnector.load_namespace_config() (config, show) = get_cmd_module db = Db() runner = CliRunner() result = runner.invoke(config.config.commands["feature"].commands["autorestart"], ["bgp", "disabled"], obj=db) print(result.exit_code) print(result.output) assert result.exit_code == 1 assert result.output == config_feature_bgp_inconsistent_autorestart_output result = runner.invoke(config.config.commands["feature"].commands["autorestart"], ["bgp", "enabled"], obj=db) print(result.exit_code) print(result.output) assert result.exit_code == 1 assert result.output == config_feature_bgp_inconsistent_autorestart_output
def test_config_database_feature_state(self, get_cmd_module): (config, show) = get_cmd_module db = Db() runner = CliRunner() result = runner.invoke(config.config.commands["feature"].commands["state"], ["database", "disabled"], obj=db) print(result.exit_code) print(result.output) result = runner.invoke(show.cli.commands["feature"].commands["status"], ["database"], obj=db) print(result.output) assert result.exit_code == 0 assert result.output == show_feature_database_always_enabled_state_output result = runner.invoke(config.config.commands["feature"].commands["state"], ["database", "enabled"], obj=db) print(result.exit_code) print(result.output) result = runner.invoke(show.cli.commands["feature"].commands["status"], ["database"], obj=db) print(result.output) assert result.exit_code == 0 assert result.output == show_feature_database_always_enabled_state_output