machine: improve multi-instance validation

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-10-20 20:27:02 -04:00
parent 8f444a908e
commit 974b37dad8
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 11 additions and 5 deletions

View File

@ -1299,7 +1299,7 @@ class InstallValidator:
if unit != "moonraker": if unit != "moonraker":
logging.info(f"Custom service file detected: {unit}") logging.info(f"Custom service file detected: {unit}")
# Not using he default unit name # Not using he default unit name
if app_args["is_default_data_path"]: if app_args["is_default_data_path"] and self.data_path_valid:
# No datapath set, create a new, unique data path # No datapath set, create a new, unique data path
df = f"~/{unit}_data" df = f"~/{unit}_data"
match = re.match(r"moonraker[-_]?(\d+)", unit) match = re.match(r"moonraker[-_]?(\d+)", unit)
@ -1314,7 +1314,10 @@ class InstallValidator:
) )
# If the current path is bare we can remove it # If the current path is bare we can remove it
if self._check_path_bare(self.data_path): if (
self.data_path.exists() and
self._check_path_bare(self.data_path)
):
shutil.rmtree(self.data_path) shutil.rmtree(self.data_path)
self.data_path = new_dp self.data_path = new_dp
if not self.data_path.exists(): if not self.data_path.exists():
@ -1409,6 +1412,8 @@ class InstallValidator:
def _check_path_bare(self, path: pathlib.Path) -> bool: def _check_path_bare(self, path: pathlib.Path) -> bool:
empty: bool = True empty: bool = True
if not path.exists():
return True
for item in path.iterdir(): for item in path.iterdir():
if ( if (
item.is_file() or item.is_file() or
@ -1417,7 +1422,7 @@ class InstallValidator:
): ):
empty = False empty = False
break break
if next(item.iterdir(), None) is not None: if item.is_dir() and next(item.iterdir(), None) is not None:
empty = False empty = False
break break
return empty return empty
@ -1659,9 +1664,10 @@ class InstallValidator:
except asyncio.CancelledError: except asyncio.CancelledError:
raise raise
except Exception as e: except Exception as e:
logging.exception(f"{name} validation failed")
raise self.server.error( raise self.server.error(
f"{name} validation failed with error:\n{e}", 500 f"{name} validation failed", 500
) from e ) from None
await self.remove_announcement() await self.remove_announcement()
db: MoonrakerDatabase = self.server.lookup_component("database") db: MoonrakerDatabase = self.server.lookup_component("database")
await db.insert_item( await db.insert_item(