Bug 1599967 - glance-manage db_sync failed due to UnicodeEncodeError
Summary: glance-manage db_sync failed due to UnicodeEncodeError
Keywords:
Status: CLOSED EOL
Alias: None
Product: Red Hat OpenStack
Classification: Red Hat
Component: puppet-openstacklib
Version: 13.0 (Queens)
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ---
: ---
Assignee: OSP Team
QA Contact: Nobody
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-07-11 03:54 UTC by Chen
Modified: 2023-07-10 19:37 UTC (History)
12 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-07-10 19:37:47 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
env output on director node (2.08 KB, text/plain)
2018-07-13 03:28 UTC, Chen
no flags Details


Links
System ID Private Priority Status Summary Last Updated
OpenStack gerrit 583675 0 None ABANDONED WIP - Force utf8 on openstack-db execs 2021-01-12 13:57:07 UTC
OpenStack gerrit 640997 0 None MERGED Keep the system locale in the openstack command. 2021-01-12 13:56:26 UTC
Red Hat Issue Tracker OSP-6101 0 None None None 2023-03-08 19:29:04 UTC

Description Chen 2018-07-11 03:54:22 UTC
Description of problem:

glance-manage db_sync failed due to UnicodeEncodeError:

2018-07-10 10:18:59.758 12330 DEBUG oslo_db.sqlalchemy.engines [-] MySQL server mode set to STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION _check_effective_sql_mode /usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/engines.py:290
2018-07-10 10:18:59.762 12330 INFO alembic.runtime.migration [-] Context impl MySQLImpl.
2018-07-10 10:18:59.762 12330 INFO alembic.runtime.migration [-] Will assume non-transactional DDL.
2018-07-10 10:18:59.774 12330 CRITICAL glance [-] Unhandled error: UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-22: ordinal not in range(128)
2018-07-10 10:18:59.774 12330 ERROR glance Traceback (most recent call last):
2018-07-10 10:18:59.774 12330 ERROR glance   File "/usr/bin/glance-manage", line 10, in <module>
2018-07-10 10:18:59.774 12330 ERROR glance     sys.exit(main())
2018-07-10 10:18:59.774 12330 ERROR glance   File "/usr/lib/python2.7/site-packages/glance/cmd/manage.py", line 551, in main
2018-07-10 10:18:59.774 12330 ERROR glance     return CONF.command.action_fn()
2018-07-10 10:18:59.774 12330 ERROR glance   File "/usr/lib/python2.7/site-packages/glance/cmd/manage.py", line 383, in sync
2018-07-10 10:18:59.774 12330 ERROR glance     self.command_object.sync(CONF.command.version)
2018-07-10 10:18:59.774 12330 ERROR glance   File "/usr/lib/python2.7/site-packages/glance/cmd/manage.py", line 159, in sync
2018-07-10 10:18:59.774 12330 ERROR glance     print(_('Database is up to date. No migrations needed.'))
2018-07-10 10:18:59.774 12330 ERROR glance UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-22: ordinal not in range(128)
2018-07-10 10:18:59.774 12330 ERROR glance

Version-Release number of selected component (if applicable):

OSP13 undercloud

How reproducible:

100% at customer's site

Steps to Reproduce:
1. openstack undercloud install
2. 
3.

Actual results:

The undercloud installation would fail and glance/api.log will output those error messages

Expected results:


Additional info:

Comment 3 Cyril Roelandt 2018-07-12 16:00:45 UTC
Could you tell me to what values the following environment variables are set? LANG, LC_ALL, LC_TYPES... Giving us the output of "env" would probably be helpful :)

How is "glance manage" run? Manually, through a script, by cron?

Is the output redirected?

2018-07-10 10:18:59.774 12330 ERROR glance     print(_('Database is up to date. No migrations needed.'))

Is this string translated? If so, to what?

Comment 5 Chen 2018-07-13 03:28:15 UTC
Created attachment 1458621 [details]
env output on director node

Comment 7 Cyril Roelandt 2018-07-16 15:07:48 UTC
OK, so I talked to Victor Stinner who knows the whole Python/UTF8 quite well and I ran some tests:

$ LANG=ja_JP.utf8  glance-manage db_sync 
/usr/local/lib/python3.5/dist-packages/oslo_db/sqlalchemy/enginefacade.py:1334: OsloDBDeprecationWarning: EngineFacade is deprecated; please use oslo_de
  expire_on_commit=expire_on_commit, _conf=conf)
DEBUG oslo_db.sqlalchemy.engines [-] MySQL server mode set to STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_}
INFO alembic.runtime.migration [-] Context impl MySQLImpl.
INFO alembic.runtime.migration [-] Will assume non-transactional DDL.
データベースは最新です。移行は必要ありません。

$ LANG=ja_JP.utf8  glance-manage db_sync | less
DEBUG oslo_db.sqlalchemy.engines [-] MySQL server mode set to STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION {{(pid=5457) _check_effective_sql_mode /usr/local/lib/python2.7/dist-packages/oslo_db/sqlalchemy/engines.py:308}}
INFO alembic.runtime.migration [-] Context impl MySQLImpl.
INFO alembic.runtime.migration [-] Will assume non-transactional DDL.
CRITICAL glance [-] Unhandled error: UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-22: ordinal not in range(128)
ERROR glance Traceback (most recent call last):
ERROR glance   File "/usr/local/bin/glance-manage", line 10, in <module>
ERROR glance     sys.exit(main())
ERROR glance   File "/opt/stack/glance/glance/cmd/manage.py", line 551, in main
ERROR glance     return CONF.command.action_fn()
ERROR glance   File "/opt/stack/glance/glance/cmd/manage.py", line 383, in sync
ERROR glance     self.command_object.sync(CONF.command.version)
ERROR glance   File "/opt/stack/glance/glance/cmd/manage.py", line 159, in sync
ERROR glance     print(_('Database is up to date. No migrations needed.'))
ERROR glance UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-22: ordinal not in range(128)
ERROR glance 


The redirection is the issue. In your case, I believe the way ooo/puppet calls "glance-manage db_sync" causes a similar issue. So, two things we could try:

1) Change the way "glance-manage db_sync" is called
2) Fix the issue in Glance (not sure how to do that)

Note that with Python 3, this bug just disappears, because Python 3 is just that much better than Python 2.

@Pranali: does the above make sense to you? Do you know how ooo/puppet calls Glance?


@Chen: I think the issue is not limited to Glance, though. You could try to remove glance.mo (that would avoid translating the Glance strings), and you'd probably get a failure later on. For instance, cinder-manage has the same kind of issue:

$ LANG=ja_JP.utf8 cinder-manage |less
Traceback (most recent call last):
  File "/usr/local/bin/cinder-manage", line 10, in <module>
    sys.exit(main())
  File "/opt/stack/cinder/cinder/cmd/manage.py", line 813, in main
    {'version': version.version_string()})
UnicodeEncodeError: 'ascii' codec can't encode characters in position 18-22: ordinal not in range(128)

This seems like a tricky issue. The short-term workaround is to work without this $LANG, but that's quite inconvenient :/

Comment 14 Cyril Roelandt 2019-05-14 18:36:06 UTC
Apparently it was fixed in puppet-openstacklib. I'm retargeting this bug.

Can we backport https://review.opendev.org/#/c/640997/ ?

Comment 16 Lon Hohberger 2023-07-10 19:37:47 UTC
OSP13 support officially ended on 27 June 2023


Note You need to log in before you can comment on or make changes to this bug.