Unable to locate package python2, hook install fails in bionic 18.04.6

Bug #1946798 reported by Bartosz Woronicz
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
charm-haproxy
Fix Released
Critical
Haw Loeung

Bug Description

haproxy-62

hook install fails here:
unit-haproxy-0: 21:36:50 WARNING unit.haproxy/0.install E: Unable to locate package python2

That's since we have
root@juju-48185c-0-lxd-0:~# cat /etc/issue
Ubuntu 18.04.6 LTS \n \l

and here's the excerpt from hook install code. One release ago it would work. But not now and it fails trying to install not existing package python2

if awk -v bionic="18.04.5" -v distrib="$(lsb_release -rs)" 'BEGIN{distrib >= bionic}'
then
    # Install missing python-yaml and python-apt packages
    apt-get install -y python2 python-yaml python-apt

    juju-log 'Invoking python-based install hook'
    python2 hooks/hooks.py install
else
    # Install missing python-yaml and python-apt packages
    apt-get install -y python-yaml python-apt

    juju-log 'Invoking python-based install hook'
    python hooks/hooks.py install
fi

Related branches

Revision history for this message
Bartosz Woronicz (mastier1) wrote (last edit ):

The python2 is missing in bionic.
beside the above statement will work incorrectly, comparing these strings seems not right way to do it. It compares their length
for example 20.04 >= 18.04.5 will give falls and will work on focal as there's python2 package
but 18.04.6 >= 18.04.5 will be true ,but there's not python2 package in bionic, only python package(version2.7.15)

Revision history for this message
Bartosz Woronicz (mastier1) wrote :
Revision history for this message
Vern Hart (vern) wrote :

A good way to compare semantic versions is with dpkg:

    dpkg --compare-versions <ver1> <op> <ver2>

The comparison operators include: lt le eq ne ge gt

So we could rewrite the comparison to:

    if dpkg --compare-versions 18.04.5 le "$(lsb_release -rs)"; then

Though I think that'd break for 18.04.6 since the python2 package was introduced in focal (https://packages.ubuntu.com/search?keywords=python2).

This might be better:

    if dpkg --compare-versions 20.04 le "$(lsb_release -rs)"; then

Haw Loeung (hloeung)
Changed in charm-haproxy:
status: New → In Progress
importance: Undecided → Critical
assignee: nobody → Haw Loeung (hloeung)
Haw Loeung (hloeung)
Changed in charm-haproxy:
status: In Progress → Fix Released
Revision history for this message
Vladimir Grevtsev (vlgrevtsev) wrote :

Hi all,

I'm not sure if the proposed fix [0] is going to work on Focal:

ubuntu@lsha01:~$ dpkg --compare-versions "$(lsb_release -rs)" lt 20.04
ubuntu@lsha01:~$ echo $?
1

That means, that the second block of code would be executed, invoking `python` command which is missing:

#### Focal: there's no "python" command available

ubuntu@lsha01:~$ lsb_release -rs
20.04
ubuntu@lsha01:~$ python3
Python 3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
ubuntu@lsha01:~$ python

Command 'python' not found, did you mean:

  command 'python3' from deb python3
  command 'python' from deb python-is-python3

ubuntu@lsha01:~$ python2
Python 2.7.18 (default, Mar 8 2021, 13:02:45)
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

#### Bionic: should be OK for both python2 and python invocations

ubuntu@nagios01:~$ lsb_release -rs
18.04
ubuntu@nagios01:~$ python
Python 2.7.17 (default, Feb 27 2021, 15:10:58)
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
ubuntu@nagios01:~$ python3
Python 3.6.9 (default, Jan 26 2021, 15:33:00)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

[0] https://bazaar.launchpad.net/~haproxy-team/charm-haproxy/trunk/revision/146/hooks/install#hooks/install

Revision history for this message
Vladimir Grevtsev (vlgrevtsev) wrote :
Download full text (4.0 KiB)

In fact, neither bionic nor focal works now:

$ j status
Model Controller Cloud/Region Version SLA Timestamp
default aws-eu-central-1 aws/eu-central-1 2.9.15 unsupported 16:47:44+03:00

App Version Status Scale Charm Store Channel Rev OS Message
haproxy-bionic error 1 haproxy charmstore stable 63 ubuntu hook failed: "install"
haproxy-focal error 1 haproxy charmstore stable 63 ubuntu hook failed: "install"

Unit Workload Agent Machine Public address Ports Message
haproxy-bionic/0* error idle 0 3.123.128.195 hook failed: "install"
haproxy-focal/0* error idle 1 3.125.120.110 hook failed: "install"

Machine State DNS Inst id Series AZ Message
0 started 3.123.128.195 i-04644b74485f1d622 bionic eu-central-1a running
1 started 3.125.120.110 i-01ef6ecc1a42b5f97 focal eu-central-1c running

$ j debug-log -i haproxy-bionic/0
unit-haproxy-bionic-0: 16:47:30 INFO juju.worker.uniter awaiting error resolution for "install" hook
unit-haproxy-bionic-0: 16:47:32 INFO unit.haproxy-bionic/0.juju-log Invoking charm-pre-install hooks
unit-haproxy-bionic-0: 16:47:33 WARNING unit.haproxy-bionic/0.install E: Unable to locate package python2
unit-haproxy-bionic-0: 16:47:33 ERROR juju.worker.uniter.operation hook "install" (via explicit, bespoke hook script) failed: exit status 100
unit-haproxy-bionic-0: 16:47:33 INFO juju.worker.uniter awaiting error resolution for "install" hook
unit-haproxy-bionic-0: 16:48:15 INFO juju.worker.uniter awaiting error resolution for "install" hook
unit-haproxy-bionic-0: 16:48:17 INFO unit.haproxy-bionic/0.juju-log Invoking charm-pre-install hooks
unit-haproxy-bionic-0: 16:48:17 WARNING unit.haproxy-bionic/0.install E: Unable to locate package python2
unit-haproxy-bionic-0: 16:48:18 ERROR juju.worker.uniter.operation hook "install" (via explicit, bespoke hook script) failed: exit status 100
unit-haproxy-bionic-0: 16:48:18 INFO juju.worker.uniter awaiting error resolution for "install" hook
^C
$ j debug-log -i haproxy-focal/0
unit-haproxy-focal-0: 16:47:33 INFO unit.haproxy-focal/0.juju-log Invoking python-based install hook
unit-haproxy-focal-0: 16:47:33 WARNING unit.haproxy-focal/0.install /var/lib/juju/agents/unit-haproxy-focal-0/charm/hooks/install: 25: python: not found
unit-haproxy-focal-0: 16:47:33 ERROR juju.worker.uniter.operation hook "install" (via explicit, bespoke hook script) failed: exit status 127
unit-haproxy-focal-0: 16:47:33 INFO juju.worker.uniter awaiting error resolution for "install" hook
unit-haproxy-focal-0: 16:48:10 INFO juju.worker.uniter awaiting error resolution for "install" hook
unit-haproxy-focal-0: 16:48:12 INFO unit.haproxy-focal/0.juju-log Invoking charm-pre-install hooks
unit-haproxy-focal-0: 16:48:13 INFO unit.haproxy-focal/0.juju-log Invoking python-based install hook
unit-haproxy-focal-0: 16:48:13 WARNING unit.haproxy-focal/0.install /var/lib/juju/agents/unit-haproxy-focal-0/charm/hooks/install: 25: python: not found
unit-haproxy-focal-0: 16:48:13 ERROR juju.wo...

Read more...

Revision history for this message
Andre Ruiz (andre-ruiz) wrote (last edit ):

Just confirming that in focal, a manual debug-hook install + apt install python-is-python2 + ./hooks/install worked around the problem.

Revision history for this message
Junien F (axino) wrote :

Proper fix has been released (and a deploy tested on bionic and focal), let me know if it still fails.

Revision history for this message
Vern Hart (vern) wrote :

We're overthinking this. Submitted a fix that way simplifies the install hook since python-yaml and python-apt both have dependencies on python2 so it's automatically installed on focal. And python-minimal on bionic comes with a python2 binary so we can just use that on both releases.

https://code.launchpad.net/~vern/charm-haproxy/fix-install-hook/+merge/410140

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.