Skip to content

Commit

Permalink
Merge pull request #569 from projectsyn/fix/invalid-output-inventory-…
Browse files Browse the repository at this point in the history
…show

Remove reclass warnings from `commodore inventory show` output
  • Loading branch information
glrf authored Jul 28, 2022
2 parents c73b995 + 47d2a76 commit 6d18805
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
18 changes: 15 additions & 3 deletions commodore/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,11 @@ def inventory_show(
inv = extract_parameters(
config,
InventoryFacts(
global_config, tenant_config, extra_values, allow_missing_classes
global_config,
tenant_config,
extra_values,
allow_missing_classes,
ignore_class_notfound_warning=False,
),
)
except ValueError as e:
Expand Down Expand Up @@ -776,7 +780,11 @@ def component_versions(
components = extract_components(
config,
InventoryFacts(
global_config, tenant_config, extra_values, allow_missing_classes
global_config,
tenant_config,
extra_values,
allow_missing_classes,
ignore_class_notfound_warning=False,
),
)
except ValueError as e:
Expand Down Expand Up @@ -815,7 +823,11 @@ def package_versions(
pkgs = extract_packages(
config,
InventoryFacts(
global_config, tenant_config, extra_values, allow_missing_classes
global_config,
tenant_config,
extra_values,
allow_missing_classes,
ignore_class_notfound_warning=False,
),
)
except ValueError as e:
Expand Down
25 changes: 21 additions & 4 deletions commodore/inventory/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ def __init__(
tenant_config: Optional[str],
extra_class_files: Iterable[Path],
allow_missing_classes: bool,
ignore_class_notfound_warning: bool = True,
):
self._global_config = global_config
self._tenant_config = tenant_config
self._extra_class_files = extra_class_files
self._allow_missing_classes = allow_missing_classes
self._ignore_class_notfound_warning = ignore_class_notfound_warning

@property
def global_config(self) -> str:
Expand All @@ -75,6 +77,10 @@ def extra_class_files(self) -> Iterable[Path]:
def allow_missing_classes(self) -> bool:
return self._allow_missing_classes

@property
def ignore_class_notfound_warning(self) -> bool:
return self._ignore_class_notfound_warning

@property
def tenant_id(self) -> str:
tenant_id = None
Expand Down Expand Up @@ -170,7 +176,9 @@ def global_dir(self) -> Path:
def tenant_dir(self) -> Optional[Path]:
return self._tenant_dir

def _reclass_config(self, allow_missing_classes: bool) -> dict:
def _reclass_config(
self, allow_missing_classes: bool, ignore_class_notfound_warning: bool = True
) -> dict:
return {
"storage_type": "yaml_fs",
"inventory_base_uri": str(self.directory.absolute()),
Expand All @@ -179,12 +187,19 @@ def _reclass_config(self, allow_missing_classes: bool) -> dict:
"compose_node_name": False,
"allow_none_override": True,
"ignore_class_notfound": allow_missing_classes,
"ignore_class_notfound_warning": ignore_class_notfound_warning,
}

def _render_inventory(
self, target: Optional[str] = None, allow_missing_classes: bool = True
self,
target: Optional[str] = None,
allow_missing_classes: bool = True,
ignore_class_notfound_warning: bool = True,
) -> dict[str, Any]:
rc = self._reclass_config(allow_missing_classes)
rc = self._reclass_config(
allow_missing_classes,
ignore_class_notfound_warning=ignore_class_notfound_warning,
)
storage = reclass.get_storage(
rc["storage_type"],
rc["nodes_uri"],
Expand Down Expand Up @@ -266,7 +281,9 @@ def reclass(self, invfacts: InventoryFacts) -> InventoryParameters:

return InventoryParameters(
self._render_inventory(
"global", allow_missing_classes=invfacts.allow_missing_classes
"global",
allow_missing_classes=invfacts.allow_missing_classes,
ignore_class_notfound_warning=invfacts.ignore_class_notfound_warning,
)
)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_component_versions_cli(
yaml.safe_dump({"classes": ["global.test"]}, f)

with open(global_config / "test.yml", "w") as f:
yaml.safe_dump({"parameters": parameters}, f)
yaml.safe_dump({"classes": ["foo.bar"], "parameters": parameters}, f)

result = cli_runner(["inventory", "components", str(global_config)] + args)

Expand Down Expand Up @@ -185,7 +185,7 @@ def test_package_versions_cli(
yaml.safe_dump({"classes": ["global.test"]}, f)

with open(global_config / "test.yml", "w") as f:
yaml.safe_dump({"parameters": parameters}, f)
yaml.safe_dump({"classes": ["foo.bar"], "parameters": parameters}, f)

result = cli_runner(["inventory", "packages", str(global_config)] + args)

Expand Down Expand Up @@ -230,7 +230,7 @@ def test_show_inventory_cli(
yaml.safe_dump({"classes": ["global.test"]}, f)

with open(global_config / "test.yml", "w") as f:
yaml.safe_dump({"parameters": parameters}, f)
yaml.safe_dump({"classes": ["foo.bar"], "parameters": parameters}, f)

result = cli_runner(["inventory", "show", str(global_config)] + args)

Expand Down

0 comments on commit 6d18805

Please sign in to comment.