363 Commits

Author SHA1 Message Date
Jenkins
6b065dd4a6 Merge "Identify segments uploaded via swiftclient" 2016-05-02 10:35:20 +00:00
Jenkins
ab636c1ee3 Merge "Fix downloading from "marker" item" 2016-04-14 02:02:34 +00:00
Cedric Brandily
450f505c35 Support client certificate/key
This change enables to specify a client certificate/key with:
 * usual CLI options (--os-cert/--os-key)
 * usual environment variables ($OS_CERT/$OS_KEY)

Closes-Bug: #1565112
Change-Id: I12e151adcb6084d801c6dfed21d82232a3259aea
2016-04-10 23:20:49 +02:00
Sergey Gotliv
909bdf8954 Fix downloading from "marker" item
The documentation of "swift download" hints that "marker" option
is supported, but in reality we forgot to patch it through, so
all downloads were always done with the default, empty marker.

Closes-Bug: #1565393
Change-Id: I38bd29d2baa9188b61397dec75ce1d864041653c
2016-04-08 20:55:18 -06:00
Tim Burke
9fd537a082 Use application/directory content-type for dir markers
Previously, we were using a content-type of text/directory, but that is
already defined in RFC 2425 and doesn't reflect our usage:

   The text/directory Content-Type is defined for holding a variety
   of directory information, for example, name, or email address,
   or logo.

(From there it goes on to describe a superset of the vCard format
defined in RFC 2426.)

application/directory, on the other hand, is used by Static Web [1] and
is used by cloudfuse [2]. Seems like as sane a choice as any to
standardize on.

[1] https://github.com/openstack/swift/blob/2.5.0/swift/common/middleware/staticweb.py#L71-L75
[2] https://github.com/redbo/cloudfuse/blob/1.0/README#L105-L106

Change-Id: I19e30484270886292d83f50e7ee997b6e1623ec7
2016-04-08 16:57:51 -07:00
Tim Burke
4a6fa02c28 Identify segments uploaded via swiftclient
...using a new "application/swiftclient-segment" content-type.

Segments uploaded by swiftclient are expected to have a many-to-one
relationship to large objects, rather than the more-general many-to-many
relationship that SLO and DLO generally allow. Later, we may use this
information to make more intelligent decisions, such as when to
automatically clean up segments.

Change-Id: Ie56a3aa10065db754ac572cc37d93f2c901aac60
2016-04-08 13:41:29 -07:00
Jenkins
015903e383 Merge "Port from optparse to argparse" 2016-04-08 09:36:31 +00:00
Tim Burke
17aa6c789e Port from optparse to argparse
Why now?

* argparse was introduced in Python 3.2 and back-ported to Python 2.7.
  Until we dropped Python 2.6 support, we were stuck on optparse.

* keystoneauth.loading.cli provides register_argparse_arguments and
  load_from_argparse_arguments helper methods. Now that we're moving
  toward Keystone Session support, argparse seems required.

Closes-Bug: 1553030
Change-Id: I5139fb64a8631a3010680090fd04345f95c55c7b
2016-04-06 14:20:27 -07:00
Tim Burke
f86b2d8138 Clean up some unnecessary variables
Change-Id: Iac93ced6344d4a6fee7e6390e891fde765814c03
2016-03-24 13:06:42 -07:00
Marek Kaleta
51a8a5a7ae Fix SwiftPostObject options usage in SwiftService
SwiftService().post(cont, [SwiftPostObject(obj, options]) currently
ignores options['header'], raises exception when options['headers']
is set and make malformed metadata when options['meta'] is set.

Fix tipos in code, add unittest for SwiftService().post
Closes-Bug: #1560052

Change-Id: Ie460f753492e9b73836b4adfc7c9c0f2130a8a91
2016-03-23 15:38:10 +01:00
Jenkins
39e017d807 Merge "Initialize delete_object mock *before* creating all the threads" 2016-03-18 10:43:09 +00:00
Tim Burke
d2bd2f0859 Initialize delete_object mock *before* creating all the threads
Previously, we'd occasionally get spurious failures like

    FAIL: test_delete_account (tests.unit.test_shell.TestShell)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File ".../mock/mock.py", line 1721, in _inner
        return f(*args, **kw)
      File ".../mock/mock.py", line 1305, in patched
        return func(*args, **keywargs)
      File ".../tests/unit/test_shell.py", line 788, in test_delete_account
        response_dict={})], any_order=True)
      File ".../mock/mock.py", line 983, in assert_has_calls
        ), cause)
      File ".../six.py", line 718, in raise_from
        raise value
    AssertionError: (call(u'container', u'object', query_string=None,
                          response_dict={}),)
    not all found in call list

Related-Bug: #1539536
Related-Bug: #1480223
Change-Id: I810894545ca74d3b2f2dbde2d0388eb69c2ba710
2016-03-17 15:43:45 -07:00
Jenkins
c4ce65f2d2 Merge "Include response headers in ClientExceptions" 2016-03-17 22:20:35 +00:00
Tim Burke
f5224a696e Add tests for thread option validation
Change-Id: If84714c7ea6be1c95c5898a82db2d4b6c9637242
2016-03-17 12:39:44 -07:00
Min Min Ren
965fd4d3fc Initialise delete_object mock before it's called
Fix the linked bug. delete_object mock should be before it's
called by swiftclient.shell.main function.
Related: https://review.openstack.org/221219

Change-Id: I52143a93c129764c02bba05267f3563c824e82cb
Partial-Bug: #1480223
2016-03-05 03:05:23 +08:00
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
c023893dd3 Merge "download method shouldn't download all object" 2016-03-02 11:15:11 +00:00
Jenkins
cd3a4dbf0a Merge "Drop testtools from test-requirements.txt" 2016-03-01 17:51:32 +00:00
Hu Bing
b7d20b8a18 download method shouldn't download all object
in python-swiftclient/swiftclient/service.py,
there is a method
def download(self, container=None, objects=None, options=None):

if container is specified but objects not, it download all
objects in specified container.
if both container and objects are specified, it download all
specified objects in the container.

when it comes to the case that, objects argument is specified,
but it turned out to be empty array [ ], the download method
download all the objects under specified container.
this may be not reasonable.

for example,
the objects was not empty when it came from command line,
but it's filtered, maybe by --prefix argument.
at last, it turned out to be empty array.

when calling download method with objects arguments
being empty array, we should download nothing instead of
all the objects under the specified container.

Change-Id: I81aab935533a50b40679c8b3575f298c285233a8
Closes-bug: #1549881
2016-03-01 03:10:34 +08:00
Jenkins
b040ce4e1a Merge "Fix wrong args for get_container with full listing" 2016-02-29 16:26:58 +00:00
Jenkins
ba2ff4a6ea Merge "Force header keys/values to bytes/unicode before coercing to unicode" 2016-02-27 01:44:38 +00:00
Tim Burke
aa0edd0096 Force header keys/values to bytes/unicode before coercing to unicode
Previously, parse_header_string was only called with data coming out of
requests, which would be either bytes or unicode. Now that we're sending
it request headers as well (see related change), we need to be more
defensive.

If the value given is neither bytes nor unicode, convert it to a native
string. This will allow developers using the client API to continue
sending header dicts like

  {'X-Delete-After': 2}

...as in Swift's test/probe/test_object_expirer.py

Change-Id: Ie57a93274507b184af5cad4260f244359a585f09
Related-Change: I43dd7254f7281d4db59b286aa2145643c64e1705
2016-02-26 11:25:10 -08:00
Joel Wright
46d8178280 Fix test for redacting sensitive data in client.http_log()
The test should have included utf8 encoded unicode data to
test that encoded unicode data stored in headers was parsed
correctly.

Also fixes the docstring for swiftclient.safe_value()

Change-Id: Id0def0b3af7a364f1257cc22f67b71c0cc5d8479
2016-02-26 11:36:45 +00:00
Tim Burke
c3f0641704 Follow-up to patch 282363
* Improve some formatting
* Be more explicit about how much will be revealed when
* Rename redact_sensitive_tokens to redact_sensitive_headers, as it
  affects more than tokens.

Change-Id: I02b375d914e9f0a210d038ecb31188d09a8ffce3
2016-02-25 10:06:48 -08:00
Joel Wright
4d44dcf360 Do not reveal auth token in swiftclient log messages by default
Currently the swiftclient logs sensitive info in headers when logging
HTTP requests. This patch hides sensitive info in headers such as
'X-Auth-Token' in a similar way to swift itself (we add a
'reveal_sensitive_prefix' configuration to the client).

With this patch, tokens are truncated by removing the specified number
of characters, after which '...' is appended to the logged token to
indicate that it has been redacted.

Co-Authored-By: Li Cheng <shcli@cn.ibm.com>
Co-Authored-By: Zack M. Davis <zdavis@swiftstack.com>
Change-Id: I43dd7254f7281d4db59b286aa2145643c64e1705
Closes-bug: #1516692
2016-02-22 17:55:51 +00:00
Alistair Coles
67f5468ee4 Fix wrong args for get_container with full listing
In client get_container(), when full_listing is true,
the calls back to get_container() pass service_token
as a positional arg which maps its value to the
full_listing arg. It should use a keyword.

Change-Id: Iac2af45df124ff33fcb7fbaf1ba959ef06c96378
Closes-Bug: #1496093
2016-02-22 15:22:44 +00:00
Jenkins
da0aa24f28 Merge "_RetryBody doesn't need to take explicit etag/content-length" 2016-02-18 23:40:51 +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
8918c292d7 Merge "more tests for pseudo/dir" 2016-02-10 19:56:27 +00:00
Jenkins
50f3396620 Merge "Fix segmented upload to pseudo-dir via <container>" 2016-02-10 19:55:30 +00:00
Jenkins
84d110c63e Merge "Accept token and tenant_id for authenticating against KS" 2016-02-10 19:39:53 +00:00
Clay Gerrard
9a97b51c0c more tests for pseudo/dir
Change-Id: Idab172aefd8e69ca8e4d623918eba1bc1da91a42
2016-02-09 13:15:22 -08: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
Jenkins
fee68f7324 Merge "Don't trust X-Object-Meta-Mtime" 2016-02-01 17:43:03 +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
Jenkins
e5f058e27e Merge "Tighten up to unittests to expect rounding" 2016-02-01 10:09:07 +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
Clay Gerrard
34ae109173 Tighten up to unittests to expect rounding
Change-Id: Ic453fd990ebbf17e0eeabc39b126d2bc14234e23
2016-01-29 19:27:11 -08:00
Tim Burke
337570a03a Don't trust X-Object-Meta-Mtime
Still use it if we can, but stop throwing ValueErrors if it's garbage.

Change-Id: I2cf25b535ad62cfacb7561954a92a4a73d91000a
2016-01-29 16:50:15 -08:00
Jenkins
6f431ee065 Merge "Prevent test runs from cluttering current directory" 2016-01-29 12:26:13 +00:00
Ondřej Nový
0fe02eb1c0 mock time in unit test
It's crashing now (sometimes):

_StringException: Traceback (most recent call last):
  File "/build/python-swiftclient-2.6.0/tests/unit/test_service.py", line 1085, in test_upload_object_job_stream
    self.assertAlmostEqual(mtime, expected_mtime, delta=0.5)
  File "/usr/lib/python3/dist-packages/unittest2/case.py", line 883, in assertAlmostEqual
    raise self.failureException(msg)
AssertionError: 1453224313.0 != 1453224312.4944572 within 0.5 delta

Change-Id: Ib2eeb13cd07febcb7c8b4e1435b885c4339093e4
2016-01-29 00:18:28 +01:00