From 3bec5ea2ce200846db8dfff9655a4e4bab12cfda Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 12 Apr 2023 19:20:01 +0300 Subject: [PATCH] s3/client: Keep server port on config Currently the code temporarily assumes that the endpoint port is 9000. This is what tests' local minio is started with. This patch keeps the port number on endpoint config and makes test get the port number from minio starting code via environment. Signed-off-by: Pavel Emelyanov --- main.cc | 1 + test/boost/s3_test.cc | 1 + test/lib/test_services.cc | 3 ++- test/object_store/run | 4 +++- test/pylib/minio_server.py | 1 + utils/s3/client.cc | 2 +- utils/s3/creds.hh | 1 + 7 files changed, 10 insertions(+), 3 deletions(-) diff --git a/main.cc b/main.cc index e91fa2699f..73532eca94 100644 --- a/main.cc +++ b/main.cc @@ -159,6 +159,7 @@ template<> struct convert<::object_storage_endpoint_param> { static bool decode(const Node& node, ::object_storage_endpoint_param& ep) { ep.endpoint = node["name"].as(); + ep.config.port = node["port"].as(); return true; } }; diff --git a/test/boost/s3_test.cc b/test/boost/s3_test.cc index 229c2d86d8..fa09d677c4 100644 --- a/test/boost/s3_test.cc +++ b/test/boost/s3_test.cc @@ -22,6 +22,7 @@ s3::endpoint_config_ptr make_minio_config() { s3::endpoint_config cfg = { + .port = std::stoul(tests::getenv_safe("S3_SERVER_PORT_FOR_TEST")), }; return make_lw_shared(std::move(cfg)); } diff --git a/test/lib/test_services.cc b/test/lib/test_services.cc index 731a307a81..a630e19653 100644 --- a/test/lib/test_services.cc +++ b/test/lib/test_services.cc @@ -169,6 +169,7 @@ std::unordered_map make_storage_options_config }, [&cfg] (const data_dictionary::storage_options::s3& os) mutable -> void { cfg[os.endpoint] = make_lw_shared(s3::endpoint_config { + .port = std::stoul(tests::getenv_safe("S3_SERVER_PORT_FOR_TEST")), }); } }, so.value); @@ -215,7 +216,7 @@ data_dictionary::storage_options make_test_object_storage_options() { data_dictionary::storage_options ret; ret.value = data_dictionary::storage_options::s3 { .bucket = tests::getenv_safe("S3_PUBLIC_BUCKET_FOR_TEST"), - .endpoint = format("{}:9000", tests::getenv_safe("S3_SERVER_ADDRESS_FOR_TEST")), + .endpoint = tests::getenv_safe("S3_SERVER_ADDRESS_FOR_TEST"), }; return ret; } diff --git a/test/object_store/run b/test/object_store/run index 8c18b197be..59ebf9c69c 100755 --- a/test/object_store/run +++ b/test/object_store/run @@ -24,6 +24,7 @@ else: test_tempdir = run.pid_to_dir(os.getpid()) os.mkdir(test_tempdir) s3_server_address = os.environ['S3_SERVER_ADDRESS_FOR_TEST'] +s3_server_port = int(os.environ['S3_SERVER_PORT_FOR_TEST']) s3_public_bucket = os.environ['S3_PUBLIC_BUCKET_FOR_TEST'] def get_tempdir(pid): @@ -33,6 +34,7 @@ with open(test_tempdir + '/object_storage.yaml', 'w') as config_file: yaml.dump({ 'endpoints': [ { 'name': s3_server_address, + 'port': s3_server_port, } ] }, config_file) @@ -59,7 +61,7 @@ run.wait_for_services(pid, [ lambda: check_cql(ip) ]) print(f'Create keyspace (minio listening at {s3_server_address})') cluster = run.get_cql_cluster(ip) conn = cluster.connect() -conn.execute("CREATE KEYSPACE test_ks WITH REPLICATION = { 'class': 'SimpleStrategy', 'replication_factor': '1' } AND STORAGE = { 'type': 'S3', 'endpoint': '" + f'{s3_server_address}' + ":9000', 'bucket': '" + f'{s3_public_bucket}' + "' };") +conn.execute("CREATE KEYSPACE test_ks WITH REPLICATION = { 'class': 'SimpleStrategy', 'replication_factor': '1' } AND STORAGE = { 'type': 'S3', 'endpoint': '" + f'{s3_server_address}' + "', 'bucket': '" + f'{s3_public_bucket}' + "' };") conn.execute("CREATE TABLE test_ks.test_cf ( name text primary key, value text );") conn.execute("INSERT INTO test_ks.test_cf ( name, value ) VALUES ('0', 'zero');") conn.execute("INSERT INTO test_ks.test_cf ( name, value ) VALUES ('1', 'one');") diff --git a/test/pylib/minio_server.py b/test/pylib/minio_server.py index 9cd89377ca..0c8b2cde2d 100644 --- a/test/pylib/minio_server.py +++ b/test/pylib/minio_server.py @@ -53,6 +53,7 @@ class MinioServer: self.address = await self.hosts.lease_host() self.log_file = self.log_filename.open("wb") os.environ['S3_SERVER_ADDRESS_FOR_TEST'] = f'{self.address}' + os.environ['S3_SERVER_PORT_FOR_TEST'] = f'{self.port}' os.environ['S3_PUBLIC_BUCKET_FOR_TEST'] = f'{self.bucket_name}' self.logger.info(f'Starting minio server at {self.address}:{self.port}') diff --git a/utils/s3/client.cc b/utils/s3/client.cc index 8ce109875f..af91ec2d77 100644 --- a/utils/s3/client.cc +++ b/utils/s3/client.cc @@ -46,7 +46,7 @@ future<> ignore_reply(const http::reply& rep, input_stream&& in_) { client::client(std::string host, endpoint_config_ptr cfg, private_tag) : _host(std::move(host)) , _cfg(std::move(cfg)) - , _http(ipv4_addr(_host, 9000 /* temporary hard-coded */)) + , _http(ipv4_addr(_host, _cfg->port)) { } diff --git a/utils/s3/creds.hh b/utils/s3/creds.hh index 6f55d1f0aa..ae22d2b990 100644 --- a/utils/s3/creds.hh +++ b/utils/s3/creds.hh @@ -13,6 +13,7 @@ namespace s3 { struct endpoint_config { + unsigned port; }; using endpoint_config_ptr = seastar::lw_shared_ptr;