swift 2.33.0__py2.py3-none-any.whl → 2.34.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. swift/account/auditor.py +11 -0
  2. swift/account/reaper.py +11 -1
  3. swift/account/replicator.py +22 -0
  4. swift/account/server.py +12 -1
  5. swift-2.33.0.data/scripts/swift-account-audit → swift/cli/account_audit.py +6 -2
  6. swift-2.33.0.data/scripts/swift-config → swift/cli/config.py +1 -1
  7. swift-2.33.0.data/scripts/swift-dispersion-populate → swift/cli/dispersion_populate.py +6 -2
  8. swift-2.33.0.data/scripts/swift-drive-audit → swift/cli/drive_audit.py +12 -3
  9. swift-2.33.0.data/scripts/swift-get-nodes → swift/cli/get_nodes.py +6 -2
  10. swift/cli/info.py +103 -2
  11. swift-2.33.0.data/scripts/swift-oldies → swift/cli/oldies.py +6 -3
  12. swift-2.33.0.data/scripts/swift-orphans → swift/cli/orphans.py +7 -2
  13. swift/cli/recon_cron.py +5 -5
  14. swift-2.33.0.data/scripts/swift-reconciler-enqueue → swift/cli/reconciler_enqueue.py +2 -3
  15. swift/cli/relinker.py +1 -1
  16. swift/cli/ringbuilder.py +24 -0
  17. swift/common/db.py +2 -1
  18. swift/common/db_auditor.py +2 -2
  19. swift/common/db_replicator.py +6 -0
  20. swift/common/exceptions.py +12 -0
  21. swift/common/manager.py +102 -0
  22. swift/common/memcached.py +6 -13
  23. swift/common/middleware/account_quotas.py +144 -43
  24. swift/common/middleware/backend_ratelimit.py +166 -24
  25. swift/common/middleware/catch_errors.py +1 -3
  26. swift/common/middleware/cname_lookup.py +3 -5
  27. swift/common/middleware/container_sync.py +6 -10
  28. swift/common/middleware/crypto/crypto_utils.py +4 -5
  29. swift/common/middleware/crypto/decrypter.py +4 -5
  30. swift/common/middleware/crypto/kms_keymaster.py +2 -1
  31. swift/common/middleware/proxy_logging.py +22 -16
  32. swift/common/middleware/ratelimit.py +6 -7
  33. swift/common/middleware/recon.py +6 -7
  34. swift/common/middleware/s3api/acl_handlers.py +9 -0
  35. swift/common/middleware/s3api/controllers/multi_upload.py +1 -9
  36. swift/common/middleware/s3api/controllers/obj.py +20 -1
  37. swift/common/middleware/s3api/s3api.py +2 -0
  38. swift/common/middleware/s3api/s3request.py +171 -62
  39. swift/common/middleware/s3api/s3response.py +35 -6
  40. swift/common/middleware/s3api/s3token.py +2 -2
  41. swift/common/middleware/s3api/utils.py +1 -0
  42. swift/common/middleware/slo.py +153 -52
  43. swift/common/middleware/tempauth.py +6 -4
  44. swift/common/middleware/tempurl.py +2 -2
  45. swift/common/middleware/x_profile/exceptions.py +1 -4
  46. swift/common/middleware/x_profile/html_viewer.py +9 -10
  47. swift/common/middleware/x_profile/profile_model.py +1 -2
  48. swift/common/middleware/xprofile.py +1 -2
  49. swift/common/request_helpers.py +69 -0
  50. swift/common/statsd_client.py +207 -0
  51. swift/common/utils/__init__.py +97 -1635
  52. swift/common/utils/base.py +138 -0
  53. swift/common/utils/config.py +443 -0
  54. swift/common/utils/logs.py +999 -0
  55. swift/common/wsgi.py +11 -3
  56. swift/container/auditor.py +11 -0
  57. swift/container/backend.py +10 -10
  58. swift/container/reconciler.py +11 -2
  59. swift/container/replicator.py +22 -1
  60. swift/container/server.py +12 -1
  61. swift/container/sharder.py +36 -12
  62. swift/container/sync.py +11 -1
  63. swift/container/updater.py +11 -2
  64. swift/obj/auditor.py +18 -2
  65. swift/obj/diskfile.py +8 -6
  66. swift/obj/expirer.py +155 -36
  67. swift/obj/reconstructor.py +28 -4
  68. swift/obj/replicator.py +61 -22
  69. swift/obj/server.py +64 -36
  70. swift/obj/updater.py +11 -2
  71. swift/proxy/controllers/base.py +38 -22
  72. swift/proxy/controllers/obj.py +23 -26
  73. swift/proxy/server.py +15 -1
  74. {swift-2.33.0.dist-info → swift-2.34.0.dist-info}/AUTHORS +11 -3
  75. {swift-2.33.0.dist-info → swift-2.34.0.dist-info}/METADATA +6 -5
  76. {swift-2.33.0.dist-info → swift-2.34.0.dist-info}/RECORD +81 -107
  77. {swift-2.33.0.dist-info → swift-2.34.0.dist-info}/entry_points.txt +38 -0
  78. swift-2.34.0.dist-info/pbr.json +1 -0
  79. swift-2.33.0.data/scripts/swift-account-auditor +0 -23
  80. swift-2.33.0.data/scripts/swift-account-info +0 -52
  81. swift-2.33.0.data/scripts/swift-account-reaper +0 -23
  82. swift-2.33.0.data/scripts/swift-account-replicator +0 -34
  83. swift-2.33.0.data/scripts/swift-account-server +0 -23
  84. swift-2.33.0.data/scripts/swift-container-auditor +0 -23
  85. swift-2.33.0.data/scripts/swift-container-info +0 -59
  86. swift-2.33.0.data/scripts/swift-container-reconciler +0 -21
  87. swift-2.33.0.data/scripts/swift-container-replicator +0 -34
  88. swift-2.33.0.data/scripts/swift-container-server +0 -23
  89. swift-2.33.0.data/scripts/swift-container-sharder +0 -37
  90. swift-2.33.0.data/scripts/swift-container-sync +0 -23
  91. swift-2.33.0.data/scripts/swift-container-updater +0 -23
  92. swift-2.33.0.data/scripts/swift-dispersion-report +0 -24
  93. swift-2.33.0.data/scripts/swift-form-signature +0 -20
  94. swift-2.33.0.data/scripts/swift-init +0 -119
  95. swift-2.33.0.data/scripts/swift-object-auditor +0 -29
  96. swift-2.33.0.data/scripts/swift-object-expirer +0 -33
  97. swift-2.33.0.data/scripts/swift-object-info +0 -60
  98. swift-2.33.0.data/scripts/swift-object-reconstructor +0 -33
  99. swift-2.33.0.data/scripts/swift-object-relinker +0 -23
  100. swift-2.33.0.data/scripts/swift-object-replicator +0 -37
  101. swift-2.33.0.data/scripts/swift-object-server +0 -27
  102. swift-2.33.0.data/scripts/swift-object-updater +0 -23
  103. swift-2.33.0.data/scripts/swift-proxy-server +0 -23
  104. swift-2.33.0.data/scripts/swift-recon +0 -24
  105. swift-2.33.0.data/scripts/swift-recon-cron +0 -24
  106. swift-2.33.0.data/scripts/swift-ring-builder +0 -37
  107. swift-2.33.0.data/scripts/swift-ring-builder-analyzer +0 -22
  108. swift-2.33.0.data/scripts/swift-ring-composer +0 -22
  109. swift-2.33.0.dist-info/pbr.json +0 -1
  110. {swift-2.33.0.dist-info → swift-2.34.0.dist-info}/LICENSE +0 -0
  111. {swift-2.33.0.dist-info → swift-2.34.0.dist-info}/WHEEL +0 -0
  112. {swift-2.33.0.dist-info → swift-2.34.0.dist-info}/top_level.txt +0 -0
swift/account/auditor.py CHANGED
@@ -16,7 +16,9 @@
16
16
 
17
17
  from swift.account.backend import AccountBroker
18
18
  from swift.common.exceptions import InvalidAccountInfo
19
+ from swift.common.daemon import run_daemon
19
20
  from swift.common.db_auditor import DatabaseAuditor
21
+ from swift.common.utils import parse_options
20
22
 
21
23
 
22
24
  class AccountAuditor(DatabaseAuditor):
@@ -45,3 +47,12 @@ class AccountAuditor(DatabaseAuditor):
45
47
  'does not match the sum of %(key)s across policies (%(sum)s)'
46
48
  % {'key': key, 'account': info.get('account'),
47
49
  'total': info[key], 'sum': policy_totals[key]})
50
+
51
+
52
+ def main():
53
+ conf_file, options = parse_options(once=True)
54
+ run_daemon(AccountAuditor, conf_file, **options)
55
+
56
+
57
+ if __name__ == '__main__':
58
+ main()
swift/account/reaper.py CHANGED
@@ -27,6 +27,7 @@ import six
27
27
  import swift.common.db
28
28
  from swift.account.backend import AccountBroker, DATADIR
29
29
  from swift.common.constraints import check_drive
30
+ from swift.common.daemon import run_daemon
30
31
  from swift.common.direct_client import direct_delete_container, \
31
32
  direct_delete_object, direct_get_container
32
33
  from swift.common.exceptions import ClientException
@@ -34,7 +35,7 @@ from swift.common.request_helpers import USE_REPLICATION_NETWORK_HEADER
34
35
  from swift.common.ring import Ring
35
36
  from swift.common.ring.utils import is_local_device
36
37
  from swift.common.utils import get_logger, whataremyips, config_true_value, \
37
- Timestamp, md5, node_to_string
38
+ Timestamp, md5, node_to_string, parse_options
38
39
  from swift.common.daemon import Daemon
39
40
  from swift.common.storage_policy import POLICIES, PolicyError
40
41
 
@@ -525,3 +526,12 @@ class AccountReaper(Daemon):
525
526
  else:
526
527
  self.stats_objects_possibly_remaining += 1
527
528
  self.logger.increment('objects_possibly_remaining')
529
+
530
+
531
+ def main():
532
+ conf_file, options = parse_options(once=True)
533
+ run_daemon(AccountReaper, conf_file, **options)
534
+
535
+
536
+ if __name__ == '__main__':
537
+ main()
@@ -13,8 +13,12 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ import optparse
17
+
16
18
  from swift.account.backend import AccountBroker, DATADIR
17
19
  from swift.common import db_replicator
20
+ from swift.common.daemon import run_daemon
21
+ from swift.common.utils import parse_options
18
22
 
19
23
 
20
24
  class AccountReplicator(db_replicator.Replicator):
@@ -22,3 +26,21 @@ class AccountReplicator(db_replicator.Replicator):
22
26
  brokerclass = AccountBroker
23
27
  datadir = DATADIR
24
28
  default_port = 6202
29
+
30
+
31
+ def main():
32
+ parser = optparse.OptionParser("%prog CONFIG [options]")
33
+ parser.add_option('-d', '--devices',
34
+ help=('Replicate only given devices. '
35
+ 'Comma-separated list. '
36
+ 'Only has effect if --once is used.'))
37
+ parser.add_option('-p', '--partitions',
38
+ help=('Replicate only given partitions. '
39
+ 'Comma-separated list. '
40
+ 'Only has effect if --once is used.'))
41
+ conf_file, options = parse_options(parser=parser, once=True)
42
+ run_daemon(AccountReplicator, conf_file, **options)
43
+
44
+
45
+ if __name__ == '__main__':
46
+ main()
swift/account/server.py CHANGED
@@ -15,6 +15,7 @@
15
15
 
16
16
  import json
17
17
  import os
18
+ import sys
18
19
  import time
19
20
  import traceback
20
21
 
@@ -30,7 +31,7 @@ from swift.common.request_helpers import get_param, \
30
31
  from swift.common.utils import get_logger, hash_path, public, \
31
32
  Timestamp, storage_directory, config_true_value, \
32
33
  timing_stats, replication, get_log_line, \
33
- config_fallocate_value, fs_has_free_space
34
+ config_fallocate_value, fs_has_free_space, parse_options
34
35
  from swift.common.constraints import valid_timestamp, check_utf8, \
35
36
  check_drive, AUTO_CREATE_ACCOUNT_PREFIX
36
37
  from swift.common import constraints
@@ -43,6 +44,7 @@ from swift.common.swob import HTTPAccepted, HTTPBadRequest, \
43
44
  HTTPPreconditionFailed, HTTPConflict, Request, \
44
45
  HTTPInsufficientStorage, HTTPException, wsgi_to_str
45
46
  from swift.common.request_helpers import is_sys_or_user_meta
47
+ from swift.common.wsgi import run_wsgi
46
48
 
47
49
 
48
50
  def get_account_name_and_placement(req):
@@ -339,3 +341,12 @@ def app_factory(global_conf, **local_conf):
339
341
  conf = global_conf.copy()
340
342
  conf.update(local_conf)
341
343
  return AccountController(conf)
344
+
345
+
346
+ def main():
347
+ conf_file, options = parse_options(test_config=True)
348
+ sys.exit(run_wsgi(conf_file, 'account-server', **options))
349
+
350
+
351
+ if __name__ == '__main__':
352
+ main()
@@ -1,4 +1,4 @@
1
- #!python
1
+ #!/usr/bin/env python
2
2
  # Copyright (c) 2010-2012 OpenStack Foundation
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -359,7 +359,7 @@ class Auditor(object):
359
359
  _print_stat("MD5 Mismatch", self.object_checksum_mismatch)
360
360
 
361
361
 
362
- if __name__ == '__main__':
362
+ def main():
363
363
  try:
364
364
  optlist, args = getopt.getopt(sys.argv[1:], 'c:r:e:d')
365
365
  except getopt.GetoptError as err:
@@ -384,3 +384,7 @@ if __name__ == '__main__':
384
384
  auditor.audit(*split_path(path, 1, 3, True))
385
385
  auditor.wait()
386
386
  auditor.print_stats()
387
+
388
+
389
+ if __name__ == '__main__':
390
+ main()
@@ -1,4 +1,4 @@
1
- #!python
1
+ #!/usr/bin/env python
2
2
  # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # you may not use this file except in compliance with the License.
4
4
  # You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- #!python
1
+ #!/usr/bin/env python
2
2
  # Copyright (c) 2010-2012 OpenStack Foundation
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -81,7 +81,7 @@ def report(success):
81
81
  stdout.flush()
82
82
 
83
83
 
84
- if __name__ == '__main__':
84
+ def main():
85
85
  global begun, created, item_type, next_report, need_to_create, retries_done
86
86
  patcher.monkey_patch()
87
87
  try:
@@ -281,3 +281,7 @@ Usage: %%prog [options] [conf_file]
281
281
  print('\r\x1B[KTotal object coverage is now %.2f%%.' %
282
282
  ((float(obj_coverage) / object_ring.partition_count * 100)))
283
283
  stdout.flush()
284
+
285
+
286
+ if __name__ == '__main__':
287
+ main()
@@ -1,4 +1,4 @@
1
- #!python
1
+ #!/usr/bin/env python
2
2
  # Copyright (c) 2010-2012 OpenStack Foundation
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -147,7 +147,12 @@ def get_errors(error_re, log_file_pattern, minutes, logger,
147
147
  log_time = datetime.datetime.strptime(
148
148
  log_time_string, '%Y %b %d %H:%M:%S')
149
149
  except ValueError:
150
- continue
150
+ # Some versions use ISO timestamps instead
151
+ try:
152
+ log_time = datetime.datetime.strptime(
153
+ line[0:19], '%Y-%m-%dT%H:%M:%S')
154
+ except ValueError:
155
+ continue
151
156
  if log_time > end_time:
152
157
  for err in error_re:
153
158
  for device in err.findall(line):
@@ -174,7 +179,7 @@ def comment_fstab(mount_point):
174
179
  os.rename('/etc/fstab.new', '/etc/fstab')
175
180
 
176
181
 
177
- if __name__ == '__main__':
182
+ def main():
178
183
  c = ConfigParser()
179
184
  try:
180
185
  conf_path = sys.argv[1]
@@ -257,3 +262,7 @@ if __name__ == '__main__':
257
262
  elif os.path.isdir("/run/systemd/system"):
258
263
  logger.debug("fstab updated, calling systemctl daemon-reload")
259
264
  subprocess.call(["/usr/bin/systemctl", "daemon-reload"])
265
+
266
+
267
+ if __name__ == '__main__':
268
+ main()
@@ -1,4 +1,4 @@
1
- #!python
1
+ #!/usr/bin/env python
2
2
  # Copyright (c) 2010-2012 OpenStack Foundation
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,7 +25,7 @@ from swift.cli.info import (parse_get_node_args, print_item_locations,
25
25
  InfoSystemExit)
26
26
 
27
27
 
28
- if __name__ == '__main__':
28
+ def main():
29
29
 
30
30
  usage = '''
31
31
  Shows the nodes responsible for the item specified.
@@ -74,3 +74,7 @@ if __name__ == '__main__':
74
74
  print_item_locations(ring, ring_name, *args, **vars(options))
75
75
  except InfoSystemExit:
76
76
  sys.exit(1)
77
+
78
+
79
+ if __name__ == '__main__':
80
+ main()
swift/cli/info.py CHANGED
@@ -10,15 +10,21 @@
10
10
  # License for the specific language governing permissions and limitations
11
11
  # under the License.
12
12
 
13
+
13
14
  from __future__ import print_function
15
+ import codecs
14
16
  import itertools
15
17
  import json
18
+ from optparse import OptionParser
16
19
  import os
17
20
  import sqlite3
21
+ import sys
18
22
  from collections import defaultdict
19
23
 
24
+ import six
20
25
  from six.moves import urllib
21
26
 
27
+ from swift.common.exceptions import LockTimeout
22
28
  from swift.common.utils import hash_path, storage_directory, \
23
29
  Timestamp, is_valid_ipv6
24
30
  from swift.common.ring import Ring
@@ -29,10 +35,10 @@ from swift.account.backend import AccountBroker, DATADIR as ABDATADIR
29
35
  from swift.container.backend import ContainerBroker, DATADIR as CBDATADIR
30
36
  from swift.obj.diskfile import get_data_dir, read_metadata, DATADIR_BASE, \
31
37
  extract_policy
32
- from swift.common.storage_policy import POLICIES
38
+ from swift.common.storage_policy import POLICIES, reload_storage_policies
33
39
  from swift.common.swob import wsgi_to_str
34
40
  from swift.common.middleware.crypto.crypto_utils import load_crypto_meta
35
- from swift.common.utils import md5
41
+ from swift.common.utils import md5, set_swift_dir
36
42
 
37
43
 
38
44
  class InfoSystemExit(Exception):
@@ -713,3 +719,98 @@ def print_item_locations(ring, ring_name=None, account=None, container=None,
713
719
  print('Object \t%s\n\n' % urllib.parse.quote(obj))
714
720
  print_ring_locations(ring, loc, account, container, obj, part, all_nodes,
715
721
  policy_index=policy_index)
722
+
723
+
724
+ def obj_main():
725
+ if not six.PY2:
726
+ # Make stdout able to write escaped bytes
727
+ sys.stdout = codecs.getwriter("utf-8")(
728
+ sys.stdout.detach(), errors='surrogateescape')
729
+
730
+ parser = OptionParser('%prog [options] OBJECT_FILE')
731
+ parser.add_option(
732
+ '-n', '--no-check-etag', default=True,
733
+ action="store_false", dest="check_etag",
734
+ help="Don't verify file contents against stored etag")
735
+ parser.add_option(
736
+ '-d', '--swift-dir', default='/etc/swift', dest='swift_dir',
737
+ help="Pass location of swift directory")
738
+ parser.add_option(
739
+ '--drop-prefixes', default=False, action="store_true",
740
+ help="When outputting metadata, drop the per-section common prefixes")
741
+ parser.add_option(
742
+ '-P', '--policy-name', dest='policy_name',
743
+ help="Specify storage policy name")
744
+
745
+ options, args = parser.parse_args()
746
+
747
+ if len(args) != 1:
748
+ sys.exit(parser.print_help())
749
+
750
+ if set_swift_dir(options.swift_dir):
751
+ reload_storage_policies()
752
+
753
+ try:
754
+ print_obj(*args, **vars(options))
755
+ except InfoSystemExit:
756
+ sys.exit(1)
757
+
758
+
759
+ def run_print_info(db_type, args, opts):
760
+ try:
761
+ print_info(db_type, *args, **opts)
762
+ except InfoSystemExit:
763
+ sys.exit(1)
764
+ except (sqlite3.OperationalError, LockTimeout) as e:
765
+ if not opts.get('stale_reads_ok'):
766
+ opts['stale_reads_ok'] = True
767
+ print('Warning: Possibly Stale Data')
768
+ run_print_info(db_type, args, opts)
769
+ sys.exit(2)
770
+ else:
771
+ print('%s info failed: %s' % (db_type.title(), e))
772
+ sys.exit(1)
773
+
774
+
775
+ def container_main():
776
+ parser = OptionParser('%prog [options] CONTAINER_DB_FILE')
777
+ parser.add_option(
778
+ '-d', '--swift-dir', default='/etc/swift',
779
+ help="Pass location of swift directory")
780
+ parser.add_option(
781
+ '--drop-prefixes', default=False, action="store_true",
782
+ help="When outputting metadata, drop the per-section common prefixes")
783
+ parser.add_option(
784
+ '-v', '--verbose', default=False, action="store_true",
785
+ help="Show all shard ranges. By default, only the number of shard "
786
+ "ranges is displayed if there are many shards.")
787
+ parser.add_option(
788
+ '--sync', '-s', default=False, action="store_true",
789
+ help="Output the contents of the incoming/outging sync tables")
790
+
791
+ options, args = parser.parse_args()
792
+
793
+ if len(args) != 1:
794
+ sys.exit(parser.print_help())
795
+
796
+ run_print_info('container', args, vars(options))
797
+
798
+
799
+ def account_main():
800
+ parser = OptionParser('%prog [options] ACCOUNT_DB_FILE')
801
+ parser.add_option(
802
+ '-d', '--swift-dir', default='/etc/swift',
803
+ help="Pass location of swift directory")
804
+ parser.add_option(
805
+ '--drop-prefixes', default=False, action="store_true",
806
+ help="When outputting metadata, drop the per-section common prefixes")
807
+ parser.add_option(
808
+ '--sync', '-s', default=False, action="store_true",
809
+ help="Output the contents of the incoming/outging sync tables")
810
+
811
+ options, args = parser.parse_args()
812
+
813
+ if len(args) != 1:
814
+ sys.exit(parser.print_help())
815
+
816
+ run_print_info('account', args, vars(options))
@@ -1,4 +1,4 @@
1
- #!python
1
+ #!/usr/bin/env python
2
2
  # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # you may not use this file except in compliance with the License.
4
4
  # You may obtain a copy of the License at
@@ -12,13 +12,12 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from __future__ import print_function
16
15
  import optparse
17
16
  import subprocess
18
17
  import sys
19
18
 
20
19
 
21
- if __name__ == '__main__':
20
+ def main():
22
21
  parser = optparse.OptionParser(usage='''%prog [options]
23
22
 
24
23
  Lists old Swift processes.
@@ -88,3 +87,7 @@ Lists old Swift processes.
88
87
  for hours, pid, args in listing:
89
88
  print('%*s %*s %s' % (hours_len, hours, pid_len,
90
89
  pid, args[:args_len]))
90
+
91
+
92
+ if __name__ == '__main__':
93
+ main()
@@ -1,4 +1,4 @@
1
- #!python
1
+ #!/usr/bin/env python
2
2
  # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # you may not use this file except in compliance with the License.
4
4
  # You may obtain a copy of the License at
@@ -22,7 +22,8 @@ import sys
22
22
 
23
23
  from swift.common.manager import RUN_DIR
24
24
 
25
- if __name__ == '__main__':
25
+
26
+ def main():
26
27
  parser = optparse.OptionParser(usage='''%prog [options]
27
28
 
28
29
  Lists and optionally kills orphaned Swift processes. This is done by scanning
@@ -130,3 +131,7 @@ Example (sends SIGTERM to all orphaned Swift processes older than two hours):
130
131
  for hours, pid, args in listing:
131
132
  os.kill(int(pid), signum)
132
133
  print('Done.')
134
+
135
+
136
+ if __name__ == '__main__':
137
+ main()
swift/cli/recon_cron.py CHANGED
@@ -18,18 +18,18 @@ import time
18
18
  from eventlet import Timeout
19
19
 
20
20
  from swift.common.utils import get_logger, dump_recon_cache, readconf, \
21
- lock_path
21
+ lock_path, listdir
22
22
  from swift.common.recon import RECON_OBJECT_FILE, DEFAULT_RECON_CACHE_PATH
23
23
  from swift.obj.diskfile import ASYNCDIR_BASE
24
24
 
25
25
 
26
26
  def get_async_count(device_dir):
27
27
  async_count = 0
28
- for i in os.listdir(device_dir):
28
+ for i in listdir(device_dir):
29
29
  device = os.path.join(device_dir, i)
30
30
  if not os.path.isdir(device):
31
31
  continue
32
- for asyncdir in os.listdir(device):
32
+ for asyncdir in listdir(device):
33
33
  # skip stuff like "accounts", "containers", etc.
34
34
  if not (asyncdir == ASYNCDIR_BASE or
35
35
  asyncdir.startswith(ASYNCDIR_BASE + '-')):
@@ -37,10 +37,10 @@ def get_async_count(device_dir):
37
37
  async_pending = os.path.join(device, asyncdir)
38
38
 
39
39
  if os.path.isdir(async_pending):
40
- for entry in os.listdir(async_pending):
40
+ for entry in listdir(async_pending):
41
41
  if os.path.isdir(os.path.join(async_pending, entry)):
42
42
  async_hdir = os.path.join(async_pending, entry)
43
- async_count += len(os.listdir(async_hdir))
43
+ async_count += len(listdir(async_hdir))
44
44
  return async_count
45
45
 
46
46
 
@@ -1,4 +1,4 @@
1
- #!python
1
+ #!/usr/bin/env python
2
2
  # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # you may not use this file except in compliance with the License.
4
4
  # You may obtain a copy of the License at
@@ -11,12 +11,10 @@
11
11
  # implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
- from __future__ import print_function
15
14
  import sys
16
15
  from optparse import OptionParser
17
16
 
18
17
  import eventlet.debug
19
- eventlet.debug.hub_exceptions(True)
20
18
 
21
19
  from swift.common.ring import Ring
22
20
  from swift.common.utils import split_path
@@ -50,6 +48,7 @@ parser.add_option('-f', '--force', action='store_true',
50
48
 
51
49
 
52
50
  def main():
51
+ eventlet.debug.hub_exceptions(True)
53
52
  options, args = parser.parse_args()
54
53
  try:
55
54
  policy_index, path, timestamp = args
swift/cli/relinker.py CHANGED
@@ -743,7 +743,7 @@ def auto_or_int(value):
743
743
  return config_auto_int_value(value, default='auto')
744
744
 
745
745
 
746
- def main(args):
746
+ def main(args=None):
747
747
  parser = argparse.ArgumentParser(
748
748
  description='Relink and cleanup objects to increase partition power')
749
749
  parser.add_argument('action', choices=['relink', 'cleanup'])
swift/cli/ringbuilder.py CHANGED
@@ -22,9 +22,11 @@ from itertools import islice
22
22
  from operator import itemgetter
23
23
  from os import mkdir
24
24
  from os.path import basename, abspath, dirname, exists, join as pathjoin
25
+ import sys
25
26
  from sys import argv as sys_argv, exit, stderr, stdout
26
27
  from textwrap import wrap
27
28
  from time import time
29
+ import traceback
28
30
  from datetime import timedelta
29
31
  import optparse
30
32
  import math
@@ -1698,3 +1700,25 @@ def main(arguments=None):
1698
1700
  exit(2)
1699
1701
  else:
1700
1702
  getattr(Commands, command, Commands.unknown)()
1703
+
1704
+
1705
+ def error_handling_main():
1706
+ # We exit code 1 on WARNING statuses, 2 on ERROR. This means we need
1707
+ # to handle any uncaught exceptions by printing the usual backtrace,
1708
+ # but then exiting 2 (not 1 as is usual for a python
1709
+ # exception).
1710
+
1711
+ # We *don't* want to do this in main(), however, because we don't want to
1712
+ # pollute the test environment or cause a bunch of test churn to mock out
1713
+ # sys.excepthook
1714
+
1715
+ def exit_with_status_two(tp, val, tb):
1716
+ traceback.print_exception(tp, val, tb)
1717
+ exit(2)
1718
+
1719
+ sys.excepthook = exit_with_status_two
1720
+ main()
1721
+
1722
+
1723
+ if __name__ == '__main__':
1724
+ error_handling_main()
swift/common/db.py CHANGED
@@ -138,7 +138,8 @@ class GreenDBConnection(sqlite3.Connection):
138
138
  timeout = BROKER_TIMEOUT
139
139
  self.timeout = timeout
140
140
  self.db_file = database
141
- super(GreenDBConnection, self).__init__(database, 0, *args, **kwargs)
141
+ super(GreenDBConnection, self).__init__(
142
+ database, timeout=0, *args, **kwargs)
142
143
 
143
144
  def cursor(self, cls=None):
144
145
  if cls is None:
@@ -96,7 +96,7 @@ class DatabaseAuditor(Daemon):
96
96
  time.sleep(random() * self.interval)
97
97
  while True:
98
98
  self.logger.info(
99
- 'Begin {} audit pass.'.format(self.server_type))
99
+ 'Begin %s audit pass.', self.server_type)
100
100
  begin = time.time()
101
101
  try:
102
102
  reported = self._one_audit_pass(reported)
@@ -116,7 +116,7 @@ class DatabaseAuditor(Daemon):
116
116
  def run_once(self, *args, **kwargs):
117
117
  """Run the database audit once."""
118
118
  self.logger.info(
119
- 'Begin {} audit "once" mode'.format(self.server_type))
119
+ 'Begin %s audit "once" mode', self.server_type)
120
120
  begin = reported = time.time()
121
121
  self._one_audit_pass(reported)
122
122
  elapsed = time.time() - begin
@@ -240,6 +240,12 @@ class Replicator(Daemon):
240
240
  self.handoffs_only = config_true_value(conf.get('handoffs_only', 'no'))
241
241
  self.handoff_delete = config_auto_int_value(
242
242
  conf.get('handoff_delete', 'auto'), 0)
243
+ if self.handoff_delete >= self.ring.replica_count:
244
+ self.logger.warning(
245
+ 'handoff_delete=%d is too high to have an effect on a ring '
246
+ 'with replica count %d. Disabling.',
247
+ self.handoff_delete, self.ring.replica_count)
248
+ self.handoff_delete = 0
243
249
 
244
250
  def _zero_stats(self):
245
251
  """Zero out the stats."""
@@ -243,6 +243,18 @@ class QuarantineRequest(SwiftException):
243
243
  pass
244
244
 
245
245
 
246
+ class MemcacheConnectionError(Exception):
247
+ pass
248
+
249
+
250
+ class MemcacheIncrNotFoundError(MemcacheConnectionError):
251
+ pass
252
+
253
+
254
+ class MemcachePoolTimeout(Timeout):
255
+ pass
256
+
257
+
246
258
  class ClientException(Exception):
247
259
 
248
260
  def __init__(self, msg, http_scheme='', http_host='', http_port='',