unable to get_one_cloud using argparse

Bug #1629331 reported by Matthew Edmonds
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack SDK
Fix Released
Undecided
Matthew Edmonds

Bug Description

Unable to use make_sdk because of bug 1629319, I tried to create an openstacksdk connection using openstack.connection.from_config, which relies on os_client_config.config.OpenStackConfig.get_one_cloud, but hit the following error:

>>> import argparse
>>> from openstack import connection
>>> sdk = connection.from_config(options=argparse.ArgumentParser())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/openstack/connection.py", line 107, in from_config
    cloud_config = occ.get_one_cloud(cloud=cloud_name, argparse=options)
  File "/usr/lib/python2.7/site-packages/os_client_config/config.py", line 1054, in get_one_cloud
    args = self._fix_args(kwargs, argparse=argparse)
  File "/usr/lib/python2.7/site-packages/os_client_config/config.py", line 811, in _fix_args
    new_args[key] = self._fix_args(args[key])
  File "/usr/lib/python2.7/site-packages/os_client_config/config.py", line 811, in _fix_args
    new_args[key] = self._fix_args(args[key])
  File "/usr/lib/python2.7/site-packages/os_client_config/config.py", line 814, in _fix_args
    key = key.replace('-', '_')
AttributeError: 'NoneType' object has no attribute 'replace'

os-client-config version 1.21.1
openstacksdk version 0.9.5
argparse version 1.2.1

Revision history for this message
Matthew Edmonds (edmondsw) wrote :

I think this may actually be an openstacksdk bug. I was able to get os_client_config.config.get_one_cloud working like this:

cloud_config = os_client_config.OpenStackConfig()
parser = argparse.ArgumentParser()
cloud_config.register_argparse_arguments(parser, sys.argv[1:])
options = parser.parse_args()
cloud = cloud_config.get_one_cloud(argparse=options)

whereas openstacksdk is just passing the ArgumentParser() instance without calling register_argparse_arguments or parse_args

Revision history for this message
Brian Curtin (brian.curtin) wrote :

If you have any input on a fix, please go ahead and try to submit one. I've never used this, am not familiar with it, and couldn't tell you when I'll be able to fix it in the lineup of other priorities I have to work through.

Also the initial failure you see in the report probably makes sense as you're just passing in an ArgumentParser instance, not a namespace that comes out of the parse_args return value.

Revision history for this message
Matthew Edmonds (edmondsw) wrote :

yeah, I'll try to throw something up later today.

no longer affects: os-client-config
Revision history for this message
Matthew Edmonds (edmondsw) wrote :
Changed in python-openstacksdk:
assignee: nobody → Matthew Edmonds (edmondsw)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-openstacksdk (master)

Reviewed: https://review.openstack.org/380484
Committed: https://git.openstack.org/cgit/openstack/python-openstacksdk/commit/?id=6f2209e2385d4292906576c3b04911acae87ad16
Submitter: Jenkins
Branch: master

commit 6f2209e2385d4292906576c3b04911acae87ad16
Author: Matthew Edmonds <email address hidden>
Date: Fri Sep 30 14:20:55 2016 -0400

    Clarify argparse connections

    The user guide shows that options passed to connection.from_config do
    not have to be an argparse Namespace, contrary to the comments in
    connection.from_config. This change corrects those comments and adds
    a user guide example showing how argparse may be used.

    Change-Id: I2a9e92cbf0aab16476001be772034e9698a24c9f
    Closes-Bug: #1629331

Changed in python-openstacksdk:
status: New → Fix Released
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.