|
1 | 1 | __author__ = "desultory" |
2 | | -__version__ = "7.1.2" |
| 2 | +__version__ = "7.1.3" |
3 | 3 |
|
4 | 4 | from pathlib import Path |
5 | 5 | from re import search |
@@ -130,13 +130,16 @@ def _get_mount_dev_fs_type(self, device: str, raise_exception=True) -> str: |
130 | 130 | self.logger.debug("No mount found for device: %s" % device) |
131 | 131 |
|
132 | 132 |
|
133 | | -def _get_mount_source_type(self, mount: dict, with_val=False) -> str: |
134 | | - """Gets the source from the mount config.""" |
| 133 | +def _get_mount_source(self, mount: dict) -> str: |
| 134 | + """Gets the source from the mount config. |
| 135 | + Uses the order of SOURCE_TYPES to determine the source type. |
| 136 | + uuid, partuuid, label, path. |
| 137 | +
|
| 138 | + Returns the source type and value if found, otherwise raises a ValueError. |
| 139 | + """ |
135 | 140 | for source_type in SOURCE_TYPES: |
136 | 141 | if source_type in mount: |
137 | | - if with_val: |
138 | | - return source_type, mount[source_type] |
139 | | - return source_type |
| 142 | + return source_type, mount[source_type] |
140 | 143 | raise ValueError("No source type found in mount: %s" % mount) |
141 | 144 |
|
142 | 145 |
|
@@ -249,8 +252,8 @@ def _get_mount_str(self, mount: dict, pad=False, pad_size=44) -> str: |
249 | 252 | """returns the mount source string based on the config, |
250 | 253 | the output string should work with fstab and mount commands. |
251 | 254 | pad: pads the output string with spaces, defined by pad_size (44).""" |
252 | | - mount_type, mount_name = _get_mount_source_type(self, mount, with_val=True) |
253 | | - out_str = mount_name if mount_type == "path" else f"{mount_type.upper()}={mount_name}" |
| 255 | + mount_type, mount_val = _get_mount_source(self, mount) |
| 256 | + out_str = mount_val if mount_type == "path" else f"{mount_type.upper()}={mount_val}" |
254 | 257 |
|
255 | 258 | if pad: |
256 | 259 | if len(out_str) > pad_size: |
@@ -899,7 +902,7 @@ def _validate_host_mount(self, mount, destination_path=None) -> bool: |
899 | 902 | if mount.get("base_mount"): |
900 | 903 | return self.logger.debug("Skipping host mount validation for base mount: %s" % mount) |
901 | 904 |
|
902 | | - mount_type, mount_val = _get_mount_source_type(self, mount, with_val=True) |
| 905 | + mount_type, mount_val = _get_mount_source(self, mount) |
903 | 906 | # If a destination path is passed, like for /, use that instead of the mount's destination |
904 | 907 | destination_path = str(mount["destination"]) if destination_path is None else destination_path |
905 | 908 |
|
@@ -994,7 +997,14 @@ def mount_root(self) -> str: |
994 | 997 |
|
995 | 998 | def export_mount_info(self) -> None: |
996 | 999 | """Exports mount info based on the config to /run/MOUNTS_ROOT_{option}""" |
997 | | - self["exports"]["MOUNTS_ROOT_SOURCE"] = _get_mount_str(self, self["mounts"]["root"]) |
| 1000 | + try: |
| 1001 | + self["exports"]["MOUNTS_ROOT_SOURCE"] = _get_mount_str(self, self["mounts"]["root"]) |
| 1002 | + except ValueError as e: |
| 1003 | + self.logger.critical(f"Failed to get source info for the root mount: {e}") |
| 1004 | + if not self["hostonly"]: |
| 1005 | + self.logger.info("Root mount infomrmation can be defined under the '[mounts.root]' section.") |
| 1006 | + raise ValidationError("Root mount source information is not set, when hostonly mode is disabled, it must be manually defined.") |
| 1007 | + raise ValidationError("Root mount source information is not set even though hostonly mode is enabled. Please report a bug.") |
998 | 1008 | self["exports"]["MOUNTS_ROOT_TYPE"] = self["mounts"]["root"].get("type", "auto") |
999 | 1009 | self["exports"]["MOUNTS_ROOT_OPTIONS"] = ",".join(self["mounts"]["root"]["options"]) |
1000 | 1010 | self["exports"]["MOUNTS_ROOT_TARGET"] = self["mounts"]["root"]["destination"] |
|
0 commit comments