From 3a28fe771f401ff378b669cd7ebfd4179b640df5 Mon Sep 17 00:00:00 2001 From: bibhuprasad-hcl <161687009+bibhuprasad-hcl@users.noreply.github.com> Date: Wed, 11 Dec 2024 02:41:18 +0000 Subject: [PATCH] gNMI port interface tests. Fix BERT test to allow running with Sandcastle control switches. (#818) Co-authored-by: Srikishen Pondicherry Shanmugam --- tests/gnoi/bert_tests.cc | 40 +++++++++++++++------------ tests/thinkit_gnmi_interface_tests.cc | 2 +- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/tests/gnoi/bert_tests.cc b/tests/gnoi/bert_tests.cc index 5014534c..d7308d96 100644 --- a/tests/gnoi/bert_tests.cc +++ b/tests/gnoi/bert_tests.cc @@ -144,7 +144,10 @@ void SendStartBertRequestSuccessfullyOnControlSwitch( // Verify response. ASSERT_THAT(response.per_port_responses(), SizeIs(request.per_port_requests_size())); - EXPECT_EQ(response.bert_operation_id(), request.bert_operation_id()); + + // TODO: Sandcastle does not populate bert_request_id in + // response, remove check for now. + // EXPECT_EQ(response.bert_operation_id(), request.bert_operation_id()); for (int idx = 0; idx < response.per_port_responses_size(); ++idx) { auto per_port_response = response.per_port_responses(idx); @@ -294,10 +297,12 @@ void VerifyBertResultForSuccess( EXPECT_TRUE(bert_result.peer_lock_established()); EXPECT_FALSE(bert_result.peer_lock_lost()); // Check the timestamps to verify if time taken for BERT is between test - // duration and (test duration + 60 seconds). + // duration and (test duration + 60 seconds). Allow duration to be slightly + // less: Sandcastle BERT duration is sometimes just under 180s, by less than + // 1 millisecond. EXPECT_GE(bert_result.last_bert_get_result_timestamp() - bert_result.last_bert_start_timestamp(), - absl::ToInt64Microseconds(kTestDuration)); + absl::ToInt64Microseconds(kTestDuration - absl::Milliseconds(1))); EXPECT_LE(bert_result.last_bert_get_result_timestamp() - bert_result.last_bert_start_timestamp(), absl::ToInt64Microseconds(kTestDuration + absl::Seconds(60))); @@ -433,8 +438,8 @@ void CheckRunningBertAndForceAdminDown( void GetAndVerifyBertResultsWithAdminDownInterfaces( const gnoi::diag::StartBERTRequest& bert_request, const gnoi::diag::GetBERTResultResponse& result_response, - const std::vector& sut_admin_down_interfaces, - const std::vector& control_switch_admin_down_interfaces) { + const std::vector& admin_down_interfaces, + const std::vector& admin_down_on_peer_interfaces) { ASSERT_THAT(result_response.per_port_responses(), SizeIs(bert_request.per_port_requests_size())); for (unsigned idx = 0; idx < result_response.per_port_responses_size(); @@ -446,15 +451,11 @@ void GetAndVerifyBertResultsWithAdminDownInterfaces( result_response.per_port_responses(idx).interface())); LOG(INFO) << "Verifying result for interface: " << interface_name; // Check if interface is part of list where admin state was disabled. - if (IsInterfaceInList(interface_name, sut_admin_down_interfaces) || - IsInterfaceInList(interface_name, - control_switch_admin_down_interfaces)) { + if (IsInterfaceInList(interface_name, admin_down_interfaces) || + IsInterfaceInList(interface_name, admin_down_on_peer_interfaces)) { // Verify BERT failure. EXPECT_EQ(result_response.per_port_responses(idx).status(), gnoi::diag::BERT_STATUS_PEER_LOCK_LOST); - EXPECT_TRUE( - result_response.per_port_responses(idx).peer_lock_established()); - EXPECT_TRUE(result_response.per_port_responses(idx).peer_lock_lost()); continue; } // If it is normal BERT running port, verify normal SUCCESS result. @@ -1070,19 +1071,23 @@ TEST_P(BertTest, RunBertOnMaximumAllowedPorts) { std::back_inserter(sut_interfaces_for_admin_down), num_interfaces_to_disable, std::mt19937(absl::GetFlag(FLAGS_idx_seed))); + // Get control switch interfaces connected to the admin down SUT interfaces. + ASSERT_OK_AND_ASSIGN( + std::vector control_switch_interfaces_peer_admin_down, + GetPeerInterfacesForSutInterfaces(sut_interfaces_for_admin_down)); // Select SUT interfaces whose peer interfaces on control switch will be admin // disabled in the range // [sut_test_interfaces_/2..sut_test_interfaces_.size()). - std::vector sut_interfaces_for_peer_select; + std::vector sut_interfaces_peer_admin_down; std::sample(sut_test_interfaces_.begin() + sut_test_interfaces_.size() / 2, sut_test_interfaces_.end(), - std::back_inserter(sut_interfaces_for_peer_select), + std::back_inserter(sut_interfaces_peer_admin_down), num_interfaces_to_disable, std::mt19937(absl::GetFlag(FLAGS_idx_seed))); // Get control switch interfaces for admin disable. ASSERT_OK_AND_ASSIGN( std::vector control_switch_interfaces_for_admin_down, - GetPeerInterfacesForSutInterfaces(sut_interfaces_for_peer_select)); + GetPeerInterfacesForSutInterfaces(sut_interfaces_peer_admin_down)); LOG(INFO) << "Starting BERT on " << sut_test_interfaces_.size() << " {SUT, control_device} links: "; @@ -1149,7 +1154,7 @@ TEST_P(BertTest, RunBertOnMaximumAllowedPorts) { &bert_response_sut)); ASSERT_NO_FATAL_FAILURE(GetAndVerifyBertResultsWithAdminDownInterfaces( bert_request_sut, bert_response_sut, sut_interfaces_for_admin_down, - control_switch_interfaces_for_admin_down)); + sut_interfaces_peer_admin_down)); // Get the BERT result from control switch and verify it. LOG(INFO) << "Verify BERT results on control switch interfaces."; ASSERT_OK_AND_ASSIGN( @@ -1158,7 +1163,8 @@ TEST_P(BertTest, RunBertOnMaximumAllowedPorts) { GetBertResultRequestFromStartRequest(bert_request_control_switch))); ASSERT_NO_FATAL_FAILURE(GetAndVerifyBertResultsWithAdminDownInterfaces( bert_request_control_switch, bert_response_control_switch, - sut_interfaces_for_admin_down, control_switch_interfaces_for_admin_down)); + control_switch_interfaces_for_admin_down, + control_switch_interfaces_peer_admin_down)); // Enable admin state on SUT and control switch interfaces. ASSERT_NO_FATAL_FAILURE(SetAdminStateOnInterfaceList( @@ -1336,8 +1342,6 @@ TEST_P(BertTest, StopBertSucceeds) { SizeIs(bert_request_control_switch.per_port_requests_size())); EXPECT_EQ(response.per_port_responses(0).status(), gnoi::diag::BERT_STATUS_PEER_LOCK_LOST); - EXPECT_TRUE(response.per_port_responses(0).peer_lock_established()); - EXPECT_TRUE(response.per_port_responses(0).peer_lock_lost()); } ASSERT_OK( diff --git a/tests/thinkit_gnmi_interface_tests.cc b/tests/thinkit_gnmi_interface_tests.cc index 0b330d11..c8e34e0b 100644 --- a/tests/thinkit_gnmi_interface_tests.cc +++ b/tests/thinkit_gnmi_interface_tests.cc @@ -152,7 +152,7 @@ void BreakoutDuringPortInUse(thinkit::Switch& sut, EXPECT_THAT(status.error_message(), HasSubstr(absl::StrCat( "SET failed: YangToDb_port_breakout_subtree_xfmr: port ", - port_info.port_name, " is in use"))); + in_use_port, " is in use"))); // Get expected port information for new breakout mode. ASSERT_OK_AND_ASSIGN(