Skip to content

Commit bdd56dc

Browse files
vmagrofacebook-github-bot
authored andcommitted
[antlir2][rpm] upgrade should install if missing
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
1 parent 001681b commit bdd56dc

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

antlir/antlir2/features/rpm/driver.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,20 @@ def resolve(out, spec, base, local_rpms, explicitly_installed_package_names):
248248
json.dump({"package_not_found": e.pkg_spec}, o)
249249
elif action == "upgrade":
250250
if isinstance(source, dnf.package.Package):
251-
base.package_upgrade(source)
251+
try:
252+
base.package_upgrade(source)
253+
except dnf.exceptions.MarkingError:
254+
# If it's not installed, upgrade should behave the same as install
255+
base.package_install(source, strict=True)
252256
else:
253257
try:
254258
base.upgrade(source)
255259
except dnf.exceptions.PackageNotFoundError as e:
256260
with out as o:
257261
json.dump({"package_not_found": e.pkg_spec}, o)
262+
except dnf.exceptions.PackagesNotInstalledError:
263+
# If it's not installed, upgrade should behave the same as install
264+
base.install(source, strict=True)
258265
elif action == "remove":
259266
# cannot remove by file path, so let's do this to be extra safe
260267
try:

antlir/antlir2/features/rpm/tests/BUCK

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,32 @@ test_rpms(
171171
parent_layer = simple,
172172
)
173173

174+
test_rpms(
175+
name = "upgrade-not-already-installed",
176+
expected = expected_t(
177+
installed = [
178+
"foo-3-1",
179+
],
180+
),
181+
features = [
182+
feature.rpms_upgrade(rpms = ["foo"]),
183+
":test-deps",
184+
],
185+
)
186+
187+
test_rpms(
188+
name = "upgrade-not-already-installed-file",
189+
expected = expected_t(
190+
installed = [
191+
"foo-2-1",
192+
],
193+
),
194+
features = [
195+
feature.rpms_upgrade(rpms = ["//antlir/antlir2/features/rpm/tests/repo:foo-2-1.noarch"]),
196+
":test-deps",
197+
],
198+
)
199+
174200
test_rpms(
175201
name = "downgrade",
176202
expected = expected_t(

0 commit comments

Comments
 (0)