Skip to content

Commit

Permalink
Implement the changes for port name update on test side. Add a test w…
Browse files Browse the repository at this point in the history
…here StartBert fails to get the lock with its peer if StartBert is requested only on one side of the link.
  • Loading branch information
kishanps authored and bibhuprasad-hcl committed Jul 19, 2024
1 parent add04f9 commit 014dc82
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
53 changes: 52 additions & 1 deletion lib/gnmi/gnmi_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
#include "absl/strings/match.h"
#include "absl/strings/str_join.h"
#include "absl/strings/str_split.h"

#include "absl/strings/string_view.h"
#include "absl/strings/substitute.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"

#include "absl/time/time.h"
#include "glog/logging.h"
#include "gmock/gmock.h"
Expand Down Expand Up @@ -166,7 +174,7 @@ absl::Status SetGnmiConfigPath(gnmi::gNMI::Stub* sut_gnmi_stub,
}

absl::Status PushGnmiConfig(gnmi::gNMI::Stub& stub,
const std::string& chassis_name,
absl::string_view chassis_name,
const std::string& gnmi_config,
absl::uint128 election_id) {
gnmi::SetRequest req;
Expand All @@ -191,6 +199,13 @@ absl::Status PushGnmiConfig(gnmi::gNMI::Stub& stub,
return absl::OkStatus();
}

absl::Status PushGnmiConfig(thinkit::Switch& chassis,
const std::string& gnmi_config) {
ASSIGN_OR_RETURN(std::unique_ptr<gnmi::gNMI::Stub> stub,
chassis.CreateGnmiStub());
return pins_test::PushGnmiConfig(*stub, chassis.ChassisName(), gnmi_config);
}

absl::Status CheckAllInterfaceUpOverGnmi(gnmi::gNMI::Stub& stub) {
ASSIGN_OR_RETURN(auto req,
BuildGnmiGetRequest("interfaces", gnmi::GetRequest::STATE));
Expand Down Expand Up @@ -303,4 +318,40 @@ GnmiGetElementFromTelemetryResponse(const gnmi::SubscribeResponse& response) {
return elements;
}

absl::StatusOr<OperStatus> GetInterfaceOperStatusOverGnmi(
gnmi::gNMI::Stub& stub, absl::string_view if_name) {
std::string if_req = absl::StrCat("interfaces/interface[name=", if_name,
"]/state/oper-status");
ASSIGN_OR_RETURN(auto request,
BuildGnmiGetRequest(if_req, gnmi::GetRequest::STATE));
LOG(INFO) << "Sending GET request: " << request.ShortDebugString();

gnmi::GetResponse response;
grpc::ClientContext context;
grpc::Status status = stub.Get(&context, request, &response);
if (!status.ok()) return gutil::GrpcStatusToAbslStatus(status);
LOG(INFO) << "Received GET response: " << response.ShortDebugString();

if (response.notification_size() != 1 ||
response.notification(0).update_size() != 1) {
return absl::InternalError(
absl::StrCat("Invalid response: ", response.DebugString()));
}
ASSIGN_OR_RETURN(
std::string oper_status,
ParseGnmiGetResponse(response, "openconfig-interfaces:oper-status"));
LOG(INFO) << "Got the operational status: " << oper_status << ".";

if (absl::StrContains((oper_status), "UP")) {
return OperStatus::kUp;
}
if (absl::StrContains((oper_status), "DOWN")) {
return OperStatus::kDown;
}
if (absl::StrContains((oper_status), "TESTING")) {
return OperStatus::kTesting;
}
return OperStatus::kUnknown;
}

} // namespace pins_test
18 changes: 17 additions & 1 deletion lib/gnmi/gnmi_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "p4_pdpi/p4_runtime_session.h"
#include "proto/gnmi/gnmi.grpc.pb.h"
#include "proto/gnmi/gnmi.pb.h"
#include "thinkit/switch.h"

namespace pins_test {

Expand All @@ -31,6 +32,13 @@ inline constexpr char kTarget[] = "target";

enum class GnmiSetType : char { kUpdate, kReplace, kDelete };

enum class OperStatus {
kUnknown,
kUp,
kDown,
kTesting,
};

// Builds gNMI Set Request for a given OC path, set type and set value.
// The path should be in the following format below.
// "interfaces/interface[Ethernet0]/config/mtu".
Expand Down Expand Up @@ -83,13 +91,21 @@ absl::StatusOr<std::vector<absl::string_view>>
GnmiGetElementFromTelemetryResponse(const gnmi::SubscribeResponse& response);

absl::Status PushGnmiConfig(
gnmi::gNMI::Stub& stub, const std::string& chassis_name,
gnmi::gNMI::Stub& stub, absl::string_view chassis_name,
const std::string& gnmi_config,
absl::uint128 election_id = pdpi::TimeBasedElectionId());

absl::Status PushGnmiConfig(thinkit::Switch& chassis,
const std::string& gnmi_config);

absl::Status CheckAllInterfaceUpOverGnmi(gnmi::gNMI::Stub& stub);

// Returns gNMI Path for OC strings.
gnmi::Path ConvertOCStringToPath(absl::string_view oc_path);

// Gets the operational status of an interface.
absl::StatusOr<OperStatus> GetInterfaceOperStatusOverGnmi(
gnmi::gNMI::Stub& stub, absl::string_view if_name);

} // namespace pins_test
#endif // GOOGLE_LIB_GNMI_GNMI_HELPER_H_
14 changes: 11 additions & 3 deletions thinkit/mirror_testbed_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class MirrorTestbedInterface {
virtual MirrorTestbed& GetMirrorTestbed() = 0;
};

// The Thinkit `TestParams` defines test parameters to
// `MirrorTestbedFixture` class.
struct TestParams {
MirrorTestbedInterface* mirror_testbed;
std::string gnmi_config;
};

// The ThinKit `MirrorTestbedFixture` class acts as a base test fixture for
// platform independent PINS tests. Any platform specific SetUp or TearDown
// requirements are abstracted through the ThinKit MirrorTestbedInterface which
Expand Down Expand Up @@ -63,8 +70,7 @@ class MirrorTestbedInterface {
// Individual tests should use the new suite name to take advantage of the
// custom setup/teardown:
// TEST_P(MyPinsTest, MyTestName) {}
class MirrorTestbedFixture
: public testing::TestWithParam<MirrorTestbedInterface*> {
class MirrorTestbedFixture : public testing::TestWithParam<TestParams> {
protected:
// A derived class that needs/wants to do its own setup can override this
// method. However, it should take care to call this base setup first. That
Expand All @@ -83,10 +89,12 @@ class MirrorTestbedFixture
return mirror_testbed_interface_->GetMirrorTestbed();
}

std::string GetGnmiConfig() { return GetParam().gnmi_config; }

private:
// Takes ownership of the MirrorTestbedInterface parameter.
std::unique_ptr<MirrorTestbedInterface> mirror_testbed_interface_ =
absl::WrapUnique<MirrorTestbedInterface>(GetParam());
absl::WrapUnique<MirrorTestbedInterface>(GetParam().mirror_testbed);
};

} // namespace thinkit
Expand Down

0 comments on commit 014dc82

Please sign in to comment.