123 Commits

Author SHA1 Message Date
Jenkins
d97ec374cb Merge "fixed unit tests when env vars are set" 2014-08-21 20:34:35 +00: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
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
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
anc
916f5cbd61 Relax requirement for tenant_name in get_auth()
get_auth() in client.py raises an exception if
tenant_name is not included in the os_options
dict. This is overly constrained since tenant_id
is equally sufficient. This patch modifies
get_auth to require either tenant_name
or tenant_id.

Change-Id: Ibbcda1704637eb887efa5895579d260a1e072327
2014-06-05 18:02:52 +01:00
Jenkins
3d0de79e26 Merge "change assertEquals to assertEqual" 2014-05-28 03:23:20 +00:00
Jenkins
1d81933921 Merge "fixed several pep8 issues" 2014-05-24 10:17:15 +00:00
Jenkins
5e18d95cb2 Merge "Remove testtools.main() call from tests" 2014-05-24 09:16:59 +00:00
anc
eaf4fcbb8d Fix wrong assertions in unit tests
A couple of assertTrue in the test_swiftclient.py
unit tests should be assertEqual. Also, the expected
values now need to be bytes literals.

Change-Id: I7cc1bd60d9ba82d1a28fbae2e1243d3c799451bd
2014-05-22 16:56:31 +01:00
Christian Berendt
d08bd458be fixed several pep8 issues
* E111 indentation is not a multiple of four
  * E128 continuation line under-indented for visual indent
  * E265 block comment should start with '# '
  * E713 test for membership should be 'not in'

Tested with pep8 version 1.5.6 (2014-04-14).

Change-Id: I7f85c143d463c501a0df20724362ad5c0f2d4dde
2014-05-21 16:31:53 +00:00
Christian Schwede
258420f410 Fix Python3 bugs
This patch fixes three issues that were found running
functional tests with Python 3:

1. python-requests sets 'application/x-www-form-urlencoded' as
   content-type if the input is not a string object and no
   content-type is given.

2. Encoding of the headers is now only done if required. This
   prevents comparisons between unencoded headers and encoded
   prefixes and avoids unnecessary forloop-iterations.
   One unittest was extended to ensure it works for unencoded
   and encoded headers with or without the prefix.

3. Functional tests recently switched to using byte data for
   testing, thus the comparison needs to be a byte object as well.

Change-Id: I035f8b4b9c9ccdc79820b907770a48f86d0343b4
2014-05-21 14:54:18 +01:00
Christian Schwede
876238a134 Remove testtools.main() call from tests
There is no testtools.main() at all (this was a
unittest.main() before). Let's remove this unused
and non-working code.

The following code can be used if someone needs
to start tests manually:

    python -m unittest <test_file.py>

Change-Id: Id5162ac73825584df6c23dbe68786ff3355fc6ae
2014-05-20 14:54:41 +00:00
anc
e7dc854257 Move test_shell.py under tests/unit/
Looks like test_shell.py got left behind when
the unit tests were relocated under tests/unit.
As a consequence they weren't included in tox
runs.

Change-Id: I93435e6141c5e3ad4a9403626f226d7c760cbd7c
2014-05-20 11:21:11 +01:00
Christian Berendt
f58a1640a1 change assert_ to assertTrue
According to http://docs.python.org/2/library/unittest.html
assert_ is a deprecated alias of assertTrue.

Change-Id: I18db0af72934dde4498502fb29579941d020cf01
2014-05-14 21:15:07 +02:00
Christian Berendt
569bbc723e change assertEquals to assertEqual
According to http://docs.python.org/2/library/unittest.html
assertEquals is a deprecated alias of assertEqual.

Change-Id: Ibf4d548b86c53f30830b7e34b019fa8f67997cd8
2014-05-14 19:08:52 +02:00
Jenkins
3895d8535a Merge "Only encode metadata for user customed headers" 2014-05-08 12:21:48 +00:00
Alex Gaynor
30244399dd Make the function tests Python3-import friendly
Change-Id: Ic73fc2a6f6712505eda71fa2e2e91ac680ced9a3
2014-05-07 07:27:58 -07:00
Chmouel Boudjnah
4467d98f30 Only encode metadata for user customed headers
Don't encode standard headers keys but just the x-*-meta- ones. That
fixes py3 to not have them casted as bytes and not properly passed to
the requests kwargs.

Other trivial py3 fixes along the way.

Change-Id: I91b95f32fb2aec9b20892a5bb95fd1bc65d002f3
2014-05-07 12:11:14 +02:00
Jenkins
4e85183019 Merge "Add functional tests for python-swiftclient" 2014-05-06 13:25:00 +00:00
Christian Schwede
eb94ac076d Add functional tests for python-swiftclient
Coverage for swiftclient.client is 71% with these tests.

Unit tests have been moved into another subdirectory
to separate them from functional tests.

Change-Id: Ib8c4d78f7169cee893f82906f6388a5b06c45602
2014-05-05 11:53:37 +02:00
Chmouel Boudjnah
0fc27f6c28 Mock auth_end_time in test_shell.test_download
If we don't we are getting an error like this under py3:

TypeError: unsupported operand type(s) for /: 'float' and 'MagicMock'

Change-Id: If5a6947757297354e6b81fc45f011cc2921d609f
2014-04-25 12:11:51 +00:00
Jenkins
37bf0ff9a1 Merge "Fixed several shell tests on Python3." 2014-04-24 06:51:27 +00:00
Jenkins
b9bd897639 Merge "Fix up StringIO use in tests for py3" 2014-04-24 00:26:47 +00:00
Jenkins
fc66708418 Merge "Updated test_shell for Python3" 2014-04-23 23:18:50 +00:00
Alex Gaynor
c3bec04485 Fixed several shell tests on Python3.
They currently fail because on Python3 arbitrary objects cannot be compared, in
this case, MagicMock and int. In Python2 these comparisons silently pass.

Change-Id: I468c2137702a454365886099e827d329cb1d7209
2014-04-23 15:52:13 -07:00
Samuel Merritt
1353f2412b Fix up StringIO use in tests for py3
Some spots in this file were already referencing six.StringIO, but
some were still using StringIO.StringIO, which does not work on
py3. This patch just makes them all use six.StringIO and removes the
now-unused (and wrong, on py3) import.

Change-Id: I3c7311c3983f4eb409eedb6f85ede6ffe4059e63
2014-04-23 13:04:54 -07:00
Jenkins
1893cbec88 Merge "Fix test_raw_upload test" 2014-04-23 19:58:10 +00:00
Alex Gaynor
0102e2e1ee Updated test_shell for Python3
Change-Id: Ia76e544fa6e0a222c260191a1ab74939078ed2fb
2014-04-23 11:40:37 -07:00
Jenkins
91075c3251 Merge "Remove validate_headers" 2014-04-23 16:57:24 +00:00
Jenkins
cda2573ab6 Merge "Add tests for bin/swift" 2014-04-18 02:28:27 +00:00
Chmouel Boudjnah
e2b7636d66 Fix test_raw_upload test
We were testing the test but we were not testing that we have actually
properly uploaded the object with the right content-len

(and it was broken under py3)

Change-Id: Ifa91c30532090cac9f8e18ff18eaf5e6c98737d1
2014-04-17 12:04:43 -04:00
Chmouel Boudjnah
504e5a7f53 Remove validate_headers
It wasn't used anymore since moved up to requests (and it fails in py3).

Change-Id: Ic8a80ae09ca6445696a9cf34ffb503c5ff51bc79
2014-04-17 12:04:43 -04:00
Jenkins
aaa563c749 Merge "Fix test_multithreading on Python 3" 2014-04-16 02:58:47 +00:00
Jenkins
c810772623 Merge "Fix swiftclient.client.quote() for Python 3" 2014-04-16 00:36:39 +00:00
Victor Stinner
ea498fb052 Fix test_multithreading on Python 3
* On Python 3, the printer doesn't encode Unicode to utf8 anymore, since
  print() expects a Unicode string.

* Update unit tests for Python 3 since repr() doesn't escape non-ASCII
  characters in Unicode strings anymore:
  http://legacy.python.org/dev/peps/pep-3138/

Change-Id: I89471019d691a46651312d6a49964b719192148a
2014-04-15 11:38:26 -04:00
Christian Schwede
f24c67cf1d Add tests for bin/swift
Tests are written to ensure bin/swift is working properly and using
functions from swiftclient modules as expected.

Change-Id: Idb0581516b7e0a41c97977bb0bb9f8290f67ad13
2014-04-14 10:41:55 -04:00
Jenkins
ec538d3720 Merge "Add requests related unit-tests" 2014-04-14 10:49:14 +00:00
Jenkins
cdd8d33ea7 Merge "Python 3: fix tests on HTTP headers" 2014-04-10 14:08:30 +00:00
Victor Stinner
155053ea61 Fix swiftclient.client.quote() for Python 3
On Python 3, urllib.parse.quote() accepts bytes and str (unicode) types and
always return str (unicode).

Add also more tests with non-ASCII characters.

Change-Id: I8e0f19da7240e874392327d0da074ed4abb7d213
2014-04-07 10:30:18 +02:00
Jenkins
c5cc2b7b7e Merge "Use the standard library's copy of mock when it's available." 2014-04-05 09:46:04 +00:00
Tristan Cacqueray
da2d8eef47 Add requests related unit-tests
This change improves unit tests of the new code added by the port to requests.
Raw upload and chunked upload in put_object are now covered.

Change-Id: I995b23a74bc4b00bf5761362b1f1405bb8662311
2014-04-05 09:14:08 +00:00