Skip to content

Commit

Permalink
[Thinkit] Adding Test cases to thinkit_gnmi_interface_util_tests file. (
Browse files Browse the repository at this point in the history
#890)



Co-authored-by: kishanps <kishanps@google.com>
  • Loading branch information
divyagayathri-hcl and kishanps authored Dec 27, 2024
1 parent 52080b1 commit 557bc9e
Showing 1 changed file with 394 additions and 0 deletions.
394 changes: 394 additions & 0 deletions tests/thinkit_gnmi_interface_util_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2211,4 +2211,398 @@ TEST_F(GNMIThinkitInterfaceUtilityTest,
"valid format (EthernetX/Y/Z)")));
}

TEST_F(GNMIThinkitInterfaceUtilityTest,
TestGetCurrentBreakoutModeForPortUnchannelizedModeSuccess) {
auto mock_gnmi_stub_ptr = absl::make_unique<gnmi::MockgNMIStub>();
ASSERT_OK_AND_ASSIGN(auto current_breakout_mode_get_req,
currentBreakoutModeGetReq("1/1"));
ASSERT_OK_AND_ASSIGN(auto current_breakout_mode_get_resp,
currentBreakoutModeGetUnchannelizedResp("1/1"));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(current_breakout_mode_get_req), _))
.WillOnce(DoAll(SetArgPointee<2>(current_breakout_mode_get_resp),
Return(grpc::Status::OK)));
const std::string port_name = "Ethernet1/1/1";
const std::string expected_breakout_mode = "1x400G";
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_req,
hardwarePortGetReq("Ethernet1/1/1"));
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_resp,
hardwarePortGetResp("Ethernet1/1/1", "1"));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(hardware_port_get_req), _))
.WillOnce(DoAll(SetArgPointee<2>(hardware_port_get_resp),
Return(grpc::Status::OK)));

EXPECT_THAT(
pins_test::GetCurrentBreakoutModeForPort(*mock_gnmi_stub_ptr, port_name),
expected_breakout_mode);
}

TEST_F(GNMIThinkitInterfaceUtilityTest,
TestGetCurrentBreakoutModeForPortMixedModeSuccess) {
auto mock_gnmi_stub_ptr = absl::make_unique<gnmi::MockgNMIStub>();
const std::string port_name = "Ethernet1/1/1";
const std::string expected_breakout_mode = "1x400G+2x200G";
ASSERT_OK_AND_ASSIGN(auto current_breakout_mode_get_req,
currentBreakoutModeGetReq("1/1"));
ASSERT_OK_AND_ASSIGN(auto current_breakout_mode_get_resp,
currentBreakoutModeGetMixedResp("1/1"));
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_req,
hardwarePortGetReq("Ethernet1/1/1"));
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_resp,
hardwarePortGetResp("Ethernet1/1/1", "1"));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(hardware_port_get_req), _))
.WillOnce(DoAll(SetArgPointee<2>(hardware_port_get_resp),
Return(grpc::Status::OK)));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(current_breakout_mode_get_req), _))
.WillOnce(DoAll(SetArgPointee<2>(current_breakout_mode_get_resp),
Return(grpc::Status::OK)));
EXPECT_THAT(
pins_test::GetCurrentBreakoutModeForPort(*mock_gnmi_stub_ptr, port_name),
expected_breakout_mode);
}

TEST_F(GNMIThinkitInterfaceUtilityTest,
TestGetCurrentBreakoutModeForPortFailureDueToNonParentPort) {
auto mock_gnmi_stub_ptr = absl::make_unique<gnmi::MockgNMIStub>();
const std::string port_name = "Ethernet1/1/5";
EXPECT_THAT(
pins_test::GetCurrentBreakoutModeForPort(*mock_gnmi_stub_ptr, port_name),
StatusIs(absl::StatusCode::kInternal,
HasSubstr(absl::StrCat("Requested port (", port_name,
") is not a parent port"))));
}

TEST_F(GNMIThinkitInterfaceUtilityTest,
TestGetCurrentBreakoutModeForPortInvalidPortFailure) {
auto mock_gnmi_stub_ptr = absl::make_unique<gnmi::MockgNMIStub>();
const std::string port_name = "Ethernet1/1/X";
EXPECT_THAT(
pins_test::GetCurrentBreakoutModeForPort(*mock_gnmi_stub_ptr, port_name),
StatusIs(absl::StatusCode::kInternal,
HasSubstr("Failed to convert string (X) to integer")));
}

TEST_F(GNMIThinkitInterfaceUtilityTest,
TestGetCurrentBreakoutModeForPortGroupNotFoundFailure) {
auto mock_gnmi_stub_ptr = absl::make_unique<gnmi::MockgNMIStub>();
const std::string port_name = "Ethernet1/1/1";
ASSERT_OK_AND_ASSIGN(auto current_breakout_mode_get_req,
currentBreakoutModeGetReq("1/1"));
gnmi::GetResponse current_breakout_mode_get_resp;
ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(
R"pb(
notification {
timestamp: 1631864194292383538
prefix { origin: "openconfig" }
update {
path {
elem { name: "openconfig-platform:components" }
elem {
name: "component"
key: { key: "name" value: "$0" }
}
elem { name: "port" }
elem { name: "breakout-mode" }
elem { name: "groups" }
}
val { json_ietf_val: "{\"openconfig-platform-port:groups\":{}}" }
}
}
)pb",
&current_breakout_mode_get_resp));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(current_breakout_mode_get_req), _))
.WillOnce(DoAll(SetArgPointee<2>(current_breakout_mode_get_resp),
Return(grpc::Status::OK)));
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_req,
hardwarePortGetReq("Ethernet1/1/1"));
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_resp,
hardwarePortGetResp("Ethernet1/1/1", "1"));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(hardware_port_get_req), _))
.WillOnce(DoAll(SetArgPointee<2>(hardware_port_get_resp),
Return(grpc::Status::OK)));
EXPECT_THAT(
pins_test::GetCurrentBreakoutModeForPort(*mock_gnmi_stub_ptr, port_name),
StatusIs(absl::StatusCode::kInternal,
HasSubstr("group not found in state path response")));
}

TEST_F(GNMIThinkitInterfaceUtilityTest,
TestGetCurrentBreakoutModeForPortIndexNotFoundInGroupFailure) {
auto mock_gnmi_stub_ptr = absl::make_unique<gnmi::MockgNMIStub>();
const std::string port_name = "Ethernet1/1/1";
ASSERT_OK_AND_ASSIGN(auto current_breakout_mode_get_req,
currentBreakoutModeGetReq("1/1"));
gnmi::GetResponse current_breakout_mode_get_resp;
ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(
R"pb(
notification {
timestamp: 1631864194292383538
prefix { origin: "openconfig" }
update {
path {
elem { name: "openconfig-platform:components" }
elem {
name: "component"
key: { key: "name" value: "$0" }
}
elem { name: "port" }
elem { name: "breakout-mode" }
elem { name: "groups" }
}
val {
json_ietf_val: "{\"openconfig-platform-port:groups\":{\"group\":[{\"config\":{\"breakout-speed\":\"openconfig-if-ethernet:SPEED_200GB\",\"num-breakouts\":2,\"num-physical-channels\":4},\"state\":{\"breakout-speed\":\"openconfig-if-ethernet:SPEED_200GB\",\"index\":0,\"num-breakouts\":2,\"num-physical-channels\":4}}]}}"
}
}
}
)pb",
&current_breakout_mode_get_resp));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(current_breakout_mode_get_req), _))
.WillOnce(DoAll(SetArgPointee<2>(current_breakout_mode_get_resp),
Return(grpc::Status::OK)));
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_req,
hardwarePortGetReq("Ethernet1/1/1"));
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_resp,
hardwarePortGetResp("Ethernet1/1/1", "1"));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(hardware_port_get_req), _))
.WillOnce(DoAll(SetArgPointee<2>(hardware_port_get_resp),
Return(grpc::Status::OK)));
EXPECT_THAT(
pins_test::GetCurrentBreakoutModeForPort(*mock_gnmi_stub_ptr, port_name),
StatusIs(absl::StatusCode::kInternal,
HasSubstr("index not found in breakout group")));
}

TEST_F(GNMIThinkitInterfaceUtilityTest,
TestGetCurrentBreakoutModeForPortStateNotFoundInGroupFailure) {
auto mock_gnmi_stub_ptr = absl::make_unique<gnmi::MockgNMIStub>();
const std::string port_name = "Ethernet1/1/1";
ASSERT_OK_AND_ASSIGN(auto current_breakout_mode_get_req,
currentBreakoutModeGetReq("1/1"));
gnmi::GetResponse current_breakout_mode_get_resp;
ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(
R"pb(
notification {
timestamp: 1631864194292383538
prefix { origin: "openconfig" }
update {
path {
elem { name: "openconfig-platform:components" }
elem {
name: "component"
key: { key: "name" value: "$0" }
}
elem { name: "port" }
elem { name: "breakout-mode" }
elem { name: "groups" }
}
val {
json_ietf_val: "{\"openconfig-platform-port:groups\":{\"group\":[{\"config\":{\"breakout-speed\":\"openconfig-if-ethernet:SPEED_400GB\",\"index\":0,\"num-breakouts\":1,\"num-physical-channels\":8},\"index\":0}]}}"
}
}
}
)pb",
&current_breakout_mode_get_resp));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(current_breakout_mode_get_req), _))
.WillOnce(DoAll(SetArgPointee<2>(current_breakout_mode_get_resp),
Return(grpc::Status::OK)));
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_req,
hardwarePortGetReq("Ethernet1/1/1"));
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_resp,
hardwarePortGetResp("Ethernet1/1/1", "1"));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(hardware_port_get_req), _))
.WillOnce(DoAll(SetArgPointee<2>(hardware_port_get_resp),
Return(grpc::Status::OK)));

EXPECT_THAT(
pins_test::GetCurrentBreakoutModeForPort(*mock_gnmi_stub_ptr, port_name),
StatusIs(absl::StatusCode::kInternal,
HasSubstr("state not found in breakout group")));
}

TEST_F(GNMIThinkitInterfaceUtilityTest,
TestGetCurrentBreakoutModeForPortNumBreakoutsNotFoundFailure) {
auto mock_gnmi_stub_ptr = absl::make_unique<gnmi::MockgNMIStub>();
const std::string port_name = "Ethernet1/1/1";
ASSERT_OK_AND_ASSIGN(auto current_breakout_mode_get_req,
currentBreakoutModeGetReq("1/1"));
gnmi::GetResponse current_breakout_mode_get_resp;
ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(
R"pb(
notification {
timestamp: 1631864194292383538
prefix { origin: "openconfig" }
update {
path {
elem { name: "openconfig-platform:components" }
elem {
name: "component"
key: { key: "name" value: "$0" }
}
elem { name: "port" }
elem { name: "breakout-mode" }
elem { name: "groups" }
}
val {
json_ietf_val: "{\"openconfig-platform-port:groups\":{\"group\":[{\"config\":{\"breakout-speed\":\"openconfig-if-ethernet:SPEED_200GB\",\"index\":0,\"num-breakouts\":2,\"num-physical-channels\":4},\"index\":0,\"state\":{\"breakout-speed\":\"openconfig-if-ethernet:SPEED_200GB\",\"index\":0,\"num-physical-channels\":4}}]}}"
}
}
}
)pb",
&current_breakout_mode_get_resp));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(current_breakout_mode_get_req), _))
.WillOnce(DoAll(SetArgPointee<2>(current_breakout_mode_get_resp),
Return(grpc::Status::OK)));
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_req,
hardwarePortGetReq("Ethernet1/1/1"));
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_resp,
hardwarePortGetResp("Ethernet1/1/1", "1"));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(hardware_port_get_req), _))
.WillOnce(DoAll(SetArgPointee<2>(hardware_port_get_resp),
Return(grpc::Status::OK)));
EXPECT_THAT(
pins_test::GetCurrentBreakoutModeForPort(*mock_gnmi_stub_ptr, port_name),
StatusIs(absl::StatusCode::kInternal,
HasSubstr("num-breakouts not found in breakout group state")));
}

TEST_F(GNMIThinkitInterfaceUtilityTest,
TestGetCurrentBreakoutModeForPortBreakoutSpeedNotFoundFailure) {
auto mock_gnmi_stub_ptr = absl::make_unique<gnmi::MockgNMIStub>();
const std::string port_name = "Ethernet1/1/1";
ASSERT_OK_AND_ASSIGN(auto current_breakout_mode_get_req,
currentBreakoutModeGetReq("1/1"));
gnmi::GetResponse current_breakout_mode_get_resp;
ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(
R"pb(
notification {
timestamp: 1631864194292383538
prefix { origin: "openconfig" }
update {
path {
elem { name: "openconfig-platform:components" }
elem {
name: "component"
key: { key: "name" value: "$0" }
}
elem { name: "port" }
elem { name: "breakout-mode" }
elem { name: "groups" }
}
val {
json_ietf_val: "{\"openconfig-platform-port:groups\":{\"group\":[{\"config\":{\"breakout-speed\":\"openconfig-if-ethernet:SPEED_200GB\",\"index\":0,\"num-breakouts\":2,\"num-physical-channels\":4},\"index\":0,\"state\":{\"index\":0,\"num-breakouts\":2,\"num-physical-channels\":4}}]}}"
}
}
}
)pb",
&current_breakout_mode_get_resp));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(current_breakout_mode_get_req), _))
.WillOnce(DoAll(SetArgPointee<2>(current_breakout_mode_get_resp),
Return(grpc::Status::OK)));
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_req,
hardwarePortGetReq("Ethernet1/1/1"));
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_resp,
hardwarePortGetResp("Ethernet1/1/1", "1"));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(hardware_port_get_req), _))
.WillOnce(DoAll(SetArgPointee<2>(hardware_port_get_resp),
Return(grpc::Status::OK)));
EXPECT_THAT(
pins_test::GetCurrentBreakoutModeForPort(*mock_gnmi_stub_ptr, port_name),
StatusIs(absl::StatusCode::kInternal,
HasSubstr("breakout-speed not found in breakout group state")));
}

TEST_F(GNMIThinkitInterfaceUtilityTest,
TestGetCurrentBreakoutModeForPortInvalidIndexFailure) {
auto mock_gnmi_stub_ptr = absl::make_unique<gnmi::MockgNMIStub>();
const std::string port_name = "Ethernet1/1/1";
ASSERT_OK_AND_ASSIGN(auto current_breakout_mode_get_req,
currentBreakoutModeGetReq("1/1"));
gnmi::GetResponse current_breakout_mode_get_resp;
ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(
R"pb(
notification {
timestamp: 1631864194292383538
prefix { origin: "openconfig" }
update {
path {
elem { name: "openconfig-platform:components" }
elem {
name: "component"
key: { key: "name" value: "$0" }
}
elem { name: "port" }
elem { name: "breakout-mode" }
elem { name: "groups" }
}
val {
json_ietf_val: "{\"openconfig-platform-port:groups\":{\"group\":[{\"config\":{\"breakout-speed\":\"openconfig-if-ethernet:SPEED_400GB\",\"index\":0,\"num-breakouts\":1,\"num-physical-channels\":8},\"index\":\"X\",\"state\":{\"breakout-speed\":\"openconfig-if-ethernet:SPEED_400GB\",\"index\":0,\"num-breakouts\":1,\"num-physical-channels\":8}}]}}"
}
}
}
)pb",
&current_breakout_mode_get_resp));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(current_breakout_mode_get_req), _))
.WillOnce(DoAll(SetArgPointee<2>(current_breakout_mode_get_resp),
Return(grpc::Status::OK)));
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_req,
hardwarePortGetReq("Ethernet1/1/1"));
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_resp,
hardwarePortGetResp("Ethernet1/1/1", "1"));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(hardware_port_get_req), _))
.WillOnce(DoAll(SetArgPointee<2>(hardware_port_get_resp),
Return(grpc::Status::OK)));
EXPECT_THAT(
pins_test::GetCurrentBreakoutModeForPort(*mock_gnmi_stub_ptr, port_name),
StatusIs(absl::StatusCode::kInternal,
HasSubstr("Failed to convert string (\"X\") to integer")));
}

TEST_F(GNMIThinkitInterfaceUtilityTest,
TestGetCurrentBreakoutModeForPortPhysicalPortGetFailure) {
auto mock_gnmi_stub_ptr = absl::make_unique<gnmi::MockgNMIStub>();
const std::string port_name = "Ethernet1/1/1";
ASSERT_OK_AND_ASSIGN(auto hardware_port_get_req,
hardwarePortGetReq("Ethernet1/1/1"));
EXPECT_CALL(*mock_gnmi_stub_ptr,
Get(_, EqualsProto(hardware_port_get_req), _))
.WillOnce(Return(grpc::Status(grpc::StatusCode::DEADLINE_EXCEEDED, "")));
EXPECT_THAT(
pins_test::GetCurrentBreakoutModeForPort(*mock_gnmi_stub_ptr, port_name),
StatusIs(absl::StatusCode::kDeadlineExceeded,
HasSubstr("Failed to get GNMI state path value for interface "
"hardware-port for port Ethernet1/1/1")));
}

TEST_F(GNMIThinkitInterfaceUtilityTest, TestIsParentPortSuccessForParentPort) {
const std::string port = "Ethernet1/1/1";
EXPECT_THAT(IsParentPort(port), true);
}

TEST_F(GNMIThinkitInterfaceUtilityTest, TestIsParentPortSuccessForChildPort) {
const std::string port = "Ethernet1/1/5";
EXPECT_THAT(IsParentPort(port), false);
}

TEST_F(GNMIThinkitInterfaceUtilityTest, TestIsParentPortIntConversionFailure) {
const std::string port = "Ethernet1/1/X";
EXPECT_THAT(IsParentPort(port),
StatusIs(absl::StatusCode::kInternal,
HasSubstr("Failed to convert string (X) to integer")));
}

} // namespace pins_test

0 comments on commit 557bc9e

Please sign in to comment.