diff --git a/tests/forwarding/smoke_test.cc b/tests/forwarding/smoke_test.cc index b1b84837..1bf37ba7 100644 --- a/tests/forwarding/smoke_test.cc +++ b/tests/forwarding/smoke_test.cc @@ -72,22 +72,6 @@ TEST_P(SmokeTestFixture, DISABLED_ModifyWorks) { ASSERT_OK(pdpi::ClearTableEntries(SutP4RuntimeSession())); } -TEST_P(SmokeTestFixture, InstallDefaultRouteForEmptyStringVrfShouldSucceed) { - GetMirrorTestbed().Environment().SetTestCaseID( - "2d67413c-9b6e-4187-84d4-c9313b84cab3"); - const sai::TableEntry pd_entry = gutil::ParseProtoOrDie( - R"pb( - ipv4_table_entry { - match { vrf_id: "" } - action { drop {} } - } - )pb"); - - ASSERT_OK_AND_ASSIGN(const p4::v1::TableEntry pi_entry, - pdpi::PartialPdTableEntryToPiTableEntry(IrP4Info(), pd_entry)); - ASSERT_OK(pdpi::InstallPiTableEntry(SutP4RuntimeSession(), pi_entry)); -} - // TODO: Enable once the bug is fixed. TEST_P(SmokeTestFixture, DISABLED_Bug181149419) { GetMirrorTestbed().Environment().SetTestCaseID( diff --git a/tests/thinkit_gnmi_interface_tests.cc b/tests/thinkit_gnmi_interface_tests.cc index 0053e8f7..0b330d11 100644 --- a/tests/thinkit_gnmi_interface_tests.cc +++ b/tests/thinkit_gnmi_interface_tests.cc @@ -58,277 +58,6 @@ using ::testing::HasSubstr; } // namespace -void TestGnmiInterfaceConfigSetAdminStatus(thinkit::Switch& sut, - absl::string_view if_name) { - ASSERT_OK_AND_ASSIGN(auto sut_gnmi_stub, sut.CreateGnmiStub()); - - // Disable front panel port. - LOG(INFO) << "Disabling front panel port: " << if_name; - const std::string if_enabled_config_path = - absl::StrCat("interfaces/interface[name=", if_name, "]/config/enabled"); - ASSERT_OK(SetGnmiConfigPath(sut_gnmi_stub.get(), if_enabled_config_path, - GnmiSetType::kUpdate, kEnabledFalse)); - absl::SleepFor(absl::Seconds(5)); - - // Perform state path verifications. - // Verify /interfaces/interface[name=]/state/enabled = false. - std::string if_state_path = - absl::StrCat("interfaces/interface[name=", if_name, "]/state/enabled"); - std::string resp_parse_str = "openconfig-interfaces:enabled"; - ASSERT_OK_AND_ASSIGN( - std::string state_path_response, - GetGnmiStatePathInfo(sut_gnmi_stub.get(), if_state_path, resp_parse_str)); - EXPECT_THAT(state_path_response, HasSubstr("false")); - - // Verify /interfaces/interface[name=]/state/admin-status = DOWN. - if_state_path = absl::StrCat("interfaces/interface[name=", if_name, - "]/state/admin-status"); - resp_parse_str = "openconfig-interfaces:admin-status"; - ASSERT_OK_AND_ASSIGN( - state_path_response, - GetGnmiStatePathInfo(sut_gnmi_stub.get(), if_state_path, resp_parse_str)); - EXPECT_THAT(state_path_response, HasSubstr(kStateDown)); - - // Verify /interfaces/interface[name=]/state/oper-status = DOWN. - if_state_path = absl::StrCat("interfaces/interface[name=", if_name, - "]/state/oper-status"); - resp_parse_str = "openconfig-interfaces:oper-status"; - ASSERT_OK_AND_ASSIGN( - state_path_response, - GetGnmiStatePathInfo(sut_gnmi_stub.get(), if_state_path, resp_parse_str)); - EXPECT_THAT(state_path_response, HasSubstr(kStateDown)); - - // Enable front panel port. - LOG(INFO) << "Enabling front panel port: " << if_name; - ASSERT_OK(SetGnmiConfigPath(sut_gnmi_stub.get(), if_enabled_config_path, - GnmiSetType::kUpdate, kEnabledTrue)); - - // Perform state path verifications. - // Verify /interfaces/interface[name=]/state/oper-status = UP using - // polling with timeout. - if_state_path = absl::StrCat("interfaces/interface[name=", if_name, - "]/state/oper-status"); - resp_parse_str = "openconfig-interfaces:oper-status"; - auto oper_status_check = false; - auto start_time = absl::Now(); - auto timeout = absl::Seconds(60); - while (absl::Now() < (start_time + timeout)) { - ASSERT_OK_AND_ASSIGN(state_path_response, - GetGnmiStatePathInfo(sut_gnmi_stub.get(), - if_state_path, resp_parse_str)); - if (absl::StrContains(state_path_response, kStateUp)) { - oper_status_check = true; - break; - } - } - EXPECT_TRUE(oper_status_check); - - // Verify /interfaces/interface[name=]/state/enabled = true. - if_state_path = - absl::StrCat("interfaces/interface[name=", if_name, "]/state/enabled"); - resp_parse_str = "openconfig-interfaces:enabled"; - ASSERT_OK_AND_ASSIGN( - state_path_response, - GetGnmiStatePathInfo(sut_gnmi_stub.get(), if_state_path, resp_parse_str)); - EXPECT_THAT(state_path_response, HasSubstr("true")); - - // Verify /interfaces/interface[name=]/state/admin-status = UP. - if_state_path = absl::StrCat("interfaces/interface[name=", if_name, - "]/state/admin-status"); - resp_parse_str = "openconfig-interfaces:admin-status"; - ASSERT_OK_AND_ASSIGN( - state_path_response, - GetGnmiStatePathInfo(sut_gnmi_stub.get(), if_state_path, resp_parse_str)); - EXPECT_THAT(state_path_response, HasSubstr(kStateUp)); -} - -void TestGnmiPortComponentPaths( - thinkit::SSHClient& ssh_client, thinkit::Switch& sut, - absl::flat_hash_map& expected_port_index_map) { - ASSERT_OK_AND_ASSIGN(auto sut_gnmi_stub, sut.CreateGnmiStub()); - - // Configure integrated circuit name on the switch. - const std::string ic_name = "integrated_circuit0"; - const std::string ic_name_config_path = - absl::StrCat("components/component[name=", ic_name, "]/config/name"); - ASSERT_OK(SetGnmiConfigPath(sut_gnmi_stub.get(), ic_name_config_path, - GnmiSetType::kUpdate, - ConstructGnmiConfigSetString("name", ic_name))); - - for (const auto& [port_name, port_index] : expected_port_index_map) { - // Fetch /interfaces/interface[name=]/state/hardware-port. - const std::string hw_port_state_path = absl::StrCat( - "interfaces/interface[name=", port_name, "]/state/hardware-port"); - const std::string hw_port_parse_str = - "openconfig-platform-port:hardware-port"; - ASSERT_OK_AND_ASSIGN( - std::string hw_port, - GetGnmiStatePathInfo(sut_gnmi_stub.get(), hw_port_state_path, - hw_port_parse_str)); - hw_port.erase(std::remove(hw_port.begin(), hw_port.end(), '"'), - hw_port.end()); - - // hardware-port is in the format 1/. Fetch port number from this - // information and verify that it is same as index attribute of the port in - // platform.json. - const auto separator_location = hw_port.find('/'); - ASSERT_NE(separator_location, std::string::npos); - const std::string port_number = hw_port.substr(separator_location + 1); - ASSERT_EQ(port_index, port_number); - - // Verify that hardware-port attribute matches information in path - // /components/component[name=]/state/name. - const std::string component_name_state_path = - absl::StrCat("components/component[name=", hw_port, "]/state/name"); - const std::string component_name_parse_str = "openconfig-platform:name"; - ASSERT_OK_AND_ASSIGN( - const std::string component_name, - GetGnmiStatePathInfo(sut_gnmi_stub.get(), component_name_state_path, - component_name_parse_str)); - EXPECT_THAT(component_name, HasSubstr(hw_port)); - - // Verify that integrated circuit name matches information in path - // /components/component[name=]/state/parent. - const std::string component_parent_state_path = - absl::StrCat("components/component[name=", hw_port, "]/state/parent"); - const std::string component_parent_parse_str = "openconfig-platform:parent"; - ASSERT_OK_AND_ASSIGN( - const std::string component_parent, - GetGnmiStatePathInfo(sut_gnmi_stub.get(), component_parent_state_path, - component_parent_parse_str)); - EXPECT_THAT(component_parent, HasSubstr(ic_name)); - } -} - -void TestGnmiInterfaceConfigSetPortSpeed( - thinkit::Switch& sut, absl::string_view if_name, - const absl::flat_hash_set& supported_speeds) { - ASSERT_OK_AND_ASSIGN(auto sut_gnmi_stub, sut.CreateGnmiStub()); - - // Get current configured port speed for the port. - std::string if_state_path = absl::StrCat( - "interfaces/interface[name=", if_name, "]/ethernet/state/port-speed"); - std::string resp_parse_str = "openconfig-if-ethernet:port-speed"; - ASSERT_OK_AND_ASSIGN( - std::string state_path_response, - GetGnmiStatePathInfo(sut_gnmi_stub.get(), if_state_path, resp_parse_str)); - state_path_response.erase( - std::remove(state_path_response.begin(), state_path_response.end(), '\"'), - state_path_response.end()); - // Save the original port speed to reset it later. - const std::string kOriginalPortSpeedStr = state_path_response; - - // Extract current port speed from port speed string. - // Port speed string is in the format: - // "openconfig-if-ethernet:SPEED_GB" - auto separator_location = state_path_response.find('_'); - ASSERT_NE(separator_location, std::string::npos); - std::string current_port_speed_str = - kOriginalPortSpeedStr.substr(separator_location + 1); - separator_location = current_port_speed_str.find(kGB); - ASSERT_NE(separator_location, std::string::npos); - current_port_speed_str = current_port_speed_str.substr(0, separator_location); - - int current_port_speed = 0; - ASSERT_TRUE(absl::SimpleAtoi(current_port_speed_str, ¤t_port_speed)); - LOG(INFO) << "Current port speed for port " << if_name << " is " - << current_port_speed << kGB << "."; - - // Pick a valid new port speed for the port that is less than current speed. - int new_port_speed = 0; - for (const auto& speed : supported_speeds) { - if (speed < current_port_speed) { - new_port_speed = speed; - break; - } - } - // Set new speed for the port if a valid lower speed is found. - if (new_port_speed) { - const std::string kNewPortSpeedStr = absl::StrCat( - "openconfig-if-ethernet:SPEED_", std::to_string(new_port_speed), kGB); - LOG(INFO) << "Changing port speed for " << if_name - << " to a lower supported speed (" << kNewPortSpeedStr << ")."; - - // Set new port speed. - std::string if_port_speed_config_path = absl::StrCat( - "interfaces/interface[name=", if_name, "]/ethernet/config/port-speed"); - ASSERT_OK(SetGnmiConfigPath( - sut_gnmi_stub.get(), if_port_speed_config_path, GnmiSetType::kUpdate, - ConstructGnmiConfigSetString(kPortSpeed, kNewPortSpeedStr))); - absl::SleepFor(absl::Seconds(30)); - - // Perform state path verifications. - // Verify /interfaces/interface[name=]/ethernet/state/port-speed = - // new port speed. - ASSERT_OK_AND_ASSIGN(state_path_response, - GetGnmiStatePathInfo(sut_gnmi_stub.get(), - if_state_path, resp_parse_str)); - EXPECT_THAT(state_path_response, HasSubstr(kNewPortSpeedStr)); - // Verify that /interfaces/interface[name=]/state/oper-status = DOWN. - if_state_path = absl::StrCat("interfaces/interface[name=", if_name, - "]/state/oper-status"); - resp_parse_str = "openconfig-interfaces:oper-status"; - ASSERT_OK_AND_ASSIGN(state_path_response, - GetGnmiStatePathInfo(sut_gnmi_stub.get(), - if_state_path, resp_parse_str)); - EXPECT_THAT(state_path_response, HasSubstr(kStateDown)); - } else { - LOG(INFO) << "No lower supported port speed found for port " << if_name - << ". Resetting original port speed."; - } - LOG(INFO) << "Setting port speed for " << if_name << " to " - << kOriginalPortSpeedStr; - // Reset port speed to original speed. - std::string if_port_speed_config_path = absl::StrCat( - "interfaces/interface[name=", if_name, "]/ethernet/config/port-speed"); - ASSERT_OK(SetGnmiConfigPath( - sut_gnmi_stub.get(), if_port_speed_config_path, GnmiSetType::kUpdate, - ConstructGnmiConfigSetString(kPortSpeed, kOriginalPortSpeedStr))); - absl::SleepFor(absl::Seconds(30)); - - // Verify /interfaces/interface[name=]/ethernet/state/port-speed = - // original speed. - if_state_path = absl::StrCat("interfaces/interface[name=", if_name, - "]/ethernet/state/port-speed"); - resp_parse_str = "openconfig-if-ethernet:port-speed"; - ASSERT_OK_AND_ASSIGN( - state_path_response, - GetGnmiStatePathInfo(sut_gnmi_stub.get(), if_state_path, resp_parse_str)); - EXPECT_THAT(state_path_response, HasSubstr(kOriginalPortSpeedStr)); - - // Verify that /interfaces/interface[name=]/state/oper-status = UP. - if_state_path = absl::StrCat("interfaces/interface[name=", if_name, - "]/state/oper-status"); - resp_parse_str = "openconfig-interfaces:oper-status"; - ASSERT_OK_AND_ASSIGN( - state_path_response, - GetGnmiStatePathInfo(sut_gnmi_stub.get(), if_state_path, resp_parse_str)); - EXPECT_THAT(state_path_response, HasSubstr(kStateUp)); -} - -void TestGnmiInterfaceConfigSetId(thinkit::Switch& sut, - absl::string_view if_name, const int id) { - ASSERT_OK_AND_ASSIGN(auto sut_gnmi_stub, sut.CreateGnmiStub()); - - // Set port Id. - const std::string if_id_config_path = - absl::StrCat("interfaces/interface[name=", if_name, "]/config/id"); - ASSERT_OK(SetGnmiConfigPath(sut_gnmi_stub.get(), if_id_config_path, - GnmiSetType::kUpdate, - ConstructGnmiConfigSetString("id", id))); - absl::SleepFor(absl::Seconds(5)); - - // Perform state path verifications. - // Verify /interfaces/interface[name=]/state/id = . - std::string if_state_path = - absl::StrCat("interfaces/interface[name=", if_name, "]/state/id"); - std::string resp_parse_str = "openconfig-p4rt:id"; - ASSERT_OK_AND_ASSIGN( - std::string state_path_response, - GetGnmiStatePathInfo(sut_gnmi_stub.get(), if_state_path, resp_parse_str)); - EXPECT_THAT(state_path_response, HasSubstr(std::to_string(id))); -} - void BreakoutDuringPortInUse(thinkit::Switch& sut, gnmi::gNMI::StubInterface* sut_gnmi_stub, RandomPortBreakoutInfo port_info, diff --git a/tests/thinkit_gnmi_interface_tests.h b/tests/thinkit_gnmi_interface_tests.h index a18746ea..d3b97e82 100644 --- a/tests/thinkit_gnmi_interface_tests.h +++ b/tests/thinkit_gnmi_interface_tests.h @@ -24,24 +24,20 @@ namespace pins_test { -// Test port admin_status related GNMI config and state paths. -void TestGnmiInterfaceConfigSetAdminStatus(thinkit::Switch& sut, - absl::string_view if_name); - -// Test GNMI component config and state paths. -void TestGnmiPortComponentPaths( - thinkit::SSHClient& ssh_client, thinkit::Switch& sut, - absl::flat_hash_map& expected_port_index_map); - -// Test port-speed GNMI config and state paths. -// The test expects that auto-negotiation has been disabled for the given port. -void TestGnmiInterfaceConfigSetPortSpeed( - thinkit::Switch& sut, absl::string_view if_name, - const absl::flat_hash_set& supported_speeds); - -// Test port Id GNMI config and state paths. -void TestGnmiInterfaceConfigSetId(thinkit::Switch& sut, - absl::string_view if_name, const int id); +// Test port breakout during parent port in use. +void TestGNMIParentPortInUseDuringBreakout(thinkit::Switch& sut, + std::string& platform_json_contents); + +// Test port breakout during child port in use. +void TestGNMIChildPortInUseDuringBreakout(thinkit::Switch& sut, + std::string& platform_json_contents); + +// Helper function to test port in use. +void BreakoutDuringPortInUse(thinkit::Switch& sut, + gnmi::gNMI::StubInterface* sut_gnmi_stub, + RandomPortBreakoutInfo port_info, + const std::string& platform_json_contents, + bool test_child_port_in_use); // Test port breakout during parent port in use. void TestGNMIParentPortInUseDuringBreakout(thinkit::Switch& sut, diff --git a/tests/thinkit_gnmi_interface_util.cc b/tests/thinkit_gnmi_interface_util.cc index fcb21243..4d6bd56b 100644 --- a/tests/thinkit_gnmi_interface_util.cc +++ b/tests/thinkit_gnmi_interface_util.cc @@ -122,20 +122,20 @@ absl::StatusOr> GetSupportedBreakoutModesForPort( } absl::StatusOr BreakoutResultsInSpeedChangeOnly( - const std::string& port, const std::string& curr_breakout_mode, + const std::string& port, const std::string& current_breakout_mode, const std::string& new_breakout_mode) { // Get list of interfaces for current and new breakout modes. - ASSIGN_OR_RETURN(auto curr_port_info, GetExpectedPortInfoForBreakoutMode( - port, curr_breakout_mode)); + ASSIGN_OR_RETURN(auto current_port_info, GetExpectedPortInfoForBreakoutMode( + port, current_breakout_mode)); ASSIGN_OR_RETURN(auto new_port_info, GetExpectedPortInfoForBreakoutMode(port, new_breakout_mode)); - for (auto& key : curr_port_info) { - if (!new_port_info.count(key.first)) { + for (const auto& [key, unused_val] : current_port_info) { + if (!new_port_info.count(key)) { return false; } } - for (auto& key : new_port_info) { - if (!curr_port_info.count(key.first)) { + for (const auto& [key, unused_val] : new_port_info) { + if (!current_port_info.count(key)) { return false; } } @@ -271,17 +271,17 @@ GetExpectedPortInfoForBreakoutMode(const std::string& port, // lanes per physical port/number of groups in a breakout mode. auto max_channels_in_group = kMaxPortLanes / modes.size(); auto port_number_str = port.substr(kEthernetLen); - int curr_port_number; - if (!absl::SimpleAtoi(port_number_str, &curr_port_number)) { + int current_port_number; + if (!absl::SimpleAtoi(port_number_str, ¤t_port_number)) { return gutil::InternalErrorBuilder().LogError() << "Failed to convert string (" << port_number_str << ") to integer"; } - if (curr_port_number % kMaxPortLanes != 0) { + if (current_port_number % kMaxPortLanes != 0) { return gutil::InternalErrorBuilder().LogError() << "Requested port (" << port << ") is not a parent port"; } - auto curr_physical_channel = 0; + auto current_physical_channel = 0; absl::flat_hash_map expected_breakout_info; for (auto& mode : modes) { @@ -302,7 +302,7 @@ GetExpectedPortInfoForBreakoutMode(const std::string& port, // leading to interfaces Ethernet0, Ethernet2 for mode 2x100G and // Ethernet4 for mode 1x200G. for (int i = 0; i < num_breakouts; i++) { - auto port = absl::StrCat(kEthernet, std::to_string(curr_port_number)); + auto port = absl::StrCat(kEthernet, std::to_string(current_port_number)); // Populate expected physical channels for each port. // Physical channels are between 0 to 7. int offset = max_channels_in_group / num_breakouts; @@ -311,15 +311,15 @@ GetExpectedPortInfoForBreakoutMode(const std::string& port, << "Invalid breakout mode (" << breakout_mode << ") found"; } std::string physical_channels = "["; - for (int j = curr_physical_channel; j < offset + curr_physical_channel; - j++) { + for (int j = current_physical_channel; + j < offset + current_physical_channel; j++) { physical_channels += std::to_string(j); // Add comma after each but last entry. - if (j < offset + curr_physical_channel - 1) physical_channels += ","; + if (j < offset + current_physical_channel - 1) physical_channels += ","; } physical_channels += "]"; - curr_physical_channel += offset; - curr_port_number += offset; + current_physical_channel += offset; + current_port_number += offset; expected_breakout_info[port] = PortBreakoutInfo{physical_channels}; } } @@ -330,11 +330,11 @@ absl::StatusOr> GetBreakoutStateInfoForPort(gnmi::gNMI::StubInterface* sut_gnmi_stub, const std::string& port, absl::string_view breakout_mode) { - absl::flat_hash_map port_info; - ASSIGN_OR_RETURN(port_info, + absl::flat_hash_map port_infos; + ASSIGN_OR_RETURN(port_infos, GetExpectedPortInfoForBreakoutMode(port, breakout_mode)); - for (auto& p : port_info) { - auto if_state_path = absl::StrCat("interfaces/interface[name=", p.first, + for (auto& [port_name, breakout_info] : port_infos) { + auto if_state_path = absl::StrCat("interfaces/interface[name=", port_name, "]/state/oper-status"); auto resp_parse_str = "openconfig-interfaces:oper-status"; ASSIGN_OR_RETURN( @@ -342,11 +342,11 @@ GetBreakoutStateInfoForPort(gnmi::gNMI::StubInterface* sut_gnmi_stub, GetGnmiStatePathInfo(sut_gnmi_stub, if_state_path, resp_parse_str), _ << "Failed to get GNMI state path value for oper-status for " "port " - << p.first); - p.second.oper_status = state_path_response; + << port_name); + breakout_info.oper_status = state_path_response; auto if_physical_channels_path = absl::StrCat( - "interfaces/interface[name=", p.first, "]/state/physical-channel"); + "interfaces/interface[name=", port_name, "]/state/physical-channel"); resp_parse_str = "openconfig-platform-transceiver:physical-channel"; ASSIGN_OR_RETURN( state_path_response, @@ -354,10 +354,10 @@ GetBreakoutStateInfoForPort(gnmi::gNMI::StubInterface* sut_gnmi_stub, resp_parse_str), _ << "Failed to get GNMI state path value for physical-channels for " "port " - << p.first); - p.second.physical_channels = state_path_response; + << port_name); + breakout_info.physical_channels = state_path_response; } - return port_info; + return port_infos; } absl::StatusOr GenerateComponentBreakoutConfig( @@ -494,12 +494,12 @@ absl::Status GetBreakoutModeConfigFromString( auto index = 0; // Get current port number. - int curr_port_number; - if (!absl::SimpleAtoi(port_index, &curr_port_number)) { + int current_port_number; + if (!absl::SimpleAtoi(port_index, ¤t_port_number)) { return gutil::InternalErrorBuilder().LogError() << "Failed to convert string (" << port_index << ") to integer"; } - curr_port_number = (curr_port_number - 1) * kMaxPortLanes; + current_port_number = (current_port_number - 1) * kMaxPortLanes; ASSIGN_OR_RETURN(bool is_copper_port, IsCopperPort(sut_gnmi_stub, intf_name)); @@ -523,14 +523,14 @@ absl::Status GetBreakoutModeConfigFromString( // Get the interface config for all ports corresponding to current breakout // group. for (int i = 0; i < num_breakouts; i++) { - auto port = absl::StrCat(kEthernet, std::to_string(curr_port_number)); + auto port = absl::StrCat(kEthernet, std::to_string(current_port_number)); ASSIGN_OR_RETURN( auto interface_config, - GenerateInterfaceBreakoutConfig(port, curr_port_number, + GenerateInterfaceBreakoutConfig(port, current_port_number, breakout_speed, is_copper_port)); interface_configs.push_back(interface_config); int offset = max_channels_in_group / num_breakouts; - curr_port_number += offset; + current_port_number += offset; } index += 1; } @@ -562,21 +562,24 @@ absl::Status GetBreakoutModeConfigFromString( } std::vector GetNonExistingPortsAfterBreakout( - const absl::flat_hash_map& orig_port_info, + const absl::flat_hash_map& + original_port_info, const absl::flat_hash_map& new_port_info, bool expected_success) { - std::vector nonExistingPortList; - const auto *orig_map = &orig_port_info, *new_map = &new_port_info; + std::vector non_existing_ports; + const auto* original_map = &original_port_info; + const auto* new_map = &new_port_info; + if (!expected_success) { - orig_map = &new_port_info; - new_map = &orig_port_info; + original_map = &new_port_info; + new_map = &original_port_info; } - for (const auto& port : *orig_map) { - if (new_map->find(port.first) == new_map->end()) { - nonExistingPortList.push_back(port.first); + for (const auto& [port_name, unused] : *original_map) { + if (new_map->find(port_name) == new_map->end()) { + non_existing_ports.push_back(port_name); } } - return nonExistingPortList; + return non_existing_ports; } absl::Status ValidateBreakoutState( @@ -589,39 +592,41 @@ absl::Status ValidateBreakoutState( << "Expected port info map is empty"; } - for (const auto& port : expected_port_info) { + for (const auto& [port_name, breakout_info] : expected_port_info) { // Verify that the oper-status state path value is as expected. - auto if_state_path = absl::StrCat("interfaces/interface[name=", port.first, - "]/state/oper-status"); - auto resp_parse_str = "openconfig-interfaces:oper-status"; + auto interface_state_path = absl::StrCat( + "interfaces/interface[name=", port_name, "]/state/oper-status"); + auto response_parse_str = "openconfig-interfaces:oper-status"; ASSIGN_OR_RETURN( auto state_path_response, - GetGnmiStatePathInfo(sut_gnmi_stub, if_state_path, resp_parse_str), + GetGnmiStatePathInfo(sut_gnmi_stub, interface_state_path, + response_parse_str), _ << "Failed to get GNMI state path value for oper-status for " "port " - << port.first); - if (!absl::StrContains(state_path_response, port.second.oper_status)) { + << port_name); + if (!absl::StrContains(state_path_response, breakout_info.oper_status)) { return gutil::InternalErrorBuilder().LogError() << absl::StrCat("Port oper-status match failed for port ", - port.first, ". got: ", state_path_response, - ", want:", port.second.oper_status); + port_name, ". got: ", state_path_response, + ", want:", breakout_info.oper_status); } // Verify that the physical-channels state path value is as expected. - if_state_path = absl::StrCat("interfaces/interface[name=", port.first, - "]/state/physical-channel"); - resp_parse_str = "openconfig-platform-transceiver:physical-channel"; + interface_state_path = absl::StrCat("interfaces/interface[name=", port_name, + "]/state/physical-channel"); + response_parse_str = "openconfig-platform-transceiver:physical-channel"; ASSIGN_OR_RETURN( state_path_response, - GetGnmiStatePathInfo(sut_gnmi_stub, if_state_path, resp_parse_str), + GetGnmiStatePathInfo(sut_gnmi_stub, interface_state_path, + response_parse_str), _ << "Failed to get GNMI state path value for physical-channels for " "port " - << port.first); + << port_name); if (!absl::StrContains(state_path_response, - port.second.physical_channels)) { + breakout_info.physical_channels)) { return gutil::InternalErrorBuilder().LogError() << absl::StrCat("Physical channel match failed for port ", - port.first, ". got: ", state_path_response, - ", want: ", port.second.physical_channels); + port_name, ". got: ", state_path_response, + ", want: ", breakout_info.physical_channels); } } diff --git a/tests/thinkit_gnmi_interface_util.h b/tests/thinkit_gnmi_interface_util.h index 73d5e666..5b27069a 100644 --- a/tests/thinkit_gnmi_interface_util.h +++ b/tests/thinkit_gnmi_interface_util.h @@ -108,7 +108,8 @@ absl::Status GetBreakoutModeConfigFromString( // the port, ports in original breakout config that were not in new breakout // config should no longer exist as new breakout is now applied. std::vector GetNonExistingPortsAfterBreakout( - const absl::flat_hash_map& orig_port_info, + const absl::flat_hash_map& + original_port_info, const absl::flat_hash_map& new_port_info, bool expected_success); diff --git a/tests/thinkit_sanity_tests.cc b/tests/thinkit_sanity_tests.cc index 247dbab1..7087bdde 100644 --- a/tests/thinkit_sanity_tests.cc +++ b/tests/thinkit_sanity_tests.cc @@ -60,7 +60,6 @@ constexpr absl::Duration kColdRebootWaitForDownTime = absl::Seconds(30); // TODO: Reduce reboot up time. constexpr absl::Duration kColdRebootWaitForUpTime = absl::Minutes(6); constexpr absl::Duration kWaitForApplicationsReady = absl::Minutes(1); -constexpr char kMtuJsonVal[] = "{\"mtu\":2000}"; constexpr char kV3ReleaseConfigBlob[] = R"({ "openconfig-platform:components" : { "component" : [ @@ -280,41 +279,6 @@ void TestGnmiConfigBlobSet(thinkit::Switch& sut) { } } -void TestGnmiInterfaceConfigSetMtu(thinkit::Switch& sut, - absl::string_view if_name) { - ASSERT_OK_AND_ASSIGN(auto sut_gnmi_stub, sut.CreateGnmiStub()); - std::string if_req = - absl::StrCat("interfaces/interface[name=", if_name, "]/config/mtu"); - - ASSERT_OK_AND_ASSIGN( - gnmi::SetRequest req, - BuildGnmiSetRequest(if_req, GnmiSetType::kUpdate, kMtuJsonVal)); - LOG(INFO) << "Sending SET request: " << req.ShortDebugString(); - gnmi::SetResponse resp; - grpc::ClientContext context; - ASSERT_OK(sut_gnmi_stub->Set(&context, req, &resp)); - LOG(INFO) << "Received SET response: " << resp.ShortDebugString(); - - ASSERT_OK_AND_ASSIGN(gnmi::GetRequest get_req, - BuildGnmiGetRequest(if_req, gnmi::GetRequest::CONFIG)); - LOG(INFO) << "Sending GET request: " << get_req.ShortDebugString(); - gnmi::GetResponse get_resp; - grpc::ClientContext get_context; - ASSERT_OK(sut_gnmi_stub->Get(&get_context, get_req, &get_resp)); - LOG(INFO) << "Received GET response: " << resp.ShortDebugString(); - ASSERT_OK_AND_ASSIGN( - std::string mtu_respose, - ParseGnmiGetResponse(get_resp, "openconfig-interfaces:mtu")); - LOG(INFO) << "mtu_respose: " << mtu_respose; - EXPECT_THAT(mtu_respose, HasSubstr("2000")); - - ASSERT_OK_AND_ASSIGN(req, BuildGnmiSetRequest(if_req, GnmiSetType::kDelete)); - LOG(INFO) << "Sending SET request: " << req.ShortDebugString(); - grpc::ClientContext new_set_context; - ASSERT_OK(sut_gnmi_stub->Set(&new_set_context, req, &resp)); - LOG(INFO) << "Received SET response: " << resp.ShortDebugString(); -} - void TestGnmiCheckSpecificInterfaceStateOperation(thinkit::Switch& sut, absl::string_view if_name) { ASSERT_OK_AND_ASSIGN(auto sut_gnmi_stub, sut.CreateGnmiStub()); diff --git a/tests/thinkit_sanity_tests.h b/tests/thinkit_sanity_tests.h index 3fae28d7..1064375d 100644 --- a/tests/thinkit_sanity_tests.h +++ b/tests/thinkit_sanity_tests.h @@ -46,9 +46,6 @@ void TestGnmiCheckAlarms(thinkit::MirrorTestbed& testbed); // Tests that SUT specific port state is UP. void TestGnmiCheckSpecificInterfaceStateOperation(thinkit::Switch& sut, absl::string_view if_name); -// Tests that SUT specific port MTU can be updated. -void TestGnmiInterfaceConfigSetMtu(thinkit::Switch& sut, - absl::string_view if_name); // Tests that SUT is updated with a config Blob. void TestGnmiConfigBlobSet(thinkit::Switch& sut);