141 Commits

Author SHA1 Message Date
Tim Burke
9b8ab67a78 Include response headers in ClientExceptions
Now, client applications can get to things like transaction IDs for
failures without needing to turn on all of logging.

While we're at it, add a from_response factory method for
ClientException.

Co-Authored-By: Alexander Corwin <ancorwin@gmail.com>
Change-Id: Ib46d5f8fc7f36f651f5908bb9d900316fdaebce3
2016-03-03 17:16:33 +00:00
Jenkins
cd3a4dbf0a Merge "Drop testtools from test-requirements.txt" 2016-03-01 17:51:32 +00:00
Jenkins
f95c03cc40 Merge "Display proper name when failing to create segments container" 2016-02-17 17:16:42 +00:00
Tim Burke
bed6bbd5ef Drop testtools from test-requirements.txt
My understanding is that it was mainly being used so we could have sane
testing on py26.  With py26 support being dropped, we no longer need it.

Also drop discover from test-requirements.txt, as we don't seem to
actually use it.

Change-Id: Iee04c42890596d3b483c1473169480a3ae19aac8
Related-Change: I37116731db11449d0c374a6a83a3a43789a19d5f
2016-02-12 09:57:58 -08:00
Jenkins
a6f171437d Merge "Add test for --debug taking precedence over --info" 2016-02-11 20:22:24 +00:00
Jenkins
2b391d47f0 Merge "Fix debug and info option parsing" 2016-02-11 20:22:09 +00:00
Alistair Coles
28558c7e0a Add test for --debug taking precedence over --info
Change-Id: Ibf0903817852edb36389028383a35e0d65f88a26
2016-02-11 15:02:09 +00:00
Jenkins
d4090d555d Merge "Support --os-identity-api-version option" 2016-02-11 05:28:17 +00:00
Tim Burke
30ca247426 Display proper name when failing to create segments container
Previously, we displayed the base container's name.

Change-Id: I70f1949a44ba61158e31178e4536f229c37aab47
2016-02-10 13:25:38 -08:00
Jenkins
50f3396620 Merge "Fix segmented upload to pseudo-dir via <container>" 2016-02-10 19:55:30 +00:00
Alistair Coles
d6ef83021e Support --os-identity-api-version option
Add support for the auth-version to be specified using
--os-identity-api-version or OS_IDENTITY_API_VERSION
for compatibility with other openstack client command
line options.

The auth version used will be selected as follows:

- if either --auth-version or --os-identity-api-version
  is set, use that value
- otherwise use the value of ST_AUTH_VERSION, if set
- otherwise use the value of OS_AUTH_VERSION, if set
- otherwise (new behaviour) use the value of
  OS_IDENTITY_API_VERSION, if set
- otherwise default to 1.0

Note that before this change the auth version might have
defaulted to 1.0 despite OS_IDENTITY_API_VERSION being set,
but with this change OS_IDENTITY_API_VERSION is preferred.

Change-Id: Ifba4c4e43560ede3013337b8cdbc77dc2de6e8ff
Closes-Bug: #1541273
2016-02-05 11:13:08 +00:00
Jenkins
d2ee01bfe4 Merge "Fix intermittent fail of test_delete_bulk_account" 2016-02-04 02:48:11 +00:00
James Nzomo
5ed02345d3 Fix segmented upload to pseudo-dir via <container>
This fix ensures creation and use of the correct default segment
container when pseudo-folder paths are passed via <container> arg.

Change-Id: I90356b041dc9dfbd55eb341271975621759476b9
Closes-Bug: 1532981
Related-Bug: 1478210
2016-02-04 05:02:17 +03:00
Jenkins
da27ad11cc Merge "Fix intermittent fail of test_delete_account" 2016-02-01 19:19:46 +00:00
Alistair Coles
14a0447491 Fix intermittent fail of test_delete_account
The test asserts calls made in specific order,
but they are made from threads so may be in
different order.

Change-Id: I1b6e7303fe0e6fb2afc7da3462b891feab90bc17
Closes-Bug: #1539536
2016-02-01 10:09:30 +00:00
Alistair Coles
fa9251a1ee Fix intermittent fail of test_delete_bulk_account
The test asserts calls made in specific order,
but they are made from threads so may be in
different order.

Change-Id: I857ad3b909c3b635927fb1a39682d66d20c6fd59
2016-02-01 10:07:55 +00:00
Jenkins
6f431ee065 Merge "Prevent test runs from cluttering current directory" 2016-01-29 12:26:13 +00:00
Jenkins
e65e01014e Merge "Convert http response(byte string) to string in python3." 2016-01-22 13:16:44 +00:00
Tim Burke
38f9664167 Prevent test runs from cluttering current directory
Previously, the following empty directories would be created:
  * container
  * container/pseudo
  * pseudo

Change-Id: I002e2da8d28a873728e0b5c2d33f94f21132d058
2016-01-19 14:26:13 -08:00
Tim Burke
7a1e192803 Use bulk-delete middleware when available
When issuing `delete` commands that would require three or more
individual deletes, check whether the cluster supports bulk deletes
and use that if it's available.

Additionally, a new option is added to the `delete` command:

  * --prefix <prefix>

    Delete all objects that start with <prefix>. This is similar to the
    --prefix option for the `list` command.

Example:

$ swift delete c --prefix obj_prefix/

    ...will delete from container "c" all objects whose name begins with
    "obj_prefix/", such as "obj_prefix/foo" and "obj_prefix/bar".

Change-Id: I6b9504848d6ef562cf4f570bbcd17db4e3da8264
2016-01-12 15:40:57 -08:00
James Nzomo
2c6f367035 Fix upload to pseudo-dir passed by <container> arg
This fix makes it possible to upload objects to pseudo-folders by
passing the upload paths via <container> arg regardless of whether the
container or folder path exist or not.

Change-Id: I575e58aa12adcf71cdaa70d025a0ea5c63f46903
Closes-Bug: #1478210
Partial-Bug: #1432734
Related-Bug: #1432734
2016-01-04 22:48:07 +03:00
Christian Schwede
109e8f519f Fix debug and info option parsing
The debug and info options need to be set before a subcommand method is called,
otherwise they are simply ignored. This is kind of irritating - other options
(for example -U, -A, -K) are usable after a positional command.

This patch fixes this, and commands like these are no longer ignoring --debug or --info:

 swift stat --debug
 swift list container --info

Co-Authored-By: Alistair Coles <alistair.coles@hpe.com>

Change-Id: Ib19b05deef7a015881f1eed4a3946025e16bf922
2015-12-30 14:22:01 -08:00
Tim Burke
2345ae54f1 Stop passing attr to keystoneclient when there's no filter_value
It was dropping warnings like "UserWarning: Providing attr without
filter_value to get_urls() is deprecated as of the 1.7.0 release and may
be removed in the 2.0.0 release. Either both should be provided or
neither should be provided."

Change-Id: Iead0bcf36b4a46bf465a55a33a21fd7f14f0ac40
2015-12-07 10:42:15 -08:00
Peter Lisák
3e1a457db0 Add content-type in list of container content
Change-Id: Ie0787d5ffbee0a7d2429cb285fa6ecdf722e4ae1
2015-11-11 12:21:40 +01:00
Tim Burke
9fed7ed5e1 Miscellaneous (mostly test) cleanup
* Always use testtools.TestCase, since we're relying on testtools
 * Always use mock (as opposed to unittest.mock) since we're relying on
   mock
 * Add note about when a missing logging handler was added
 * Stop %-formatting the giant usage string that doesn't actually need
   any formatting
 * Prefer assertIs, assertIn, assertIsInstance over assertTrue
 * Use else-self.fail instead of sentinel values
 * Check resp.get('error') is None before checking resp['success'] is
   True, so test failures actually tell you something useful
 * Tighten some isinstance assertions
 * Import MockHttpTest from correct location
 * Only populate clean_os_environ once
 * Use setUp for setup, not __init__
 * Replace assertIn(key, dict) and assertEqual(foo, dict[key]) with
   assertEqual(foo, dict.get(key)) when key is a literal and foo is not
   None
 * Use mock.patch.object instead of manually patching for tests
 * Use six.binary_type instead of type(''.encode('utf-8'))
 * Stop shadowing builtin bytes
 * Reclaim some margin
 * Stop checking the return-type of encode_utf8; we already know it's
   bytes

Change-Id: I2138ea553378ce88810b7353147c8645a8f8c90e
2015-10-07 22:33:42 -07:00
Alistair Coles
1841bd6010 Initialise delete_object mock before it is called
Attempt to fix the linked bug by initialising the mock instance for
Connection.delete_object before calling the SwiftService upload
method, so that the delete_object mock already exists before the
delete_segments jobs that run in multiple threads call it.  Otherwise
there is a risk that the delete_segment job threads could race while
creating either the delete_object mock or the
delete_object.return_value mock, resulting in each thread getting a
different instance. That would explain the intermittent test failures
reported in the bug.

Change-Id: Ia82697c093529076b0bbcc6bccd577afdf0839e1
Partial-Bug: #1480223
2015-09-08 10:22:32 +01:00
Charles Hsu
ee8c1bab98 Convert http response(byte string) to string in python3.
Avoid a TypeError exception in python3.

Change-Id: I4039e3f2a88b5f681288b5ca8dd5c63c13b7764f
Closes-bug: #1457012
2015-09-06 00:24:30 +08:00
Zack M. Davis
52d39bebc1 absolute expiry option for tempURL generation
The `tempurl` subcommand's second positional argument is called
`seconds` and has heretofore interpreted as the number of seconds for
which the tempURL should be valid, counting from the moment of running
the command. This is indeed a common, if not the most common,
use-case. But some users, occasionally, might want to generate a tempURL
that expires at some particular ("absolute") time, rather than a
particular amount of time relative to the moment of happening to run the
command. (One might make an analogy to the way in which Swift's expiring
object support supports an `X-Delete-At` header in addition to
`X-Delete-After`—and it's the former that must be regarded as
ontologically prior.) Thus, this commit adds an `--absolute` optional
argument to the `tempurl` subcommand; if present, the `seconds` argument
will be interpreted as a Unix timestamp of when the tempURL should be
expire, rather than a duration for which the tempURL should be valid
starting from "now".

Change-Id: If9ded96f2799800958d5063127f3de812f50ef06
2015-09-04 14:57:30 -07:00
Alistair Coles
d5eb818228 Cleanup and improve tests for download
Some improvements to the tests for staggered download
that were added in [1].

[1] Ie737cbb7f8b1fa8a79bbb88914730b05aa7f2906

Change-Id: Ib999bc7bd198c1d9c217c57501f751e854d4c6ad
2015-09-02 13:06:13 +01:00
Jenkins
e52df5d8a5 Merge "Reduce memory usage for download/delete and add --no-shuffle option to st_download" 2015-08-28 00:48:52 +00:00
Hiroshi Miura
38a82e9035 flake8 ignores same hacks as swift
- blacklisted flake8 hacking
- fix against E122 continuation line missing
  indentation or outdented

Closes-bug: #1475516

Change-Id: I708d0a3466a1f85c84e478873e142821ce0774cb
Signed-off-by: Hiroshi Miura <miurahr@nttdata.co.jp>
2015-08-18 19:19:22 -07:00
Hiroshi Miura
be0f1aad8a change deprecated assertEquals to assertEqual
fix against H234: assertEquals() logs a DeprecationWarning
in Python3.x. use assertEqual() instead.

Closes-bug: #1480776

Change-Id: Iffda6bb5f2616d4af4567eeea37bb26531e34371
Signed-off-by: Hiroshi Miura <miurahr@nttdata.co.jp>
2015-08-06 18:50:33 +09:00
Ondrej Novy
847f135f97 Block comment PEP8 fix.
Change-Id: I999425902a5c82f7af129a8a1b6998d80edb225a
2015-07-30 09:55:51 +02:00
Ondrej Novy
1c644d8dc1 Test auth params together with --help option.
Change-Id: I2691739cc14bb8d384cc7ef0f8a3e73d1b898f88
2015-07-30 09:48:00 +02:00
Joel Wright
a8c4df98ee Reduce memory usage for download/delete and add --no-shuffle option to st_download
The current code builds a full object listing before performing either a multiple
download or delete operation (and also shuffles this complete list in the case of
a download). This patch removes the creation of the full object list and adds the
ability to turn off shuffle for files when downloading. Also added is a limit on
the number of list results that can be queued by a single call to service.list
without consuming results (reduces memory overhead for large listings).

Some tests added for service.py download and list.

Change-Id: Ie737cbb7f8b1fa8a79bbb88914730b05aa7f2906
2015-07-20 20:44:51 +01:00
Jenkins
a56eac13b1 Merge "Always decode command-line arguments as UTF-8" 2015-07-16 11:27:31 +00:00
Jenkins
605ec92507 Merge "Add some bash helpers for auth stuff" 2015-07-11 06:41:45 +00:00
Tim Burke
bb252130ac Always decode command-line arguments as UTF-8
There was always an implicit assumption that they were UTF-8 before, and
by converting them to unicode we close another hole allowing raw bytes
to appear in user-facing messages.

Closes-Bug: #1431866
Change-Id: If2e41d9a592c3ad02818e9c6f0959fd4b73cd0e0
2015-07-07 15:39:55 -07:00
Jenkins
92b8277752 Merge "SwiftClient object upload beginning with / or "./"" 2015-07-07 22:21:38 +00:00
Jenkins
249dd1a393 Merge "Added check for negative segment-size" 2015-07-07 01:36:50 +00:00
Jenkins
0df888ea55 Merge "Remove all DLO segments on upload of replacement" 2015-07-02 00:04:50 +00:00
Pradeep Kumar Singh
e596489020 Added check for negative segment-size
Closes-Bug: #1453135

Change-Id: Ia9c2b27d998e6ac1889cc74c12e456c06ecd84d9
2015-06-23 10:50:34 +09:00
Pradeep Kumar Singh
794b125e76 SwiftClient object upload beginning with / or "./"
Currently SwiftClient populate response dictionary before
removing "./" or "/" at begining of object name. This patch
fixes that by changing that order.

Closes-bug: #1412425
Change-Id: I80222754caba5d42a468f4677ac539e46682dd31
2015-06-17 12:27:43 +05:30
Clay Gerrard
17feec709c Add some bash helpers for auth stuff
Change-Id: If61ac9a050e7a115f37dbf4e74b904ac5dfd2052
2015-06-15 12:38:21 -07:00
Tim Burke
317df7e527 Remove simplejson dependency
In addition to removing an unnecessary dependency, this closes another
hole that was allowing raw bytes to appear in user-facing messages.

Change-Id: Ia0b76426a38e5a5c368c4c7e7ba2aef286758aca
2015-05-20 18:14:53 -07:00
Jenkins
52b849217f Merge "Add tests for uploads deleting DLO segments" 2015-05-21 00:47:28 +00:00
Alistair Coles
a39e18ff5a Add test for timeout being passed to keystone client
Extends existing unit test for timeout being passed to get_auth
to cover v2.0 auth when keystone client should get the timeout
kwarg.

Related-Bug: 1447847
Change-Id: Ie9cfc86fa2156b94b45d290ac12e3f71b20d6c4f
2015-04-28 16:58:23 +01:00
Tim Burke
d931ec1381 Remove all DLO segments on upload of replacement
Previously, only the first container-listing's worth of segments was
deleted, which would leave behind orphaned segments when the object was
very large with small segments or the server's container_listing_limit
was small.

In addition, process DLO and SLO deletions on the segment thread pool,
rather than the object thread pool.

Change-Id: I1587375261a6237fa55a9cb96bda8dae918cc795
Related-Bug: #1418007
2015-03-23 12:11:47 -07:00
Daniel Wakefield
13780f37c3 Add improvements to MD5 validation.
With MD5Sum checking being added, a concern was brought up that It was
a change with no possibility of reverting to the old behaviour.
This change adds the flag '--ignore-checksum' to the upload subcommand
allowing the checks to be turned off.

Changed occurrences of the magic string for a null md5 to use a descriptive
constant instead.

Updated Error messages generated when validation fails. They should now be more descriptive
and not output a literal newline sequence.

Change-Id: Id1756cbb6700bb7e38f0ee0e75bc535e37f777ed
2015-03-04 14:01:55 +00:00
Alistair Coles
dcf2124d41 Add tests for uploads deleting DLO segments
This patch adds unit tests to verify that
uploads overwriting an existing DLO manifest
will delete any segments pointed to by the
manifest, unless --leave-segments is specified.

Also test the --leave-segments option with an
existing SLO manifest.

Related-Bug: 1418007

Change-Id: I54e8eb138976269bb36392a811089c33c1ace4d3
2015-02-25 16:52:23 +00:00