From d8911f2490628241f0aa238c98c3f96874c5d318 Mon Sep 17 00:00:00 2001 From: Vladimir Domnich Date: Tue, 26 Jul 2022 11:16:29 +0300 Subject: [PATCH] Fix parsing of CLI output Formatting has been changed in CLI tools in version v0.30 and it required us to change logic in tests: - Fix authmate output parsing. - Fix format of container name in assert. Signed-off-by: Vladimir Domnich --- .../testsuites/container/test_container.py | 4 +-- .../lib/python_keywords/s3_gate_bucket.py | 31 ++++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/pytest_tests/testsuites/container/test_container.py b/pytest_tests/testsuites/container/test_container.py index 9224ffa..9e513e1 100644 --- a/pytest_tests/testsuites/container/test_container.py +++ b/pytest_tests/testsuites/container/test_container.py @@ -21,10 +21,10 @@ def test_container_creation(prepare_wallet_and_deposit, name): json_wallet = json.load(fp) placement_rule = 'REP 2 IN X CBF 1 SELECT 2 FROM * AS X' - info_to_check = {'basic ACL: 0x1c8c8ccc (private)', + info_to_check = {'basic ACL: 1c8c8ccc (private)', f'owner ID: {json_wallet.get("accounts")[0].get("address")}'} if name: - info_to_check.add(f'attribute: Name={name}') + info_to_check.add(f'Name={name}') name = f' --name {name}' cid = create_container(wallet, rule=placement_rule, options=name) diff --git a/robot/resources/lib/python_keywords/s3_gate_bucket.py b/robot/resources/lib/python_keywords/s3_gate_bucket.py index 0f9af21..08a8951 100644 --- a/robot/resources/lib/python_keywords/s3_gate_bucket.py +++ b/robot/resources/lib/python_keywords/s3_gate_bucket.py @@ -2,6 +2,7 @@ import json import os +import re import uuid from enum import Enum from time import sleep @@ -52,19 +53,25 @@ def init_s3_credentials(wallet_path, s3_bearer_rules_file: str = None): try: output = _run_with_passwd(cmd) logger.info(f'Command completed with output: {output}') - # first five string are log output, cutting them off and parse - # the rest of the output as JSON - output = '\n'.join(output.split('\n')[5:]) - try: - output_dict = json.loads(output) - except json.JSONDecodeError: - raise AssertionError(f'Could not parse info from output\n{output}') - return (output_dict['container_id'], - bucket, - output_dict['access_key_id'], - output_dict['secret_access_key'], - output_dict['owner_private_key']) + # output contains some debug info and then several JSON structures, so we find each + # JSON structure by curly brackets (naive approach, but works while JSON is not nested) + # and then we take JSON containing secret_access_key + json_blocks = re.findall(r'\{.*?\}', output, re.DOTALL) + for json_block in json_blocks: + try: + parsed_json_block = json.loads(json_block) + if 'secret_access_key' in parsed_json_block: + return ( + parsed_json_block['container_id'], + bucket, + parsed_json_block['access_key_id'], + parsed_json_block['secret_access_key'], + parsed_json_block['owner_private_key'] + ) + except json.JSONDecodeError: + raise AssertionError(f'Could not parse info from output\n{output}') + raise AssertionError(f'Could not find AWS credentials in output:\n{output}') except Exception as exc: raise RuntimeError(f'Failed to init s3 credentials because of error\n{exc}') from exc