Skip to content

Commit

Permalink
Config blob set test case, gNMI port component tests, Changing integr…
Browse files Browse the repository at this point in the history
…ated-circuit to integrated_circuit based on gNMI naming convention & gNOI system stub integration in thinkit.
  • Loading branch information
rhalstea authored and divyagayathri-hcl committed Jul 18, 2024
1 parent e2edec1 commit 5f545e2
Show file tree
Hide file tree
Showing 7 changed files with 336 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/gnmi/gnmi_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace pins_test {
namespace {

using ::nlohmann::json;
const LazyRE2 kSplitNameValueRE = {R"((\w+)\[(\w+)\=(\w+)\])"};
const LazyRE2 kSplitNameValueRE = {R"((\w+)\[(\w+)=([\w-]+)\])"};
} // namespace

gnmi::Path ConvertOCStringToPath(absl::string_view oc_path) {
Expand Down
3 changes: 3 additions & 0 deletions lib/gnmi/gnmi_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
#define GOOGLE_LIB_GNMI_GNMI_HELPER_H_

#include <cstddef>
#include <string>
#include <type_traits>

#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "proto/gnmi/gnmi.grpc.pb.h"
Expand Down
78 changes: 78 additions & 0 deletions tests/thinkit_gnmi_interface_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "tests/thinkit_gnmi_interface_tests.h"

#include <algorithm>
#include <string>
#include <utility>

Expand Down Expand Up @@ -115,4 +116,81 @@ void TestGnmiInterfaceConfigSetAdminStatus(thinkit::Switch& sut,
EXPECT_THAT(state_path_response, HasSubstr(kStateUp));
}

void TestGnmiPortComponentPaths(thinkit::SSHClient& ssh_client,
thinkit::Switch& sut,
absl::string_view platform_json_path) {
ASSERT_OK_AND_ASSIGN(auto sut_gnmi_stub, sut.CreateGnmiStub());

// Configure integrated circuit name on the switch.
const std::string ic_name = "integrated-circuit0";
const std::string ic_name_config_path =
absl::StrCat("components/component[name=", ic_name, "]/config/name");
ASSERT_OK(SetGnmiConfigPath(sut_gnmi_stub.get(), ic_name_config_path,
GnmiSetType::kUpdate,
ConstructGnmiConfigSetString("name", ic_name)));

// Fetch platform.json from the switch.
const std::string ssh_command =
absl::StrCat("cat ", platform_json_path, kPlatformJson);
LOG(INFO) << "Fetching " << kPlatformJson
<< " contents from switch path: " << platform_json_path;
ASSERT_OK_AND_ASSIGN(std::string platform_json_contents,
ssh_client.RunCommand(sut.ChassisName(), ssh_command,
absl::ZeroDuration()));
LOG(INFO) << kPlatformJson << " contents: " << platform_json_contents;

// Fetch interface information from platform.json.
const auto platform_json = json::parse(platform_json_contents);
const auto interface_json = platform_json.find(kInterfaces);
ASSERT_NE(interface_json, platform_json.end());

for (const auto& interface : interface_json->items()) {
const std::string port_name = interface.key();
const auto port_info = interface.value();
ASSERT_EQ(port_info.count("index"), 1);

// Fetch /interfaces/interface[name=<port>]/state/hardware-port.
const std::string hw_port_state_path = absl::StrCat(
"interfaces/interface[name=", port_name, "]/state/hardware-port");
const std::string hw_port_parse_str =
"openconfig-platform-port:hardware-port";
ASSERT_OK_AND_ASSIGN(
std::string hw_port,
GetGnmiStatePathInfo(sut_gnmi_stub.get(), hw_port_state_path,
hw_port_parse_str));
hw_port.erase(std::remove(hw_port.begin(), hw_port.end(), '"'),
hw_port.end());

// hardware-port is in the format 1/<port_no>. Fetch port number from this
// information and verify that it is same as index attribute of the port in
// platform.json.
const auto separator_location = hw_port.find("/");
ASSERT_NE(separator_location, std::string::npos);
const std::string port_number = hw_port.substr(separator_location + 1);
ASSERT_EQ(port_info["index"], port_number);

// Verify that hardware-port attribute matches information in path
// /components/component[name=<port>]/state/name.
const std::string component_name_state_path =
absl::StrCat("components/component[name=", hw_port, "]/state/name");
const std::string component_name_parse_str = "openconfig-platform:name";
ASSERT_OK_AND_ASSIGN(
const std::string component_name,
GetGnmiStatePathInfo(sut_gnmi_stub.get(), component_name_state_path,
component_name_parse_str));
EXPECT_THAT(component_name, HasSubstr(hw_port));

// Verify that integrated circuit name matches information in path
// /components/component[name=<port>]/state/parent.
const std::string component_parent_state_path =
absl::StrCat("components/component[name=", hw_port, "]/state/parent");
const std::string component_parent_parse_str = "openconfig-platform:parent";
ASSERT_OK_AND_ASSIGN(
const std::string component_parent,
GetGnmiStatePathInfo(sut_gnmi_stub.get(), component_parent_state_path,
component_parent_parse_str));
EXPECT_THAT(component_parent, HasSubstr(ic_name));
}
}

} // namespace pins_test
5 changes: 5 additions & 0 deletions tests/thinkit_gnmi_interface_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@
#define GOOGLE_TESTS_THINKIT_GNMI_INTERFACE_TESTS_H_

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

namespace pins_test {

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

void TestGnmiPortComponentPaths(thinkit::SSHClient& ssh_client,
thinkit::Switch& sut,
absl::string_view platform_json_path);

} // namespace pins_test

#endif // GOOGLE_TESTS_THINKIT_GNMI_INTERFACE_TESTS_H_
Loading

0 comments on commit 5f545e2

Please sign in to comment.