FAIL: curtin command apt-config (KeyError: 'RELEASE')

Bug #1964115 reported by Michael Weiss
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
curtin
New
Undecided
Unassigned
curtin (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

I'm getting the following error since I've updated the installer ISO image from the Ubuntu 20.04.3 LTS to Ubuntu 20.04.4 LTS:
Edit: Posted as attachment to avoid the formatting issues: https://bugs.launchpad.net/curtin/+bug/1964115/+attachment/5567000/+files/subiquity_log.txt
```
finish: cmd-apt-config: FAIL: curtin command apt-config
Traceback (most recent call last):
  File "/snap/subiquity/3119/lib/python3.8/site-packages/curtin/commands/main.py", line 202, in main
    ret = args.func(args)
  File "/snap/subiquity/3119/lib/python3.8/site-packages/curtin/commands/apt_config.py", line 663, in apt_command
    handle_apt(apt_cfg, target)
  File "/snap/subiquity/3119/lib/python3.8/site-packages/curtin/commands/apt_config.py", line 77, in handle_apt
    generate_sources_list(cfg, release, mirrors, target)
  File "/snap/subiquity/3119/lib/python3.8/site-packages/curtin/commands/apt_config.py", line 354, in generate_sources_list
    entries = update_mirrors(entries, mirrors)
  File "/snap/subiquity/3119/lib/python3.8/site-packages/curtin/commands/apt_config.py", line 255, in update_mirrors
    entry.uri = util.render_string(entry.uri, mirrors)
  File "/snap/subiquity/3119/lib/python3.8/site-packages/curtin/util.py", line 1203, in render_string
    return basic_template_render(content, params)
  File "/snap/subiquity/3119/lib/python3.8/site-packages/curtin/util.py", line 1193, in basic_template_render
    return BASIC_MATCHER.sub(replacer, content)
  File "/snap/subiquity/3119/lib/python3.8/site-packages/curtin/util.py", line 1191, in replacer
    return str(selected_params[key])
KeyError: 'RELEASE'
'RELEASE'
```

I'm using Packer (https://www.packer.io/) to perform an automated installation so nothing else has changed (and if I downgrade to Ubuntu 20.04.3 LTS everything works again).

The relevant part of my Ubuntu autoinstall configuration:
```
  apt:
    primary:
      - arches: [default]
        uri: "http://ubuntu.my-company.tld"
    sources_list: | # written by curtin custom template
      deb $MIRROR/$RELEASE $RELEASE main restricted
      deb $MIRROR/$RELEASE-updates $RELEASE-updates main restricted
      deb $MIRROR/$RELEASE-security $RELEASE-security main restricted

      deb $MIRROR/$RELEASE $RELEASE universe
      deb $MIRROR/$RELEASE-updates $RELEASE-updates universe
      deb $MIRROR/$RELEASE-security $RELEASE-security universe
```

I've based that on the following example configuration:
https://github.com/canonical/curtin/blob/600d6a19e26d773d1c4efae874e8c8785d0e3196/examples/apt-source.yaml#L118

description: updated
Revision history for this message
Michael Weiss (primeos-work) wrote :
description: updated
description: updated
Revision history for this message
Michael Weiss (primeos-work) wrote :
Download full text (4.7 KiB)

The problem persists with Ubuntu 22.04 LTS (tested with one of the final RCs: https://iso.qa.ubuntu.com/qatracker/milestones/432/builds/247146/downloads).

I did some analysis and the issue seems to be the "$MIRROR/$RELEASE" part of the custom template.

The relevant source code part (the generate_sources_list function in curtin/commands/apt_config.py):
```
   333 def generate_sources_list(cfg, release, mirrors, target=None, arch=None):
   334 """ generate_sources_list
   335 create a source.list file based on a custom or default template
   336 by replacing mirrors and release in the template
   337 """
   338 aptsrc = "/etc/apt/sources.list"
   339
   340 tmpl = cfg.get('sources_list', None)
   341 from_file = False
   342 if tmpl is None:
   343 LOG.info("No custom template provided, fall back to modify"
   344 "mirrors in %s on the target system", aptsrc)
   345 tmpl = util.load_file(paths.target_path(target, aptsrc))
   346 from_file = True
   347
   348 entries = [SourceEntry(line) for line in tmpl.splitlines(True)]
   349 if from_file:
   350 # when loading from an existing file, we also replace default
   351 # URIs with configured mirrors
   352 entries = update_default_mirrors(entries, mirrors, target, arch)
   353
   354 entries = update_mirrors(entries, mirrors)
   355 entries = update_dist(entries, release)
```

After SourceEntry from python-apt ("from aptsources.sourceslist import SourceEntry") parses the custom template (s. apt.sources_list above), the data ("entries") looks as follows:
```
{'invalid': False, 'disabled': False, 'type': 'deb', 'architectures': [], 'trusted': None, 'uri': '$MIRROR/$RELEASE', 'dist': '$RELEASE', 'comps': ['main', 'restricted'], 'comment': '', 'line': 'deb $MIRROR/$RELEASE $RELEASE main restricted\n', 'file': '/etc/apt/sources.list', 'template': None, 'children': []}
{'invalid': False, 'disabled': False, 'type': 'deb', 'architectures': [], 'trusted': None, 'uri': '$MIRROR/$RELEASE-updates', 'dist': '$RELEASE-updates', 'comps': ['main', 'restricted'], 'comment': '', 'line': 'deb $MIRROR/$RELEASE-updates $RELEASE-updates main restricted\n', 'file': '/etc/apt/sources.list', 'template': None, 'children': []}
{'invalid': False, 'disabled': False, 'type': 'deb', 'architectures': [], 'trusted': None, 'uri': '$MIRROR/$RELEASE-security', 'dist': '$RELEASE-security', 'comps': ['main', 'restricted'], 'comment': '', 'line': 'deb $MIRROR/$RELEASE-security $RELEASE-security main restricted\n', 'file': '/etc/apt/sources.list', 'template': None, 'children': []}
{'invalid': True, 'disabled': False, 'type': '', 'architectures': [], 'trusted': None, 'uri': '', 'dist': '', 'comps': [], 'comment': '', 'line': '\n', 'file': '/etc/apt/sources.list', 'template': None, 'children': []}
{'invalid': False, 'disabled': False, 'type': 'deb', 'architectures': [], 'trusted': None, 'uri': '$MIRROR/$RELEASE', 'dist': '$RELEASE', 'comps': ['universe'], 'comment': '', 'line': 'deb $MIRROR/$RELEASE $RELEASE universe\n', 'file': '/etc/apt/sources.list', 'template': None, 'children': []}
{'invalid'...

Read more...

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in curtin (Ubuntu):
status: New → Confirmed
Revision history for this message
Andrei (foxfluffy) wrote :

This bug affects me too as well. Crash has gone after I removed $RELEASE from uri and codename sections.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.