Commit Graph

215 Commits

Author SHA1 Message Date
Stephen Finucane ab7cdb4c25 Blacken code
Another library down.

Change-Id: Id29f29331ba994a1f09376763702fcca82ec6f1c
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-11-15 10:05:52 +00:00
Zuul 9d02ad3460 Merge "Fix pre-commit issues" 2023-11-13 18:29:46 +00:00
Stephen Finucane 147c01e734 Fix pre-commit issues
Change-Id: Ie973475b714e01b0619acd5554a88f7da9014edc
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-08-30 19:29:30 +01:00
Stephen Finucane 9af8b45dd6 utils: Don't warn for partial formatter classes
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>
2023-08-30 19:18:29 +01:00
suheoon d889faa0cd Fix comment of auth_config_hook
Change-Id: I86ded6871026f32e395e9fa15bf55e0367e7ced6
2023-08-19 17:48:05 +09:00
Zuul 2f5167f475 Merge "Revert "Do not output log on bash autocomplete generation"" 2023-07-29 18:35:15 +00:00
Stephen Finucane 6152b686b7 Add 'SizeColumn' formatter
Present file sizes in human readable format.

Change-Id: I7e4a013cba7f91e38ba496d3ba7c4a67c4cd81c5
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-03-29 12:38:02 +01:00
Stephen Finucane 1deaaecc09 formatters: Cast *all* columns before outputting
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>
2022-12-20 11:18:29 +00:00
Dr. Jens Harbott 1a6c1c2a26 Revert "Do not output log on bash autocomplete generation"
This reverts commit 973e16960d.

Reason for revert: This patch is wrong, it actually breaks the generated autocomplete output.

Change-Id: I553b76da9ba32d04d6ec4fcac88217616b7fc3ac
2022-10-10 19:26:50 +00:00
David Hill 973e16960d Do not output log on bash autocomplete generation
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
2022-05-10 12:52:15 -04:00
Zuul 0d088d62a0 Merge "Fixed test for interface key" 2022-03-07 15:18:21 +00:00
Zuul a8fde07fe4 Merge "Fix TestTagHelps for python3.10" 2022-02-21 12:20:34 +00:00
Zuul ce936a2f72 Merge "Respect 'interface' key from clouds.yaml" 2022-02-21 12:20:26 +00:00
Jakob Meng 333c681a4c Fixed test for interface key
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
2022-02-21 10:55:31 +00:00
Zuul 78d276e722 Merge "parseractions: Make key validation reusable" 2022-02-11 18:28:22 +00:00
Jakob Meng 4b593699bc Respect 'interface' key from clouds.yaml
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
2022-02-11 09:38:55 +00:00
Artem Goncharov 650795af70 Replace allow_get check with allow_fetch
We got rid of all allow_get checks in the code and now can let SDK drop
the attribute

Change-Id: I61750cc491cf769b1daf42af2eca6b6199fa2b5d
2022-01-17 15:19:38 +01:00
Dr. Jens Harbott d538d6ed68 Fix TestTagHelps for python3.10
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
2021-12-22 21:18:08 +01:00
yatinkarel 97c578bcad Close session at clean_up if available
To avoid unclosed socket[1] left overs, explicitly
close session at clean_up if available.

[1] sys:1: ResourceWarning: unclosed <socket.socket fd=4>

Story: 2009015
Task: 42735
Related-Bug: #1934098
Change-Id: Idf4865686c37f6f9f61d1f3333b976cc687de9e1
2021-06-30 14:36:38 +05:30
Kevin Carter dd75c8fdbf Add check for sdk_connection
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
2021-05-19 13:24:55 -05:00
Stephen Finucane 86a42cc7ec parseractions: Make key validation reusable
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>
2021-03-05 12:37:54 +00:00
Artem Goncharov 25011a09df Add support for SDK auth caching
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
2020-12-05 15:36:48 +01:00
sunyandi 239b001a14 Replace 'assertFalse(a in b)' with 'assertNotIn(a, b)'
Trivial fix.

Change-Id: Id034f3ddb9be5f1a05e99b5d36b3381edda58ddb
2020-11-06 10:26:20 +00:00
Stephen Finucane 4bb55ce75d formatters: Cast columns before outputting
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
2020-11-04 15:30:09 +00:00
Zuul d55bc8676a Merge "Fix the misspelling of "argument"" 2020-06-12 17:00:32 +00:00
Zuul dd6cafdf99 Merge "Revert "Add error message when occurrence Forbidden error"" 2020-06-12 15:53:05 +00:00
Zuul 5b65b5f000 Merge "Remove commandmanager subclass" 2020-06-12 14:58:08 +00:00
lijunjie 03feaaa205 Fix the misspelling of "argument"
Change-Id: I8d3713aafe2f567c07e975574bb95e84b4ca09fb
2020-06-12 14:28:32 +00:00
Monty Taylor b6d1d539c8 Remove commandmanager subclass
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
2020-06-10 19:10:20 -05:00
Artem Goncharov 29a0c5a570 Add get_osc_show_columns_for_sdk_resource function
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
2020-06-03 15:31:38 +02:00
Zuul e4f103ec6e Merge "Save the results from the early authentication" 2020-05-25 14:42:39 +00:00
Riccardo Pittau a55d153635 Remove six library from dependencies
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
2020-05-07 11:11:09 +02:00
Dean Troyer f0749f8fb7 Save the results from the early authentication
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>
2020-05-06 19:24:37 +00:00
Riccardo Pittau 20b922357e Add pep8 import order check
Set flake8-import-order version to 0.17.1
Full py3 compatible version.
Add all Python3 modules to stdlib list.

Change-Id: I787202eee18c99aaa659e0267235f4c413a389e9
2020-05-01 23:11:56 +02:00
Riccardo Pittau 2d98486d06 Use mock from unittest
Since mock is part of unittest std lib now, we can just use it and
remove the external dependency.

Change-Id: Id71c701b8053af5f8ab26c9f6fa66140e76aa8fc
2020-05-01 20:28:01 +02:00
Andreas Jaeger 592d80ac1c Update hacking for Python3
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
2020-03-28 08:08:20 +01:00
Feilong Wang 1ff3720dae Revert "Add error message when occurrence Forbidden error"
This reverts commit 3c0559def3.

This patch is breaking the Glance image share function.

Change-Id: Ic380b4fdeb334b70be39fcf07670902c0bc89dd9
2020-03-18 08:58:37 +00:00
Alfredo Moralejo 32742e784a Replace assertItemsEqual with assertCountEqual
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
2020-03-13 14:55:29 +00:00
Eric Fried 7d3b801911 Add enhance_help kwarg to tags option generators
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
2019-11-15 14:15:39 -06:00
Stephen Finucane 1420035836 Add KeyValueAppendAction to osc-lib
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>
2019-09-27 15:11:18 +01:00
Dean Troyer a0d9746eb5 format_dict() returns no value for None
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>
2019-09-02 09:45:03 -05:00
Monty Taylor 6db6492a7d Handle nested dicts in format_dict()
Some dicts have dicts in them. Handle them.

Story: 2006480
Task: 36423
Change-Id: Id57fc34c676059d8b13a490bfb74d1ee1ff52891
2019-08-31 00:02:47 -05:00
Zuul 17179a72b0 Merge "Cleanups to prepare for OSC 4 release" 2019-08-23 16:04:13 +00:00
Zuul 9b863b6f60 Merge "Fix usage of NotFound exception" 2019-08-22 20:57:23 +00:00
Dean Troyer fccfee11ef Cleanups to prepare for OSC 4 release
* Copy OSC_Config.load_auth_plugin() from OSC
* Remove OSC_Config._validate_auth_ksc() - completely unused

Change-Id: I5caf021ad1ab498b6f7c50e05b3103243405baca
Signed-off-by: Dean Troyer <dtroyer@gmail.com>
2019-08-22 14:16:18 -05:00
Andrey Kurilin 2d4f3da090 Fix usage of NotFound exception
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
2019-08-08 14:42:23 +00:00
yanpuqing 3c0559def3 Add error message when occurrence Forbidden error
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
2019-07-30 11:09:09 +08:00
Zuul bf125b8175 Merge "Corrent using auth_type=none in clouds.yaml" 2019-06-14 02:44:46 +00:00
Zuul 8315e5015c Merge "Move the _tag module from OSC to osc-lib" 2019-06-14 02:38:14 +00:00
Dmitry Tantsur d2a97c14a6 Corrent using auth_type=none in clouds.yaml
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
2019-06-12 11:17:34 +02:00