Trusty to Xenial upgrade KeyError: 'SUDO_UID'

Bug #1570947 reported by Mark Haney on 2016-04-15
78
This bug affects 15 people
Affects Status Importance Assigned to Milestone
ubuntu-release-upgrader (Ubuntu)
Critical
Brian Murray

Bug Description

I've been testing upgrading my 15.10 and 14.04 servers to 16.04 the last handful of weeks using do-release-upgrade -d. Up until today, it's been fine to do so. However, when doing this on a 14.04 VM that I updated in the same manner only yesterday I get this output after running do-release-upgrade -d:

Traceback (most recent call last):
  File "/tmp/ubuntu-release-upgrader-kww9zzfn/xenial", line 8, in <module>
    sys.exit(main())
  File "/tmp/ubuntu-release-upgrader-kww9zzfn/DistUpgrade/DistUpgradeMain.py", line 229, in main
    app = DistUpgradeController(view, options, datadir=options.datadir)
  File "/tmp/ubuntu-release-upgrader-kww9zzfn/DistUpgrade/DistUpgradeController.py", line 159, in __init__
    self.quirks = DistUpgradeQuirks(self, self.config)
  File "/tmp/ubuntu-release-upgrader-kww9zzfn/DistUpgrade/DistUpgradeQuirks.py", line 63, in __init__
    self._uid = os.environ['SUDO_UID']
  File "/usr/lib/python3.4/os.py", line 633, in __getitem__
    raise KeyError(key) from None
KeyError: 'SUDO_UID'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/problem_report.py", line 416, in add_to_existing
    self.write(f)
  File "/usr/lib/python3/dist-packages/problem_report.py", line 371, in write
    crc = zlib.crc32(block, crc)
TypeError: 'str' does not support the buffer interface

Original exception was:
Traceback (most recent call last):
  File "/tmp/ubuntu-release-upgrader-kww9zzfn/xenial", line 8, in <module>
    sys.exit(main())
  File "/tmp/ubuntu-release-upgrader-kww9zzfn/DistUpgrade/DistUpgradeMain.py", line 229, in main
    app = DistUpgradeController(view, options, datadir=options.datadir)
  File "/tmp/ubuntu-release-upgrader-kww9zzfn/DistUpgrade/DistUpgradeController.py", line 159, in __init__
    self.quirks = DistUpgradeQuirks(self, self.config)
  File "/tmp/ubuntu-release-upgrader-kww9zzfn/DistUpgrade/DistUpgradeQuirks.py", line 63, in __init__
    self._uid = os.environ['SUDO_UID']
  File "/usr/lib/python3.4/os.py", line 633, in __getitem__
    raise KeyError(key) from None
KeyError: 'SUDO_UID'
=== Command detached from window (Fri Apr 15 11:45:47 2016) ===

To clarify, this is a 14.04, completely updated VM that I have been testing upgrading to 16.04, specifically for the best way to migrate our websites to PHP7. I had upgraded it yesterday without trouble, but rolled back to a previous snapshot to test a different method. Nothing on this VM has changed on the OS side, including packages. I have no idea what's caused the breakage.

Related branches

affects: crmsh (Ubuntu) → ubuntu-release-upgrader (Ubuntu)
Jean-Baptiste Lallement (jibel) wrote :

Confirmed with a desktop upgrade from 14.04 to 16.04 in a VM.

Changed in ubuntu-release-upgrader (Ubuntu):
importance: Undecided → Critical
status: New → Confirmed
assignee: nobody → Brian Murray (brian-murray)

That environment isn't available if the program isn't run in sudo; this is partly a bug in the program, and possibly happening because it wasn't run in sudo?

I suppose we could replace get the _uid value using something like 'id -u `who am i | cut -d\ -f 1`' instead of looking at the environment; or a try-catch block that falls back to just running id -u.

Mark Haney (mark-haney-t) wrote :

For clarification, this was run as root directly. As this is a test server, I more or less run everything as root. (I know, I know.)

tags: added: xenial
Mark Haney (mark-haney-t) wrote :

Update to my previous comment. If I login as a normal user and then sudo su to root, the upgrade doesn't bomb. I would assume just doing sudo do-release-upgrade -d would work just as well.

Suppose that teaches me not to just do things as root.

Brian Murray (brian-murray) wrote :

Some of the upgrade paths use pkexec, so checking for PKEXEC_UID would be a good idea.

@Mark Haney - the inhibitIdle function should only run if /usr/bin/gnome-session-inhibit is available. Is it on your server?

Mark Haney (mark-haney-t) wrote :

No it is not. As it's a server, the install was pretty basic, no GUI just ssh, nginx and php5 (originally). So, unless that file is included in the based install of the server version, I certainly didn't add it.

Changed in ubuntu-release-upgrader (Ubuntu):
status: Confirmed → In Progress
c2h5oh (c2h5oh) wrote :

Desktop 15.10 has the same problem

update-manager -d ==> KeyError: 'SUDO_UID'

sudo update-manager -d ==> KeyError: 'SUDO_UID'

sudo su
update-manager -d ==> KeyError: 'SUDO_UID'

c2h5oh (c2h5oh) wrote :

Interesting:

sudo echo $SUDO_UID

returns nothing

aaron (jhao-sun) wrote :

me too

Danel-dnl-93 (danel-dnl-93) wrote :

I have Ubuntu 15.10 x64 and i have this problem too.

Alexander List (alexlist) wrote :

I just ran into the same issue testing the release upgrade from 15.10 to 16.04 in a Docker container.

I started the container with

docker run -ti ubuntu:15.10 /bin/bash

and then installed ubuntu-release-upgrader-core and tried the upgrade, and hit exactly the same problem.

Alexander List (alexlist) wrote :

Of course, a workaround is to set these env variables when not using sudo but logging in as root and doing release upgrade:

export SUDO_USER=root
export SUDO_UID=0
export SUDO_COMMAND=/bin/bash
export SUDO_GID=0

Wolfgang (wt-lists) wrote :

Workaround with sudo does not work for me!
I get the same error as "normal" user also when trying to upgrade from 15.10 to 16.04:

user@computername:~$ sudo update-manager -d
Neue Veröffentlichungen von Ubuntu werden gesucht
Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.
»xenial.tar.gz« wird gegenüber »xenial.tar.gz.gpg« legitimiert
»xenial.tar.gz« wird entpackt
Traceback (most recent call last):
  File "/tmp/ubuntu-release-upgrader-osqpzv7k/xenial", line 8, in <module>
    sys.exit(main())
  File "/tmp/ubuntu-release-upgrader-osqpzv7k/DistUpgrade/DistUpgradeMain.py", line 229, in main
    app = DistUpgradeController(view, options, datadir=options.datadir)
  File "/tmp/ubuntu-release-upgrader-osqpzv7k/DistUpgrade/DistUpgradeController.py", line 159, in __init__
    self.quirks = DistUpgradeQuirks(self, self.config)
  File "/tmp/ubuntu-release-upgrader-osqpzv7k/DistUpgrade/DistUpgradeQuirks.py", line 63, in __init__
    self._uid = os.environ['SUDO_UID']
  File "/usr/lib/python3.4/os.py", line 633, in __getitem__
    raise KeyError(key) from None
KeyError: 'SUDO_UID'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/problem_report.py", line 480, in add_to_existing
    self.write(f)
  File "/usr/lib/python3/dist-packages/problem_report.py", line 435, in write
    crc = zlib.crc32(block, crc)
TypeError: 'str' does not support the buffer interface

Original exception was:
Traceback (most recent call last):
  File "/tmp/ubuntu-release-upgrader-osqpzv7k/xenial", line 8, in <module>
    sys.exit(main())
  File "/tmp/ubuntu-release-upgrader-osqpzv7k/DistUpgrade/DistUpgradeMain.py", line 229, in main
    app = DistUpgradeController(view, options, datadir=options.datadir)
  File "/tmp/ubuntu-release-upgrader-osqpzv7k/DistUpgrade/DistUpgradeController.py", line 159, in __init__
    self.quirks = DistUpgradeQuirks(self, self.config)
  File "/tmp/ubuntu-release-upgrader-osqpzv7k/DistUpgrade/DistUpgradeQuirks.py", line 63, in __init__
    self._uid = os.environ['SUDO_UID']
  File "/usr/lib/python3.4/os.py", line 633, in __getitem__
    raise KeyError(key) from None
KeyError: 'SUDO_UID'

Wolfgang (wt-lists) wrote :

Workaround suggested as comment #13 does also not work for me...

root@MacBookAir:~# export SUDO_USER=root
root@MacBookAir:~# export SUDO_UID=0
root@MacBookAir:~# export SUDO_COMMAND=/bin/bash
root@MacBookAir:~# export SUDO_GID=0
root@MacBookAir:~# update-manager -d
Neue Veröffentlichungen von Ubuntu werden gesucht
Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.
»xenial.tar.gz« wird gegenüber »xenial.tar.gz.gpg« legitimiert
»xenial.tar.gz« wird entpackt
Traceback (most recent call last):
  File "/tmp/ubuntu-release-upgrader-rwci_0e6/xenial", line 8, in <module>
    sys.exit(main())
  File "/tmp/ubuntu-release-upgrader-rwci_0e6/DistUpgrade/DistUpgradeMain.py", line 229, in main
    app = DistUpgradeController(view, options, datadir=options.datadir)
  File "/tmp/ubuntu-release-upgrader-rwci_0e6/DistUpgrade/DistUpgradeController.py", line 159, in __init__
    self.quirks = DistUpgradeQuirks(self, self.config)
  File "/tmp/ubuntu-release-upgrader-rwci_0e6/DistUpgrade/DistUpgradeQuirks.py", line 63, in __init__
    self._uid = os.environ['SUDO_UID']
  File "/usr/lib/python3.4/os.py", line 633, in __getitem__
    raise KeyError(key) from None
KeyError: 'SUDO_UID'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/problem_report.py", line 480, in add_to_existing
    self.write(f)
  File "/usr/lib/python3/dist-packages/problem_report.py", line 435, in write
    crc = zlib.crc32(block, crc)
TypeError: 'str' does not support the buffer interface

Original exception was:
Traceback (most recent call last):
  File "/tmp/ubuntu-release-upgrader-rwci_0e6/xenial", line 8, in <module>
    sys.exit(main())
  File "/tmp/ubuntu-release-upgrader-rwci_0e6/DistUpgrade/DistUpgradeMain.py", line 229, in main
    app = DistUpgradeController(view, options, datadir=options.datadir)
  File "/tmp/ubuntu-release-upgrader-rwci_0e6/DistUpgrade/DistUpgradeController.py", line 159, in __init__
    self.quirks = DistUpgradeQuirks(self, self.config)
  File "/tmp/ubuntu-release-upgrader-rwci_0e6/DistUpgrade/DistUpgradeQuirks.py", line 63, in __init__
    self._uid = os.environ['SUDO_UID']
  File "/usr/lib/python3.4/os.py", line 633, in __getitem__
    raise KeyError(key) from None
KeyError: 'SUDO_UID'

hova888 (hova888) wrote :

sudo apt update
sudo apt upgrade
sudo do-release-upgrade -d

Trying to upgrade from 15.10 (x86 64bit) and I've got the issue too.

Launchpad Janitor (janitor) wrote :

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

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

  * DistUpgradeQuirks.py: Fix the quirk which inhibits screensavers.
    (LP: #1570947)

 -- Brian Murray <email address hidden> Fri, 15 Apr 2016 17:11:11 -0700

Changed in ubuntu-release-upgrader (Ubuntu):
status: In Progress → Fix Released

Just tried to upgrade from 15.10 after the fix release and this error does not occur anymore.

Nice job Brian!

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

Other bug subscribers