410 Commits

Author SHA1 Message Date
Jeremy Stanley
79fb53190e Workflow documentation is now in infra-manual
Replace URLs for workflow documentation to appropriate parts of the
OpenStack Project Infrastructure Manual.

Change-Id: I7513a141c95f3126ad348ed679b2baa335bdf45f
2014-12-05 15:32:57 +11:00
Clay Gerrard
d89e08f722 Capture test output better
This change adds some new classes to test.unit.utils which wrap up the
collection and mocking of the std err and std out.  This will make the
testing code easier to write and maintain.

Change-Id: I50ad2a736b2bb550ab83f6a43fb5a0fb5393573e
2014-11-20 14:42:55 +00:00
Jenkins
cfbabe7266 Merge "Fix misnamed variable in SwiftReader." 2014-11-17 11:12:13 +00:00
Daniel Wakefield
0f2b0dc300 Add unit tests for _encode_meta_headers
Also move it to a module level function.
Change-Id: I2da64876815619a6db7ff208061df2191767806c
2014-11-13 11:25:45 +00:00
Jenkins
202bbab2d0 Merge "Make swift post output an error message when failing" 2014-11-13 03:30:01 +00:00
Jenkins
f99e71da0f Merge "Fix KeyError raised from client Connection" 2014-11-13 03:12:53 +00:00
Daniel Wakefield
93cc42b21d Fix misnamed variable in SwiftReader.
actual_md5 was being used instead of _actual_md5 only when assigning
the md5 object. This resulted in all checks and updates of the md5
to be skipped.

When fixed it revealed another bug that the md5 of the read content
is always checked even if there is no _expected_etag.

Added tests

Change-Id: Iaf1e21324ce592049d02cd5be123604b99833e86
2014-11-07 12:55:51 +00:00
Jenkins
19b427eacb Merge "Adds user friendly message when --segment-size is a non-integer" 2014-10-28 20:52:03 +00:00
Mahati Chamarthy
51ed14d9ae Adds user friendly message when --segment-size is a non-integer
Change-Id: Ic2c062110b2fe2e725b0f4a4517a300cfbf663a8
2014-10-28 21:33:58 +05:30
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
871a3e40f3 Fix KeyError raised from client Connection
Some client.Connection methods will raise a KeyError
if a response_dict argument is passed and an error
occurs during authentication or making the request.

The fix is straightforward: add a test for existence
of a response_dict before attempting to get it from
kwargs.

The bulk of this patch is adding unit tests for the
response_dict feature.

Closes-Bug: 1381304

Change-Id: Ic7e1b3dfae33909533931c52ac97355867a08a07
2014-10-20 12:00:54 +01: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
Alistair Coles
589d34ecda Fix race between container create jobs during upload
During a segmented object upload, attempts are made
to create the container for the manifest and the
segment container. These jobs are currently placed
on separate threads and can occur out of order which
causes the unit test failure seen in the bug report.

The container jobs should be ordered because the
segment container job attempts to HEAD the manifest
container to determine correct storage policy.

This patch enforces ordering of the two jobs and
modifies the unit test to assert that both container
PUTs occur in the expected order.

Change-Id: If90bec126867a4be2df34067ccefee660202f59f
Closes-Bug: #1376878
2014-10-20 08:57:37 +01:00
Jenkins
bbe3378ebb Merge "Fix the info command with --insecure" 2014-10-19 03:00:38 +00:00
Pete Zaitcev
b27ca7c0c0 Fix the info command with --insecure
We forgot to propagate options into http_connection() for the info
aka capabilities command. Fix is to use the proper helper.

Fixes bug: 1381866

Change-Id: I9515203c969a1bba38dd909412355080383905f9
2014-10-17 13:38:01 -06: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
Jenkins
83ca0b825d Merge "Use skipTest from testtools instead of inherited Exception" 2014-10-09 10:14:00 +00:00
Christian Schwede
5ecff2868e Use skipTest from testtools instead of inherited Exception
SkipTest is raised if there is no func_test section in the Swift test
config file. However, the currently raised Exception will result in a
failed test, not in a test marked as skipped.

Since we already use testtools we can use the included skipTest easily.

Change-Id: I1bbb1f9dbe31fb0698d774550708d1196b266625
2014-10-08 07:10:23 +00:00
Christian Schwede
c37cecb616 Add tests for account listing using --lh switch
Change-Id: I2e68a24212eda463f39a5d0be13f1645ca2a23d8
2014-10-01 16:11:55 +00: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
Jenkins
bb4d2ab59c Merge "Remove a debugging print statement" 2.3.1 2014-09-26 22:35:39 +00:00
Jenkins
08c111e771 Merge "Fix unit tests failing when OS_ env vars are set" 2014-09-26 15:48:49 +00:00
Jenkins
d721871cfa Merge "Add per policy container count to account stat output" 2014-09-25 19:10:31 +00:00
Joel Wright
3496e07ea4 Remove a debugging print statement
This patch removes a debugging print statement that slipped into
service.py in patch https://review.openstack.org/#/c/85453/

Change-Id: I80eee49eaa74b52e9c36f00669206aa7b2cdec9b
2014-09-25 11:03:43 +00:00
Alistair Coles
b13c84b2ef Fix unit tests failing when OS_ env vars are set
tests/unit/test_shell.py:TestParsing tests can fail if
there are OS_* variables set in the environment. There
is already code in the test setUp to remove ST_* variables,
so we should do the same for OS_* variables.

This patch also changes the mechanism used to remove and
then restore any unwanted variables found in os.environ.

The existing setUp() takes a copy of os.environ and then
deletes any ST_* variables in the original. In tearDown() it
sets os.environ as the copy. However, the environ imported
into shell.py remains pointing to the original os.environ
object. So after the first call to tearDown, subsequent
mocking of os.environ has no effect on shell.environ.
This renders some of the tests ineffective e.g.
test_insufficient_env_vars_v3 is not actually setting any
vars in shell.environ.

The issue can be provoked by repeating a test:
nosetests -w tests/unit/ test_shell.py:TestParsing.test_args_v3 \
 test_shell.py:TestParsing.test_args_v3

The test will pass first time and fail second time.

Change-Id: I5d100f81115e74878d510326acb5777e6a3626c8
2014-09-25 11:44:39 +01:00
Alistair Coles
f90d7f28e5 Fix bug with some OS options not being passed to client
Fixes a regression that is preventing swiftclient from
authenticating using keystone v3 options.

swiftclient/shell.py processes the dict of command
line options to set up a child dict ('os_options')
of keystone auth specific options (line 960). The
processing includes stripping --os- prefixes from
the command line options before adding keys to
os_options.

A recent patch https://review.openstack.org/#/c/85453/
introduced a duplication of this option processing
in service.py (line 79) which replaces the os_options
created in shell.py, but omits keystone v3 related
options. Consequently the keystone v3 options are
not being passed to the client get_auth() method.

This patch adds the keystone v3 related options to
the option processing in service.py.

For pragmatic reasons (i.e. fixing the bug quickly)
the option processing code has not been removed from
parse_args in shell.py. It is likely that the code in
parse_args is now redundant, but all code paths between
parse_args and process_options should be inspected and
test coverage added before removing that code.

Unit tests have been added in test_shell.py to verify
that command line options are correctly passed to the
client get_auth method.

The MockHttpTest class is re-used in test_shell.py,
so it is moved from test_swiftclient.py
to tests/unit/utils.py

Closes-bug: #1372465

Change-Id: I4fed013cdb8936509609d06093337cc147ade0d6
2014-09-24 18:19:12 +01:00
Clay Gerrard
40857cfe4c Add per policy container count to account stat output
When the account response includes 'X-Storage-Policy-X-Container-Count' the
command helpers will stick a helpful extra line in the output.

If the swift response doesn't include the information the behavior is
unchanged.

Change-Id: Iaaa55d207ebe6a9c16e52adb56eb858c57cfb26a
2014-09-19 17:07:48 -07:00
Pete Zaitcev
8f1b394325 Stop creating extraneous directories
Cannot help streamlining the code a bit, sorry. But the meat is that
we should not try to make directories if output path is explicit.

Previously we created directories using the URL path, which is
obviously wrong if explicit output file is supplied... unless
a crafty user supplied the same path with -o that is contained
in the URL path. If anyone was doing such tricks, it's not going
to work anymore (we are forcing a regression for the sake of
theoretical correctness here).

Fixes bug: 1369546

Change-Id: Ifce31f2ba233eb55550f3810348bf16bf2447d62
2014-09-17 20:32:03 -06:00
Jeremy Stanley
45465c70e3 Work toward Python 3.4 support and testing
Change-Id: Ie213bec8d12e277d8c3d18ccc127831004d710a9
2.3.0
2014-09-03 19:05:55 +00:00
Jenkins
d13441d262 Merge "Adds console script entry point" 2014-08-28 14:03:21 +00: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
d97ec374cb Merge "fixed unit tests when env vars are set" 2014-08-21 20:34:35 +00:00
Alessandro Pilotti
cb059f2f3e Adds console script entry point
A Swift client executable needs to be provided on Windows since Python scripts
cannot be executed directly.

This approach is also consistent with other OpenStack Python clients (e.g.
Nova, Neutron, Cinder, etc.).

Change-Id: I7f03b7c305dceed4fa6f4fe1c1281659820606e4
Closes-Bug: #1359360
2014-08-21 01:01:24 +03:00
Pete Zaitcev
309437bb52 Do not create an empty directory 'pseudo/'
This is a fix-up for the commit 3d56b65c. The code change was good,
but the additional test had a side effect of creating an empty
directory "pseudo/". Fix this by mocking-out mkdirs().

Change-Id: Iead55e72d8a75d96bde0a7491aca12bbdcc269cf
2014-08-18 16:51:01 -06:00
John Dickinson
2eca5278e6 fixed unit tests when env vars are set
Change-Id: Ia73c10c7c81b9434895941ea29282dbcdc667556
2014-08-18 15:09:33 -07:00
Jenkins
eedb0d4ab5 Merge "Fix crash when downloading a pseudo-directory" 2014-08-17 19:08:15 +00:00
Jenkins
23474b7d11 Merge "Add keystone v3 auth support" 2014-08-15 23:24:00 +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
Jenkins
8664eadd19 Merge "Clean up raw policy stats in account stat" 2014-08-14 15:11:18 +00:00
Yuan Zhou
776133bd29 Clean up raw policy stats in account stat
Storage policy stats was not well parsed in account stat. This
patch parses the stats and print out the stats in a format like below:

$swift -A http://swift_cluster/auth/v1.0 -U test:tester -K testing stat
                   Account: AUTH_test
                Containers: 5
                   Objects: 1
                     Bytes: 2097152
Objects in policy "golden": 1
 Bytess in policy "golden": 2097152
Objects in policy "silver": 0
  Bytes in policy "silver": 0
               X-Timestamp: 1404697760.88809
                X-Trans-Id: txec519e24b44a413abb705-0053da2dcb
              Content-Type: text/plain; charset=utf-8
             Accept-Ranges: bytes

Change-Id: I7ad0ee6d88f8393e3a93e90cd52b9b592da7072d
2014-08-06 16:07:17 +08:00
Steve Martinelli
6b836ac368 Update theme for docs
The current developer docs theme used is out of sync with the other
openstack projects. This patch will update the docs to provide a more
consistent look and feel when using developer docs

Change-Id: I2c66f60f6cfdd7b7b50a457c931f11851f668fa6
2014-07-24 20:59:45 -04:00
Steve Martinelli
fd1594937d Add a tox job for generating docs
Add a tox job to make it easier for developers to generate their
own docs before submitting a patch.

Change-Id: I86dbfc64a9d174697048c254c6d3d042a62350b4
2014-07-24 17:54:10 -04: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
2.2.0
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