41 Commits

Author SHA1 Message Date
Pradeep Kumar Singh
e596489020 Added check for negative segment-size
Closes-Bug: #1453135

Change-Id: Ia9c2b27d998e6ac1889cc74c12e456c06ecd84d9
2015-06-23 10:50:34 +09: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
Jenkins
eedb0d4ab5 Merge "Fix crash when downloading a pseudo-directory" 2014-08-17 19:08:15 +00:00
Pete Zaitcev
3d56b65c89 Fix crash when downloading a pseudo-directory
If a user creates an object with name ending with a slash, then
downloading such container ends in a traceback like this:

..............
test5g.file [auth 1.516s, headers 1.560s, total 244.565s, 22.089 MB/s]
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/swiftclient/multithreading.py", lin
    result = self.func(item, *self.args, **self.kwargs)
  File "/usr/lib/python2.6/site-packages/swiftclient/shell.py", line 403, in
    fp = open(path, 'wb')
IOError: [Errno 21] Is a directory: 'first-pseudo-folder/'

The proposed fix is not to save this object. Note that the contents of
the object are available with --output option, as before. Only the
crash is fixed.

Even though we do not use the contents, we download the object and
check its Etag, in case. We also create a corresponding directory,
in case the pseudo-directory contains no objects.

The format of printout is changed, so user realizes easier when
pseudo-directory convention is in effect. Note that this is not a
compatibility issue because previously there was crash in such case.

Change-Id: I3352f7a4eaf9970961af0cc84c4706fc1eab281d
2014-08-14 13:57:53 -06:00
anc
cae12940b1 Add keystone v3 auth support
Enables swiftclient to authenticate using
the keystone v3 API, allowing user id's, user
domains and tenant/project domains to be
specified.

Since swiftclient imports keystoneclient, the
main changes in swiftclient/client.py are to
selectively import the correct keystoneclient
library version and pass a number of new
options to it via the get_auth() function. In
addition the get_keystoneclient_2_0 method
has been renamed get_auth_keystone to better
reflect its purpose since it now deals with
both v2 and v3 use cases.

In swiftclient/shell.py the new options are
added to the parser. To make the default help
message shorter, help for all the --os-*
options (including the existing v2 options)
is only displayed when explicitly requested
usng a new --os-help option.

A new set of unit tests is added to
test_shell.py to verify the parser. A comment
in tests/sample.conf explains how to
configure the existing functional tests to
run using keystone v3 API.

Note that to use keystone v3
with swift you will need to set
auth_version = v3.0 in the auth_token
middleware config section of
proxy-server.conf.

Change-Id: Ifda0b3263eb919a8c6a1b204ba0a1215ed6f642f
2014-07-23 16:55:38 +01:00
Alistair Coles
394cb57f63 Fix context sensitive help for info and tempurl
Make it so that swift <cmd> --help will print the info
subcommand help for info and tempurl just like all the
other subcommands.

Also add unit tests to verify subcommand help.

Change-Id: Id3666dcf72a9727fbfda2f74c23293ada1c53aa0
2014-07-21 15:27:40 -07:00
Jenkins
f9ea672322 Merge "Allow to specify storage policy when uploading objects" 2014-07-21 21:43:59 +00:00
Jenkins
4cc2201e21 Merge "Adding Swift Temporary URL support" 2014-07-18 03:22:41 +00:00
Yuan Zhou
defdf1929c Allow to specify storage policy when uploading objects
Client already supports -H/--header option when creating container
or uploading objects. This patch extends this option to support
Storage Policy.

e.g.,
    swift post con -H 'X-Storage-Policy:p1'
This creates one container 'con' with storage policy 'p1'.

    swift upload con obj -H 'X-Storage-Policy:p2'
This creates container 'con' with storage policy 'p2' and uploads
object 'obj' into it.

Also fixes segmented uploading to non-default storage policy container

When uploading large objects with segmentation to container with
non-default storage policy, there will be another 'xxx_segments'
container created, but with the default storage policy. This
results all the segments to be stored with the wrong policy.

This patch is for the Storage Policy feature, and also
compatible with old versions w/o Storage Policy support.

Change-Id: I5c19e90604a0bcf2c85e1732b8a0b97ae6801994
2014-07-17 11:44:03 +08:00
Josh Gachnang
def0e0a643 Adding Swift Temporary URL support
Temporary URLs allow a user to sign an object URL with a shared
secret to so that the object can be downloaded without auth for
a specified amount of time.

http://docs.openstack.org/trunk/config-reference/content/object-storage-tempurl.html

Change-Id: Ife0b6c98c975e074d4dad0a31145573b784747c5
2014-07-11 13:05:22 -07:00
Mark Seger
0e302d3d3a Add context sensitive help
Change-Id: I9aaadbaba2c43a12a83f8200eaaa96f48c52028e
2014-06-25 14:36:38 +00:00
Jenkins
09eb1843f1 Merge "fixed typos found by RETF rules" 2014-05-16 15:41:30 +00:00
Christian Berendt
2d30656f41 fixed typos found by RETF rules
rules are avaialble at https://en.wikipedia.org/wiki/Wikipedia:AutoWikiBrowser/Typos

Change-Id: I98b6e46cb84962ffdac02e9007b5ad3b30bc2817
2014-05-12 12:02:32 +02:00
Andreas Jaeger
9340122817 Add "." for help strings
The command descriptions did not include a "." at the end but the
argument description does. Add "." everywhere.

Also capitalize and add "." for parameter of capabilities.

Change-Id: I2355e0d0c38170d669c8e568361faf4b68203d16
2014-05-08 16:51:51 +02:00
Chmouel Boudjnah
8830c81db7 Use quote/unquote from six module for py3
Change-Id: I42cff32fbf3febd6dd6a7171b9214f93b4414f9a
2014-04-17 12:04:43 -04:00
Florent Flament
1eaf4c549f Update help message to specify unit of --segment-size option.
Change-Id: Ic3f9a733329c19c4e0bb85676da28a8d1d74232b
Closes-Bug: 1302566
2014-04-04 15:10:40 +00:00
Jenkins
132c643156 Merge "Removed usage of tuple unpacking in parameters." 2014-04-02 19:55:59 +00:00
Alex Gaynor
1d0c97fdb3 Replaced print statements with print function.
This is needed for Python3 compatibility.

Change-Id: Iadd21e4b3a936b601a69f1db2aba8e1597f13fc3
2014-03-30 12:56:43 -07:00
Alex Gaynor
97662952fd Removed usage of tuple unpacking in parameters.
Replaced it with traditional tuple unpacking. Needed for Python 3 support.

Change-Id: I714f32859f9b1ec7216eae777ea8968b5826af3b
2014-03-30 12:50:12 -07:00
Christian Schwede
100419c0b3 Make bin/swift testable part 1
To make bin/swift importable for testing it needs to be renamed/moved.
The final idea is to move it to swiftclient/shell.py and add only a stub
in bin/swift to import swiftclient/shell.py.

However, doing this in a single step makes reviewing very hard, because
now there are > 1400 lines deleted from bin/swift and added to
swiftclient/shell.py - Gerrit doesn't detect the moved file.

For example: https://review.openstack.org/#/c/73710/2/

This patch first moves the code to swiftclient/shell.py and uses
setup.py/cfg to create the stub file in bin/swift. A follow up
(https://review.openstack.org/#/c/76489/) will then add the stub itself
in bin/swift (and remove the entry in setup.py).

The change to tox.ini is related to bug 1290562 and can be removed in
the future.

Change-Id: Id86392ccaf09e1d80a5d808fb49827d6d18c2588
2014-03-25 11:32:51 +00:00