apt: an unavailable package given with a version is still passed to apt-get and fails the whole install

Aperta Adatta ai principianti
#7,265 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@HemanthGangula ci sta già lavorando.

Dal 3/12/2026.

  • #7293 di @HemanthGangula — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
debian, python

Direzione di ricerca

Inizia da Apt.install_packages nel modulo apt di cloud-init, dove l'issue mostra che il controllo di disponibilità rimuove le versioni mentre il filtro confronta stringhe pkg=version complete. Mantieni la mappatura originale tra nome del pacchetto e voce, così che i nomi non disponibili rimuovano le relative voci con versione prima che venga chiamato apt-get install. Riproduci il problema con la cloud-config versionata [nosuchpkg, "1.2"] e conferma che nosuchpkg=1.2 viene omesso mentre l'altro pacchetto viene installato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug report

When a package that APT doesn't know is given with a version, for example
[nosuchpkg, "1.2"] in packages:, cloud-init logs that APT will not
attempt to install it, but still passes nosuchpkg=1.2 to apt-get install.
apt-get then fails the whole call, so none of the other packages in the
list are installed either. The same package without a version is skipped
as intended and the rest of the list is installed.

In Apt.install_packages, the availability check is made on names with the
version cut off, and its result is compared against the full strings:

pkglist = util.expand_package_list("%s=%s", list(pkglist))
unavailable = self.get_unavailable_packages(
    [x.split("=")[0] for x in pkglist]
)
...
to_install = [p for p in pkglist if p not in unavailable]

unavailable holds nosuchpkg, pkglist holds nosuchpkg=1.2, so the
filter never removes it. This has been the case since the availability
check was added in 23.4 (#4202).

Steps to reproduce the problem

Two cloud-configs that differ only in the version:

#cloud-config
packages:
  - hello
  - nosuchpkg
#cloud-config
packages:
  - hello
  - [nosuchpkg, "1.2"]

In an images:debian/13/cloud LXD container, from a snapshot taken after
first boot (hello not installed), run with each file:

python3 -m cloudinit.cmd.main single --name package_update_upgrade_install --frequency always --file <cfg>
Config apt-get install arguments Exit hello installed
nosuchpkg hello 1 (nosuchpkg reported as not installed) yes
[nosuchpkg, "1.2"] nosuchpkg=1.2 hello 1 no

Environment details

  • Cloud-init version: main at 2e29ad07d; the code is unchanged on current main (d8f758fcc)
  • Operating System Distribution: Debian 13 (trixie) amd64
  • Cloud provider, platform or installer type: LXD (NoCloud)

cloud-init logs

Versioned config:

apt.py[DEBUG]: The following packages were not found by APT so APT will not attempt to install them: ['nosuchpkg']
subp.py[DEBUG]: Running command ['eatmydata', 'apt-get', '--option=Dpkg::Options::=--force-confold', '--option=Dpkg::options::=--force-unsafe-io', '--assume-yes', '--quiet', 'install', 'nosuchpkg=1.2', 'hello'] ...

Unversioned config, for comparison:

apt.py[DEBUG]: The following packages were not found by APT so APT will not attempt to install them: ['nosuchpkg']
subp.py[DEBUG]: Running command ['eatmydata', 'apt-get', '--option=Dpkg::Options::=--force-confold', '--option=Dpkg::options::=--force-unsafe-io', '--assume-yes', '--quiet', 'install', 'hello'] ...

A possible fix is to keep the name-to-entry mapping and filter on the
name, so nosuchpkg=1.2 is left out like nosuchpkg. I can open a PR
for it.

Lingua principale
Python
Stelle
3.9k
Fork
1.2k
Merge medio
2g 24m
PR unite (30g)
18

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di canonical/cloud-init

Tutte le issue di canonical/cloud-init

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.