Skip to content

Commit

Permalink
[Comb] Config blob set test case & gNMI set admin-status test. (#345)
Browse files Browse the repository at this point in the history
Co-authored-by: rhalstea <[email protected]>
  • Loading branch information
divyagayathri-hcl and rhalstea authored Jul 17, 2024
1 parent 41af8d8 commit e2edec1
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 4 deletions.
34 changes: 32 additions & 2 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ package(
cc_library(
name = "thinkit_sanity_tests",
testonly = 1,
srcs = ["thinkit_sanity_tests.cc"],
hdrs = ["thinkit_sanity_tests.h"],
srcs = [
"thinkit_sanity_tests.cc",
],
hdrs = [
"thinkit_sanity_tests.h",
"thinkit_util.h",
],
deps = [
"//gutil:status",
"//gutil:status_matchers",
Expand All @@ -47,6 +52,31 @@ cc_library(
],
)

cc_library(
name = "thinkit_gnmi_tests",
testonly = 1,
srcs = [
"thinkit_gnmi_interface_tests.cc",
],
hdrs = [
"thinkit_gnmi_interface_tests.h",
"thinkit_util.h",
],
deps = [
"//gutil:status_matchers",
"//lib/gnmi:gnmi_helper",
"//thinkit:ssh_client",
"//thinkit:switch",
"@com_github_gnmi//proto/gnmi:gnmi_cc_grpc_proto",
"@com_github_google_glog//:glog",
"@com_github_nlohmann_json//:nlohmann_json",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/time",
"@com_google_googletest//:gtest",
],
)

cc_library(
name = "thinkit_gnmi_subscribe_tests",
testonly = 1,
Expand Down
118 changes: 118 additions & 0 deletions tests/thinkit_gnmi_interface_tests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "tests/thinkit_gnmi_interface_tests.h"

#include <string>
#include <utility>

#include "absl/status/statusor.h"
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "glog/logging.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "gutil/status_matchers.h"
#include "lib/gnmi/gnmi_helper.h"
#include "proto/gnmi/gnmi.grpc.pb.h"
#include "include/nlohmann/json.hpp"
#include "tests/thinkit_util.h"
#include "thinkit/ssh_client.h"
#include "thinkit/switch.h"

namespace pins_test {
namespace {

using ::nlohmann::json;
using ::testing::HasSubstr;

} // namespace

void TestGnmiInterfaceConfigSetAdminStatus(thinkit::Switch& sut,
absl::string_view if_name) {
ASSERT_OK_AND_ASSIGN(auto sut_gnmi_stub, sut.CreateGnmiStub());

// Disable front panel port.
LOG(INFO) << "Disabling front panel port: " << if_name;
const std::string if_enabled_config_path =
absl::StrCat("interfaces/interface[name=", if_name, "]/config/enabled");
ASSERT_OK(SetGnmiConfigPath(sut_gnmi_stub.get(), if_enabled_config_path,
GnmiSetType::kUpdate, kEnabledFalse));

// Perform state path verifications.
// Verify /interfaces/interface[name=<port>]/state/enabled = false.
std::string if_state_path =
absl::StrCat("interfaces/interface[name=", if_name, "]/state/enabled");
std::string resp_parse_str = "openconfig-interfaces:enabled";
ASSERT_OK_AND_ASSIGN(
std::string state_path_response,
GetGnmiStatePathInfo(sut_gnmi_stub.get(), if_state_path, resp_parse_str));
EXPECT_THAT(state_path_response, HasSubstr("false"));

// Verify /interfaces/interface[name=<port>]/state/admin-status = DOWN.
if_state_path = absl::StrCat("interfaces/interface[name=", if_name,
"]/state/admin-status");
resp_parse_str = "openconfig-interfaces:admin-status";
ASSERT_OK_AND_ASSIGN(
state_path_response,
GetGnmiStatePathInfo(sut_gnmi_stub.get(), if_state_path, resp_parse_str));
EXPECT_THAT(state_path_response, HasSubstr(kStateDown));

// Verify /interfaces/interface[name=<port>]/state/oper-status = DOWN.
if_state_path = absl::StrCat("interfaces/interface[name=", if_name,
"]/state/oper-status");
resp_parse_str = "openconfig-interfaces:oper-status";
ASSERT_OK_AND_ASSIGN(
state_path_response,
GetGnmiStatePathInfo(sut_gnmi_stub.get(), if_state_path, resp_parse_str));
EXPECT_THAT(state_path_response, HasSubstr(kStateDown));

// Enable front panel port.
LOG(INFO) << "Enabling front panel port: " << if_name;
ASSERT_OK(SetGnmiConfigPath(sut_gnmi_stub.get(), if_enabled_config_path,
GnmiSetType::kUpdate, kEnabledTrue));

// Perform state path verifications.
// Verify /interfaces/interface[name=<port>]/state/enabled = true.
if_state_path =
absl::StrCat("interfaces/interface[name=", if_name, "]/state/enabled");
resp_parse_str = "openconfig-interfaces:enabled";
ASSERT_OK_AND_ASSIGN(
state_path_response,
GetGnmiStatePathInfo(sut_gnmi_stub.get(), if_state_path, resp_parse_str));
EXPECT_THAT(state_path_response, HasSubstr("true"));

// Verify /interfaces/interface[name=<port>]/state/admin-status = UP.
if_state_path = absl::StrCat("interfaces/interface[name=", if_name,
"]/state/admin-status");
resp_parse_str = "openconfig-interfaces:admin-status";
ASSERT_OK_AND_ASSIGN(
state_path_response,
GetGnmiStatePathInfo(sut_gnmi_stub.get(), if_state_path, resp_parse_str));
EXPECT_THAT(state_path_response, HasSubstr(kStateUp));

// Verify /interfaces/interface[name=<port>]/state/oper-status = UP.
absl::SleepFor(absl::Seconds(5));
if_state_path = absl::StrCat("interfaces/interface[name=", if_name,
"]/state/oper-status");
resp_parse_str = "openconfig-interfaces:oper-status";
ASSERT_OK_AND_ASSIGN(
state_path_response,
GetGnmiStatePathInfo(sut_gnmi_stub.get(), if_state_path, resp_parse_str));
EXPECT_THAT(state_path_response, HasSubstr(kStateUp));
}

} // namespace pins_test
28 changes: 28 additions & 0 deletions tests/thinkit_gnmi_interface_tests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef GOOGLE_TESTS_THINKIT_GNMI_INTERFACE_TESTS_H_
#define GOOGLE_TESTS_THINKIT_GNMI_INTERFACE_TESTS_H_

#include "absl/strings/string_view.h"
#include "thinkit/switch.h"

namespace pins_test {

void TestGnmiInterfaceConfigSetAdminStatus(thinkit::Switch& sut,
absl::string_view if_name);

} // namespace pins_test

#endif // GOOGLE_TESTS_THINKIT_GNMI_INTERFACE_TESTS_H_
3 changes: 1 addition & 2 deletions tests/thinkit_sanity_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "p4_pdpi/p4_runtime_session.h"
#include "proto/gnmi/gnmi.grpc.pb.h"
#include "include/nlohmann/json.hpp"
#include "tests/thinkit_util.h"
#include "thinkit/ssh_client.h"
#include "thinkit/switch.h"

Expand All @@ -46,8 +47,6 @@ using ::testing::HasSubstr;

} // namespace

constexpr char kStateUp[] = "UP";
constexpr char kInterfaces[] = "interfaces";
constexpr char kMtuJsonVal[] = "{\"mtu\":2000}";

void TestSSHCommand(thinkit::SSHClient& ssh_client, thinkit::Switch& sut) {
Expand Down

0 comments on commit e2edec1

Please sign in to comment.