[#180] preset_grpc: Add ability to attach rule for created container
All checks were successful
All checks were successful
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
f0cbf9c301
commit
ebea190737
2 changed files with 23 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
||||||
import re
|
import re
|
||||||
from helpers.cmd import execute_cmd, log
|
from helpers.cmd import execute_cmd, log
|
||||||
|
|
||||||
def create_container(endpoint, policy, container_creation_retry, wallet_path, config, local=False, retry=0):
|
def create_container(endpoint, policy, container_creation_retry, wallet_path, config, rules, local=False, retry=0):
|
||||||
if retry > int(container_creation_retry):
|
if retry > int(container_creation_retry):
|
||||||
raise ValueError(f"unable to create container: too many unsuccessful attempts")
|
raise ValueError(f"unable to create container: too many unsuccessful attempts")
|
||||||
|
|
||||||
|
@ -34,6 +34,21 @@ def create_container(endpoint, policy, container_creation_retry, wallet_path, co
|
||||||
|
|
||||||
log(f"Created container: {cid} ({policy})", endpoint)
|
log(f"Created container: {cid} ({policy})", endpoint)
|
||||||
|
|
||||||
|
# Add rule for container
|
||||||
|
if rules:
|
||||||
|
r = ""
|
||||||
|
for rule in rules:
|
||||||
|
rule = rule.replace("CONTAINER_ID", cid)
|
||||||
|
r += f" --rule '{rule}' "
|
||||||
|
cmd_line = f"frostfs-cli --rpc-endpoint {endpoint} ape-manager add {wallet_file} {wallet_config} " \
|
||||||
|
f" --chain-id 'chain-id' {r} --target-name '{cid}' --target-type 'container'"
|
||||||
|
output, success = execute_cmd(cmd_line)
|
||||||
|
if not success:
|
||||||
|
log(f"{cmd_line}\n"
|
||||||
|
f"Rule has not been added\n"
|
||||||
|
f"{output}", endpoint)
|
||||||
|
return False
|
||||||
|
|
||||||
if not local:
|
if not local:
|
||||||
return cid
|
return cid
|
||||||
|
|
||||||
|
@ -86,7 +101,7 @@ def create_container(endpoint, policy, container_creation_retry, wallet_path, co
|
||||||
return cid
|
return cid
|
||||||
|
|
||||||
log(f"Created container {cid} is not stored on {endpoint}, creating another one...", endpoint)
|
log(f"Created container {cid} is not stored on {endpoint}, creating another one...", endpoint)
|
||||||
return create_container(endpoint, policy, container_creation_retry, wallet_path, config, local, retry + 1)
|
return create_container(endpoint, policy, container_creation_retry, wallet_path, config, rules, local, retry + 1)
|
||||||
|
|
||||||
|
|
||||||
def upload_object(container, payload_filepath, endpoint, wallet_file, wallet_config):
|
def upload_object(container, payload_filepath, endpoint, wallet_file, wallet_config):
|
||||||
|
|
|
@ -37,6 +37,10 @@ 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), '
|
parser.add_argument('--sleep', help='Time to sleep between containers creation and objects upload (in seconds), '
|
||||||
'Default = 8', default=8)
|
'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('--local', help='Create containers that store data on provided endpoints. Warning: additional empty containers may be created.', action='store_true')
|
||||||
|
parser.add_argument(
|
||||||
|
'--rule',
|
||||||
|
help='Rule attached to created containers. All entries of CONTAINER_ID will be replaced with id of created container.',
|
||||||
|
action="append")
|
||||||
|
|
||||||
args: Namespace = parser.parse_args()
|
args: Namespace = parser.parse_args()
|
||||||
print(args)
|
print(args)
|
||||||
|
@ -55,6 +59,7 @@ def main():
|
||||||
wallet_config = args.config
|
wallet_config = args.config
|
||||||
workers = int(args.workers)
|
workers = int(args.workers)
|
||||||
objects_per_container = int(args.preload_obj)
|
objects_per_container = int(args.preload_obj)
|
||||||
|
rules = args.rule
|
||||||
|
|
||||||
ignore_errors = args.ignore_errors
|
ignore_errors = args.ignore_errors
|
||||||
if args.update:
|
if args.update:
|
||||||
|
@ -67,7 +72,7 @@ def main():
|
||||||
containers_count = int(args.containers)
|
containers_count = int(args.containers)
|
||||||
print(f"Create containers: {containers_count}")
|
print(f"Create containers: {containers_count}")
|
||||||
with ProcessPoolExecutor(max_workers=min(MAX_WORKERS, workers)) as executor:
|
with ProcessPoolExecutor(max_workers=min(MAX_WORKERS, workers)) as executor:
|
||||||
containers_runs = [executor.submit(create_container, endpoint, policy, container_creation_retry, wallet, wallet_config, args.local)
|
containers_runs = [executor.submit(create_container, endpoint, policy, container_creation_retry, wallet, wallet_config, rules, args.local)
|
||||||
for _, endpoint, policy in
|
for _, endpoint, policy in
|
||||||
zip(range(containers_count), cycle(endpoints), cycle(args.policy))]
|
zip(range(containers_count), cycle(endpoints), cycle(args.policy))]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue