DistUpgradeController to release apt lock during PostInstallScripts

Bug #1897778 reported by Chad Smith
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ubuntu-release-upgrader (Ubuntu)
Undecided
Chad Smith
Xenial
Undecided
Unassigned
Bionic
Undecided
Unassigned
Focal
Undecided
Unassigned

Bug Description

=== Begin SRU Template ===
[Impact]

Any Ubuntu Advantage apt-based service is enbled via a PPA. If those PPAs are not listed as valid mirrors in mirrors.cfg the PPAs get disabled across upgrade.

UA-client has a script which will enable those PPAs across upgrade path, but needs the apt cache lock released during runPostInstallScripts.

Validate Ubuntu Advantage apt access is retained across do-release-upgrade path so customers to not lose access to security updates after performing an upgrade.

[Test Case]

#!/bin/bash

#
# SRU Verification ubuntu-release-upgrader + ubuntu=advantage-tools
# Test procedure:
# - launch container Trusty, Xenial or Bionic
# - Attach container to UA subscription (which activates a number of commerical PPAs
# - download and run -proposed ubuntu-release-upgrader tool for upgrade release
# - Assert successful upgrade
# - Confirm valid mirrors not disabled
# - Confirm third party non-commercial PPA URLs still disabled
# - Confirm third party UA commercial URLs still disabled
# (due to expected feature gap)
# - Confirm UA status reports esm-infra still disabled (known feature gap)

set -e
UA_TOKEN=$1
if [ -z "$1" ]; then
 echo "Usage: $0 <contractTOKEN>"
 exit 1
fi
# sources:
# ua.proposed:
# source: deb http://ppa.launchpad.net/ua-client/proposed/ubuntu \$RELEASE main
# keyid: 6E34E7116C0BC933
# sources:
# ua.proposed:
# source: deb http://ppa.launchpad.net/canonical-server/ua-client-daily/ubuntu \$RELEASE main
# keyid: 94E187AD53A59D1847E4880F8A295C4FB8B190B7
cat > test-uru.yaml <<EOF
#cloud-config
package_update: true
package_upgrade: true
apt:
  sources:
    ua.daily:
      source: deb http://ppa.launchpad.net/canonical-server/ua-client-daily/ubuntu \$RELEASE main
      keyid: 94E187AD53A59D1847E4880F8A295C4FB8B190B7
EOF

# ua.list:
# source: deb http://ppa.launchpad.net/canonical-server/ua-client-daily/ubuntu \$RELEASE main
# keyid: 94E187AD53A59D1847E4880F8A295C4FB8B190B7

cat > checkaptpolicy.sh <<EOF
#!/bin/bash
set -x
RELEASE=\`lsb_release -sc\`
echo -n "Current release: $RELEASE"
echo "Assert no disabled valid mirrors in /eta/apt/sources.list"
! grep disable /etc/apt/sources.list || echo "FAILURE: found disabled valid mirror urls"
echo "Checking commercial Ubuntu Advantage PPAs apt policy and config"
apt-cache policy | grep esm.ubuntu.com
for file in \`ls /etc/apt/sources.list.d/ubuntu-*.list\`; do
    echo "--- file: \${file}"
    cat \${file}
done
EOF
chmod 755 checkaptpolicy.sh

declare -A NEXTDIST=( [bionic]=focal [xenial]=bionic [trusty]=xenial )

wait_for_boot() {
  local vm=$1 release=$2
  echo "--- Wait for cloud-init to finish"
  sleep 5
  if [ "${release}" = "trusty" ]; then
    while [ "N 2" != "$(lxc exec ${vm} -- runlevel)" ]; do
       echo "waiting on runlevel 2"
       sleep 5
    done
    status=$(lxc exec ${vm} -- test -f /var/run/cloud-init/result.json && echo "done" || echo "running" )
    while [ "done" != "${status}" ]; do
        status=$(lxc exec ${vm} -- test -f /var/run/cloud-init/result.json && echo "done" || echo "running" )
        echo -n '.'
        sleep 5
    done

  else
    lxc exec ${vm} -- cloud-init status --wait --long
  fi
}

for release in xenial; do
  vm=test-sru-$release
  echo "--- Launch cloud-init with ua-client-${release}-daily enabled"
  lxc launch ubuntu-daily:${release} ${vm} -c user.user-data="$(cat test-uru.yaml)"
  upgraderelease=${NEXTDIST[$release]}
  if [ "${release}" != "trusty" ]; then
      dist_upgrade_disable_reason="no Release"
  fi
  wait_for_boot ${vm} ${release}
  echo "--- Attach Ubuntu-Advantage, enabling services"
  lxc exec ${vm} -- ua attach ${UA_TOKEN}
  lxc exec ${vm} -- ua status --wait | tee ua-status.orig
  lxc file push checkaptpolicy.sh ${vm}/
  lxc exec ${vm} -- /checkaptpolicy.sh > policy.orig
  lxc exec ${vm} -- wget http://archive.ubuntu.com/ubuntu/dists/$upgraderelease-proposed/main/dist-upgrader-all/current/$upgraderelease.tar.gz
  lxc exec ${vm} -- tar xzvf $upgraderelease.tar.gz
  echo "--- Add proposed PPA to valid mirrors to exercise ua-tools do-release-upgrade"
  lxc file pull ${vm}/root/mirrors.cfg .
  echo "http://ppa.launchpad.net/canonical-server/ua-client-daily/ubuntu/" >> mirrors.cfg
  lxc file push mirrors.cfg ${vm}/root/
  lxc exec ${vm} -- /root/$upgraderelease --datadir=/root --frontend DistUpgradeViewNonInteractive | egrep 'Warning|Error|ubuntu-advantage'
  lxc exec ${vm} -- reboot || true
  sleep 10
  lxc exec ${vm} grep disable /etc/apt/sources.list && "FAILURE: valid mirrors got disabled" || echo "SUCCESS: no valid mirrors disabled"
  lxc exec ${vm} -- ua status --wait | tee ua-status.upgrade
  if [ ! -z "${dist_upgrade_disable_reason}" ]; then
      echo "--- Expect do-release-upgrade disable reason to be '$dist_upgrade_disable_reason' for ESM* PPAs"
      lxc exec ${vm} grep "${dist_upgrade_disable_reason}" /var/log/dist-upgrade/main.log || echo "FAILURE: didn't find disabled update logs for esm"
  fi
  echo "--- Expect no diffs from original and upgraded ua status"
  status_diff=$(diff -urN ua-status.orig ua-status.upgrade)
  [ -z "$status_diff" ] && echo "SUCCESS: no diff" || echo -e "FAILURE: unexpected diff\n${status_diff}"
  echo "--- Ensure UA re-enabled esm across upgrade"
  lxc exec ${vm} -- egrep 'lts|change' /var/log/ubuntu-advantage.log
  echo "--- Ensure UA status reports ESM enabled after upgrade"
  egrep 'esm-infra.*enabled' ua-status.upgrade || echo "FAILURE: expected enabled esm-infra after upgrade"
done

[Regression Potential]
None as UA support is not yet officially introduced in Xenial or later.
This patch only allows anyone currently overriding PostUpgradeScripts in DistUpgrade.cfg to perform apt update|install operations, which were previously prohibited due to apt lock.
=== End SRU Template ===

==== Original Description ===

In order for custom PostInstallScript to add/remove apt packages and call apt update, DistUpgradecontroller needs to release the apt cache directory lock before that stage.

If the lock is still in place, DistUpgradeController.runPostUpgradeScripts hits errors such as:

E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/

Related branches

Chad Smith (chad.smith)
Changed in ubuntu-release-upgrader (Ubuntu):
assignee: nobody → Chad Smith (chad.smith)
status: New → In Progress
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ubuntu-release-upgrader - 1:20.10.12

---------------
ubuntu-release-upgrader (1:20.10.12) groovy; urgency=medium

  [ Chad Smith ]
  * data/mirrors.cfg: add ubuntu advantage pro PPA url as valid mirror
    (LP: #1893717)
  * DistUpgrade/DistUpgradeController.py: release cache lock during
    runPostInstallScripts (LP: #1897778)

  [ Brian Murray ]
  * DistUpgrade/DistUpgradeQuirks.py: In addition to quirking python-minimal
    we also need to quirk python-dbg. (LP: #1887544)
  * Update demotions and mirrors data.

 -- Chad Smith <email address hidden> Tue, 22 Sep 2020 16:59:52 -0600

Changed in ubuntu-release-upgrader (Ubuntu):
status: In Progress → Fix Released
Chad Smith (chad.smith)
description: updated
Revision history for this message
Timo Aaltonen (tjaalton) wrote : Please test proposed package

Hello Chad, or anyone else affected,

Accepted ubuntu-release-upgrader into focal-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/ubuntu-release-upgrader/1:20.04.28 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-focal to verification-done-focal. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-focal. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in ubuntu-release-upgrader (Ubuntu Focal):
status: New → Fix Committed
tags: added: verification-needed verification-needed-focal
Revision history for this message
Timo Aaltonen (tjaalton) wrote :

Hello Chad, or anyone else affected,

Accepted ubuntu-release-upgrader into bionic-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/ubuntu-release-upgrader/1:18.04.40 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-bionic to verification-done-bionic. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-bionic. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in ubuntu-release-upgrader (Ubuntu Bionic):
status: New → Fix Committed
tags: added: verification-needed-bionic
Changed in ubuntu-release-upgrader (Ubuntu Xenial):
status: New → Fix Committed
tags: added: verification-needed-xenial
Revision history for this message
Timo Aaltonen (tjaalton) wrote :

Hello Chad, or anyone else affected,

Accepted ubuntu-release-upgrader into xenial-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/ubuntu-release-upgrader/1:16.04.32 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-xenial to verification-done-xenial. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-xenial. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Revision history for this message
Ubuntu SRU Bot (ubuntu-sru-bot) wrote : Autopkgtest regression report (ubuntu-release-upgrader/1:16.04.32)

All autopkgtests for the newly accepted ubuntu-release-upgrader (1:16.04.32) for xenial have finished running.
The following regressions have been reported in tests triggered by the package:

ubuntu-release-upgrader/1:16.04.32 (armhf)

Please visit the excuses page listed below and investigate the failures, proceeding afterwards as per the StableReleaseUpdates policy regarding autopkgtest regressions [1].

https://people.canonical.com/~ubuntu-archive/proposed-migration/xenial/update_excuses.html#ubuntu-release-upgrader

[1] https://wiki.ubuntu.com/StableReleaseUpdates#Autopkgtest_Regressions

Thank you!

Chad Smith (chad.smith)
description: updated
tags: added: verification-done-bionic verification-done-focal
removed: verification-needed-bionic verification-needed-focal
Chad Smith (chad.smith)
description: updated
Revision history for this message
Chad Smith (chad.smith) wrote :

Updated SRU verification logs for upgrade to Focal

Revision history for this message
Chad Smith (chad.smith) wrote :

Updated SRU verification logs for upgrade to Bionic

Revision history for this message
Chad Smith (chad.smith) wrote :

Updated SRU verification logs for upgrade to Xenial

tags: added: verification-done verification-done-xenial
removed: verification-needed verification-needed-xenial
Revision history for this message
Chad Smith (chad.smith) wrote :

As Brian mentioned on the other bug related to this SRU. He re-ran the armhf regression alert and it passed https://bugs.launchpad.net/ubuntu/+source/ubuntu-release-upgrader/+bug/1893717/comments/15

Revision history for this message
Chris Halse Rogers (raof) wrote : Update Released

The verification of the Stable Release Update for ubuntu-release-upgrader has completed successfully and the package is now being released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

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

This bug was fixed in the package ubuntu-release-upgrader - 1:20.04.28

---------------
ubuntu-release-upgrader (1:20.04.28) focal; urgency=medium

  [ Brian Murray ]
  * DistUpgrade/DistUpgradeQuirks.py: In addition to quirking python-minimal
    we also need to quirk python-dbg, python-doc, and python-dev.
    (LP: #1887544)
  * drop changes to data/DistUpgrade.cfg.bionic regarding
    gnome-software-plugin-snap as it failed verification.

  [ Chad Smith ]
  * data/mirrors.cfg: add all ubuntu-advantage services as valid mirrors.
    This includes: fips, fips-updates, esm-infra, esm-apps and cc-eal and
    Ubuntu Pro stable public PPA. (LP: #1893717)
  * DistUpgrade/DistUpgradeController.py: release cache lock during
    runPostInstallScripts (LP: #1897778)

 -- Chad Smith <email address hidden> Wed, 07 Oct 2020 10:49:37 -0600

Changed in ubuntu-release-upgrader (Ubuntu Focal):
status: Fix Committed → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ubuntu-release-upgrader - 1:18.04.40

---------------
ubuntu-release-upgrader (1:18.04.40) bionic; urgency=medium

  [ Chad Smith ]
  * data/mirrors.cfg: add ubuntu advantage pro PPA url as valid mirror
    (LP: #1893717)
  * DistUpgrade/DistUpgradeController.py: release cache lock during
    runPostInstallScripts (LP: #1897778)

 -- Chad Smith <email address hidden> Mon, 05 Oct 2020 14:50:15 -0600

Changed in ubuntu-release-upgrader (Ubuntu Bionic):
status: Fix Committed → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ubuntu-release-upgrader - 1:16.04.32

---------------
ubuntu-release-upgrader (1:16.04.32) xenial; urgency=medium

  [ Chad Smith ]
  * data/mirrors.cfg: add ubuntu advantage pro PPA url as valid mirror
    (LP: #1893717)
  * DistUpgrade/DistUpgradeController.py: release cache lock during
    runPostInstallScripts (LP: #1897778)

 -- Chad Smith <email address hidden> Mon, 05 Oct 2020 14:54:27 -0600

Changed in ubuntu-release-upgrader (Ubuntu Xenial):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers