53 Commits

Author SHA1 Message Date
Tim Burke
668242c422 pep8: Turn on E305
Change-Id: Ia968ec7375ab346a2155769a46e74ce694a57fc2
2020-04-03 21:22:38 +02:00
Tim Burke
3f88907012 sharding: Better-handle newlines in container names
Previously, if you were on Python 2.7.10+ [0], such a newline would cause the
sharder to fail, complaining about invalid header values when trying to create
the shard containers. On older versions of Python, it would most likely cause a
parsing error in the container-server that was trying to handle the PUT.

Now, quote all places that we pass around container paths. This includes:

  * The X-Container-Sysmeta-Shard-(Quoted-)Root sent when creating the (empty)
    remote shards
  * The X-Container-Sysmeta-Shard-(Quoted-)Root included when initializing the
    local handoff for cleaving
  * The X-Backend-(Quoted-)Container-Path the proxy sends to the object-server
    for container updates
  * The Location header the container-server sends to the object-updater

Note that a new header was required in requests so that servers would
know whether the value should be unquoted or not. We can get away with
reusing Location in responses by having clients opt-in to quoting with
a new X-Backend-Accept-Quoted-Location header.

During a rolling upgrade,

  * old object-servers servicing requests from new proxy-servers will
    not know about the container path override and so will try to update
    the root container,
  * in general, object updates are more likely to land in the root
    container; the sharder will deal with them as misplaced objects, and
  * shard containers created by new code on servers running old code
    will think they are root containers until the server is running new
    code, too; during this time they'll fail the sharder audit and report
    stats to their account, but both of these should get cleared up upon
    upgrade.

Drive-by: fix a "conainer_name" typo that prevented us from testing that
we can shard a container with unicode in its name. Also, add more UTF8
probe tests.

[0] See https://bugs.python.org/issue22928

Change-Id: Ie08f36e31a448a547468dd85911c3a3bc30e89f1
Closes-Bug: 1856894
2020-01-03 16:04:57 -08:00
Pete Zaitcev
575538b55b py3: port the container
This started with ShardRanges and its CLI. The sharder is at the
bottom of the dependency chain. Even container backend needs it.
Once we started tinkering with the sharder, it all snowballed to
include the rest of the container services.

Beware, this does affect some of Python 2 code. Mostly it's trivial
and obviously correct, but needs checking by reviewers.

About killing the stray "from __future__ import unicode_literals":
we do not do it in general. The specific problem it caused was
a failure of functional tests because unicode leaked into a field
that was supposed to be encoded. It is just too hard to track the
types when rules change from file to file, so off with its head.

Change-Id: Iba4e65d0e46d8c1f5a91feb96c2c07f99ca7c666
2019-02-20 21:30:46 -06:00
Tim Burke
3420921a33 Clean up HASH_PATH_* patching
Previously, we'd sometimes shove strings into HASH_PATH_PREFIX or
HASH_PATH_SUFFIX, which would blow up on py3. Now, always use bytes.

Change-Id: Icab9981e8920da505c2395eb040f8261f2da6d2e
2018-11-01 20:52:33 +00:00
Zuul
fc9b9e55c5 Merge "container-updater: Always report zero objects/bytes used for shards" 2018-06-22 21:45:56 +00:00
Tim Burke
5652dec43b container-updater: Always report zero objects/bytes used for shards
Otherwise, a sharded container AUTH_test/sharded will have its stats
included in the totals for both AUTH_test *and* .shards_AUTH_test

Co-Authored-By: Alistair Coles <alistairncoles@gmail.com>
Change-Id: I7fa74e13347601c5f44fd7e6cf65656cc3ebc2c5
2018-06-22 10:35:36 +01:00
Tim Burke
f192f51d37 Have check_drive raise ValueError on errors
...which helps us differentiate between a drive that's not mounted vs.
not a dir better in log messages. We were already doing that a bit in
diskfile.py, and it seems like a useful distinction; let's do it more.

While we're at it, remove some log translations.

Related-Change: I941ffbc568ebfa5964d49964dc20c382a5e2ec2a
Related-Change: I3362a6ebff423016bb367b4b6b322bb41ae08764
Change-Id: Ife0d34f9482adb4524d1ab1fe6c335c6b287c2fd
Partial-Bug: 1674543
2018-06-20 17:15:07 -07:00
Zuul
56aeb20f98 Merge "container-updater: log LockTimeout exceptions at INFO, not ERROR" 2018-05-30 18:14:54 +00:00
Samuel Merritt
a954f59f4c container-updater: log LockTimeout exceptions at INFO, not ERROR
Lock timeouts happen, especially on very busy containers. It's not
worth a stack trace, and it's not an error. Now we still log the
lock timeout, but at INFO level and without a stack trace.

Change-Id: Ia202c876fb726f9ae6040d875a83105dd975539b
2018-05-29 17:38:19 -07:00
Tim Burke
31623f740b Catch and log errors from process_container, then keep updating
Previously, we'd bomb out hard, and you'd get no more container updates.

Change-Id: I0cea6018269d172bc758eec6348329d1f65de028
Related-Bug: 1400939
2018-05-29 10:42:31 -07:00
Hu Bing
4189a117d2 catch lock fail exception in container updater
in process of container update, when locking one container failed,
container updater stops with LockTimeout exception.

it's better for updater server to continue processing
other containers, partitions instead of stop updating.

this path is to catch timeout exception and log it,
then continue processing other containers and partitions.

Closes-bug: #1400939

Change-Id: I42adec07d980be22044a5d4ef6771318a3eed168
2018-05-29 10:42:31 -07:00
Clay Gerrard
feee399840 Use check_drive consistently
We added check_drive to the account/container servers to unify how all
the storage wsgi servers treat device dirs/mounts.  Thus pushes that
unification down into the consistency engine.

Drive-by:
 * use FakeLogger less
 * clean up some repeititon in probe utility for device re-"mounting"

Related-Change-Id: I3362a6ebff423016bb367b4b6b322bb41ae08764
Change-Id: I941ffbc568ebfa5964d49964dc20c382a5e2ec2a
2017-11-01 16:33:40 +00:00
Jenkins
2d18ecdf4b Merge "Replace slowdown option with *_per_second option" 2017-06-22 01:18:26 +00:00
Ondřej Nový
a8bc94c7e3 Replace slowdown option with *_per_second option
container and object updaters sleeps "slowdown" (default 0.01) seconds
after every processed container/object. Because time.sleep call adds overhead,
use ratelimit_sleep from common.utils instead. Same as in auditor.

Change-Id: I362aa0f13c78ad03ce1f76ee0257b0646f981212
2017-06-16 19:22:00 +00:00
Pete Zaitcev
5dfc3a75fb Open-code eventlet.listen()
Recently out gate started blowing up intermittently with a strange
case of ports mixed up. Sometimes a functional tests tries to
authorize on a port that's clearly an object server port, and
the like. As it turns out, eventlet developers added an unavoidable
SO_REUSEPORT into listen(), which makes listen(("localhost",0)
to reuse ports.

There's an issue about it:
 https://github.com/eventlet/eventlet/issues/411

This patch is working around the problem while eventlet people
consider the issue.

Change-Id: I67522909f96495a6a30e1acdb79835dce2189549
2017-05-11 01:39:14 -06:00
Cao Xuan Hoang
d4da920d9b Use assertGreater(len(x), 0) instead of assertTrue(len(x) > 0)
assertGreater provides a nicer error message if it fails.

Change-Id: I5b045042b5991280a5b6a12ccde09fa733a19e26
2016-12-08 15:45:24 +07:00
zheng yin
f3be45c059 Simplify container_updater test code
This patch simplifies the container_updater unit test code by
refactoring the creation of the continer_updater into a helper method.
This method by default will use a default configuration. However
this configuration can be changed by passing in a dictionary of
configuration elements to update, for example:

    self._get_container_updater({'mount_check': 'true'})

Change-Id: Ide211d559bf9381c520a04cd90d278d9b2beae50
2016-10-12 13:14:39 +08:00
Alistair Coles
5d8d2e98ee Minor improvement to updater unit tests
Follow up for change I7c57bba053711a27d3802efe6f2a0bf53483a54f

The current tests won't prevent this kind of regression in the
updaters' __init__ methods:

  self.node_timeout = int(float(conf.get('node_timeout', 10)))

so this makes them a little tighter.

Change-Id: I60bd79ac392deb1e8a108357d48474dddd9028c1
2015-10-23 16:38:24 +01:00
Lisak, Peter
b6b7578190 node_timeout as float in configs
It is more convenient to use float node_timeout for fine tunning latency.

Change-Id: I7c57bba053711a27d3802efe6f2a0bf53483a54f
2015-10-19 21:14:34 +02:00
Christian Schwede
58fcc07523 Test if container_sweep is executed on unmounted devices
This change ensures that container_sweep is not run if a device is not mounted
and mount_check is set to True.

Change-Id: I823083c8431d9e61fd426508033ec9188503957b
2015-09-02 10:53:09 +00:00
Bill Huber
5b01c5eadc Add unit test for container_update for unmounted device
This unit test case gains coverage for container/update.py
where a device (i.e. sda1) is not mounted and the code
responds with a warning logger that the device is not
mounted and continues.  Coverage increases 2% as a result.

Change-Id: I33d247a930b28604093df4ade1ce7dbbd24aac54
2015-08-18 17:43:26 -05:00
janonymous
ed3aec2146 pep8 fix: assertEquals -> assertEqual
assertEquals is deprecated in py3 in
dir: test/unit/container/*

Change-Id: I3333022ed63ce03198bc73147246d91d2442a440
2015-08-06 00:18:52 +05:30
Jenkins
e7205fd7d6 Merge "cPickle is deprecated in py3, replacing it from six.moves" 2015-07-28 12:33:24 +00:00
janonymous
cd7b2db550 unit tests: Replace "self.assert_" by "self.assertTrue"
The assert_() method is deprecated and can be safely replaced by assertTrue().
This patch makes sure that running the tests does not create undesired
warnings.

Change-Id: I0602ba39ef93263386644ee68088d5f65fcb4a71
2015-07-21 19:23:00 +05:30
janonymous
c907107fe4 cPickle is deprecated in py3, replacing it from six.moves
cPickle is deprecated and should be replaced with six.moves
to provide py2 and py3 compatibility.

Change-Id: Ibad990708722360d188c641e61444d50a16a1e93
2015-07-07 22:46:37 +05:30
Victor Stinner
e5c962a28c Replace xrange() with six.moves.range()
Patch generated by the xrange operation of the sixer tool:
https://pypi.python.org/pypi/sixer

Manual changes:

* Fix indentation for pep8 checks
* Fix TestGreenthreadSafeIterator.test_access_is_serialized of
  test.unit.common.test_utils:
  replace range(1, 11) with list(range(1, 11))
* Fix UnsafeXrange docstring, revert change

Change-Id: Icb7e26135c5e57b5302b8bfe066b33cafe69fe4d
2015-06-23 07:29:15 +00:00
Jay S. Bryant
8cc075a8fb mock out os.listdir to return a list
os.listdir returns a list of items.  The test case had been
written to return a single item which, though not really changing
the result of the test, was not the best approach.

This patch updates the test case to return a list instead of a single
item.

Change-Id: I793e0636440c0de0ca339c6592adec3e8b4ee1b4
2014-11-20 16:45:22 -06:00
Jay S. Bryant
d895cea07f Handle os.listdir failures in container-updater
While investigating bug 1375348 I discovered the problem
reported there was not limited to the object-auditor.  The
container-updated has similar bugs.

This patch catches the unhandled exception that can be thrown by
os.listdir.

Change-Id: I7eed122bf6b663e6e7894ace136b6f4653db4985
Related-bug: 1375348
2014-10-27 17:27:14 -05:00
Clay Gerrard
4321bb0af6 Add Storage Policy support to Containers
Containers now have a storage policy index associated with them,
stored in the container_stat table. This index is only settable at
container creation time (PUT request), and cannot be changed without
deleting and recreating the container. This is because a container's
policy index will apply to all its objects, so changing a container's
policy index would require moving large amounts of object data
around. If a user wants to change the policy for data in a container,
they must create a new container with the desired policy and move the
data over.

Keep status_changed_at up-to-date with status changes.

In particular during container recreation and replication.

When a container-server receives a PUT for a deleted database an extra UPDATE
is issued against the container_stat table to notate the x-timestamp of the
request.

During replication if merge_timestamps causes a container's status to change
(from DELETED to ACTIVE or vice-versa) the status_changed_at field is set to
the current time.

Accurate reporting of status_changed_at is useful for container replication
forensics and allows resolution of "set on create" attributes like the
upcoming storage_policy_index.

Expose Backend container info on deleted containers.

Include basic container info in backend headers on 404 responses from the
container server.  Default empty values are used as placeholders if the
database does not exist.

Specifically the X-Backend-Status-Changed-At, X-Backend-DELETE-Timestamp and
the X-Backend-Storage-Policy-Index value will be needed by the reconciler to
deal with reconciling out of order object writes in the face of recently
deleted containers.

 * Add "status_changed_at" key to the response from ContainerBroker.get_info.
 * Add "Status Timestamp" field to swift.cli.info.print_db_info_metadata.
 * Add "status_changed_at" key to the response from AccountBroker.get_info.

DocImpact
Implements: blueprint storage-policies
Change-Id: Ie6d388f067f5b096b0f96faef151120ba23c8748
2014-06-18 17:31:38 -07:00
Pete Zaitcev
a7cfcc3d7a Relocate DATADIR to backends
It simply makes sense that the definition of DATADIR belongs to
backends. After all, some of them may not even have any.

Coincidentially, a few unnecessary imports are dropped.

By the way, on the object server side, diskfile.py provides DATADIR
in the same way already.

Change-Id: I60bfd522c77c4a0ee13697a2e31141777c7e2398
2014-04-01 23:22:22 -06:00
Peter Portante
9411a24ba7 Revert "Refactor common/utils methods to common/ondisk"
This reverts commit 7760f41c3ce436cb23b4b8425db3749a3da33d32

Change-Id: I95e57a2563784a8cd5e995cc826afeac0eadbe62
Signed-off-by: Peter Portante <peter.portante@redhat.com>
2013-10-07 17:18:09 -04:00
ZhiQiang Fan
f72704fc82 Change OpenStack LLC to Foundation
Change-Id: I7c3df47c31759dbeb3105f8883e2688ada848d58
Closes-bug: #1214176
2013-09-20 01:02:31 +08:00
Peter Portante
7760f41c3c Refactor common/utils methods to common/ondisk
Place all the methods related to on-disk layout and / or configuration
into a new common module that can be shared by the various modules
using the same on-disk layout.

Change-Id: I27ffd4665d5115ffdde649c48a4d18e12017e6a9
Signed-off-by: Peter Portante <peter.portante@redhat.com>
2013-09-17 17:32:04 -04:00
Pete Zaitcev
d4b024ad7d Split backends off swift/common/db.py
The main purpose of this patch is to lay the groundwork for allowing
the container and account servers to optionally use pluggable backend
implementations. The backend.py files will eventually be the module
where the backend APIs are defined via docstrings of this reference
implementation. The swift/common/db.py module will remain an internal
module used by the reference implementation.

We have a raft of changes to docstrings staged for later, but this
patch takes care to relocate ContainerBroker and AccountBroker into
their new home intact.

Change-Id: Ibab5c7605860ab768c8aa5a3161a705705689b04
2013-09-10 13:30:28 -06:00
Dirk Mueller
3d36a76156 Use Python 3.x compatible except construct
except x,y: was deprected and is removed in Python 3.x.
Use "except x as y:" instead which works in any Python
version >= 2.6.

Change-Id: I7008c74b807340f3457d3a0c8bd0b83f23169d14
2013-09-07 10:50:54 +02:00
Peter Portante
be1cff4f1f Pep8 unit test modules w/ <= 10 violations (5 of 12)
Change-Id: I8e82c14ada52d44df5a31e08982ac79cd7e5c969
Signed-off-by: Peter Portante <peter.portante@redhat.com>
2013-09-01 15:12:48 -04:00
Alex Gaynor
c1f8f266d0 Ensure that files in tests are closed.
This is needed on Pythons which do not have
reference counting GCs (e.g. PyPy).

Change-Id: I5a613e832e9a7a149b3e9317c053c3048f34afcb
2013-07-20 16:08:53 -07:00
Greg Lange
44f00a23c1 fixed some minor things in tests that pyflakes complained about
Change-Id: Ifeab56a964630bcf941e932fcbe39e6572e62975
2013-03-26 20:42:26 +00:00
David Hadas
a979c8007b Add support for Hash Prefix
A new configuration parameter is added to /etc/swift/swift.conf
[swift-hash]
swift_hash_path_prefix = 'random unique string'

New installations are advised to set this parameter to a random secret,
which would not be disclosed ouside the organization.
The same secret needs to be used by all swift servers of the same cluster.

Existing installations should set this parameter to an empty string
(the default)

DocImpact

Fixes: Bug #1157454

Change-Id: I63b10d0b7d6dd3f74e0f10bb41b5f240fa03578a
2013-03-22 19:41:55 +02:00
John Dickinson
1ecf5ebba1 updated copyright date for all files
Change-Id: Ifd909d3561c2647770a7e0caa3cd91acd1b4f298
2012-03-19 13:45:34 -05:00
gholt
dd839048f1 Updated TimeoutError and except Exception refs...
Updated eventlet.TimeoutError (deprecated) references to
Timeout and, more importantly, updated many except Exception
clauses to except (Exception, Timeout).

Change-Id: Ib089265551bd20b94c00ea84f11140ccd795d301
2011-11-07 16:26:03 +00:00
gholt
d41e77417c Merge from trunk 2011-01-25 15:24:09 -08:00
gholt
cc00bd40e0 Fix tests to cleanup their /tmp dirs 2011-01-24 17:12:38 -08:00
gholt
217198b83b container-updater: temporrar account update suppression on errors 2011-01-21 12:43:50 -08:00
Clay Gerrard
e784f1c3a4 obsolete PATH_TO_TEST_XFS 2011-01-20 00:31:55 +00:00
gholt
9dd1e2ae84 Updates to remove _ usage that is not i18n related 2011-01-19 15:21:57 -08:00
Clay Gerrard
105315dfc4 obsolete PATH_TO_TEST_XFS 2011-01-19 14:18:37 -06:00
Anne Gentle
8823427161 Changed copyright notices on py files and the single rst file with a copyright notice 2011-01-04 17:34:43 -06:00
gholt
57970bdeb5 Cleaned up the bins; patched the broken test (when run standalone) 2010-12-29 12:00:08 -08:00
Chuck Thier
158e6c3ae9 refactored bins to by more DRY 2010-08-31 23:12:59 +00:00