Skip to content

Commit

Permalink
gNMI port interface tests. Fix BERT test to allow running with Sandca…
Browse files Browse the repository at this point in the history
…stle control switches. (#818)

Co-authored-by: Srikishen Pondicherry Shanmugam <[email protected]>
  • Loading branch information
bibhuprasad-hcl and kishanps authored Dec 11, 2024
1 parent bf0191a commit 3a28fe7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
40 changes: 22 additions & 18 deletions tests/gnoi/bert_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -433,8 +438,8 @@ void CheckRunningBertAndForceAdminDown(
void GetAndVerifyBertResultsWithAdminDownInterfaces(
const gnoi::diag::StartBERTRequest& bert_request,
const gnoi::diag::GetBERTResultResponse& result_response,
const std::vector<std::string>& sut_admin_down_interfaces,
const std::vector<std::string>& control_switch_admin_down_interfaces) {
const std::vector<std::string>& admin_down_interfaces,
const std::vector<std::string>& 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();
Expand All @@ -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.
Expand Down Expand Up @@ -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<std::string> 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<std::string> sut_interfaces_for_peer_select;
std::vector<std::string> 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<std::string> 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: ";
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/thinkit_gnmi_interface_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 3a28fe7

Please sign in to comment.