Adding acl to container and bucket creation #128

Merged
abereziny merged 1 commits from abereziny/xk6-frostfs:feature-add-acl-argument into master 2024-02-06 11:59:28 +00:00
4 changed files with 17 additions and 10 deletions

View File

@ -3,15 +3,18 @@ import uuid
from helpers.cmd import execute_cmd, log
def create_bucket(endpoint, versioning, location, no_verify_ssl):
def create_bucket(endpoint, versioning, location, acl, no_verify_ssl):
if location:
location = f"--create-bucket-configuration 'LocationConstraint={location}'"
if acl:
acl = f"--acl {acl}"
bucket_name = str(uuid.uuid4())
no_verify_ssl_str = "--no-verify-ssl" if no_verify_ssl else ""
cmd_line = f"aws {no_verify_ssl_str} s3api create-bucket --bucket {bucket_name} " \
f"--endpoint {endpoint} {location}"
f"--endpoint {endpoint} {location} {acl} "
cmd_line_ver = f"aws {no_verify_ssl_str} s3api put-bucket-versioning --bucket {bucket_name} " \
f"--versioning-configuration Status=Enabled --endpoint {endpoint} "
f"--versioning-configuration Status=Enabled --endpoint {endpoint} {acl} "
output, success = execute_cmd(cmd_line)

View File

@ -1,16 +1,18 @@
import re
from helpers.cmd import execute_cmd, log
def create_container(endpoint, policy, wallet_path, config, local=False, depth=0):
def create_container(endpoint, policy, wallet_path, config, acl, local=False, depth=0):
if depth > 20:
raise ValueError(f"unable to create container: too many unsuccessful attempts")
if wallet_path:
wallet_file = "--wallet " + wallet_path
wallet_file = f"--wallet {wallet_path}"
if config:
wallet_config = "--config " + config
wallet_config = f"--config {config}"
if acl:
acl = f"--basic-acl {acl}"
cmd_line = f"frostfs-cli --rpc-endpoint {endpoint} container create {wallet_file} {wallet_config} " \
f" --policy '{policy}' --basic-acl public-read-write --await"
f" --policy '{policy}' {acl} --await"
output, success = execute_cmd(cmd_line)
@ -86,7 +88,7 @@ def create_container(endpoint, policy, wallet_path, config, local=False, depth=0
return cid
log(f"Created container {cid} is not stored on {endpoint}, creating another one...", endpoint)
return create_container(endpoint, policy, wallet_path, config, local, depth + 1)
return create_container(endpoint, policy, wallet_path, config, acl, local, depth + 1)
def upload_object(container, payload_filepath, endpoint, wallet_file, wallet_config):

View File

@ -35,6 +35,7 @@ parser.add_argument('--workers', help='Count of workers in preset. Max = 50, Def
parser.add_argument('--sleep', help='Time to sleep between containers creation and objects upload (in seconds), '
'Default = 8', default=8)
parser.add_argument('--local', help='Create containers that store data on provided endpoints. Warning: additional empty containers may be created.', action='store_true')
parser.add_argument('--acl', help='Container ACL. Default is public-read-write.', default='public-read-write')
dkirillov marked this conversation as resolved

question: Why default isn't private?

question: Why default isn't `private`?

@dkirillov Before the change public-read-write was hardcoded, so to support backward compatibility with anyone who uses it.

@dkirillov Before the change public-read-write was hardcoded, so to support backward compatibility with anyone who uses it.
args: Namespace = parser.parse_args()
print(args)
@ -62,7 +63,7 @@ def main():
containers_count = int(args.containers)
print(f"Create containers: {containers_count}")
with ProcessPoolExecutor(max_workers=min(MAX_WORKERS, workers)) as executor:
containers_runs = [executor.submit(create_container, endpoint, args.policy, wallet, wallet_config, args.local)
containers_runs = [executor.submit(create_container, endpoint, args.policy, wallet, wallet_config, args.acl, args.local)
for _, endpoint in
zip(range(containers_count), cycle(endpoints))]

View File

@ -27,6 +27,7 @@ parser.add_argument('--no-verify-ssl', help='Ignore SSL verifications', action='
parser.add_argument('--workers', help='Count of workers in preset. Max = 50, Default = 50', default=50)
parser.add_argument('--sleep', help='Time to sleep between buckets creation and objects upload (in seconds), '
'Default = 8', default=8)
parser.add_argument('--acl', help='Bucket ACL. Default is private. Expected values are: private, public-read or public-read-write.', default="private")
args = parser.parse_args()
print(args)
@ -58,7 +59,7 @@ def main():
print(f"Create buckets: {buckets_count}")
with ProcessPoolExecutor(max_workers=min(MAX_WORKERS, workers)) as executor:
buckets_runs = [executor.submit(create_bucket, endpoint, args.versioning, args.location, no_verify_ssl)
buckets_runs = [executor.submit(create_bucket, endpoint, args.versioning, args.location, args.acl, no_verify_ssl)
for _, endpoint in
zip(range(buckets_count), cycle(endpoints))]