mirror of
https://github.com/planetmint/planetmint.git
synced 2025-07-03 03:02:29 +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)
|
logger.info("Create database `%s`.", dbname)
|
||||||
create_tables(connection, dbname)
|
|
||||||
|
|
||||||
|
|
||||||
def run_command_with_output(command):
|
def run_command_with_output(command):
|
||||||
@ -167,9 +166,10 @@ def run_command_with_output(command):
|
|||||||
Config().get()["database"]["host"],
|
Config().get()["database"]["host"],
|
||||||
Config().get()["database"]["port"],
|
Config().get()["database"]["port"],
|
||||||
)
|
)
|
||||||
output = run(["tarantoolctl", "connect", host_port], input=command, capture_output=True).stderr
|
output = run(["tarantoolctl", "connect", host_port], input=command, capture_output=True)
|
||||||
output = output.decode()
|
if output.returncode != 0:
|
||||||
return output
|
raise Exception(f"Error while trying to execute cmd {command} on host:port {host_port}: {output.stderr}")
|
||||||
|
return output.stdout
|
||||||
|
|
||||||
|
|
||||||
@register_schema(TarantoolDBConnection)
|
@register_schema(TarantoolDBConnection)
|
||||||
@ -179,8 +179,8 @@ def create_tables(connection, dbname):
|
|||||||
cmd = SPACE_COMMANDS[_space].encode()
|
cmd = SPACE_COMMANDS[_space].encode()
|
||||||
run_command_with_output(command=cmd)
|
run_command_with_output(command=cmd)
|
||||||
print(f"Space '{_space}' created.")
|
print(f"Space '{_space}' created.")
|
||||||
except Exception:
|
except Exception as err:
|
||||||
print(f"Unexpected error while trying to create '{_space}'")
|
print(f"Unexpected error while trying to create '{_space}': {err}")
|
||||||
create_schema(space_name=_space)
|
create_schema(space_name=_space)
|
||||||
create_indexes(space_name=_space)
|
create_indexes(space_name=_space)
|
||||||
|
|
||||||
@ -191,8 +191,8 @@ def create_indexes(space_name):
|
|||||||
try:
|
try:
|
||||||
run_command_with_output(command=index_cmd.encode())
|
run_command_with_output(command=index_cmd.encode())
|
||||||
print(f"Index '{index_name}' created succesfully.")
|
print(f"Index '{index_name}' created succesfully.")
|
||||||
except Exception:
|
except Exception as err:
|
||||||
print(f"Unexpected error while trying to create index '{index_name}'")
|
print(f"Unexpected error while trying to create index '{index_name}': '{err}'")
|
||||||
|
|
||||||
|
|
||||||
def create_schema(space_name):
|
def create_schema(space_name):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user