placement unit test placement.tests.unit.cmd.test_manage.TestCommandParsers.test_commands_associated fails on CentOS 7

Bug #1804420 reported by Javier Peña
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
High
Lee Yarwood

Bug Description

Test placement.tests.unit.cmd.test_manage.TestCommandParsers.test_commands_associated fails to run using tox -epy27 on CentOS 7. However, it works fine on Fedora 28 (with a different Python 2 version).

I get the following:

placement.tests.unit.cmd.test_manage.TestCommandParsers.test_commands_associated
--------------------------------------------------------------------------------

Captured stdout:
~~~~~~~~~~~~~~~~
    usage: run db [-h] {sync,version} ...

    optional arguments:
      -h, --help show this help message and exit

    subcommands:
      database commands

      {sync,version}
        sync Sync the datatabse to the current version.
        version Report the current database version.

Captured traceback:
~~~~~~~~~~~~~~~~~~~
    Traceback (most recent call last):
      File "placement/tests/unit/cmd/test_manage.py", line 55, in test_commands_associated
        mock_command.assert_called_once_with()
      File "/placement/.tox/py27/lib/python2.7/site-packages/mock/mock.py", line 947, in assert_called_once_with
        raise AssertionError(msg)
    AssertionError: Expected 'db_version' to be called once. Called 0 times.

This started to fail since https://review.openstack.org/600161 was merged.

tags: added: placement testing
Revision history for this message
Lee Yarwood (lyarwood) wrote :

I've attached a simple script to reproduce this behaviour outside of placement.

I'm struggling to find where but AFAICT the oslo.config code parsing the command line args is failing and defaulting to the default help func for the top level command parser.

# cat /etc/redhat-release
Fedora release 28 (Twenty Eight)
# python --version
Python 2.7.15
# pip freeze | grep oslo.config
oslo.config==6.7.0
# python reproduce.py cmd bar
<bound method Commands.bar of <__main__.Commands object at 0x7f50d187c110>>

# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
# python --version
Python 2.7.5
# pip freeze | grep oslo.config
oslo.config==6.7.0
# python reproduce.py cmd bar
<bound method _CachedArgumentParser.print_help of _CachedArgumentParser(prog='reproduce cmd', usage=None, description=None, version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)>

Revision history for this message
Chris Dent (cdent) wrote :

Is it possible that the 2.7.5 Python on CentOS has an older argparse module and that installing the one from PyPI clears the issue? If it does that ought to lend a clue.

Revision history for this message
Lee Yarwood (lyarwood) wrote :

https://github.com/python/cpython/commit/af26c15110b76195e62a06d17e39176d42c0511c

This argparse change appears to be the culprit here, without this the default `func` attribute set on the subparsers are ignored and the parents print_help `func` is used.

Lee Yarwood (lyarwood)
no longer affects: oslo.config
Revision history for this message
Chris Dent (cdent) wrote :
Changed in nova:
status: New → Triaged
status: Triaged → In Progress
assignee: nobody → Lee Yarwood (lyarwood)
Chris Dent (cdent)
Changed in nova:
status: In Progress → Fix Committed
Lee Yarwood (lyarwood)
Changed in nova:
importance: Undecided → High
Lee Yarwood (lyarwood)
Changed in nova:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.