OP-3426 - raise better exception if mongorestore not found

This commit is contained in:
Petr Kalis 2022-11-04 15:32:45 +01:00
parent 8aa05190c6
commit fc99a9a35e

View file

@ -118,7 +118,7 @@ class DBHandler:
"Run with overwrite=True")
else:
if collection:
if collection in self.client[db_name_out].list_collection_names():
if collection in self.client[db_name_out].list_collection_names(): # noqa
self.client[db_name_out][collection].drop()
else:
self.teardown(db_name_out)
@ -132,7 +132,11 @@ class DBHandler:
db_name=db_name, db_name_out=db_name_out,
collection=collection)
print("mongorestore query:: {}".format(query))
subprocess.run(query)
try:
subprocess.run(query)
except FileNotFoundError:
raise RuntimeError("'mongorestore' utility must be on path."
"Please install it.")
def teardown(self, db_name):
"""Drops 'db_name' if exists."""