483 Commits

Author SHA1 Message Date
Pavel Abalikhin
95f68cd673 Add timeout for Swift service
Connection class has timeout parameter but SwiftService and shell don't use it.
That can lead to an endless wait when network is unreachable.

Change-Id: Iafa42fc2f8b56feefa2bc8ea6a1b8845717d3bab
2022-04-21 18:00:27 +03:00
Stephen Finucane
20d837a276 Remove unnecessary unicode prefixes
All strings are unicode by default in Python 3. No need to mark them as
such.

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Change-Id: I68fb60ef271abfddebcc9d2137424f5db2a17e92
2022-03-21 18:32:30 +00:00
Stephen Finucane
61ce5ac824 Remove unnecessary object subclassing
All classes subclass from object by default in Python 3.

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Change-Id: I5a1ad57bcc092861ce969759b06a07c880ad3d35
2022-03-21 18:32:00 +00:00
Stephen Finucane
fa137a5bf1 Remove six
This mostly affects tests. Nothing too complicated

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Change-Id: Iabc78f651e1d48db35638280722f8019798eccd6
2022-03-21 18:31:10 +00:00
Stephen Finucane
4983b90983 Remove coding comments
Everything is unicode in Python 3.

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Change-Id: I6a076dc67c461f265ed99878e3959e1992a88189
2022-03-21 18:29:25 +00:00
Stephen Finucane
3d10744c55 Remove __future__ imports
These aren't needed in modern Python 3 versions.

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Change-Id: I5e81d6fb2e2cb8e4bfae4ed746da002f44e871c4
2022-03-21 18:29:25 +00:00
Aarni Koskela
c09621eb42 Don't patch Requests globally on import
This also upgrades the Requests dependency to 2.4+ (released in 2014)
to avoid having to do version comparisons altogether.

Refs https://bugs.launchpad.net/python-swiftclient/+bug/1904551

Signed-off-by: Aarni Koskela <akx@iki.fi>
Change-Id: I58399f6c526b0b78462f31739c43076314ba9e76
2022-03-21 08:05:54 -07:00
Stephen Finucane
2636965f38 Drop support for Python 2
There's a lot of cleanup possible, but this is a start.

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Change-Id: Ia1176b7fd5434d52070d482a37abfbb98800cdb3
2022-03-16 15:06:19 -07:00
Zuul
3f5d5b0252 Merge "Include storage policy when listing account with --long" 2021-10-13 01:11:03 +00:00
Tim Burke
373fa26ce1 Correctly aggregate totals for >10k items
Previously, we would write out totals for every page of listings, like

    $ swift list sync --prefix=09-21 --total -l
     80000000000
     80000000000
     80000000000
     58096000000

Now, roll those all into a single total:

    $ swift list sync --prefix=09-21 --total -l
    298096000000

Change-Id: Icc265636815220e33e8c9eec0a3ab80e9f899038
2021-09-21 16:06:56 -07:00
Tim Burke
ad3e8e49d0 Include storage policy when listing account with --long
Change-Id: Ibc2f9445b5a8e80cfb73d0706e20a7e4c62eec4a
2021-09-21 08:40:45 -07:00
Tim Burke
5129b33505 Only log the traceback for non-404s
Change-Id: I08ba4a3120e99b444b13f1ca6f5493529868df26
2021-09-20 15:49:59 -07:00
Tim Burke
553e34ebfe Improve formatting for billions of objects
Change-Id: If8aa08c4c8c8ad6ca2c861602baf1eefa8642a8a
2021-09-20 15:49:59 -07:00
jonasdlindner
58f0700ad9 Fix Typo in shell.py
Change-Id: I2615e0d6b54d8cc020c24d1b5b4064e038f0934b
2021-04-29 17:39:28 +02:00
Tim Burke
74c50dee2d Have delete --all imply --versions for the CLI
Change-Id: Id5a6d4cef3d4ed76c897a099a62a4ba3ed8f8dab
2020-10-16 13:57:02 -07:00
Zuul
bf862981a6 Merge "Close connections created when calling module-level functions" 2020-10-15 22:41:10 +00:00
Tim Burke
97aa3e6541 Close connections created when calling module-level functions
Co-Authored-By: Clay Gerrard <clay.gerrard@gmail.com>
Change-Id: Id62e63afc6f2ffa32eb8640787c78559481050f9
Related-Change: I200ad0cdc8b7999c3f5521b9a822122bd18714bf
Related-Bug: #1873435
Closes-Bug: #1838775
2020-10-13 10:45:07 -07:00
Zuul
d63ec1b38d Merge "Include transaction ID in ClientException.__str__" 2020-09-22 01:56:50 +00:00
Tim Burke
0f6713ed5b Include transaction ID in ClientException.__str__
It's fairly annoying getting a traceback in swift's probe tests then
only having a URL and status code to go searching for in logs.

Leave the shell.py output untouched, though, since we output the
transaction ID on a new line anyway.

Change-Id: Idb849848ec08b6c04812b088467c9a687c2a7e27
2020-09-09 15:32:43 -07:00
Tim Burke
0c70d164ba (Mostly) revert "Cleanup session on delete"
This reverts commit 1f26c5736949e1c3b57c024a315e33fc419f126e for py2.
Apparently the existence of the __del__ method on Python 2 prevents us
from cleaning up all file descriptors.

Change-Id: Id6cff5dd7b9faf9c4240c0cb26b74d05ed37da5b
Closes-Bug: #1873435
Related-Bug: #1838775
2020-09-08 15:04:54 -07:00
Meuh
842086d27f Add max_backoff and starting_backoff for get_conn in swift service
Change-Id: I45f5d3009e0e2015c7366384ee826113fc27c70b
2020-07-28 20:03:11 +02:00
Tim Burke
22d1f3a39a Clean up some warnings
Change-Id: Iae149533d04c7b173c4ef88fb775f5fe13c16466
2020-06-17 21:05:25 -07:00
Tim Burke
257a7185a8 Application credential support follow-up
Following the recent v3applicationcredentials patch, if you have your
environment variables set up to work with python-openstackclient using
swiftclient's v1password plugin, swiftclient won't work:

   $ env | egrep '^(OS|ST)_'
   ST_KEY=testing
   ST_USER=test:tester
   OS_AUTH_URL=http://saio/auth/v1.0
   ST_AUTH=http://saio/auth/v1.0
   OS_USERNAME=test:tester
   OS_AUTH_TYPE=v1password
   OS_PASSWORD=testing

   $ openstack object store account show
   +------------+----------------------------+
   | Field      | Value                      |
   +------------+----------------------------+
   | Account    | AUTH_test                  |
   | Bytes      | 0                          |
   | Containers | 11                         |
   | Objects    | 0                          |
   +------------+----------------------------+

   $ swift stat
   Only "v3applicationcredential" is supported for --os-auth-type

We don't really want to allow (and mostly ignore) arbitrary OS_AUTH_TYPE
values, though -- there are a whole bunch of plugins we don't remotely
support. But it seems OK to allow any of the password plugins; while we
won't actually use them (currently), we provide roughly equivalent
functionality.

Handful of other drive-bys:
 * Use a None sentinel to determine whether keystoneauth1 is installed
   instead of trying to catch a NameError.
 * Clarify error state when keystoneauth1 is not installed.
 * Fix a typo: "sses" -> "sess".

Change-Id: Id7ea9c3ea8278ae86a04d057a472a8f8a87b8eae
Related-Change: I9190e5e7e24b6a741970fa0d0ac792deccf73d25
2020-05-27 15:17:09 -07:00
Zuul
5840efe1d6 Merge "Support v3 application credentials auth." 2020-05-13 08:36:17 +00:00
Ivan Kolodyazhny
947c09f30c Fixed capability discovery endpoint hardcode
It fixes get_capabilities() method to process
correctly endpoints like: 'https://<ip>:<port>/v1',
'https://<ip>:<port>/swift/v1'.

Co-Authored-By: Daniel Cech <dcech@mirantis.com>
Change-Id: Ib4037d0b49da1bce959947100629370805f510d5
Closes-bug: #1712358
2020-04-24 12:50:58 +03:00
Charles Hsu
02b637cdca Support v3 application credentials auth.
Use keystoneauth1 application credential plugin and session to fetch
a token and endpoint catalog url.

$ swift --os-auth-url http://172.16.1.2:5000/v3 --auth-version 3\
      --os-application-credential-id THE_ID \
      --os-application-credential-secret THE_SECRET \
      --os-auth-type v3applicationcredential auth

Change-Id: I9190e5e7e24b6a741970fa0d0ac792deccf73d25
Closes-Bug: 1843901
Closes-Bug: 1856635
2020-04-16 12:41:04 +08:00
Tim Burke
9b0da49c0b Improve list --versions output
Have `--versions` imply `--long` and add a new column for version_id.

Also, have version-aware listings show all versions as "null" on old
Swifts that don't support object versioning (or when object versioning
is not enabled).

Change-Id: I0e009bce2471d1c140ac9b83700591cb355fee3f
2020-04-10 17:16:15 -07:00
Clay Gerrard
78edffa46c object versioning features
* add --versions to list
 * add --versions to delete
 * add --version-id to stat
 * add --version-id to delete
 * add --version-id to download

Change-Id: I89802064921778fee7efe57c7d60c976cdde3a27
2020-04-08 13:07:26 -07:00
Zuul
80cdada0c2 Merge "Add test for bulk-delete-attempt-counter fix" 2020-01-16 00:58:12 +00:00
Zuul
90e71f5506 Merge "Cleanup session on delete" 2019-12-09 23:39:57 +00:00
Alex Schultz
1f26c57369 Cleanup session on delete
If an external http connection was not passed into the client, we
create one with a requests.Session() on our own. Once this is used,
it may still have an open socket when the connection is closed. We need
to handle the closing of the requests.Session() ourselves if we created
one. If you do not close it, a ResourceWarning may be reported about the
socket that is left open.

Change-Id: I200ad0cdc8b7999c3f5521b9a822122bd18714bf
Closes-Bug: #1838775
2019-12-08 20:11:17 -06:00
Tim Burke
e83cd32e2a Add test for bulk-delete-attempt-counter fix
Change-Id: Ifdeefeb4a5a3fc6895bd6cda695684de02f8c602
Related-Change: If4af9141fe4f3436a4e9e0e2dfc24c6ec7292996
Related-Bug: #1852808
2019-11-15 22:08:51 +00:00
Sébastien Blaisot
709ab385c6 Fix printed object names on successful bulk-delete
Replace the 1 always concatenated to printed object names for each
successfully deleted object in bulk-delete with an optional [after x
attempts] if x > 1

Change-Id: If4af9141fe4f3436a4e9e0e2dfc24c6ec7292996
Closes-Bug: 1852808
2019-11-15 22:37:38 +01:00
Tim Burke
c4bef14fc1 v1auth: support endpoint_data_for() api
...so we can be used with openstacksdk.

Also, add a few functests that use openstacksdk.

Change-Id: Ie6987f5de48914ec8932254cde79a973a0264877
2019-11-06 08:47:24 +00:00
Tim Burke
a0f0aedb41 docs: Fix warning treated as error
Change-Id: I669533334419e94ca925e859f2b0d5d2afe9f7f1
2019-09-04 11:21:04 -07:00
Zuul
4f320bd034 Merge "Fix up requests so we can send non-RFC-compliant headers on py3" 2019-08-02 07:55:23 +00:00
Tim Burke
7875398746 Delete/overwrite symlinks better
Previously, when deleting a symlink that points to an xLO, we'd clean
up the xLO's segments then delete the symlink, leaving the xLO itself
busted.

Similar trouble would come from overwriting a symlink pointing to an
xLO. Check for a Content-Location in the HEAD response and leave such
segments.

Co-Authored-By: Clay Gerrard <clay.gerrard@gmail.com>
Change-Id: I45b210cf380a68bd88187c91fa2d63a8b2bb709b
2019-08-01 20:42:31 -07:00
Tim Burke
7175069b3e Fix up requests so we can send non-RFC-compliant headers on py3
Change-Id: I3dac826c1f208569c5f40431f59a2045e5744415
2019-07-25 14:21:43 -07:00
Zuul
2fcd4d8727 Merge "Optionally display listings in raw json" 2019-07-10 18:54:30 +00:00
Zuul
7cf8541b38 Merge "Add missing <sync-to> value in command line docs" 2019-07-09 22:57:56 +00:00
Clay Gerrard
936631eac6 Optionally display listings in raw json
Symlinks have recently added some new keys to container listings.  It's
very convenient to be able to see and reason about the extra information
in container listings.

Allowing raw json output is similar with what the client already does
for the info command, and it's forward compatible with any listing
enhancements added by future middleware development.

Change-Id: I88fb38529342ac4e4198aeccd2f10c69c7396704
2019-07-09 13:25:52 -07:00
Zuul
4b3e33b3c2 Merge "Clean up warnings from newer flake8" 2019-06-28 08:13:46 +00:00
Tim Burke
9021a58c24 Fix SLO re-upload
Previously, if you uploaded a file as an SLO then re-uploaded it
with the same segment size and mtime, the second upload would
go delete the segments it just (re)uploaded. This was due to
us tracking old_slo_manifest_paths and new_slo_manifest_paths
in different formats; one would have a leading slash while the
other would not.

Now, normalize to the stripped-slash version so we stop deleting
segments we just uploaded.

Change-Id: Ibcbed3df4febe81cdf13855656e2daaca8d521b4
2019-06-27 21:45:10 -07:00
Tim Burke
3b21157a84 Clean up warnings from newer flake8
Change-Id: I18a6327b3acdd4db5ae80097080c043f7c20c353
2019-06-27 21:43:46 -07:00
Tim Burke
113eacf3b8 Isolate docs requirements
...since modern sphinx won't install on py27.

While we're at it, clean up some warnings and treat warnings as errors.

Also, fix up how we parse test configs so we can run func tests.

Related-Change: Id3c2ed87230c5918c18e2c01d086df8157f036b1
Change-Id: I3718f69610545b0dbcb0a2ab45b400da3a45682c
2019-06-27 16:48:33 -07:00
Tim Burke
0ee7c8272e Make proper functions instead of assigning lambdas
Change-Id: I89255f6923c649c7b9d3d36e96c09f8bc4f51a3c
2019-02-21 09:26:32 -08:00
ZhijunWei
2ff36fde57 Update hacking version
1. update hacking version to latest
2. fix pep8 failed

Change-Id: Ifc3bfeff4038c93d8c8cf2c9d7814c3003e73504
2019-01-03 13:09:22 +08:00
Timur Alperovich
edfeae3723 Add delimiter to get_account().
Exposes the delimiter parameter, which the Swift API supports for
container listings.

Change-Id: Id8dfce01a9b64de9d1222aab9a4a682ce9e0f2b7
2018-11-30 22:58:36 +00:00
Tim Burke
411ef48e5b Stop leaking quite so many connections
While investigating the failures when you move func tests to py3, I
noticed a whole bunch of

   ResourceWarning: unclosed <socket.socket ...>

noise. This should fix it.

While we're at it, make get_capabilities less stupid.

Change-Id: I3913e9334090b04a78143e0b70f621aad30fc642
Related-Change: I86d24104033b490a35178fc504d88c1e4a566628
2018-11-09 09:55:30 -08:00
Tim Burke
d1e1f8d8d6 Stop lazy importing keystoneclient
There were two basic problems:

  - We'd try to import on every attempt at getting auth, even when we
    already know keystoneclient isn't available.
  - Sometimes devs would hit some crazy import race involving (some
    combination of?) greenthreads and OS threads.

So let's just try the imports *once*, at import time, and have None
sentinels if it fails. Try both versions separately to decouple
failures; this should let us support a wider range of keystoneclient
versions.

Change-Id: I2367310aac74f1b7c5ea0cb1a822a491e4ba8e68
2018-09-07 16:56:13 -07:00