Bug 1410480

Summary: "NameError: global name '_' is not defined" appears in rhui.log if there's an issue with Docker
Product: Red Hat Update Infrastructure for Cloud Providers Reporter: Radek Bíba <rbiba>
Component: ToolsAssignee: RHUI Bug List <rhui-bugs>
Status: CLOSED ERRATA QA Contact: Radek Bíba <rbiba>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 3.0.0CC: bizhang, pcreech
Target Milestone: ---   
Target Release: 3.0.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-03-01 22:15:14 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Radek Bíba 2017-01-05 15:31:09 UTC
Description of problem:
While debugging the recent issue with the registry, I noticed a bug in the way docker_utils.py uses logging. There are two affected lines:

LOG.debug(_('Failed to connect to upstream registry %s' % url ))
LOG.debug(_('Search for upstream container failed with message %s' % str(request_error)))

For example, if you set the IP address of the registry to 127.0.0.1 in your resolv.conf (just to trigger the logging), you get:

====
2017-01-05 09:52:54,384 - <type 'exceptions.NameError'>
2017-01-05 09:52:54,384 - Unexpected error caught at the shell level
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/rhui/tools/shell.py", line 88, in safe_listen
    self.listen(clear=first_run)
  File "/usr/lib/python2.7/site-packages/rhui/tools/shell.py", line 127, in listen
    Shell.listen(self)
  File "/usr/lib/python2.7/site-packages/rhui/common/shell.py", line 186, in listen
    item.func(*args, **item.kwargs)
  File "/usr/lib/python2.7/site-packages/rhui/tools/screens/repo.py", line 211, in add_docker
    if docker_utils.is_valid_docker_upstream(upstream_name):
  File "/usr/lib/python2.7/site-packages/rhui/common/docker_utils.py", line 23, in is_valid_docker_upstream
    LOG.debug(_('Search for upstream container failed with message %s' % str(request_error)))
NameError: global name '_' is not defined
====

Version-Release number of selected component (if applicable):
rh-rhui-tools-pre.3.0.39-1.el7ui (Beta 2)

How reproducible:
Always, on both RHEL 6 and 7.

Steps to Reproduce:
1. Append registry.access.redhat.com to the line in /etc/resolv.conf that contains the IP address of localhost.
2. Run rhui-manager --debug.
3. r > ad > enter something

Actual results:
An unexpected error has occurred during the last operation.
More information can be found in /root/.rhui/rhui.log.

The log contains the aforementioned traceback.

Expected results:
Nice debug information. Perhaps:
2017-01-05 10:11:23,627 - Search for upstream container failed with message [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)

Additional info:
Oddly enough, with _() removed, rhui-manager logs the message above but proceeds anyway, letting me add an invalid container that can't ever be synced!

====
Name of the container in the registry: 
qwe

Unique ID for the container (alphanumerics, _, and - only) [qwe]:


Display name for the container [qwe]:


The following container will be added:
  Container Id:              qwe
  Display Name:              qwe
  Upstream Container Name:   qwe
Proceed? (y/n) y

Successfully added container qwe
====

Now go the the repo sync screen, sync the "qwe" repo immediately, and watch the progress:

====
qwe
01-05-2017 16:17             01-05-2017 10:19             Error
====

The root cause is in the same file, where "return True" is used (twice) even though something went wrong. When changed to "return False", I get:

====
Could not find qwe on registry https://registry.access.redhat.com, please make sure that the name is valid

Name of the container in the registry:
====

Comment 2 Radek Bíba 2017-01-18 10:40:08 UTC
This is only partially fixed. I see that "from gettext import gettext as _" has been added, which resolves the traceback, but I can still add a nonexisting repo:

------------------------------------------------------------------------------
rhui (repo) => ad

Name of the container in the registry: 
qwe

Unique ID for the container (alphanumerics, _, and - only) [qwe]:


Display name for the container [qwe]:


The following container will be added:
  Container Id:              qwe
  Display Name:              qwe
  Upstream Container Name:   qwe
Proceed? (y/n) y

Successfully added container qwe

------------------------------------------------------------------------------

Meanwhile, in rhui.log, a correct message appears reflecting the fact that the registry isn't available at 127.0.0.1:

2017-01-18 05:36:46,111 - Search for upstream container failed with message [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)

Please see the note about "return True" in comment 0.

Comment 3 Radek Bíba 2017-01-19 08:24:45 UTC
I see a change in the way invalid (non-existing) containers in the real and accessible (and working) registry are handled. Previously, rhui-manager would print:

------------------------------------------------------------------------------
rhui (repo) => ad

Name of the container in the registry: 
qwe

Could not find qwe on registry https://registry.access.redhat.com, please make sure that the name is valid

Name of the container in the registry:

------------------------------------------------------------------------------

As the repeated prompt suggests, this would allow one to try again with a different (correctly spelled?) name. With ISO 20170118, however, rhui-manager prints:

------------------------------------------------------------------------------
rhui (repo) => ad

Name of the container in the registry: 
qwe

Could not validate qwe on registry https://registry.access.redhat.com, this may cause problems during repo creation. Please check ~/.rhui/rhui.log for more details.

Unique ID for the container (alphanumerics, _, and - only) [qwe]:
------------------------------------------------------------------------------

Meaning, it's assumed that the entered name is OK but only can't be found/validated at the moment. There are no details in the rhui log, though.

Is that the intended fix?

OTOH, details are in the rhui.log if there's a network problem, which is good.

Comment 4 bizhang 2017-01-19 14:07:23 UTC
Radek, yes. This reason for this change is the registry search api issue that happened a couple of weeks ago. 

After discussion with pcreech we decided that not being able to validate a container name should not block the attempted creation of the container. This ensures that if the search api ever malfunctions again, it does not affect the rhui container creation use case.

Comment 5 Radek Bíba 2017-01-19 14:18:24 UTC
I see. Thanks for the explanation, Bihan.

Comment 6 errata-xmlrpc 2017-03-01 22:15:14 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2017:0367