autopkgtests failures due to debhelper 13.6 changes

Bug #1973382 reported by Athos Ribeiro
14
This bug affects 1 person
Affects Status Importance Assigned to Milestone
postgresql-common (Debian)
Fix Released
Unknown
postgresql-common (Ubuntu)
Fix Released
Undecided
Athos Ribeiro
Jammy
Fix Committed
Undecided
Athos Ribeiro

Bug Description

[ Impact ]

The current postgresql-common DEP8 test suite will fail for any new postgresql-common builds in jammy (even if they are no-change-rebuilds), hindering the SRU process for any needed bug fixes.

This happens because new builds will pick-up different versions of debhelper/debconf than the ones used to build the package shipped in jammy. These new debhelper/debconf versions changed the built package control preinst output to stop the service upon installation.

The proposed fix intends to mimic jammy's postgresql-common behavior even when built with the new debhelper/debconf versions.

[ Test Plan ]

- Rebuild the package (no changes) in a PPA
- Run the DEP8 test suite for that PPA package
- Verify the autopkgtest fails
- Apply the proposed fix
- Verify that tests now pass

Finally, verify that the binary packages control data did not change for the maintscripts to avoid future upgrade unexpected issues (i.e., maintain the package behavior - no control logical changes).

[ Where problems could occur ]

By Verifying that the binary packages control logical data did not change for the maintscripts, we are actually ensuring this SRU suppresses the changes that would be applied to the package by the debhelper/debconf change. Still, there may be other unaccounted dependency changes (as this one was once) that may affect the package usability. If that is the case, we will need to evaluate and deal with possible issues in future SRUs.

[ Other info ]

The reason this issue is only manifesting in jammy now is because our latest postgresql-common build in jammy was performed during jammy's development, before the aforementioned debhelper/debconf changes landed.

When trying to SRU a fix for LP: #2007794, we realized jammy is also affected by this bug.

[ Original message ]

As seen in
https://autopkgtest.ubuntu.com/results/autopkgtest-kinetic/kinetic/amd64/p/postgresql-common/20220513_042035_38c41@/log.gz
postgresql-common autopkgtest suite have been failing with

# BEGIN LOGS

=== Running test 012_maintscripts.t ... ===
1..14
# We are running systemd
ok 1 - pg_createcluster 14 main --start
ok 2 - postmaster PID is 3634
ok 3 - dpkg-reconfigure --frontend=noninteractive postgresql-common
head: cannot open '/var/lib/postgresql/14/main/postmaster.pid' for reading: No such file or directory
not ok 4 - postmaster PID is
not ok 5 - postmaster was not restarted
# Failed test 'postmaster PID is '
# at ./t/012_maintscripts.t line 32.
# Failed test 'postmaster was not restarted'
# at ./t/012_maintscripts.t line 33.
# got: '3634'
# expected: ''
ok 6 - pg_dropcluster 14 main --stop
# Cleanup
ok 7 - Cleanup: No clusters left behind
ok 8 - No postgres processes left behind
ok 9 - No files in /etc/postgresql left behind
ok 10 - No files in /var/lib/postgresql left behind
ok 11 - No files in /var/run/postgresql left behind
ok 12 - No files in /var/log/postgresql left behind
ok 13 - netstat -avptn 2>/dev/null | grep ":543[2-9]\b.*LISTEN"
ok 14 - PostgreSQL TCP ports are closed
# Looks like you failed 2 tests of 14.

# END LOGS

The test fails because, in Ubuntu, running

dpkg-reconfigure --frontend=noninteractive postgresql-common

results in a call to

deb-systemd-invoke stop 'postgresql.service',

stopping the service which the test expects to be up and running (untouched).

This started happening after the following debhelper change introduced in debhelper 13.6:

https://salsa.debian.org/debian/debhelper/-/commit/742b0c5ac8f4a6cfcd699f08915a8109a5ebec35

Which resulted in the following diff in the postgresql-common preinst script:

# BEGIN DIFF

--- 238-comm/preinst 2022-02-10 07:02:57.000000000 -0300
+++ 241-comm/preinst 2022-05-11 10:57:04.000000000 -0300
@@ -16,7 +16,12 @@
         ;;
 esac

-# Automatically added by dh_installdeb/13.5.2ubuntu1
+# Automatically added by dh_installdeb/13.7.1ubuntu1
 dpkg-maintscript-helper rm_conffile /etc/apt/apt.conf.d/01autoremove-postgresql 229\~ postgresql-common -- "$@"
 # End automatically added section
+# Automatically added by dh_installsystemd/13.7.1ubuntu1
+if [ -z "${DPKG_ROOT:-}" ] && [ "$1" = upgrade ] && [ -d /run/systemd/system ] ; then
+ deb-systemd-invoke stop 'postgresql.service' >/dev/null || true
+fi
+# End automatically added section

# END DIFF

Tests passed in Debian as shown in
https://ci.debian.net/data/autopkgtest/testing/amd64/p/postgresql-common/21568780/log.gz

Note that it was using debhelper 13.7.1, which did introduce the new snipped into the preinst script. Local autopkgtest runs for Debian also succeed.

The reason for the test to fail in Ubuntu and pass in Debian lies in

https://salsa.debian.org/pkg-debconf/debconf/-/merge_requests/10/diffs#8c2015059db93e56eaf3ed8ea7a2c9bf142c0c8f_198_197

which is applied in Ubuntu delta (but not in Debian).

A possible solution to the issue would be to introduce the "-r" (or --no-stop-on-upgrade) option to dh_installsystemd in Ubuntu's postgresql-common d/rules. This should be enough to keep the expected (old) behavior in the package maintainer scripts.

Then, if/once https://salsa.debian.org/pkg-debconf/debconf/-/merge_requests/10 is merged, we can merge the delta in Debian.

Related branches

Changed in postgresql-common (Ubuntu):
status: New → Triaged
assignee: nobody → Athos Ribeiro (athos-ribeiro)
Revision history for this message
Dave Jones (waveform) wrote :

Hi Athos -- this is an interesting one.

Forgive my ignorance, but per Colin's comments in https://salsa.debian.org/pkg-debconf/debconf/-/merge_requests/10 "... dpkg-reconfigure is simulating the process of reinstalling a package without actually unpacking its files again" (which aligned with my understanding of dpkg-reconfigure). Surely if it's "simulating [...] reinstalling a package", then:

> dpkg-reconfigure --frontend=noninteractive postgresql-common

should:

> [result] in a call to
>
> deb-systemd-invoke stop 'postgresql.service',

After all, if it's simulating a reinstallation, shouldn't it restart the service? Surely the error is the test suite assuming that it shouldn't? You are certainly correct that:

> A possible solution to the issue would be to introduce the "-r" (or
> --no-stop-on-upgrade) option to dh_installsystemd in Ubuntu's
> postgresql-common d/rules. This should be enough to keep the
> expected (old) behavior in the package maintainer scripts.

(aside: I'd beg people to use the long option and never touch "-r" or "-R" given we wound up having to grep thru maintscripts to find instances of --no-{restart,stop}-{on,after}-upgrade when fixing the debhelper issue -- not to mention they're just more readable)

Still, it seems to me that the assumption that dpkg-reconfigure *won't* restart postgres is incorrect? Then again, if it's already commonly expected behaviour, maintaining it may well be the wisest course. It would mean that upgrades won't restart the service which may not be desirable, although needsrestart may provide a fallback there?

Interested to hear any thoughts you may have on this -- in tinkering with debhelper and dpkg-reconfigure, I'm painfully aware I'm messing with widely used stuff with a long history of assumed quirks!

Revision history for this message
Dave Jones (waveform) wrote :

Sorry, I'd mis-interpreted this bug! I'd gone digging through the history of debconf and couldn't understand how dpkg-reconfigure was only restarting things just *now*, but hadn't correctly understood that your bug was complaining the service was stopped, but *not started* again. So, my apologies: must read more carefully!

Anyway, to the problem as described: checking d/rules in postgresql-common we find:

# do not (re)start postgresql.service on postgresql-common install/upgrades
override_dh_installinit:
 dh_installinit -ppostgresql-common --name=postgresql -u'defaults 19 21' --no-start
override_dh_installsystemd:
 dh_installsystemd --no-start

This strongly suggests you *do* want to add --no-stop-on-upgrade because the comment indicates a mis-understanding of --no-start. The --no-start option tells dh_install{init,systemd} that you don't want the service automatically started upon installation but in the absence of --no-stop-on-upgrade it *will* still attempt to restart it on upgrades (this isn't terribly well documented in the dh_installsystemd manpage -- I should correct that).

There is one other way you could go about solving this, but it's horribly subtle. The reason preinst is stopping postgres is that --no-start implies --no-restart-after-upgrade, the (terribly named) option that specifies a service *should* be restarted but by stopping it before and upgrade and starting it again afterward (as opposed to --restart-after-upgrade, the usual default which simply runs a restart after an upgrade). Quite *why* --no-start implies --no-restart-after-upgrade I've no idea; I did note it at the time I was hacking on debhelper and it's one of those things that, given free reign, I'd excise. However, as mentioned before I tried to be extremely conservative with my changes to debhelper (and dpkg-reconfigure).

Anyway, the other way you could solve this would be by specifying --no-start and --restart-after-upgrade. This would mean preinst doesn't try to stop the service, but postinst will "try-restart" the service (which means restart if it's already running, but don't start it if it isn't). However, that would run contrary to the comment in d/rules so I suspect it's not what you want to do.

Hope that's not too confusing! Do let me know if there's anything that needs clarification above.

Revision history for this message
Athos Ribeiro (athos-ribeiro) wrote :

Hi Dave,

Thanks for the thoughtful reply!

> After all, if it's simulating a reinstallation, shouldn't it restart the service? [...]

Usually, yes, I agree it should restart the service. In this specific postgresql-common case, debian/rules was crafted so a restart would not happen at this point:

https://salsa.debian.org/postgresql/postgresql-common/-/blob/master/debian/rules#L27-31

Now, while the test suite regression is only present in Ubuntu (and not in Debian) due to the dpkg-reconfigure delta, a change of behavior was also introduced in the upgrade path due to the debhelper change at

https://salsa.debian.org/debian/debhelper/-/commit/742b0c5ac8f4a6cfcd699f08915a8109a5ebec35.

The service, which would be left untouched on postgresql-common upgrades, will now be stopped on upgrades.

Finally,

> You are certainly correct that [we should add --no-stop-on-upgrade option to dh_installsystemd?]

This would restore the previous, designed behavior of the package upgrade path. Still, the preinst script would differ from the Debian one. Therefore, I filed

https://code.launchpad.net/~athos-ribeiro/ubuntu/+source/postgresql-common/+git/postgresql-common/+merge/422669

and will also file a Debian bug to include the Debian maintainers in the discussion before we do introduce the delta here.

Changed in postgresql-common (Debian):
status: Unknown → New
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package postgresql-common - 241ubuntu1

---------------
postgresql-common (241ubuntu1) kinetic; urgency=medium

  * d/rules: do not stop service on package upgrades. (LP: #1973382)

 -- Athos Ribeiro <email address hidden> Mon, 16 May 2022 09:58:44 -0300

Changed in postgresql-common (Ubuntu):
status: Triaged → Fix Released
tags: removed: server-todo
Changed in postgresql-common (Debian):
status: New → Fix Released
Changed in postgresql-common (Ubuntu Jammy):
assignee: nobody → Athos Ribeiro (athos-ribeiro)
description: updated
tags: added: block-proposed-jammy
Revision history for this message
Steve Langasek (vorlon) wrote :

It's unclear to me from a reading of this diff that the changes to debian/rules are correct. --no-start --no-stop-on-upgrade reads to me as meaning the service will not be restarted on upgrade. That means security updates will not be applied to the running service, which is the expected behavior by default.

The dh_installsystemd manpage appears to agree with me:

       -r, --no-stop-on-upgrade, --no-restart-on-upgrade
           Do not stop service on upgrade. This has the side-effect of not
           restarting the service as a part of the upgrade.

Why is --no-start there in the first place?

Changed in postgresql-common (Ubuntu Jammy):
status: New → Incomplete
Revision history for this message
Steve Langasek (vorlon) wrote :

There is also the --restart-after-upgrade option to dh_installsystemd, which the manpage says "This is the default behaviour in compat 10." And we're using compat 13....

Of course, the postgresql-common package doesn't actually ship the daemon; that's shipped in the versioned 'postgresql' package. So perhaps the concerns about not restarting on upgrade of postgresql-common are moot, as long as the versioned package itself handles restarting?

Revision history for this message
Athos Ribeiro (athos-ribeiro) wrote :

Thanks for the review, Steve!

> Why is --no-start there in the first place?

This was introduced in [1]. It is there because the versioned package handles restarting, as stated next in

> So perhaps the concerns about not restarting on upgrade of postgresql-common are moot, as long as the versioned package itself handles restarting?

With the current jammy delta in debhelper/debconf, the next build of postgresql-common will result in the following snippet being added in the postinst.

+if [ -z "${DPKG_ROOT:-}" ] && [ "$1" = upgrade ] && [ -d /run/systemd/system ] ; then
+ deb-systemd-invoke stop 'postgresql.service' >/dev/null || true
+fi

This will stop the service and not re-start it. The desired outcome of applying the proposed fix is to maintain the postinst script as it is now, for the next time the package is re-built (preventing a regression).

[1] https://salsa.debian.org/postgresql/postgresql-common/-/commit/36a608c4f69b47d546192a686b4ad7f8e86f9493

Revision history for this message
Steve Langasek (vorlon) wrote :

Thanks, that explanation suffices.

Since the current package in jammy isn't broken and this only affects autopkgtests and rebuilds, this should like LP: #2007794 be block-proposed.

Changed in postgresql-common (Ubuntu Jammy):
status: Incomplete → In Progress
Revision history for this message
Steve Langasek (vorlon) wrote :

(which it already is)

Changed in postgresql-common (Ubuntu Jammy):
status: In Progress → Fix Committed
tags: added: verification-needed verification-needed-jammy
Revision history for this message
Steve Langasek (vorlon) wrote : Please test proposed package

Hello Athos, or anyone else affected,

Accepted postgresql-common into jammy-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/postgresql-common/238ubuntu0.1 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-jammy to verification-done-jammy. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-jammy. 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 (postgresql-common/238ubuntu0.1)

All autopkgtests for the newly accepted postgresql-common (238ubuntu0.1) for jammy have finished running.
The following regressions have been reported in tests triggered by the package:

resource-agents/1:4.7.0-1ubuntu7 (amd64)

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/jammy/update_excuses.html#postgresql-common

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

Thank you!

Revision history for this message
Athos Ribeiro (athos-ribeiro) wrote :

The regressions above were not related to the proposed changes. re-triggering some tests fixed the issue.

Revision history for this message
Athos Ribeiro (athos-ribeiro) wrote :

Tests pass as designed in the test plan. Moreover, There is no logical changes in the new package control information files.

tags: added: verification-done verification-done-jammy
removed: verification-needed verification-needed-jammy
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.