Skip to content

Commit

Permalink
helpers: Use regex to find container ID in neofs_cli output
Browse files Browse the repository at this point in the history
It can find the container ID not just in the first line of the `neofs_cli`
output, as the output differs between `aio` and `dev-env`.

Signed-off-by: Tatiana Nesterenko <[email protected]>
  • Loading branch information
tatiana-nspcc committed Mar 11, 2024
1 parent 735b7ca commit fd10681
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions scenarios/preset/helpers/neofs_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ def create_container(endpoint, policy, wallet_file, wallet_config):
print(f" > Container has not been created:\n{output}")
return False
else:
try:
fst_str = output.split('\n')[0]
except Exception:
print(f"Got empty output: {output}")
return False
splitted = fst_str.split(": ")
if len(splitted) != 2:
raise ValueError(f"no CID was parsed from command output: \t{fst_str}")

print(f"Created container: {splitted[1]}")

return splitted[1]
# Regular expression to find the container ID, case-insensitive
pattern = r"container ID: ([A-Za-z0-9]{44})"

# Search for the pattern in the output text with case-insensitive flag
match = re.search(pattern, output, re.IGNORECASE)
if match:
container_id = match.group(1)
print(f"Created container: {container_id}")
return container_id
else:
raise ValueError(f"no CID was parsed from command output: \t{output}")


def upload_object(container, payload_filepath, endpoint, wallet_file, wallet_config):
Expand Down

0 comments on commit fd10681

Please sign in to comment.