We make use of functools.partial in OSC to allow us to pass additional
configuration to formatters. This incorrectly results in a warning being
raised for these formatters since they are of type 'partial', not
'type'.
DeprecationWarning: The usage of formatter functions is now
discouraged. Consider using cliff.columns.FormattableColumn instead.
See reviews linked with bug 1687955 for more detail.
Add a special handler for these since it's likely a somewhat
widespread pattern.
Change-Id: Icf8644d51e1f6fa9fc3a5896edd76db1c4ec38f0
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Present file sizes in human readable format.
Change-Id: I7e4a013cba7f91e38ba496d3ba7c4a67c4cd81c5
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This is a continuation of a previous change, change
Ib7db6a25f2352a013cb2ce603e60ca48b6cc70e6 ("formatters: Cast columns
before outputting"). As noted in that change, libraries can return
non-primitive types for many operations which can break YAML output
formatting since PyYAML only works with primitive types in safe mode.
That change was not complete as it only handled the formatters for dicts
and lists, not dicts of lists or lists of dicts. Close this gap now.
While we're here, we improve test coverage and catch a number of bugs
with the existing tests.
Change-Id: Ifd8db5b725f46a1ca216986167a0bcde5aec1e16
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This reverts commit 973e16960d.
Reason for revert: This patch is wrong, it actually breaks the generated autocomplete output.
Change-Id: I553b76da9ba32d04d6ec4fcac88217616b7fc3ac
Do not output log on bash autocomplete generation as it requires
manual sanitizing. For instance, when running `openstack complete`,
it appends the following two lines:
~~~
complete -F _openstack openstack
2022-05-10 12:50:25.052 863 INFO osc_lib.shell [-] END return value: 0
~~~
and in the current .spec file, we manually remove the `complete -F`
line but we still get that LOG.info output in train at least. This
behavior was not seen on master/wallaby.
Change-Id: Id99791831ffc145b10a0ec8c211a99f8a714fa0a
Previously, key interface was asserted to be 'public'
when testing reads from clouds.yaml. But to effectively
assert values from clouds.yaml, one has to use values
which differ from the defaults.
Change-Id: Ifc9a10e6ca02369c2f00b10d9b2b5412140dbeee
Commit c500b63703 assigned DEFAULT_INTERFACE as the default value of cli
parser's 'interface' key. But this resulted in the 'interface' key from
clouds.yaml aka OSC_Config always being ignored/overridden.
Instead this commit overrides the config default for 'interface' key with
DEFAULT_INTERFACE which can still be overridden with keys 'interface' or
'endpoint_type' in clouds.yaml or via the existing
--os-interface/OS_INTERFACE methods.
Ref.: c500b63703
Task: 38955
Story: 2007380
Change-Id: Ia4e511c9d47201cca175711e1c4cfa596168202f
With pytheon3.10 the naming of the "optional arguments" section has been
changed to "options"[0]. Adapt the reference texts accordingly.
[0] https://docs.python.org/3/whatsnew/3.10.html#argparse
Signed-off-by: Dr. Jens Harbott <harbott@osism.tech>
Change-Id: I4c572153b53ca381e2f100456bf77f6fe2892b5c
This change checks if the attribute sdk_connection exists
before attempting to close it. Without this change we're
seeing the following exception:
> Could not clean up: 'ClientManager' object has no attribute 'sdk_connection'
Related-Change: https://review.opendev.org/c/openstack/osc-lib/+/765650
Signed-off-by: Kevin Carter <kecarter@redhat.com>
Change-Id: Ib7e9958d5a64e6500bc38eed9d3e783d5a48d21f
Sub-classes of 'MultiKeyValueAction' may wish to reuse the key
validation aspects of the action (Do I have the required keys? Do I have
unknown keys?) wile overriding other aspects of the action. Make this
possible, reducing some duplication in the process.
Change-Id: I549d0897ef3704b7f47000f867d6731ad15d3f2b
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
SDK starts caching authorization state in keyring (when available and
enabled). Respecting it requires few minor changes: closing connection
and reusing auth_ref.
Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/735352
Change-Id: I7b7cff4887ec77e4c9d98809150d9064eedafaf6
Libraries like 'novaclient' return non-primitive types for many
operations. These are typically wrappers around primitive types, e.g.
'OrderedDict', but they all break YAML output formatting since PyYAML is
only compatible with primitive types when operating in safe mode.
The solution is rather simple: simply cast the values for these to their
expected format.
Change-Id: Ib7db6a25f2352a013cb2ce603e60ca48b6cc70e6
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Story: #2008320
Task: #41217
We've moved this functionality into cliff, so remove it here. This
will let us update cliff to optimize away the common case pkg_resources.
Change-Id: I75922010bdb29dbea530b6527c8b71eb064fdb30
Move get_osc_show_columns_for_sdk_resource function, which is currently
present in OSC (network and future image) here, to allow usage in separate
plugins.
Change-Id: Ib63cdb49caa639adb92d998053aae8a07da731cb
Since we're not testing or supporting Python 2 anymore, we can
convert six calls to Python 3 and get rid of it.
Change-Id: I474c01ab6ed60aecf16524935f2866e76a66569a
Somehow we lost the benefit of doing early authentication forcing
some of the project clients (particularly Identity) to do it again.
Saving the auth_ref in ClientManager is not enough, we need to stuff
it back into the Session too so it is also available to the non-SDK
clients.
Arguably this could be fixed in ClientManager.auth_ref itself but I
am not certain that is a desirable side-effect. This solution
addresses the immediate concern.
Change-Id: Ie7aca398bba6fba30ef1b432daaefcd7d8b780e0
Signed-off-by: Dean Troyer <dtroyer@gmail.com>
Set flake8-import-order version to 0.17.1
Full py3 compatible version.
Add all Python3 modules to stdlib list.
Change-Id: I787202eee18c99aaa659e0267235f4c413a389e9
Since mock is part of unittest std lib now, we can just use it and
remove the external dependency.
Change-Id: Id71c701b8053af5f8ab26c9f6fa66140e76aa8fc
The repo is Python 3 now, so update hacking to version 2.0 which
supports Python 3.
Blacklist:
W504 line break after binary operator
Fix:
E305 expected 2 blank lines after class or function definition, found 1
Change-Id: I713186061d5484ee2cd5317eb9192646fd3a1099
assertItemsEqual was removed from Python's unittest.TestCase in
Python 3.3 [1][2]. We have been able to use them since then, because
testtools required unittest2, which still included it. With testtools
removing Python 2.7 support [3][4], we will lose support for
assertItemsEqual, so we should switch to use assertCountEqual.
[1] - https://bugs.python.org/issue17866
[2] - https://hg.python.org/cpython/rev/d9921cb6e3cd
[3] - testing-cabal/testtools#286
[4] - testing-cabal/testtools#277
Change-Id: I631fb791ece68aac607aeae56ce96a0d472964c8
Some callers, such as python-openstackclient needing to deal with
consolidated neutron and nova-network documentation builds, need to be
able to decorate help texts in certain circumstances. This commit adds
an enhance_help kwarg to the tag-related option generators. The kwarg
accepts a callable, which by default is a no-op.
Change-Id: If700daf8a38b1c426bcfcb5ac37202e8aa0178e5
This is required to support things like the '--hint' option for
'openstack server create', which allows you to specify arguments
multiple times.
Change-Id: If73cab759fa09bddf1ff519923c5972c3b2052b1
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
We have some subtle cases to distinguish:
* value of None (the Python literal)
* value of '' (an empty string)
* value of 'None' (a string)
Return no representation of data when the value is the Python literal None
rather than the string 'None' which can be confused for an actual string value.
Returning an empty string ('') can be confused for an actual empty
string so that is also not an option. By leaving off the quotes we can accurately
reflect the distinct value of None.
Change-Id: Icdc1712e626a7e8a706348586a6be2e7612c4376
Signed-off-by: Dean Troyer <dtroyer@gmail.com>
All built-in inheritors of osc_lib.exceptions.ClientException expects
3 positional arguments: first argument is code, the second one is
message.
osc_lib.api.api.BaseAPI raises NotFound exception with transmitting only
message arguments which goes to position of 'code' argument.
This patch adds `code=404` argument and passes actual message as
'message'.
Also, this patch adds a hack that processes code as message
n case when code is not an integer and None was found at 'message'
argument.
Funny fact:
More than 4 years ago, I proposed a similar fix to oslo-incubator... it
was so long ago...
https://review.opendev.org/#/c/94884 :)
Change-Id: I022bbf3ce4bdd48b3bdcb008ee872c4f62a7b12b
When we get Forbidden error of finding resource, the osc just
return none, it causes the openstackclient to report an error
ambiguously.
The patch add an error message when we are not authorized to
find resource.
Task: 34754
Story: 2006052
Change-Id: I9d2b60e1408a71d432350f6486e03c5d4ae20cc3
First, we expect the 'auth' dict to never be empty, but it's actually
empty for the none auth type.
Second, we do not respect <service type>_endpoint_override, which are
very handy when used with the none auth type.
This change fixes both.
Change-Id: If05498095da88a85342e994bba9841a304c963a0