openstack commands fail with GTK3 error

Bug #1945661 reported by Amit Bhardwaj
26
This bug affects 5 people
Affects Status Importance Assigned to Milestone
python-openstackclient (Ubuntu)
Confirmed
Undecided
Tom Moyer

Bug Description

Openstack release: Wallaby
OS: Ubuntu 20.04 server edition
After installation of python3-openstackclient from apt, while setting up user, roles and project, I executed following command:
openstack domain create --description "An Example Domain" example

Error:
Traceback (most recent call last):
  File "/usr/bin/openstack", line 6, in <module>
    from openstackclient.shell import main
  File "/usr/lib/python3/dist-packages/openstackclient/shell.py", line 23, in <module>
    from osc_lib import shell
  File "/usr/lib/python3/dist-packages/osc_lib/shell.py", line 24, in <module>
    from cliff import app
  File "/usr/lib/python3/dist-packages/cliff/app.py", line 22, in <module>
    import cmd2
  File "/usr/lib/python3/dist-packages/cmd2.py", line 585, in <module>
    _ = pyperclip.paste()
  File "/usr/lib/python3/dist-packages/pyperclip/__init__.py", line 667, in lazy_load_stub_paste
    copy, paste = determine_clipboard()
  File "/usr/lib/python3/dist-packages/pyperclip/__init__.py", line 558, in determine_clipboard
    return init_gi_clipboard()
  File "/usr/lib/python3/dist-packages/pyperclip/__init__.py", line 167, in init_gi_clipboard
    gi.require_version('Gtk', '3.0')
  File "/usr/lib/python3/dist-packages/gi/__init__.py", line 129, in require_version
    raise ValueError('Namespace %s not available' % namespace)

Had to install GTK3 to make openstack commands work but it is taking huge time to get a response to the commands. The wait time after firing any openstack cli command is around 30 seconds.

Anybody faced the issue? What is the fix for it if it exists?

Revision history for this message
Amit Bhardwaj (bhardwajamit23) wrote :

Anyone looking into this. This error is consistent.

Revision history for this message
Amit Bhardwaj (bhardwajamit23) wrote :

I figured out that the error is coming only when I try installation using SSH terminals from a windows host. I shifted to linux and SSH'd into the controller and there wasn't any error.

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

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in python-openstackclient (Ubuntu):
status: New → Confirmed
Revision history for this message
Mark (airon21) wrote :

I also get this error when I execute the "openstack XXX" command remotely in an Xshell, and I noticed that the same prompt seems to be related to trying to open the GUI - initialization.
So, I run "openstack XXX" in putty, and no more related errors.

System version: ubuntu20.04 tls
openstack: W
Possible solutions: use terminal tools without desktop functions, or cancel the installation of the desktop from the underlying system

Revision history for this message
Mario David (mariojmdavid) wrote :

I have the same problem (and I don't have any windows machine, terminal, etc,)

on ubuntu20.04 LTS
openstack yoga
python3-openstackclient 5.8.0-0ubuntu1~cloud0

this is in one of the openstack controllers, and I login/ssh from a linux terminal

root@test-ctl001:~# openstack domain list
Traceback (most recent call last):
  File "/usr/bin/openstack", line 6, in <module>
    from openstackclient.shell import main
  File "/usr/lib/python3/dist-packages/openstackclient/shell.py", line 23, in <module>
    from osc_lib import shell
  File "/usr/lib/python3/dist-packages/osc_lib/shell.py", line 24, in <module>
    from cliff import app
  File "/usr/lib/python3/dist-packages/cliff/app.py", line 23, in <module>
    import cmd2
  File "/usr/lib/python3/dist-packages/cmd2.py", line 585, in <module>
    _ = pyperclip.paste()
  File "/usr/lib/python3/dist-packages/pyperclip/__init__.py", line 667, in lazy_load_stub_paste
    copy, paste = determine_clipboard()
  File "/usr/lib/python3/dist-packages/pyperclip/__init__.py", line 558, in determine_clipboard
    return init_gi_clipboard()
  File "/usr/lib/python3/dist-packages/pyperclip/__init__.py", line 167, in init_gi_clipboard
    gi.require_version('Gtk', '3.0')
  File "/usr/lib/python3/dist-packages/gi/__init__.py", line 129, in require_version
    raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gtk not available

Revision history for this message
Mario David (mariojmdavid) wrote :

I have
apt install libgtk-3-dev

(installed a few hundredths of packages/deps)

and after that

root@test-ctl002:~# openstack project list
Gtk-Message: 08:52:39.226: Failed to load module "canberra-gtk-module"
/usr/lib/python3/dist-packages/secretstorage/dhcrypto.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
/usr/lib/python3/dist-packages/secretstorage/util.py:19: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes

Revision history for this message
eblock@nde.ag (eblock) wrote :

I just upgraded my test environment from Victoria to Wallaby (Ubuntu 20.04, our own package based deployment, no kolla/ansible etc. involved) and now I'm seeing the same error message when trying to use the openstack cli:

root@control01:~# openstack network agent list
Traceback (most recent call last):
  File "/usr/bin/openstack", line 6, in <module>
    from openstackclient.shell import main
  File "/usr/lib/python3/dist-packages/openstackclient/shell.py", line 23, in <module>
    from osc_lib import shell
  File "/usr/lib/python3/dist-packages/osc_lib/shell.py", line 24, in <module>
    from cliff import app
  File "/usr/lib/python3/dist-packages/cliff/app.py", line 22, in <module>
    import cmd2
  File "/usr/lib/python3/dist-packages/cmd2.py", line 585, in <module>
    _ = pyperclip.paste()
  File "/usr/lib/python3/dist-packages/pyperclip/__init__.py", line 667, in lazy_load_stub_paste
    copy, paste = determine_clipboard()
  File "/usr/lib/python3/dist-packages/pyperclip/__init__.py", line 558, in determine_clipboard
    return init_gi_clipboard()
  File "/usr/lib/python3/dist-packages/pyperclip/__init__.py", line 167, in init_gi_clipboard
    gi.require_version('Gtk', '3.0')
  File "/usr/lib/python3/dist-packages/gi/__init__.py", line 129, in require_version
    raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gtk not available

Revision history for this message
eblock@nde.ag (eblock) wrote :

I found one way to get the openstack shell to work by installing libgtk-3-dev (I found a hint in a search engine). Apparently, python3-cmd2 requires python3-pyperclip which requires python3-gi and so on. Is this really the required way? I didn't notice anything in the release notes (maybe I missed it). When comparing to a different environment (Victoria on baremetal) I see that libgtk-3 is installed there (not -dev though), but with libgtk-3-0 only the error message was still present. So the question is, which dependencies are missing where? It's not really obvious to me. Could this already be fixed in Xena? If it is fixed there I could do the double upgrade, of course, especially since Wallaby is already under extended maintenance.

Revision history for this message
eblock@nde.ag (eblock) wrote :

I reinstalled my lab environment with Wallaby from scratch, no upgrade, still the same error.
Then I reinstalled with Xena, with the same error. This is the Xena version of python3-openstackclient:
root@control01:~# apt show python3-openstackclient
Package: python3-openstackclient
Version: 5.6.0-0ubuntu1~cloud0

Revision history for this message
eblock@nde.ag (eblock) wrote :

Maybe my comments are invalid. It must have something to do with my VM image where I'm testing all of this. When I removed a lot of packages which I refer to openstack and then reinstalled only python3-openstackclient it works as expected in W, X and Y releases. I just didn't test the upgrade yet after cleaning up properly. Hopefully, this won't be an issue during the actual upgrade of the baremetal nodes as I'm not sure which package(s) exactly is (are) responsible for this misconfiguration in my lab env.

Revision history for this message
Chris Morgan (cmorgan2) wrote :

I ran into this too. We determined that something was setting up my DISPLAY variable which is how X11 knows where to send X11 GUI windows. When I unset that environment variable and tried again, the openstack client command worked. My environment had not changed, however we had upgraded the target openstack cluster from Ussuri to Yoga. It appears in newer openstack versions, something tries to be helpful and (perhaps?) paste the results of an openstack CLI command to the X11 paste buffer (aka clipboard)? Sorry I don't know more about this, but wanted to share an easy fix!

Revision history for this message
David A. Desrosiers (setuid) wrote :

I've successfully built and tested 5.2.0 (ussuri) and 5.8.0 (yoga) versions of python3-openstackclient _without_ the `pyperclip==1.5.27` dependency, and run a full battery of openstack CLI tests, with and without $DISPLAY being set (ssh -Y <host> vs. not), and all worked perfectly without incident.

Since the clipboard is managed by the terminal of choice (iTerm/Terminal/Termius on macOS, PuTTY on Windows, xterm/rxvt/term on Linux), there is no reason for the _remote_ CLI tools to contain any clipboard sharing capabilities, such as those provided by `pyperclip`. Removing this Python dependency is a no-op to the function of the openstack client tools.

This is an easy, 1-line PR. I'll see if I can push this upstream and encourage our internal repackaging of the same to mitigate this issue on Ubuntu.

Tom Moyer (tom-tom)
Changed in python-openstackclient (Ubuntu):
assignee: nobody → Tom Moyer (tom-tom)
Revision history for this message
David A. Desrosiers (setuid) wrote :

I believe I've nailed this one down, after a day of heads-down testing.

The issue boils down to this bit of code, in /usr/lib/python3/dist-packages/cmd2.py:

    # The extraneous output bug in pyperclip on Linux using xclip was fixed in more recent versions of pyperclip
    if sys.platform.startswith('linux') and pyperclip_ver < 1.6:
        # Avoid extraneous output to stderr from xclip when clipboard is empty at cost of overwriting clipboard contents
        pyperclip.copy('')
    else:
        # Try getting the contents of the clipboard
        _ = pyperclip.paste()

Specifically that last line: `_ = pyperclip.paste()`, which assumes a clipboard exists and has been initialized. In most cases, it has not/will not be.

The attached diff to cmd2.py will allow these commands to succeed. I initially added some debug to allow me to see if the clipboard was accessible or not, and that's how I found this.

Let me know if this is sufficient to SRU into the python3-cmd2 package to address this.

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "cmd2-diff.patch" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
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.