Skip to content

Commit

Permalink
[antlir2][rpm] upgrade should install if missing
Browse files Browse the repository at this point in the history
Summary: If an rpm is not installed, upgrade should install it, not fail

Test Plan:
```
❯ buck2 test fbcode//antlir/antlir2/features/rpm/tests:upgrade-not-already-installed
Buck UI: https://www.internalfb.com/buck2/d0351215-69da-4675-8529-3bb752bf4574
Test UI: https://www.internalfb.com/intern/testinfra/testrun/7036874653273252
Tests finished: Pass 1. Fail 0. Fatal 0. Skip 0. Build failure 0
```

Reviewed By: naveedgol

Differential Revision: D63806983

fbshipit-source-id: ebcba322cfa568de61a7fba4fc8dfc59f8b85a4c
  • Loading branch information
vmagro authored and facebook-github-bot committed Oct 3, 2024
1 parent 001681b commit bdd56dc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
9 changes: 8 additions & 1 deletion antlir/antlir2/features/rpm/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,20 @@ def resolve(out, spec, base, local_rpms, explicitly_installed_package_names):
json.dump({"package_not_found": e.pkg_spec}, o)
elif action == "upgrade":
if isinstance(source, dnf.package.Package):
base.package_upgrade(source)
try:
base.package_upgrade(source)
except dnf.exceptions.MarkingError:
# If it's not installed, upgrade should behave the same as install
base.package_install(source, strict=True)
else:
try:
base.upgrade(source)
except dnf.exceptions.PackageNotFoundError as e:
with out as o:
json.dump({"package_not_found": e.pkg_spec}, o)
except dnf.exceptions.PackagesNotInstalledError:
# If it's not installed, upgrade should behave the same as install
base.install(source, strict=True)
elif action == "remove":
# cannot remove by file path, so let's do this to be extra safe
try:
Expand Down
26 changes: 26 additions & 0 deletions antlir/antlir2/features/rpm/tests/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,32 @@ test_rpms(
parent_layer = simple,
)

test_rpms(
name = "upgrade-not-already-installed",
expected = expected_t(
installed = [
"foo-3-1",
],
),
features = [
feature.rpms_upgrade(rpms = ["foo"]),
":test-deps",
],
)

test_rpms(
name = "upgrade-not-already-installed-file",
expected = expected_t(
installed = [
"foo-2-1",
],
),
features = [
feature.rpms_upgrade(rpms = ["//antlir/antlir2/features/rpm/tests/repo:foo-2-1.noarch"]),
":test-deps",
],
)

test_rpms(
name = "downgrade",
expected = expected_t(
Expand Down

0 comments on commit bdd56dc

Please sign in to comment.