Skip to content

Commit 5817734

Browse files
kishanpsVSuryaprasad-HCL
authored andcommitted
[Thinkit] Add ControlDevice method to filter out interfaces that cause a collateral link down on admin down.Add SCOPED_TRACE for interface names. Move helper functions in factory_reset_test from header into anonymous namespace in source.Add ConfigureSwitchPair function that returns status instead of P4RT sessions.Update to clear all entities instead of just table entries. Generalize APIs to dual-switch testbeds with different configs for each switch.
1 parent 0904d70 commit 5817734

9 files changed

+420
-138
lines changed

tests/gnoi/BUILD.bazel

+5-3
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,17 @@ cc_library(
6767
],
6868
deps = [
6969
"//gutil:status_matchers",
70-
"//lib/gnmi:gnmi_helper",
7170
"//lib/validator:validator_lib",
72-
"//thinkit:mirror_testbed_fixture",
7371
"//thinkit:ssh_client",
72+
"//thinkit:switch",
7473
"@com_github_gnoi//factory_reset:factory_reset_cc_proto",
7574
"@com_github_google_glog//:glog",
76-
"@com_google_absl//absl/container:flat_hash_set",
75+
"@com_github_grpc_grpc//:grpc++",
76+
"@com_google_absl//absl/status",
77+
"@com_google_absl//absl/status:statusor",
7778
"@com_google_absl//absl/strings",
7879
"@com_google_absl//absl/time",
80+
"@com_google_absl//absl/types:span",
7981
"@com_google_googletest//:gtest",
8082
],
8183
alwayslink = True,

tests/gnoi/bert_tests.cc

+21-9
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ void GetAndVerifyBertResultsWithAdminDownInterfaces(
541541
GetInterfaceNameFromOcInterfacePath(
542542
result_response.per_port_responses(idx).interface()));
543543
LOG(INFO) << "Verifying result for interface: " << interface_name;
544+
SCOPED_TRACE(absl::Substitute("Interface: $0", interface_name));
544545
// Check if interface is part of list where admin state was disabled.
545546
if (IsInterfaceInList(interface_name, admin_down_interfaces) ||
546547
IsInterfaceInList(interface_name, admin_down_on_peer_interfaces)) {
@@ -1192,16 +1193,27 @@ TEST_P(BertTest, RunBertOnMaximumAllowedPorts) {
11921193
// Select SUT interfaces whose peer interfaces on control switch will be admin
11931194
// disabled in the range
11941195
// [sut_test_interfaces_/2..sut_test_interfaces_.size()).
1195-
std::vector<std::string> sut_interfaces_peer_admin_down;
1196-
std::sample(sut_test_interfaces_.begin() + sut_test_interfaces_.size() / 2,
1197-
sut_test_interfaces_.end(),
1198-
std::back_inserter(sut_interfaces_peer_admin_down),
1199-
num_interfaces_to_disable,
1200-
std::mt19937(absl::GetFlag(FLAGS_idx_seed)));
1201-
// Get control switch interfaces for admin disable.
1196+
std::vector<std::string> sut_interfaces_peer_admin_down_candidates(
1197+
sut_test_interfaces_.begin() + sut_test_interfaces_.size() / 2,
1198+
sut_test_interfaces_.end());
1199+
ASSERT_OK_AND_ASSIGN(std::vector<std::string>
1200+
control_switch_interfaces_for_admin_down_candidates,
1201+
GetPeerInterfacesForSutInterfaces(
1202+
sut_interfaces_peer_admin_down_candidates));
12021203
ASSERT_OK_AND_ASSIGN(
1203-
std::vector<std::string> control_switch_interfaces_for_admin_down,
1204-
GetPeerInterfacesForSutInterfaces(sut_interfaces_peer_admin_down));
1204+
std::vector<std::string>
1205+
control_switch_interfaces_for_admin_down_filtered_candidates,
1206+
control_device.FilterCollateralDownOnAdminDownInterfaces(
1207+
control_switch_interfaces_for_admin_down_candidates));
1208+
std::vector<std::string> control_switch_interfaces_for_admin_down;
1209+
std::sample(
1210+
control_switch_interfaces_for_admin_down_filtered_candidates.begin(),
1211+
control_switch_interfaces_for_admin_down_filtered_candidates.end(),
1212+
std::back_inserter(control_switch_interfaces_for_admin_down),
1213+
num_interfaces_to_disable, std::mt19937(absl::GetFlag(FLAGS_idx_seed)));
1214+
ASSERT_OK_AND_ASSIGN(std::vector<std::string> sut_interfaces_peer_admin_down,
1215+
GetSutInterfacesForControlInterfaces(
1216+
control_switch_interfaces_for_admin_down));
12051217

12061218
LOG(INFO) << "Starting BERT on " << sut_test_interfaces_.size()
12071219
<< " {SUT, control_device} links: ";

tests/gnoi/bert_tests.h

+14
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,20 @@ class BertTest : public thinkit::GenericTestbedFixture<> {
129129
return peer_interfaces;
130130
}
131131

132+
absl::StatusOr<std::vector<std::string>> GetSutInterfacesForControlInterfaces(
133+
const std::vector<std::string> &control_interfaces) {
134+
std::vector<std::string> sut_interfaces;
135+
sut_interfaces.reserve(control_interfaces.size());
136+
for (const std::string &control_interface : control_interfaces) {
137+
if (control_to_peer_interface_mapping_.count(control_interface) == 0) {
138+
return absl::NotFoundError("Failed to find peer.");
139+
}
140+
sut_interfaces.push_back(
141+
control_to_peer_interface_mapping_[control_interface]);
142+
}
143+
return sut_interfaces;
144+
}
145+
132146
protected:
133147
std::unique_ptr<thinkit::GenericTestbed> generic_testbed_;
134148
std::unique_ptr<gnmi::gNMI::StubInterface> sut_gnmi_stub_;

tests/gnoi/factory_reset_test.cc

+20-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Google LLC
1+
// Copyright 2025 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -14,28 +14,29 @@
1414

1515
#include "tests/gnoi/factory_reset_test.h"
1616

17-
#include <cstdint>
18-
#include <cstdlib>
19-
#include <map>
2017
#include <memory>
2118
#include <string>
22-
#include <utility>
23-
#include <valarray>
2419

25-
#include "absl/container/flat_hash_set.h"
20+
#include "absl/status/status.h"
21+
#include "absl/status/statusor.h"
2622
#include "absl/strings/numbers.h"
27-
#include "absl/strings/str_cat.h"
28-
#include "absl/strings/string_view.h"
2923
#include "absl/time/clock.h"
3024
#include "absl/time/time.h"
25+
#include "absl/types/span.h"
26+
#include "factory_reset/factory_reset.pb.h"
3127
#include "glog/logging.h"
3228
#include "gmock/gmock.h"
29+
#include "grpcpp/client_context.h"
30+
#include "grpcpp/support/status.h"
3331
#include "gtest/gtest.h"
32+
#include "gutil/status.h"
3433
#include "gutil/status_matchers.h"
35-
#include "lib/gnmi/gnmi_helper.h"
3634
#include "lib/validator/validator_lib.h"
35+
#include "thinkit/ssh_client.h"
36+
#include "thinkit/switch.h"
3737

3838
namespace factory_reset {
39+
namespace {
3940

4041
// TODO: investigate why shutdown time is increasing and revert
4142
// to 60s if possible.
@@ -49,7 +50,7 @@ constexpr absl::Duration kSshSessionTimeout = absl::Seconds(5);
4950
void IssueGnoiFactoryResetAndValidateStatus(
5051
thinkit::Switch& sut, const gnoi::factory_reset::StartRequest& request,
5152
gnoi::factory_reset::StartResponse* response,
52-
grpc::Status expected_status) {
53+
grpc::Status expected_status = {}) {
5354
LOG(INFO) << "Issuing factory reset with parameters: "
5455
<< request.DebugString();
5556
ASSERT_OK_AND_ASSIGN(auto sut_gnoi_factory_reset_stub,
@@ -104,6 +105,8 @@ void ValidateStackState(thinkit::Switch& sut,
104105
<< "System did not come up in " << kFactoryResetWaitForUpTime;
105106
}
106107

108+
} // namespace
109+
107110
void TestFactoryResetSuccess(thinkit::Switch& sut,
108111
thinkit::SSHClient& ssh_client,
109112
absl::Span<const std::string> interfaces) {
@@ -142,14 +145,15 @@ void TestGnoiFactoryResetGnoiServerUnreachableFail(
142145
while (consecutive_unreachable_count < kConsecutivePingsRequired) {
143146
if (pins_test::Pingable(sut, kPingTimeout).ok()) {
144147
consecutive_unreachable_count = 0;
148+
LOG(INFO) << "System still reachable";
149+
if (absl::Now() - start > kFactoryResetWaitForDownTime) {
150+
FAIL() << "System did not go down in " << kFactoryResetWaitForDownTime;
151+
}
145152
} else {
146153
consecutive_unreachable_count++;
154+
LOG(INFO) << "System unreachable for " << consecutive_unreachable_count
155+
<< " consecutive pings";
147156
}
148-
if (absl::Now() - start > kFactoryResetWaitForDownTime) {
149-
FAIL() << "System did not go down in " << kFactoryResetWaitForDownTime;
150-
}
151-
LOG(INFO) << "System unreachable for " << consecutive_unreachable_count
152-
<< " consecutive pings";
153157
absl::SleepFor(kPingReachabilityInterval);
154158
}
155159
LOG(INFO) << "Device became unreachable after: " << absl::Now() - start;

tests/gnoi/factory_reset_test.h

+12-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Google LLC
1+
// Copyright 2025 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -15,32 +15,26 @@
1515
#ifndef PINS_TESTS_GNOI_FACTORY_RESET_TEST_H_
1616
#define PINS_TESTS_GNOI_FACTORY_RESET_TEST_H_
1717

18-
#include "factory_reset/factory_reset.pb.h"
19-
#include "thinkit/mirror_testbed_fixture.h"
18+
#include <string>
19+
20+
#include "absl/types/span.h"
2021
#include "thinkit/ssh_client.h"
22+
#include "thinkit/switch.h"
2123

2224
namespace factory_reset {
2325

24-
void IssueGnoiFactoryResetAndValidateStatus(
25-
thinkit::Switch &sut, const gnoi::factory_reset::StartRequest &request,
26-
gnoi::factory_reset::StartResponse *response,
27-
grpc::Status expected_status = grpc::Status());
28-
29-
void ValidateStackState(thinkit::Switch &sut,
30-
absl::Span<const std::string> interfaces);
31-
32-
void TestFactoryResetSuccess(thinkit::Switch &sut,
33-
thinkit::SSHClient &ssh_client,
26+
void TestFactoryResetSuccess(thinkit::Switch& sut,
27+
thinkit::SSHClient& ssh_client,
3428
absl::Span<const std::string> interfaces);
3529

36-
void TestDuplicateFactoryResetFailure(thinkit::Switch &sut,
37-
thinkit::SSHClient &ssh_client,
30+
void TestDuplicateFactoryResetFailure(thinkit::Switch& sut,
31+
thinkit::SSHClient& ssh_client,
3832
absl::Span<const std::string> interfaces);
3933

4034
void TestGnoiFactoryResetGnoiServerUnreachableFail(
41-
thinkit::Switch &sut, thinkit::SSHClient &ssh_client,
35+
thinkit::Switch& sut, thinkit::SSHClient& ssh_client,
4236
absl::Span<const std::string> interfaces);
4337

44-
} // namespace factory_reset
38+
} // namespace factory_reset
4539

46-
#endif // PINS_TESTS_GNOI_FACTORY_RESET_TEST_H_
40+
#endif // PINS_TESTS_GNOI_FACTORY_RESET_TEST_H_

tests/lib/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ cc_library(
113113
"@com_github_p4lang_p4runtime//:p4info_cc_proto",
114114
"@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
115115
"@com_github_p4lang_p4runtime//:p4types_cc_proto",
116+
"@com_google_absl//absl/base:core_headers",
116117
"@com_google_absl//absl/container:btree",
117118
"@com_google_absl//absl/container:flat_hash_map",
118119
"@com_google_absl//absl/status",

0 commit comments

Comments
 (0)