Skip to content

Commit

Permalink
rpc: bazelize rpc_gen_cycling_test
Browse files Browse the repository at this point in the history
  • Loading branch information
IoannisRP committed Dec 3, 2024
1 parent 8cf9e87 commit afd764d
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 21 deletions.
110 changes: 109 additions & 1 deletion src/v/rpc/test/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
load("//bazel:test.bzl", "redpanda_cc_bench", "redpanda_cc_btest")
load("//bazel:build.bzl", "redpanda_cc_library")
load("//bazel:cert.bzl", "redpanda_selfsigned_cert", "redpanda_signed_cert")
load("//bazel:test.bzl", "redpanda_cc_bench", "redpanda_cc_btest", "redpanda_test_cc_library")
load("//src/v/rpc:compiler.bzl", "redpanda_cc_rpc_library")

redpanda_test_cc_library(
name = "rpc_integration_fixture",
hdrs = [
"rpc_integration_fixture.h",
],
include_prefix = "rpc/test",
deps = [
"//src/v/base",
"//src/v/config",
"//src/v/net",
"//src/v/rpc",
"@seastar",
],
)

redpanda_cc_btest(
name = "netbuf_test",
timeout = "short",
Expand Down Expand Up @@ -101,6 +118,37 @@ redpanda_cc_btest(
],
)

redpanda_cc_btest(
name = "rpc_gen_cycling_test",
timeout = "short",
srcs = [
"rpc_gen_cycling_test.cc",
],
cpu = 1,
data = [
":cert",
":cert_ca",
":other_cert",
":other_cert_ca",
],
tags = ["exclusive"],
deps = [
":cycling_rpc",
":echo_rpc",
":echo_v2_rpc",
":rpc_integration_fixture",
"//src/v/bytes:random",
"//src/v/model",
"//src/v/random:generators",
"//src/v/rpc",
"//src/v/test_utils:fixture",
"//src/v/test_utils:seastar_boost",
"@boost//:test",
"@seastar",
"@seastar//:testing",
],
)

redpanda_cc_bench(
name = "rpc_bench",
timeout = "short",
Expand All @@ -114,17 +162,77 @@ redpanda_cc_bench(
],
)

redpanda_cc_library(
name = "rpc_gen_types",
hdrs = [
"rpc_gen_types.h",
],
include_prefix = "rpc/test",
deps = [
"//src/v/base",
"//src/v/reflection:adl",
"//src/v/rpc",
"//src/v/serde",
"//src/v/serde:enum",
"//src/v/serde:sstring",
"@seastar",
],
)

redpanda_cc_rpc_library(
name = "cycling_rpc",
src = "cycling_service.json",
out = "cycling_service.h",
include_prefix = "rpc/test",
deps = [
":rpc_gen_types",
],
)

redpanda_cc_rpc_library(
name = "echo_rpc",
src = "echo_service.json",
out = "echo_service.h",
include_prefix = "rpc/test",
deps = [
":rpc_gen_types",
],
)

redpanda_cc_rpc_library(
name = "echo_v2_rpc",
src = "echo_v2_service.json",
out = "echo_v2_service.h",
include_prefix = "rpc/test",
deps = [
":rpc_gen_types",
],
)

redpanda_selfsigned_cert(
name = "cert_ca",
certificate = "root_certificate_authority",
common_name = "redpanda.com",
)

redpanda_selfsigned_cert(
name = "other_cert_ca",
certificate = "root_certificate_authority.other",
common_name = "redpanda.other.com",
)

redpanda_signed_cert(
name = "cert",
ca = "root_certificate_authority",
certificate = "redpanda",
common_name = "cert.com",
serial_number = 1,
)

redpanda_signed_cert(
name = "other_cert",
ca = "root_certificate_authority.other",
certificate = "redpanda.other",
common_name = "cert.other.com",
serial_number = 2,
)
2 changes: 1 addition & 1 deletion src/v/rpc/test/cycling_service.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"namespace": "cycling",
"service_name": "team_movistar",
"includes": [
"rpc_gen_types.h"
"rpc/test/rpc_gen_types.h"
],
"methods": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/v/rpc/test/echo_service.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"namespace": "echo",
"service_name": "echo",
"includes": [
"rpc_gen_types.h"
"rpc/test/rpc_gen_types.h"
],
"methods": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/v/rpc/test/echo_v2_service.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"namespace": "echo_v2",
"service_name": "echo",
"includes": [
"rpc_gen_types.h"
"rpc/test/rpc_gen_types.h"
],
"methods": [
{
Expand Down
69 changes: 52 additions & 17 deletions src/v/rpc/test/rpc_gen_cycling_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
#include "rpc/test/cycling_service.h"
#include "rpc/test/echo_service.h"
#include "rpc/test/echo_v2_service.h"
#include "rpc/test/rpc_integration_fixture.h"
#include "rpc/types.h"
#include "rpc_gen_types.h"
#include "rpc_integration_fixture.h"
#include "serde/rw/iobuf.h"
#include "test_utils/async.h"
#include "test_utils/fixture.h"

Expand Down Expand Up @@ -135,6 +133,41 @@ class rpc_integration_fixture : public rpc_simple_integration_fixture {
static constexpr uint16_t redpanda_rpc_port = 32147;
};

struct certificate {
ss::sstring key;
ss::sstring crt;
ss::sstring ca;
};

namespace {
ss::sstring root_path() {
// if this file exists, we are running in cmake
if (std::filesystem::exists("redpanda.key")) {
return "";
}

// otherwise we are running in bazel and we need
// the full path
return "src/v/rpc/test/";
}

certificate redpanda_cert() {
const auto root = root_path();
return {
.key = root + "redpanda.key",
.crt = root + "redpanda.crt",
.ca = root + "root_certificate_authority.crt"};
}

certificate redpanda_other_cert() {
const auto root = root_path();
return {
.key = root + "redpanda.other.key",
.crt = root + "redpanda.other.crt",
.ca = root + "root_certificate_authority.other.crt"};
}
} // namespace

FIXTURE_TEST(echo_round_trip, rpc_integration_fixture) {
configure_server();
register_services();
Expand Down Expand Up @@ -237,7 +270,7 @@ FIXTURE_TEST(echo_from_cache, rpc_integration_fixture) {
// Check that we can create connections from a cache, and moreover that we
// can run several clients targeted at the same server, if we provide
// multiple node IDs to the cache.
constexpr const size_t num_nodes_ids = 10;
constexpr const int num_nodes_ids = 10;
const auto ccfg = client_config();
for (int i = 0; i < num_nodes_ids; ++i) {
const auto payload = random_generators::gen_alphanum_string(100);
Expand Down Expand Up @@ -301,10 +334,11 @@ FIXTURE_TEST(rpc_abort_from_cache, rpc_integration_fixture) {
}

FIXTURE_TEST(echo_round_trip_tls, rpc_integration_fixture) {
const auto cert = redpanda_cert();
auto creds_builder = config::tls_config(
true,
config::key_cert{"redpanda.key", "redpanda.crt"},
"root_certificate_authority.crt",
config::key_cert{cert.key, cert.crt},
cert.ca,
std::nullopt, /* CRL */
false)
.get_credentials_builder()
Expand Down Expand Up @@ -367,16 +401,18 @@ struct certificate_reload_ctx {
};

FIXTURE_TEST(rpcgen_reload_credentials_integration, rpc_integration_fixture) {
const certificate cert = redpanda_cert();
const certificate other_cert = redpanda_other_cert();

// Server starts with bad credentials, files are updated on disk and then
// client connects. Expected behavior is that client can connect without
// issues. Condition variable is used to wait for credentials to reload.
auto context = ss::make_lw_shared<certificate_reload_ctx>();
temporary_dir tmp;
// client credentials
auto client_key = tmp.copy_file("redpanda.key", "client.key");
auto client_crt = tmp.copy_file("redpanda.crt", "client.crt");
auto client_ca = tmp.copy_file(
"root_certificate_authority.crt", "ca_client.pem");
auto client_key = tmp.copy_file(cert.key.c_str(), "client.key");
auto client_crt = tmp.copy_file(cert.crt.c_str(), "client.crt");
auto client_ca = tmp.copy_file(cert.ca.c_str(), "ca_client.pem");
auto client_creds_builder = config::tls_config(
true,
config::key_cert{
Expand All @@ -387,10 +423,9 @@ FIXTURE_TEST(rpcgen_reload_credentials_integration, rpc_integration_fixture) {
.get_credentials_builder()
.get();
// server credentials
auto server_key = tmp.copy_file("redpanda.other.key", "server.key");
auto server_crt = tmp.copy_file("redpanda.other.crt", "server.crt");
auto server_ca = tmp.copy_file(
"root_certificate_authority.other.crt", "ca_server.pem");
auto server_key = tmp.copy_file(other_cert.key.c_str(), "server.key");
auto server_crt = tmp.copy_file(other_cert.crt.c_str(), "server.crt");
auto server_ca = tmp.copy_file(other_cert.ca.c_str(), "ca_server.pem");
auto server_creds_builder = config::tls_config(
true,
config::key_cert{
Expand Down Expand Up @@ -432,9 +467,9 @@ FIXTURE_TEST(rpcgen_reload_credentials_integration, rpc_integration_fixture) {

// fix client credentials and reconnect
info("replacing files");
tmp.copy_file("redpanda.key", "server.key");
tmp.copy_file("redpanda.crt", "server.crt");
tmp.copy_file("root_certificate_authority.crt", "ca_server.pem");
tmp.copy_file(cert.key.c_str(), "server.key");
tmp.copy_file(cert.crt.c_str(), "server.crt");
tmp.copy_file(cert.ca.c_str(), "ca_server.pem");

context->cvar.wait([context] { return context->updated.size() == 3; })
.get();
Expand Down

0 comments on commit afd764d

Please sign in to comment.