68 Commits

Author SHA1 Message Date
Jenkins
2b391d47f0 Merge "Fix debug and info option parsing" 2016-02-11 20:22:09 +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
e65e01014e Merge "Convert http response(byte string) to string in python3." 2016-01-22 13:16:44 +00: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
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
62bfe10f58 Fix some typos
Change-Id: Iaf7f30a7ae0c2ac76fc5cdcee31ea74c08ce601e
2015-12-30 11:01:33 -08:00
Jenkins
a564eb0e4c Merge "Unification of manpages and docstrings" 2015-12-01 13:03:05 +00:00
Jenkins
e675e1e938 Merge "Suppress iso8601 logging from --debug output" 2015-12-01 00:31:54 +00:00
Peter Lisák
3b1f4fda72 Unification of manpages and docstrings
* adding missing options
* unification of help

Change-Id: I2365e66433b63de8fd4da205611d9c1bf3bb6730
2015-11-13 17:32:12 +01: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
Qiu Yu
f65641c44d Suppress iso8601 logging from --debug output
This change silences logging from iso8601 when --debug option set

Change-Id: Ib8b8423012d43ef78d7138609fa98f40d46e7d4b
Closes-bug: #1324470
2015-09-12 03:10:15 +08: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
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
Jenkins
207e80c65c Merge "swiftclient: add short options to help message" 2015-07-31 04:54:13 +00: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
Hiroshi Miura
7442f0dcc8 swiftclient: add short options to help message
- add usage strings for short option such as '-a' for '--all'
  This add all short options  to usage text.
- add missing --header usage help for download command
- some cometic changes

Closes-bug: #1475511

Change-Id: Ibfecac8764669540fa025787548133a50fa50b10
Signed-off-by: Hiroshi Miura <miurahr@nttdata.co.jp>
2015-07-17 16:03:39 +09:00
Jenkins
a56eac13b1 Merge "Always decode command-line arguments as UTF-8" 2015-07-16 11:27:31 +00:00
Jenkins
de3fe02ba7 Merge "Correct the help message of swift tempurl" 2015-07-11 06:47:09 +00:00
Jenkins
605ec92507 Merge "Add some bash helpers for auth stuff" 2015-07-11 06:41:45 +00:00
Jenkins
0b592caabf Merge "Add ability to download objects to particular folder." 2015-07-11 06:21:40 +00:00
Charles Hsu
d5d3127744 Add ability to download objects to particular folder.
This patch adds "--output-dir" and "--remove-prefix" options
to the "download" command and unit tests for it.

Example:

    $ swift list example --prefix swift2.2
    swift2.2/bin/swift-object-auditor
    swift2.2/bin/swift-object-expirer
    swift2.2/bin/swift-object-info
    swift2.2/bin/swift-object-replicator
    swift2.2/bin/swift-object-server
    swift2.2/bin/swift-object-updater

When given "--output-dir <directory>", client downloads objects to <directory>.

    $ swift download example --prefix swift2.2 \
                    --output-dir new/swift/dir

    The folder structure:
    .
    └── new
        └── swift
            └── dir
                └── swift2.2
                    └── bin
                        ├── swift-object-auditor
                        ├── swift-object-expirer
                        ├── swift-object-info
                        ├── swift-object-replicator
                        ├── swift-object-server
                        └── swift-object-updater

When given "--remove-prefix", client downloads objects without <prefix>.

    $ swift download example --prefix swift2.2 \
                    --remove-prefix \
                    --output-dir swift

    The folder structure:
    .
    └── swift
        └── bin
            ├── swift-object-auditor
            ├── swift-object-expirer
            ├── swift-object-info
            ├── swift-object-replicator
            ├── swift-object-server
            └── swift-object-updater

Co-Authored-By: Clay Gerrard <clay.gerrard@gmail.com>
Change-Id: I7463fe2941cc94f9a50a4756a97c2ccdf946294d
Implements: blueprint swiftclient-download-pseudo-folder-to-specific-target
2015-07-08 14:23:05 +08: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
YangLei
91855bd912 Correct the help message of swift tempurl
correct the help message of swift tempurl
use <> instead of [] in Positional arguments.

Change-Id: Ib60ce97cef03e0423082c497604525eba2300fa9
2015-06-30 15:10:44 +08: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
Clay Gerrard
17feec709c Add some bash helpers for auth stuff
Change-Id: If61ac9a050e7a115f37dbf4e74b904ac5dfd2052
2015-06-15 12:38:21 -07:00
Andreas Jaeger
e48f487335 Fix inconsistent usage of "Positional argument"
All help texts uses "Positional argument" with the exception of tempurl.
Update tempurl to use this as well so that the formatting tools work
fine and can show this nicely on
http://docs.openstack.org/cli-reference/content/swiftclient_commands.html#swiftclient_subcommand_tempurl
like it's done for other options.

Change-Id: Ib5502c23b236986bea5a4d4a63a46fca411a8494
Closes-Bug: #1463081
2015-06-08 20:20:21 +02:00
John Dickinson
888bf6f1a0 be more explicit in the --version CLI option
Change-Id: I14f33c7ea90ab1fe58aa67f1ff70e527c88cd141
2015-05-13 16:46:14 -07:00
Tim Burke
c9f79e641c Mention --segment-size option after 413 response
Previously, it would only output something like

  ClientException: Object PUT failed <url> 413 Request Entity Too Large
  Your request is too large.

... which is misleading as it implies that Swift simply can't handle
large objects.

Change-Id: Icec9e76b2671490c3a2249ec08992950107c6828
2015-03-05 15:37:18 -08:00
Jenkins
8e94ca6394 Merge "Unindent a chunk of st_list" 2015-03-05 21:19:06 +00: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
Pete Zaitcev
35bcad638c Unindent a chunk of st_list
The chunk looks like nicely containable, but it pushes against the
right edge of the screen annoyingly. This patch _only_ prettifies,
without any observable changes.

Change-Id: I96fcb5848e3e5e0e8a8ebbe398b1d4a0bea5fa24
2015-02-26 15:46:13 -07:00
Pete Zaitcev
fec5d068a0 Fix crash with -l, -d /, and pseudo folders
Using -l, -d /, or a pseduo folder by itself works fine, but if you
combine all of them, this happens:

[zaitcev@guren s]$ swift list -d / testcont
amazon_lili.jpg
pseudodir/
rin_shibuya_pixiv.jpg
swift-c134855-5a.diff
[zaitcev@guren s]$ swift list -d / -l testcont
      151954 2014-06-20 17:13:52 amazon_lili.jpg
Traceback (most recent call last):
  File "/q/zaitcev/hail/python-swiftclient-tip/bin/swift", line 24, in <module>
    sys.exit(main())
  File "/q/zaitcev/hail/python-swiftclient-tip/swiftclient/shell.py", line 1301, in main
    globals()['st_%s' % args[0]](parser, argv[1:], output)
  File "/q/zaitcev/hail/python-swiftclient-tip/swiftclient/shell.py", line 414, in st_list
    total_bytes += item_bytes
TypeError: unsupported operand type(s) for +=: 'int' and 'NoneType'

The patch is a straightforward fix that assigns expected variables.

Change-Id: If24dcc2491e8b8982455107d2aca30c0491a398a
Closes-Bug: 1399678
2015-02-18 19:46:41 -07:00
Jenkins
eb28d8aff6 Merge "This patch fixes downloading files to stdout." 2015-02-03 18:55:47 +00:00
Joel Wright
bd42c2b00d This patch fixes downloading files to stdout.
This patch fixes downloading files to stdout and modifies
_SwiftReader to operate as an iterator that performs file
checks at the end of iteration as well as a context manager.
File verification checks have been removed from __exit__
and added to __iter__.

Change-Id: I3250bdeeef8484a9122c4b5b854756a7c8f8731e
Closes-Bug: 1395922
Closes-Bug: 1387376
2015-01-23 11:46:13 +00:00
Alistair Coles
9593d4b58a Fix cross account upload using --os-storage-url
Removes an account stat from the object upload path.
This stat fails when user is not account admin even
though the user may have container ACL permission to
write objects.

Reduces the severity of the CLI output message when
upload fails to create the given container (this is
not an error since the container may exist - the user
just does not have permission to PUT or POST the
container).

Changes the 'swift upload' exit return code from 1 to
0 if container PUT fails but object PUT succeeds.

For segment uploads, makes the attempt to create the
segment container conditional on it not being the same
as the manifest container. This avoids an unnecessary
container PUT.

Fixes another bug that became apparent: with segmented
upload a container HEAD may be attempted to determine
the policy to be used for the segment container. When
this failed the result dict has headers=None which was
causing an exception in the shell result handler.

Add unit tests for object upload/download and container
list with --os-storage-url option.

Closes-Bug: #1371650
Change-Id: If1f8a02ee7459ea2158ffa6e958f67d299ec529e
2015-01-06 16:13:39 +00:00
Jiří Suchomel
5d57018707 Print info message about incorrect --totals usage
when neither -l nor --lh is provided.
Added test coverage for --totals.

Change-Id: I3245e715c26ec28457a21dec07311a58c475c066
Closes-Bug: 1258392
2015-01-05 11:02:00 +00:00
Jenkins
dfbb1807fb Merge "Change tests to use new CaptureOutput class." 2014-12-30 21:28:43 +00:00
Daniel Wakefield
5756fcc4f2 Fix misnamed dictionary key.
The response dictionary in _delete_segment attach's any error
it encounters to the dict key 'exception', all other response
dict's use 'error' to store the exception.

Changed to make it consistent and added tests

Also added a third branch in st_delete as messages
created in _delete_container where being silently dropped.

Change-Id: Ifbc3b1fae78910fbc6acf4a86cfb0f60bb1aa336
2014-12-08 15:45:40 +00:00
Daniel Wakefield
49a80f734c Change tests to use new CaptureOutput class.
Added the ability to clear the buffers in the
CaptureOutput class so it can be easily used multiple
times in the same context manager.
Also added a option to suppress the SystemExit
associated with printing an error.

Change-Id: Ib59bbbe88256f215eed0a8ebc8282e02181d4377
2014-12-05 10:57:09 +00:00
Jenkins
202bbab2d0 Merge "Make swift post output an error message when failing" 2014-11-13 03:30:01 +00:00
Alistair Coles
95056d1ef4 Make swift post output an error message when failing
swiftclient.shell.st_post was ignoring the result dict
returned from SwiftService.post and therefore giving no
indication when posts failed e.g. due to invalid auth
credentials.

This patch ensures that SwiftService always returns a
result_dict from post() and then checks the result dict.
On failure the shell now outputs the ClientException
message and exits with error code 1.

Also adds unit tests and cleans up some unnecessary mocked
return values in existing tests.

Closes-Bug: 1383243

Change-Id: I111150eb3d026c8d01c2cac13d3613ca7304e5b9
2014-10-24 18:13:37 +01:00
Daniel Wakefield
025da14326 Replaces Stacktraces with useful error messages.
Changed the message shown when a user doesn't enter project/tenant
id/name to be more informative.

When attempting to stat a container without supplying project/tenant
name or id, an empty response was being returned instead of an error
being raised.

Changed the error raised in swiftclient.client when no tenant or project
is specified to be more specific.

Add tests for basic regression checking.

Closes-Bug: #1372589

Change-Id: I4eb6964d9f1702db119cc0294edc02841b1ecd5f
2014-10-21 08:23:26 +00:00
Alistair Coles
43c1141baa Fix race in shell when testing for errors to raise SysExit
SysExit is raised if the OutputManager has non-zero
error_count. However, error_count is incremented in
a print thread, but tested on the main thread.
Currently error_count is tested before the OutputManager
print threads have exited, which results in a race. This race
means that SysExit is not always raised even when an error
has occured.

This change moves the error_count test after the
OutputManager context manager has exited, which ensures that
the OutputManager threads have exited.

Change-Id: I5ef7d9f10057fe2b41f48ab95066a7265b86a3ac
Closes-Bug: #1379229
2014-10-20 08:58:19 +01:00
Jenkins
c88cddd2d8 Merge "Allow segment size to be specified in a human readable way." 2014-10-17 19:33:06 +00:00
Daniel Wakefield
5f89dcc46e Allow segment size to be specified in a human readable way.
Instead of always specifying segment size in bytes the user
can now use B,K,M or G as suffixes for the corresponding
size.

Conversion is done with Binary units (1024) rather than SI
units (1000).

e.g

swift upload test_container -S 1073741824 large_file
can now be written
swift upload test_container -S 1G large_file

The change is backwards compatible as it ignores arguments to -S
that don't have a valid suffix.

Updated unit tests and help message.

Change-Id: I6314b4e45cf2fbffde2fe57a02df77a25e911e84
2014-10-10 12:57:35 +01:00
Jiří Suchomel
21fb6f6798 Do not crash with "swift list --lh" for Ceph RadosGW.
If 'x-timestamp' header is not present in 'swift list' result,
date string cannot be correctly generated. Check for correct
exception to catch this case and return a special string value.
This is just a workaround for faulty RadosGW behavior.

Change-Id: I172843a2668e33efac00924906ff0dca3e790050
Closes-Bug: 1349528
2014-10-01 17:24:11 +02:00
Joel Wright
24673f8d19 Add importable SwiftService incorporating shell.py logic
This patch adds a SwiftService class that incorporates the high
level logic from swiftclient/shell.py. It also ports shell.py to
use the new class, and updates the code in swiftclient/multithreading.py
to allow the SwiftService to be used for multiple operations whilst
using only one thread pool.

Currently, code that imports swiftclient has to have its own logic for
things like creating large objects, parallel uploads, and parallel
downloads. This patch adds a SwiftService class that makes that
functionality available in Python code as well as through the shell.

Change-Id: I08c5796b4c01001d79fd571651c3017c16462ffd
Implements: blueprint bin-swift-logic-as-importable-library
2014-08-26 14:14:21 +02:00