Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packaging: fix preremove script preventing the upgrade #4801

Merged
merged 1 commit into from
Apr 21, 2023

Conversation

wilfriedroset
Copy link
Collaborator

@wilfriedroset wilfriedroset commented Apr 20, 2023

What this PR does

nfpm migration introduce a regression in the prerm step. This step is used by the OS for doing necessary cleaning before removing a package. The underlying script is called upon remove or upgrade of a package by passing an argument to it, argument being remove or upgrade. The script expect only remove and raises an error for anything else. Therefore when trying to upgrade the script would failed with such error:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  mimir
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/20.8 MB of archives.
After this operation, 5,796 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
(Reading database ... 53494 files and directories currently installed.)
Preparing to unpack .../mimir_2.8.0~rc.0_amd64.deb ...
Unsupported action: upgrade <--- breaking change here
dpkg: warning: old mimir package pre-removal script subprocess returned error exit status 1
dpkg: trying script from the new package instead ...
Unsupported action: failed-upgrade
dpkg: error processing archive /var/cache/apt/archives/mimir_2.8.0~rc.0_amd64.deb (--unpack):
 new mimir package pre-removal script subprocess returned error exit status 1
 Alpine Post Install of an clean install
 Reload the service unit from disk
 Unmask the service
 Set the preset flag for the service unit
 Set the enabled flag for the service unit
Errors were encountered while processing:
 /var/cache/apt/archives/mimir_2.8.0~rc.0_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

The error is also triggered when trying to downgrade:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be DOWNGRADED:
  mimir
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
Need to get 0 B/19.4 MB of archives.
After this operation, 5,796 kB disk space will be freed.
Do you want to continue? [Y/n] y
dpkg: warning: downgrading mimir from 2.8.0~rc.0 to 2.7.1
(Reading database ... 53400 files and directories currently installed.)
Preparing to unpack .../archives/mimir_2.7.1_amd64.deb ...
Unsupported action: upgrade <-- again
dpkg: error processing archive /var/cache/apt/archives/mimir_2.7.1_amd64.deb (--unpack):
 installed mimir package pre-removal script subprocess returned error exit status 1
 Alpine Post Install of an clean install
 Reload the service unit from disk
 Unmask the service
 Set the preset flag for the service unit
 Set the enabled flag for the service unit
Errors were encountered while processing:
 /var/cache/apt/archives/mimir_2.7.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

With the resulting package built with the patched preremove script we have the following, notice that the error is gone:

Selecting previously unselected package mimir.
(Reading database ... 53397 files and directories currently installed.)
Preparing to unpack mimir_2.8.0~rc.0_amd64.deb ...
Unpacking mimir (2.8.0~rc.0) ...
Setting up mimir (2.8.0~rc.0) ...
 Post Install of an upgrade
 Post Install of an upgrade

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be DOWNGRADED:
  mimir
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
Need to get 0 B/19.4 MB of archives.
After this operation, 6,148 kB disk space will be freed.
Do you want to continue? [Y/n] y
dpkg: warning: downgrading mimir from 2.8.0~rc.0 to 2.7.1
(Reading database ... 53400 files and directories currently installed.)
Preparing to unpack .../archives/mimir_2.7.1_amd64.deb ...
Unpacking mimir (2.7.1) over (2.8.0~rc.0) ...
Setting up mimir (2.7.1) ...
 Post Install of an upgrade
 Post Install of an upgrade

With this information we can patch the prerm script to do nothing on upgrade as nothing is necessary.

Unfortunately there is nothing we can do from here for fixing the upgrade from 2.7 to 2.8

Alternatively we could do like loki or tempo packaging and not include. This way it would be consistent across all three of them.

Which issue(s) this PR fixes or relates to

N/A

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@wilfriedroset
Copy link
Collaborator Author

wilfriedroset commented Apr 20, 2023

If possible include this fix when building 2.8.0~rc1 or 2.8.0 otherwise the upgrade process from 2.7 -> 2.8 & 2.8 -> 2.9 would raise error.
See: #4739

@wilfriedroset wilfriedroset marked this pull request as ready for review April 20, 2023 22:04
@wilfriedroset wilfriedroset requested review from vaxvms, bubu11e and a team as code owners April 20, 2023 22:04
@aknuds1 aknuds1 added the bug Something isn't working label Apr 21, 2023
Copy link
Contributor

@aknuds1 aknuds1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my question.

packaging/nfpm/mimir/preremove.sh Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@aknuds1 aknuds1 requested a review from lamida April 21, 2023 12:09
nfpm migration introduce a regression in the prerm step. This step is
used by the OS for doing necessary cleaning before removing a package.
The underlying script is called upon remove or upgrade of a package by
passing an argument to it, argument being `remove` or `upgrade`.
The script expect *only* `remove` and raises an error for anything else.
Therefore when trying to upgrade the script would failed with such
error:

```
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  mimir
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/20.8 MB of archives.
After this operation, 5,796 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
(Reading database ... 53494 files and directories currently installed.)
Preparing to unpack .../mimir_2.8.0~rc.0_amd64.deb ...
Unsupported action: upgrade <--- breaking change here
dpkg: warning: old mimir package pre-removal script subprocess returned error exit status 1
dpkg: trying script from the new package instead ...
Unsupported action: failed-upgrade
dpkg: error processing archive /var/cache/apt/archives/mimir_2.8.0~rc.0_amd64.deb (--unpack):
 new mimir package pre-removal script subprocess returned error exit status 1
 Alpine Post Install of an clean install
 Reload the service unit from disk
 Unmask the service
 Set the preset flag for the service unit
 Set the enabled flag for the service unit
Errors were encountered while processing:
 /var/cache/apt/archives/mimir_2.8.0~rc.0_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
```

The error is also triggered when trying to downgrade:
```
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be DOWNGRADED:
  mimir
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
Need to get 0 B/19.4 MB of archives.
After this operation, 5,796 kB disk space will be freed.
Do you want to continue? [Y/n] y
dpkg: warning: downgrading mimir from 2.8.0~rc.0 to 2.7.1
(Reading database ... 53400 files and directories currently installed.)
Preparing to unpack .../archives/mimir_2.7.1_amd64.deb ...
Unsupported action: upgrade <-- again
dpkg: error processing archive /var/cache/apt/archives/mimir_2.7.1_amd64.deb (--unpack):
 installed mimir package pre-removal script subprocess returned error exit status 1
 Alpine Post Install of an clean install
 Reload the service unit from disk
 Unmask the service
 Set the preset flag for the service unit
 Set the enabled flag for the service unit
Errors were encountered while processing:
 /var/cache/apt/archives/mimir_2.7.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
```

With the resulting package built with the patched preremove script we
have the following, notice that the error is gone:

```
Selecting previously unselected package mimir.
(Reading database ... 53397 files and directories currently installed.)
Preparing to unpack mimir_2.8.0~rc.0_amd64.deb ...
Unpacking mimir (2.8.0~rc.0) ...
Setting up mimir (2.8.0~rc.0) ...
 Post Install of an upgrade
 Post Install of an upgrade

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be DOWNGRADED:
  mimir
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
Need to get 0 B/19.4 MB of archives.
After this operation, 6,148 kB disk space will be freed.
Do you want to continue? [Y/n] y
dpkg: warning: downgrading mimir from 2.8.0~rc.0 to 2.7.1
(Reading database ... 53400 files and directories currently installed.)
Preparing to unpack .../archives/mimir_2.7.1_amd64.deb ...
Unpacking mimir (2.7.1) over (2.8.0~rc.0) ...
Setting up mimir (2.7.1) ...
 Post Install of an upgrade
 Post Install of an upgrade
```

With this information we can patch the prerm script to do nothing on
upgrade as nothing is necessary.

Unfortunately there is nothing we can do from here for fixing the
upgrade from 2.7 to 2.8

Signed-off-by: Wilfried Roset <wilfriedroset@users.noreply.github.com>
Copy link
Contributor

@aknuds1 aknuds1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@aknuds1
Copy link
Contributor

aknuds1 commented Apr 21, 2023

I received confirmation from @lamida btw that he will backport your fix into 2.8.0.rc1 on Monday.

@aknuds1 aknuds1 merged commit 26fdb45 into grafana:main Apr 21, 2023
@grafanabot
Copy link
Contributor

The backport to release-2.8 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-4801-to-release-2.8 origin/release-2.8
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x 26fdb452ee21c62ef5e0ca0c474c47a8b1be33cc
# Push it to GitHub
git push --set-upstream origin backport-4801-to-release-2.8
git switch main
# Remove the local backport branch
git branch -D backport-4801-to-release-2.8

Then, create a pull request where the base branch is release-2.8 and the compare/head branch is backport-4801-to-release-2.8.

@lamida
Copy link
Contributor

lamida commented Apr 21, 2023

I will fix the backport later.

lamida pushed a commit that referenced this pull request Apr 21, 2023
nfpm migration introduces a regression in the prerm step. This step is
used by the OS for doing necessary cleaning before removing a package.
The underlying script is called upon remove or upgrade of a package by
passing an argument to it, argument being `remove` or `upgrade`.
The script expects *only* `remove` and raises an error for anything else.
Therefore when trying to upgrade, the script will fail with such an
error:

```
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  mimir
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/20.8 MB of archives.
After this operation, 5,796 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
(Reading database ... 53494 files and directories currently installed.)
Preparing to unpack .../mimir_2.8.0~rc.0_amd64.deb ...
Unsupported action: upgrade <--- breaking change here
dpkg: warning: old mimir package pre-removal script subprocess returned error exit status 1
dpkg: trying script from the new package instead ...
Unsupported action: failed-upgrade
dpkg: error processing archive /var/cache/apt/archives/mimir_2.8.0~rc.0_amd64.deb (--unpack):
 new mimir package pre-removal script subprocess returned error exit status 1
 Alpine Post Install of an clean install
 Reload the service unit from disk
 Unmask the service
 Set the preset flag for the service unit
 Set the enabled flag for the service unit
Errors were encountered while processing:
 /var/cache/apt/archives/mimir_2.8.0~rc.0_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
```

The error is also triggered when trying to downgrade:
```
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be DOWNGRADED:
  mimir
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
Need to get 0 B/19.4 MB of archives.
After this operation, 5,796 kB disk space will be freed.
Do you want to continue? [Y/n] y
dpkg: warning: downgrading mimir from 2.8.0~rc.0 to 2.7.1
(Reading database ... 53400 files and directories currently installed.)
Preparing to unpack .../archives/mimir_2.7.1_amd64.deb ...
Unsupported action: upgrade <-- again
dpkg: error processing archive /var/cache/apt/archives/mimir_2.7.1_amd64.deb (--unpack):
 installed mimir package pre-removal script subprocess returned error exit status 1
 Alpine Post Install of an clean install
 Reload the service unit from disk
 Unmask the service
 Set the preset flag for the service unit
 Set the enabled flag for the service unit
Errors were encountered while processing:
 /var/cache/apt/archives/mimir_2.7.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
```

With the resulting package built with the patched preremove script we
have the following, notice that the error is gone:

```
Selecting previously unselected package mimir.
(Reading database ... 53397 files and directories currently installed.)
Preparing to unpack mimir_2.8.0~rc.0_amd64.deb ...
Unpacking mimir (2.8.0~rc.0) ...
Setting up mimir (2.8.0~rc.0) ...
 Post Install of an upgrade
 Post Install of an upgrade

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be DOWNGRADED:
  mimir
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
Need to get 0 B/19.4 MB of archives.
After this operation, 6,148 kB disk space will be freed.
Do you want to continue? [Y/n] y
dpkg: warning: downgrading mimir from 2.8.0~rc.0 to 2.7.1
(Reading database ... 53400 files and directories currently installed.)
Preparing to unpack .../archives/mimir_2.7.1_amd64.deb ...
Unpacking mimir (2.7.1) over (2.8.0~rc.0) ...
Setting up mimir (2.7.1) ...
 Post Install of an upgrade
 Post Install of an upgrade
```

With this information we can patch the prerm script to do nothing on
upgrade as nothing is necessary.

Unfortunately there is nothing we can do from here for fixing the
upgrade from 2.7 to 2.8

Signed-off-by: Wilfried Roset <wilfriedroset@users.noreply.github.com>
(cherry picked from commit 26fdb45)
lamida added a commit that referenced this pull request Apr 22, 2023
nfpm migration introduces a regression in the prerm step. This step is
used by the OS for doing necessary cleaning before removing a package.
The underlying script is called upon remove or upgrade of a package by
passing an argument to it, argument being `remove` or `upgrade`.
The script expects *only* `remove` and raises an error for anything else.
Therefore when trying to upgrade, the script will fail with such an
error:

```
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  mimir
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/20.8 MB of archives.
After this operation, 5,796 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
(Reading database ... 53494 files and directories currently installed.)
Preparing to unpack .../mimir_2.8.0~rc.0_amd64.deb ...
Unsupported action: upgrade <--- breaking change here
dpkg: warning: old mimir package pre-removal script subprocess returned error exit status 1
dpkg: trying script from the new package instead ...
Unsupported action: failed-upgrade
dpkg: error processing archive /var/cache/apt/archives/mimir_2.8.0~rc.0_amd64.deb (--unpack):
 new mimir package pre-removal script subprocess returned error exit status 1
 Alpine Post Install of an clean install
 Reload the service unit from disk
 Unmask the service
 Set the preset flag for the service unit
 Set the enabled flag for the service unit
Errors were encountered while processing:
 /var/cache/apt/archives/mimir_2.8.0~rc.0_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
```

The error is also triggered when trying to downgrade:
```
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be DOWNGRADED:
  mimir
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
Need to get 0 B/19.4 MB of archives.
After this operation, 5,796 kB disk space will be freed.
Do you want to continue? [Y/n] y
dpkg: warning: downgrading mimir from 2.8.0~rc.0 to 2.7.1
(Reading database ... 53400 files and directories currently installed.)
Preparing to unpack .../archives/mimir_2.7.1_amd64.deb ...
Unsupported action: upgrade <-- again
dpkg: error processing archive /var/cache/apt/archives/mimir_2.7.1_amd64.deb (--unpack):
 installed mimir package pre-removal script subprocess returned error exit status 1
 Alpine Post Install of an clean install
 Reload the service unit from disk
 Unmask the service
 Set the preset flag for the service unit
 Set the enabled flag for the service unit
Errors were encountered while processing:
 /var/cache/apt/archives/mimir_2.7.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
```

With the resulting package built with the patched preremove script we
have the following, notice that the error is gone:

```
Selecting previously unselected package mimir.
(Reading database ... 53397 files and directories currently installed.)
Preparing to unpack mimir_2.8.0~rc.0_amd64.deb ...
Unpacking mimir (2.8.0~rc.0) ...
Setting up mimir (2.8.0~rc.0) ...
 Post Install of an upgrade
 Post Install of an upgrade

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be DOWNGRADED:
  mimir
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
Need to get 0 B/19.4 MB of archives.
After this operation, 6,148 kB disk space will be freed.
Do you want to continue? [Y/n] y
dpkg: warning: downgrading mimir from 2.8.0~rc.0 to 2.7.1
(Reading database ... 53400 files and directories currently installed.)
Preparing to unpack .../archives/mimir_2.7.1_amd64.deb ...
Unpacking mimir (2.7.1) over (2.8.0~rc.0) ...
Setting up mimir (2.7.1) ...
 Post Install of an upgrade
 Post Install of an upgrade
```

With this information we can patch the prerm script to do nothing on
upgrade as nothing is necessary.

Unfortunately there is nothing we can do from here for fixing the
upgrade from 2.7 to 2.8

Signed-off-by: Wilfried Roset <wilfriedroset@users.noreply.github.com>
(cherry picked from commit 26fdb45)

Co-authored-by: Wilfried ROSET <wilfriedroset@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants