mirror of
https://github.com/planetmint/planetmint.git
synced 2025-03-30 15:08:31 +00:00
added exception to handle erroneus cmd output (#239)
* added exception to handle erroneus cmd output Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * linted the schema.py Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> Co-authored-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
0a21b0a9d9
commit
6be78c052f
@ -157,7 +157,6 @@ def create_database(connection, dbname):
|
||||
|
||||
"""
|
||||
logger.info("Create database `%s`.", dbname)
|
||||
create_tables(connection, dbname)
|
||||
|
||||
|
||||
def run_command_with_output(command):
|
||||
@ -167,9 +166,10 @@ def run_command_with_output(command):
|
||||
Config().get()["database"]["host"],
|
||||
Config().get()["database"]["port"],
|
||||
)
|
||||
output = run(["tarantoolctl", "connect", host_port], input=command, capture_output=True).stderr
|
||||
output = output.decode()
|
||||
return output
|
||||
output = run(["tarantoolctl", "connect", host_port], input=command, capture_output=True)
|
||||
if output.returncode != 0:
|
||||
raise Exception(f"Error while trying to execute cmd {command} on host:port {host_port}: {output.stderr}")
|
||||
return output.stdout
|
||||
|
||||
|
||||
@register_schema(TarantoolDBConnection)
|
||||
@ -179,8 +179,8 @@ def create_tables(connection, dbname):
|
||||
cmd = SPACE_COMMANDS[_space].encode()
|
||||
run_command_with_output(command=cmd)
|
||||
print(f"Space '{_space}' created.")
|
||||
except Exception:
|
||||
print(f"Unexpected error while trying to create '{_space}'")
|
||||
except Exception as err:
|
||||
print(f"Unexpected error while trying to create '{_space}': {err}")
|
||||
create_schema(space_name=_space)
|
||||
create_indexes(space_name=_space)
|
||||
|
||||
@ -191,8 +191,8 @@ def create_indexes(space_name):
|
||||
try:
|
||||
run_command_with_output(command=index_cmd.encode())
|
||||
print(f"Index '{index_name}' created succesfully.")
|
||||
except Exception:
|
||||
print(f"Unexpected error while trying to create index '{index_name}'")
|
||||
except Exception as err:
|
||||
print(f"Unexpected error while trying to create index '{index_name}': '{err}'")
|
||||
|
||||
|
||||
def create_schema(space_name):
|
||||
|
Loading…
x
Reference in New Issue
Block a user