1
0
Fork 0

Consistently use csv_operator_name and csv_operator_version when building upgrade graph

This commit is contained in:
Maurizio Porrato 2023-08-05 08:55:22 +01:00
parent 8d7e461544
commit f72700feb9
2 changed files with 15 additions and 5 deletions

View File

@ -29,7 +29,9 @@ class Bundle:
METADATA_DIR = "metadata"
MANIFESTS_DIR = "manifests"
def __init__(self, bundle_path: Union[str, Path], operator: Optional["Operator"] = None):
def __init__(
self, bundle_path: Union[str, Path], operator: Optional["Operator"] = None
):
log.debug("Loading bundle at %s", bundle_path)
self._bundle_path = Path(bundle_path).resolve()
if not self.probe(self._bundle_path):
@ -383,6 +385,12 @@ class Operator:
if update_strategy == "replaces-mode":
edges: Dict[Bundle, set[Bundle]] = {}
all_bundles_set = set(all_bundles)
operator_names = {x.csv_operator_name for x in all_bundles_set}
if len(operator_names) != 1:
raise ValueError(
f"{self} has bundles with different operator names: {operator_names}"
)
version_to_bundle = {x.csv_operator_version: x for x in all_bundles_set}
for bundle in all_bundles_set:
spec = bundle.csv.get("spec", {})
replaces = spec.get("replaces")
@ -404,15 +412,15 @@ class Operator:
f"{self}: {bundle} replaces a bundle from a different operator"
)
try:
replaced_bundle = self.bundle(
replaced_bundle = version_to_bundle[
replaced_bundle_version.lstrip("v")
)
]
if (
channel in bundle.channels
and channel in replaced_bundle.channels
):
edges.setdefault(replaced_bundle, set()).add(bundle)
except InvalidBundleException:
except KeyError:
pass
return edges
raise ValueError(f"{self}: unknown updateGraph value: {update_strategy}")

View File

@ -110,4 +110,6 @@ def test_bundle_invalid(tmp_path: Path) -> None:
assert repo.has("missing_csv")
with pytest.raises(InvalidBundleException, match="CSV file for .* not found"):
_ = repo.operator("missing_csv").bundle("0.0.1").csv_operator_name
assert list(repo.operator("one_empty_bundle")) == [repo.operator("one_empty_bundle").bundle("0.0.1")]
assert list(repo.operator("one_empty_bundle")) == [
repo.operator("one_empty_bundle").bundle("0.0.1")
]