From ce7b05a1f9fd89e29567249b5dac340e0fe23654 Mon Sep 17 00:00:00 2001 From: Lee Yarwood Date: Thu, 22 Nov 2018 13:41:00 +0000 Subject: [PATCH] manage: Do not use set_defaults on parent parsers with py2 Doing so with cpython < 2.7.9 results in the following bug being hit: argparse set_defaults on subcommands should override top level set_defaults https://bugs.python.org/issue9351 As CentOS 7 continues to ship with cpython 2.7.5 this change simply removes the parent parser call to set_defaults for py2 while leaving the associated tests unchanged. This should ensure that the actual behaviour of placement-manage is unchanged while allowing these tests to pass once again on CentOS. Change-Id: I87989ced31b1d39e30c992b34fe2ae6db06f7883 Closes-Bug: #1804420 --- placement/cmd/manage.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/placement/cmd/manage.py b/placement/cmd/manage.py index dea2b8086..48dc924d2 100644 --- a/placement/cmd/manage.py +++ b/placement/cmd/manage.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. +import six import sys from oslo_config import cfg @@ -43,7 +44,9 @@ def add_db_command_parsers(subparsers): # help text. subparsers.required = False parser = subparsers.add_parser('db') - parser.set_defaults(func=parser.print_help) + # Avoid https://bugs.python.org/issue9351 with cpython < 2.7.9 + if not six.PY2: + parser.set_defaults(func=parser.print_help) db_parser = parser.add_subparsers(description='database commands') help = _('Sync the datatabse to the current version.')