Merge lp:~cthier/swift/drybins into lp:~hudson-openstack/swift/trunk

Proposed by Chuck Thier
Status: Merged
Approved by: gholt
Approved revision: 68
Merged at revision: 67
Proposed branch: lp:~cthier/swift/drybins
Merge into: lp:~hudson-openstack/swift/trunk
Diff against target: 1152 lines (+241/-320)
26 files modified
bin/swift-account-auditor (+1/-30)
bin/swift-account-reaper (+1/-30)
bin/swift-account-replicator (+8/-25)
bin/swift-container-auditor (+1/-30)
bin/swift-container-replicator (+8/-24)
bin/swift-container-updater (+1/-23)
bin/swift-object-auditor (+1/-27)
bin/swift-object-replicator (+5/-44)
bin/swift-object-updater (+1/-24)
etc/proxy-server.conf-sample (+2/-2)
swift/account/auditor.py (+5/-4)
swift/account/reaper.py (+9/-7)
swift/account/replicator.py (+26/-0)
swift/common/daemon.py (+60/-0)
swift/common/db_replicator.py (+7/-6)
swift/common/utils.py (+2/-0)
swift/container/auditor.py (+5/-3)
swift/container/replicator.py (+25/-0)
swift/container/updater.py (+7/-5)
swift/obj/auditor.py (+8/-6)
swift/obj/replicator.py (+34/-8)
swift/obj/updater.py (+6/-4)
test/unit/common/test_db_replicator.py (+2/-2)
test/unit/container/test_updater.py (+7/-7)
test/unit/obj/test_replicator.py (+3/-3)
test/unit/obj/test_updater.py (+6/-6)
To merge this branch: bzr merge lp:~cthier/swift/drybins
Reviewer Review Type Date Requested Status
gholt (community) Approve
Review via email: mp+34256@code.launchpad.net

Description of the change

Refactored bin files to be more DRY

To post a comment you must log in.
Revision history for this message
Chuck Thier (cthier) wrote :

unit tests, functest, and probe tests all ran on my vm

Revision history for this message
gholt (gholt) wrote :

swift/account/reaper.py 110 has reference to self.reap_once()
swift/account/reaper.py 119 has reference to reap_forever
swift/common/db_replicator.py 435 has reference to self.replicate_once()

review: Needs Fixing
Revision history for this message
Chuck Thier (cthier) wrote :

> swift/account/reaper.py 110 has reference to self.reap_once()
> swift/account/reaper.py 119 has reference to reap_forever
> swift/common/db_replicator.py 435 has reference to self.replicate_once()

oops... thanks for catching that, should be fixed now

Revision history for this message
Jay Pipes (jaypipes) wrote :

Hi! You may want to use the existing daemon Python library instead of rewriting that stuff ;)

http://pypi.python.org/pypi/python-daemon/

Also, a litte nit: the standard way of passing options for daemonizing a process is not to pass "once" as a CLI arg, but to use CLI options, such as --nodaemon

Revision history for this message
Chuck Thier (cthier) wrote :

> Hi! You may want to use the existing daemon Python library instead of
> rewriting that stuff ;)
>
> http://pypi.python.org/pypi/python-daemon/
>
> Also, a litte nit: the standard way of passing options for daemonizing a
> process is not to pass "once" as a CLI arg, but to use CLI options, such as
> --nodaemon

Hey Jay, The main purpose of this was to refactor what we have currently to be more DRY. I'm not against moving to a standard lib for doing the daemon stuff, but don't have time to evaulate them. And as to the CLI args, I would like for those to change eventually as well, but that requires other changes as well, and was trying to keep the changes as minimal as possible.

Revision history for this message
gholt (gholt) wrote :

Thanks Chuck!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/swift-account-auditor'
--- bin/swift-account-auditor 2010-08-24 13:41:58 +0000
+++ bin/swift-account-auditor 2010-09-01 15:57:44 +0000
@@ -14,10 +14,7 @@
14# See the License for the specific language governing permissions and14# See the License for the specific language governing permissions and
15# limitations under the License.15# limitations under the License.
1616
17import os
18import signal
19import sys17import sys
20from ConfigParser import ConfigParser
2118
22from swift.account.auditor import AccountAuditor19from swift.account.auditor import AccountAuditor
23from swift.common import utils20from swift.common import utils
@@ -26,32 +23,6 @@
26 if len(sys.argv) < 2:23 if len(sys.argv) < 2:
27 print "Usage: swift-account-auditor CONFIG_FILE [once]"24 print "Usage: swift-account-auditor CONFIG_FILE [once]"
28 sys.exit()25 sys.exit()
29
30 once = len(sys.argv) > 2 and sys.argv[2] == 'once'26 once = len(sys.argv) > 2 and sys.argv[2] == 'once'
31
32 conf = utils.readconf(sys.argv[1], 'account-auditor')27 conf = utils.readconf(sys.argv[1], 'account-auditor')
33 logger = utils.get_logger(conf)28 auditor = AccountAuditor(conf).run(once)
34 # log uncaught exceptions
35 sys.excepthook = lambda *exc_info: \
36 logger.critical('UNCAUGHT EXCEPTION', exc_info=exc_info)
37 sys.stdout = sys.stderr = utils.LoggerFileObject(logger)
38
39 utils.drop_privileges(conf.get('user', 'swift'))
40
41 try:
42 os.setsid()
43 except OSError:
44 pass
45
46 def kill_children(*args):
47 signal.signal(signal.SIGTERM, signal.SIG_IGN)
48 os.killpg(0, signal.SIGTERM)
49 sys.exit()
50
51 signal.signal(signal.SIGTERM, kill_children)
52
53 auditor = AccountAuditor(conf)
54 if once:
55 auditor.audit_once()
56 else:
57 auditor.audit_forever()
5829
=== modified file 'bin/swift-account-reaper'
--- bin/swift-account-reaper 2010-08-24 13:41:58 +0000
+++ bin/swift-account-reaper 2010-09-01 15:57:44 +0000
@@ -14,10 +14,7 @@
14# See the License for the specific language governing permissions and14# See the License for the specific language governing permissions and
15# limitations under the License.15# limitations under the License.
1616
17import os
18import signal
19import sys17import sys
20from ConfigParser import ConfigParser
2118
22from swift.account.reaper import AccountReaper19from swift.account.reaper import AccountReaper
23from swift.common import utils20from swift.common import utils
@@ -26,32 +23,6 @@
26 if len(sys.argv) < 2:23 if len(sys.argv) < 2:
27 print "Usage: account-reaper CONFIG_FILE [once]"24 print "Usage: account-reaper CONFIG_FILE [once]"
28 sys.exit()25 sys.exit()
29
30 once = len(sys.argv) > 2 and sys.argv[2] == 'once'26 once = len(sys.argv) > 2 and sys.argv[2] == 'once'
31
32 conf = utils.readconf(sys.argv[1], 'account-reaper')27 conf = utils.readconf(sys.argv[1], 'account-reaper')
33 logger = utils.get_logger(conf)28 reaper = AccountReaper(conf).run(once)
34 # log uncaught exceptions
35 sys.excepthook = lambda *exc_info: \
36 logger.critical('UNCAUGHT EXCEPTION', exc_info=exc_info)
37 sys.stdout = sys.stderr = utils.LoggerFileObject(logger)
38
39 utils.drop_privileges(conf.get('user', 'swift'))
40
41 try:
42 os.setsid()
43 except OSError:
44 pass
45
46 def kill_children(*args):
47 signal.signal(signal.SIGTERM, signal.SIG_IGN)
48 os.killpg(0, signal.SIGTERM)
49 sys.exit()
50
51 signal.signal(signal.SIGTERM, kill_children)
52
53 reaper = AccountReaper(conf)
54 if once:
55 reaper.reap_once()
56 else:
57 reaper.reap_forever()
5829
=== modified file 'bin/swift-account-replicator'
--- bin/swift-account-replicator 2010-08-24 13:41:58 +0000
+++ bin/swift-account-replicator 2010-09-01 15:57:44 +0000
@@ -15,31 +15,14 @@
15# limitations under the License.15# limitations under the License.
1616
17import sys17import sys
18from ConfigParser import ConfigParser18
19import getopt19from swift.common import utils
2020from swift.account.replicator import AccountReplicator
21from swift.account import server as account_server
22from swift.common import db, db_replicator, utils
23
24class AccountReplicator(db_replicator.Replicator):
25 server_type = 'account'
26 ring_file = 'account.ring.gz'
27 brokerclass = db.AccountBroker
28 datadir = account_server.DATADIR
29 default_port = 6002
3021
31if __name__ == '__main__':22if __name__ == '__main__':
32 optlist, args = getopt.getopt(sys.argv[1:], '', ['once'])23 if len(sys.argv) < 2:
3324 print "Usage: swift-account-replicator CONFIG_FILE [once]"
34 if not args:25 sys.exit(1)
35 print "Usage: swift-account-replicator <--once> CONFIG_FILE [once]"26 once = len(sys.argv) > 2 and sys.argv[2] == 'once'
36 sys.exit()
37
38 once = len(args) > 1 and args[1] == 'once'
39 conf = utils.readconf(sys.argv[1], 'account-replicator')27 conf = utils.readconf(sys.argv[1], 'account-replicator')
40 utils.drop_privileges(conf.get('user', 'swift'))28 AccountReplicator(conf).run(once)
41 if once or '--once' in [opt[0] for opt in optlist]:
42 AccountReplicator(conf).replicate_once()
43 else:
44 AccountReplicator(conf).replicate_forever()
45
4629
=== modified file 'bin/swift-container-auditor'
--- bin/swift-container-auditor 2010-08-24 13:41:58 +0000
+++ bin/swift-container-auditor 2010-09-01 15:57:44 +0000
@@ -14,10 +14,7 @@
14# See the License for the specific language governing permissions and14# See the License for the specific language governing permissions and
15# limitations under the License.15# limitations under the License.
1616
17import os
18import signal
19import sys17import sys
20from ConfigParser import ConfigParser
2118
22from swift.container.auditor import ContainerAuditor19from swift.container.auditor import ContainerAuditor
23from swift.common import utils20from swift.common import utils
@@ -26,32 +23,6 @@
26 if len(sys.argv) < 2:23 if len(sys.argv) < 2:
27 print "Usage: swift-container-auditor CONFIG_FILE [once]"24 print "Usage: swift-container-auditor CONFIG_FILE [once]"
28 sys.exit()25 sys.exit()
29
30 once = len(sys.argv) > 2 and sys.argv[2] == 'once'26 once = len(sys.argv) > 2 and sys.argv[2] == 'once'
31
32 conf = utils.readconf(sys.argv[1], 'container-auditor')27 conf = utils.readconf(sys.argv[1], 'container-auditor')
33 logger = utils.get_logger(conf)28 ContainerAuditor(conf).run(once)
34 # log uncaught exceptions
35 sys.excepthook = lambda *exc_info: \
36 logger.critical('UNCAUGHT EXCEPTION', exc_info=exc_info)
37 sys.stdout = sys.stderr = utils.LoggerFileObject(logger)
38
39 utils.drop_privileges(conf.get('user', 'swift'))
40
41 try:
42 os.setsid()
43 except OSError:
44 pass
45
46 def kill_children(*args):
47 signal.signal(signal.SIGTERM, signal.SIG_IGN)
48 os.killpg(0, signal.SIGTERM)
49 sys.exit()
50
51 signal.signal(signal.SIGTERM, kill_children)
52
53 auditor = ContainerAuditor(conf)
54 if once:
55 auditor.audit_once()
56 else:
57 auditor.audit_forever()
5829
=== modified file 'bin/swift-container-replicator'
--- bin/swift-container-replicator 2010-08-24 13:41:58 +0000
+++ bin/swift-container-replicator 2010-09-01 15:57:44 +0000
@@ -15,31 +15,15 @@
15# limitations under the License.15# limitations under the License.
1616
17import sys17import sys
18from ConfigParser import ConfigParser18
19import getopt19from swift.common import db, utils
2020from swift.container.replicator import ContainerReplicator
21from swift.container import server as container_server
22from swift.common import db, db_replicator, utils
23
24class ContainerReplicator(db_replicator.Replicator):
25 server_type = 'container'
26 ring_file = 'container.ring.gz'
27 brokerclass = db.ContainerBroker
28 datadir = container_server.DATADIR
29 default_port = 6001
3021
31if __name__ == '__main__':22if __name__ == '__main__':
32 optlist, args = getopt.getopt(sys.argv[1:], '', ['once'])23 if len(sys.argv) < 2:
3324 print "Usage: swift-container-replicator CONFIG_FILE [once]"
34 if not args:
35 print "Usage: swift-container-replicator <--once> CONFIG_FILE [once]"
36 sys.exit(1)25 sys.exit(1)
3726 once = len(sys.argv) > 2 and sys.argv[2] == 'once'
38 once = len(args) > 1 and args[1] == 'once'27 conf = utils.readconf(sys.argv[1], 'container-replicator')
39 conf = utils.readconf(args[0], 'container-replicator')28 ContainerReplicator(conf).run(once)
40 utils.drop_privileges(conf.get('user', 'swift'))
41 if once or '--once' in [opt[0] for opt in optlist]:
42 ContainerReplicator(conf).replicate_once()
43 else:
44 ContainerReplicator(conf).replicate_forever()
4529
4630
=== modified file 'bin/swift-container-updater'
--- bin/swift-container-updater 2010-08-24 14:55:20 +0000
+++ bin/swift-container-updater 2010-09-01 15:57:44 +0000
@@ -14,10 +14,7 @@
14# See the License for the specific language governing permissions and14# See the License for the specific language governing permissions and
15# limitations under the License.15# limitations under the License.
1616
17import os
18import signal
19import sys17import sys
20from ConfigParser import ConfigParser
2118
22from swift.container.updater import ContainerUpdater19from swift.container.updater import ContainerUpdater
23from swift.common import utils20from swift.common import utils
@@ -26,25 +23,6 @@
26 if len(sys.argv) < 2:23 if len(sys.argv) < 2:
27 print "Usage: swift-container-updater CONFIG_FILE [once]"24 print "Usage: swift-container-updater CONFIG_FILE [once]"
28 sys.exit()25 sys.exit()
29
30 once = len(sys.argv) > 2 and sys.argv[2] == 'once'26 once = len(sys.argv) > 2 and sys.argv[2] == 'once'
31 conf = utils.readconf(sys.argv[1], 'container-updater')27 conf = utils.readconf(sys.argv[1], 'container-updater')
32 utils.drop_privileges(conf.get('user', 'swift'))28 ContainerUpdater(conf).run(once)
33
34 try:
35 os.setsid()
36 except OSError:
37 pass
38
39 def kill_children(*args):
40 signal.signal(signal.SIGTERM, signal.SIG_IGN)
41 os.killpg(0, signal.SIGTERM)
42 sys.exit()
43
44 signal.signal(signal.SIGTERM, kill_children)
45
46 updater = ContainerUpdater(conf)
47 if once:
48 updater.update_once_single_threaded()
49 else:
50 updater.update_forever()
5129
=== modified file 'bin/swift-object-auditor'
--- bin/swift-object-auditor 2010-08-24 13:41:58 +0000
+++ bin/swift-object-auditor 2010-09-01 15:57:44 +0000
@@ -14,8 +14,6 @@
14# See the License for the specific language governing permissions and14# See the License for the specific language governing permissions and
15# limitations under the License.15# limitations under the License.
1616
17import os
18import signal
19import sys17import sys
2018
21from swift.obj.auditor import ObjectAuditor19from swift.obj.auditor import ObjectAuditor
@@ -28,28 +26,4 @@
2826
29 once = len(sys.argv) > 2 and sys.argv[2] == 'once'27 once = len(sys.argv) > 2 and sys.argv[2] == 'once'
30 conf = utils.readconf(sys.argv[1], 'object-auditor')28 conf = utils.readconf(sys.argv[1], 'object-auditor')
31 logger = utils.get_logger(conf)29 ObjectAuditor(conf).run(once)
32 # log uncaught exceptions
33 sys.excepthook = lambda *exc_info: \
34 logger.critical('UNCAUGHT EXCEPTION', exc_info=exc_info)
35 sys.stdout = sys.stderr = utils.LoggerFileObject(logger)
36
37 utils.drop_privileges(conf.get('user', 'swift'))
38
39 try:
40 os.setsid()
41 except OSError:
42 pass
43
44 def kill_children(*args):
45 signal.signal(signal.SIGTERM, signal.SIG_IGN)
46 os.killpg(0, signal.SIGTERM)
47 sys.exit()
48
49 signal.signal(signal.SIGTERM, kill_children)
50
51 auditor = ObjectAuditor(conf)
52 if once:
53 auditor.audit_once()
54 else:
55 auditor.audit_forever()
5630
=== modified file 'bin/swift-object-replicator'
--- bin/swift-object-replicator 2010-08-24 13:41:58 +0000
+++ bin/swift-object-replicator 2010-09-01 15:57:44 +0000
@@ -15,54 +15,15 @@
15# limitations under the License.15# limitations under the License.
1616
17import sys17import sys
18import logging
19import time
20
21from eventlet import sleep, hubs
22hubs.use_hub('poll')
2318
24from swift.obj.replicator import ObjectReplicator19from swift.obj.replicator import ObjectReplicator
25from swift.common.utils import get_logger, drop_privileges, LoggerFileObject, \20from swift.common import utils
26 readconf
27
28TRUE_VALUES = set(('true', '1', 'yes', 'True', 'Yes'))
2921
30if __name__ == '__main__':22if __name__ == '__main__':
31 if len(sys.argv) < 2:23 if len(sys.argv) < 2:
32 print "Usage: swift-object-replicator CONFIG_FILE [once]"24 print "Usage: swift-object-replicator CONFIG_FILE [once]"
33 sys.exit()25 sys.exit()
34 conf = readconf(sys.argv[1], "object-replicator")26 conf = utils.readconf(sys.argv[1], "object-replicator")
35 once = len(sys.argv) > 2 and sys.argv[2] == 'once'27 once = (len(sys.argv) > 2 and sys.argv[2] == 'once') or \
36 logger = get_logger(conf)28 conf.get('daemonize', 'true') not in utils.TRUE_VALUES
37 # log uncaught exceptions29 ObjectReplicator(conf).run(once)
38 sys.excepthook = lambda *exc_info: \
39 logger.critical('UNCAUGHT EXCEPTION', exc_info=exc_info)
40 sys.stdout = sys.stderr = LoggerFileObject(logger)
41 drop_privileges(conf.get('user', 'swift'))
42 if not once and conf.get('daemonize', 'true') in TRUE_VALUES:
43 logger.info("Starting object replicator in daemon mode.")
44 # Run the replicator continually
45 while True:
46 start = time.time()
47 logger.info("Starting object replication pass.")
48 # Run the replicator
49 replicator = ObjectReplicator(conf, logger)
50 replicator.run()
51 total = (time.time() - start)/60
52 # Reload the config
53 logger.info("Object replication complete. (%.02f minutes)" % total)
54 conf = read_configs(sys.argv[1])
55 if conf.get('daemonize', 'true') not in TRUE_VALUES:
56 # Stop running
57 logger.info("Daemon mode turned off in config, stopping.")
58 break
59 logger.debug('Replication sleeping for %s seconds.' %
60 conf['run_pause'])
61 sleep(int(conf['run_pause']))
62 else:
63 start = time.time()
64 logger.info("Running object replicator in script mode.")
65 replicator = ObjectReplicator(conf, logger)
66 replicator.run()
67 total = (time.time() - start)/60
68 logger.info("Object replication complete. (%.02f minutes)" % total)
6930
=== modified file 'bin/swift-object-updater'
--- bin/swift-object-updater 2010-08-24 13:41:58 +0000
+++ bin/swift-object-updater 2010-09-01 15:57:44 +0000
@@ -14,8 +14,6 @@
14# See the License for the specific language governing permissions and14# See the License for the specific language governing permissions and
15# limitations under the License.15# limitations under the License.
1616
17import os
18import signal
19import sys17import sys
2018
21from swift.obj.updater import ObjectUpdater19from swift.obj.updater import ObjectUpdater
@@ -25,27 +23,6 @@
25 if len(sys.argv) < 2:23 if len(sys.argv) < 2:
26 print "Usage: swift-object-updater CONFIG_FILE [once]"24 print "Usage: swift-object-updater CONFIG_FILE [once]"
27 sys.exit(1)25 sys.exit(1)
28
29 once = len(sys.argv) > 2 and sys.argv[2] == 'once'26 once = len(sys.argv) > 2 and sys.argv[2] == 'once'
30
31 conf = utils.readconf(sys.argv[1], 'object-updater')27 conf = utils.readconf(sys.argv[1], 'object-updater')
32 utils.drop_privileges(conf.get('user', 'swift'))28 ObjectUpdater(conf).run(once)
33
34 try:
35 os.setsid()
36 except OSError:
37 pass
38
39 def kill_children(*args):
40 signal.signal(signal.SIGTERM, signal.SIG_IGN)
41 os.killpg(0, signal.SIGTERM)
42 sys.exit()
43
44 signal.signal(signal.SIGTERM, kill_children)
45
46 updater = ObjectUpdater(conf)
47 if once:
48 updater.update_once_single_threaded()
49 else:
50 updater.update_forever()
51
5229
=== modified file 'etc/proxy-server.conf-sample'
--- etc/proxy-server.conf-sample 2010-08-24 13:58:32 +0000
+++ etc/proxy-server.conf-sample 2010-09-01 15:57:44 +0000
@@ -8,9 +8,9 @@
8# key_file = /etc/swift/proxy.key8# key_file = /etc/swift/proxy.key
99
10[pipeline:main]10[pipeline:main]
11pipeline = healthcheck cache auth proxy11pipeline = healthcheck cache auth proxy-server
1212
13[app:proxy]13[app:proxy-server]
14use = egg:swift#proxy14use = egg:swift#proxy
15# log_name = proxy-server15# log_name = proxy-server
16# log_facility = LOG_LOCAL016# log_facility = LOG_LOCAL0
1717
=== modified file 'swift/account/auditor.py'
--- swift/account/auditor.py 2010-08-20 00:42:38 +0000
+++ swift/account/auditor.py 2010-09-01 15:57:44 +0000
@@ -26,16 +26,18 @@
26from swift.common.exceptions import ConnectionTimeout26from swift.common.exceptions import ConnectionTimeout
27from swift.common.ring import Ring27from swift.common.ring import Ring
28from swift.common.utils import get_logger28from swift.common.utils import get_logger
29from swift.common.daemon import Daemon
2930
3031
31class AuditException(Exception):32class AuditException(Exception):
32 pass33 pass
3334
3435
35class AccountAuditor(object):36class AccountAuditor(Daemon):
36 """Audit accounts."""37 """Audit accounts."""
3738
38 def __init__(self, conf):39 def __init__(self, conf):
40 self.conf = conf
39 self.logger = get_logger(conf, 'account-auditor')41 self.logger = get_logger(conf, 'account-auditor')
40 self.devices = conf.get('devices', '/srv/node')42 self.devices = conf.get('devices', '/srv/node')
41 self.mount_check = conf.get('mount_check', 'true').lower() in \43 self.mount_check = conf.get('mount_check', 'true').lower() in \
@@ -60,12 +62,11 @@
60 """62 """
61 if not self.container_ring:63 if not self.container_ring:
62 self.logger.debug(64 self.logger.debug(
63
64 'Loading container ring from %s' % self.container_ring_path)65 'Loading container ring from %s' % self.container_ring_path)
65 self.container_ring = Ring(self.container_ring_path)66 self.container_ring = Ring(self.container_ring_path)
66 return self.container_ring67 return self.container_ring
6768
68 def audit_forever(self): # pragma: no cover69 def run_forever(self): # pragma: no cover
69 """Run the account audit until stopped."""70 """Run the account audit until stopped."""
70 reported = time.time()71 reported = time.time()
71 time.sleep(random() * self.interval)72 time.sleep(random() * self.interval)
@@ -92,7 +93,7 @@
92 if elapsed < self.interval:93 if elapsed < self.interval:
93 time.sleep(self.interval - elapsed)94 time.sleep(self.interval - elapsed)
9495
95 def audit_once(self):96 def run_once(self):
96 """Run the account audit once."""97 """Run the account audit once."""
97 self.logger.info('Begin account audit "once" mode')98 self.logger.info('Begin account audit "once" mode')
98 begin = time.time()99 begin = time.time()
99100
=== modified file 'swift/account/reaper.py'
--- swift/account/reaper.py 2010-08-20 00:42:38 +0000
+++ swift/account/reaper.py 2010-09-01 15:57:44 +0000
@@ -27,9 +27,10 @@
27 direct_delete_container, direct_delete_object, direct_get_container27 direct_delete_container, direct_delete_object, direct_get_container
28from swift.common.ring import Ring28from swift.common.ring import Ring
29from swift.common.utils import get_logger, whataremyips29from swift.common.utils import get_logger, whataremyips
3030from swift.common.daemon import Daemon
3131
32class AccountReaper(object):32
33class AccountReaper(Daemon):
33 """34 """
34 Removes data from status=DELETED accounts. These are accounts that have35 Removes data from status=DELETED accounts. These are accounts that have
35 been asked to be removed by the reseller via services36 been asked to be removed by the reseller via services
@@ -51,6 +52,7 @@
51 """52 """
5253
53 def __init__(self, conf):54 def __init__(self, conf):
55 self.conf = conf
54 self.logger = get_logger(conf)56 self.logger = get_logger(conf)
55 self.devices = conf.get('devices', '/srv/node')57 self.devices = conf.get('devices', '/srv/node')
56 self.mount_check = conf.get('mount_check', 'true').lower() in \58 self.mount_check = conf.get('mount_check', 'true').lower() in \
@@ -95,7 +97,7 @@
95 self.object_ring = Ring(self.object_ring_path)97 self.object_ring = Ring(self.object_ring_path)
96 return self.object_ring98 return self.object_ring
9799
98 def reap_forever(self):100 def run_forever(self):
99 """101 """
100 Main entry point when running the reaper in its normal daemon mode.102 Main entry point when running the reaper in its normal daemon mode.
101 This repeatedly calls :func:`reap_once` no quicker than the103 This repeatedly calls :func:`reap_once` no quicker than the
@@ -105,16 +107,16 @@
105 sleep(random.random() * self.interval)107 sleep(random.random() * self.interval)
106 while True:108 while True:
107 begin = time()109 begin = time()
108 self.reap_once()110 self.run_once()
109 elapsed = time() - begin111 elapsed = time() - begin
110 if elapsed < self.interval:112 if elapsed < self.interval:
111 sleep(self.interval - elapsed)113 sleep(self.interval - elapsed)
112114
113 def reap_once(self):115 def run_once(self):
114 """116 """
115 Main entry point when running the reaper in 'once' mode, where it will117 Main entry point when running the reaper in 'once' mode, where it will
116 do a single pass over all accounts on the server. This is called118 do a single pass over all accounts on the server. This is called
117 repeatedly by :func:`reap_forever`. This will call :func:`reap_device`119 repeatedly by :func:`run_forever`. This will call :func:`reap_device`
118 once for each device on the server.120 once for each device on the server.
119 """121 """
120 self.logger.debug('Begin devices pass: %s' % self.devices)122 self.logger.debug('Begin devices pass: %s' % self.devices)
121123
=== added file 'swift/account/replicator.py'
--- swift/account/replicator.py 1970-01-01 00:00:00 +0000
+++ swift/account/replicator.py 2010-09-01 15:57:44 +0000
@@ -0,0 +1,26 @@
1# Copyright (c) 2010 OpenStack, LLC.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12# implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from swift.account import server as account_server
17from swift.common import db, db_replicator
18
19
20class AccountReplicator(db_replicator.Replicator):
21 server_type = 'account'
22 ring_file = 'account.ring.gz'
23 brokerclass = db.AccountBroker
24 datadir = account_server.DATADIR
25 default_port = 6002
26
027
=== added file 'swift/common/daemon.py'
--- swift/common/daemon.py 1970-01-01 00:00:00 +0000
+++ swift/common/daemon.py 2010-09-01 15:57:44 +0000
@@ -0,0 +1,60 @@
1# Copyright (c) 2010 OpenStack, LLC.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12# implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import os
17import sys
18import signal
19from swift.common import utils
20
21class Daemon(object):
22 """Daemon base class"""
23
24 def __init__(self, conf):
25 self.conf = conf
26 self.logger = utils.get_logger(conf, 'swift-daemon')
27
28 def run_once(self):
29 """Override this to run the script once"""
30 raise NotImplementedError('run_once not implemented')
31
32 def run_forever(self):
33 """Override this to run forever"""
34 raise NotImplementedError('run_forever not implemented')
35
36 def run(self, once=False):
37 """Run the daemon"""
38 # log uncaught exceptions
39 sys.excepthook = lambda *exc_info: \
40 self.logger.critical('UNCAUGHT EXCEPTION', exc_info=exc_info)
41 sys.stdout = sys.stderr = utils.LoggerFileObject(self.logger)
42
43 utils.drop_privileges(self.conf.get('user', 'swift'))
44
45 try:
46 os.setsid()
47 except OSError:
48 pass
49
50 def kill_children(*args):
51 signal.signal(signal.SIGTERM, signal.SIG_IGN)
52 os.killpg(0, signal.SIGTERM)
53 sys.exit()
54
55 signal.signal(signal.SIGTERM, kill_children)
56
57 if once:
58 self.run_once()
59 else:
60 self.run_forever()
061
=== modified file 'swift/common/db_replicator.py'
--- swift/common/db_replicator.py 2010-08-20 00:50:12 +0000
+++ swift/common/db_replicator.py 2010-09-01 15:57:44 +0000
@@ -33,6 +33,7 @@
33from swift.common import ring33from swift.common import ring
34from swift.common.bufferedhttp import BufferedHTTPConnection34from swift.common.bufferedhttp import BufferedHTTPConnection
35from swift.common.exceptions import DriveNotMounted, ConnectionTimeout35from swift.common.exceptions import DriveNotMounted, ConnectionTimeout
36from swift.common.daemon import Daemon
3637
3738
38def quarantine_db(object_file, server_type):39def quarantine_db(object_file, server_type):
@@ -84,14 +85,14 @@
84 return None85 return None
8586
8687
87class Replicator(object):88class Replicator(Daemon):
88 """89 """
89 Implements the logic for directing db replication.90 Implements the logic for directing db replication.
90 """91 """
9192
92 def __init__(self, conf):93 def __init__(self, conf):
93 self.logger = \94 self.conf = conf
94 get_logger(conf)95 self.logger = get_logger(conf)
95 # log uncaught exceptions96 # log uncaught exceptions
96 sys.excepthook = lambda * exc_info: \97 sys.excepthook = lambda * exc_info: \
97 self.logger.critical('UNCAUGHT EXCEPTION', exc_info=exc_info)98 self.logger.critical('UNCAUGHT EXCEPTION', exc_info=exc_info)
@@ -396,7 +397,7 @@
396 except StopIteration:397 except StopIteration:
397 its.remove(it)398 its.remove(it)
398399
399 def replicate_once(self):400 def run_once(self):
400 """Run a replication pass once."""401 """Run a replication pass once."""
401 self._zero_stats()402 self._zero_stats()
402 dirs = []403 dirs = []
@@ -425,13 +426,13 @@
425 self.logger.info('Replication run OVER')426 self.logger.info('Replication run OVER')
426 self._report_stats()427 self._report_stats()
427428
428 def replicate_forever(self):429 def run_forever(self):
429 """430 """
430 Replicate dbs under the given root in an infinite loop.431 Replicate dbs under the given root in an infinite loop.
431 """432 """
432 while True:433 while True:
433 try:434 try:
434 self.replicate_once()435 self.run_once()
435 except:436 except:
436 self.logger.exception('ERROR trying to replicate')437 self.logger.exception('ERROR trying to replicate')
437 sleep(self.run_pause)438 sleep(self.run_pause)
438439
=== modified file 'swift/common/utils.py'
--- swift/common/utils.py 2010-08-24 13:41:58 +0000
+++ swift/common/utils.py 2010-09-01 15:57:44 +0000
@@ -55,6 +55,8 @@
55# will end up with would also require knowing this suffix.55# will end up with would also require knowing this suffix.
56HASH_PATH_SUFFIX = os.environ.get('SWIFT_HASH_PATH_SUFFIX', 'endcap')56HASH_PATH_SUFFIX = os.environ.get('SWIFT_HASH_PATH_SUFFIX', 'endcap')
5757
58# Used when reading config values
59TRUE_VALUES = set(('true', '1', 'yes', 'True', 'Yes'))
5860
59def load_libc_function(func_name):61def load_libc_function(func_name):
60 """62 """
6163
=== modified file 'swift/container/auditor.py'
--- swift/container/auditor.py 2010-08-20 00:42:38 +0000
+++ swift/container/auditor.py 2010-09-01 15:57:44 +0000
@@ -27,16 +27,18 @@
27from swift.common.exceptions import ConnectionTimeout27from swift.common.exceptions import ConnectionTimeout
28from swift.common.ring import Ring28from swift.common.ring import Ring
29from swift.common.utils import get_logger29from swift.common.utils import get_logger
30from swift.common.daemon import Daemon
3031
3132
32class AuditException(Exception):33class AuditException(Exception):
33 pass34 pass
3435
3536
36class ContainerAuditor(object):37class ContainerAuditor(Daemon):
37 """Audit containers."""38 """Audit containers."""
3839
39 def __init__(self, conf):40 def __init__(self, conf):
41 self.conf = conf
40 self.logger = get_logger(conf)42 self.logger = get_logger(conf)
41 self.devices = conf.get('devices', '/srv/node')43 self.devices = conf.get('devices', '/srv/node')
42 self.mount_check = conf.get('mount_check', 'true').lower() in \44 self.mount_check = conf.get('mount_check', 'true').lower() in \
@@ -81,7 +83,7 @@
81 self.object_ring = Ring(self.object_ring_path)83 self.object_ring = Ring(self.object_ring_path)
82 return self.object_ring84 return self.object_ring
8385
84 def audit_forever(self): # pragma: no cover86 def run_forever(self): # pragma: no cover
85 """Run the container audit until stopped."""87 """Run the container audit until stopped."""
86 reported = time.time()88 reported = time.time()
87 time.sleep(random() * self.interval)89 time.sleep(random() * self.interval)
@@ -114,7 +116,7 @@
114 if elapsed < self.interval:116 if elapsed < self.interval:
115 time.sleep(self.interval - elapsed)117 time.sleep(self.interval - elapsed)
116118
117 def audit_once(self):119 def run_once(self):
118 """Run the container audit once."""120 """Run the container audit once."""
119 self.logger.info('Begin container audit "once" mode')121 self.logger.info('Begin container audit "once" mode')
120 begin = time.time()122 begin = time.time()
121123
=== added file 'swift/container/replicator.py'
--- swift/container/replicator.py 1970-01-01 00:00:00 +0000
+++ swift/container/replicator.py 2010-09-01 15:57:44 +0000
@@ -0,0 +1,25 @@
1# Copyright (c) 2010 OpenStack, LLC.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12# implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from swift.container import server as container_server
17from swift.common import db, db_replicator
18
19class ContainerReplicator(db_replicator.Replicator):
20 server_type = 'container'
21 ring_file = 'container.ring.gz'
22 brokerclass = db.ContainerBroker
23 datadir = container_server.DATADIR
24 default_port = 6001
25
026
=== modified file 'swift/container/updater.py'
--- swift/container/updater.py 2010-08-20 00:42:38 +0000
+++ swift/container/updater.py 2010-09-01 15:57:44 +0000
@@ -28,12 +28,14 @@
28from swift.common.exceptions import ConnectionTimeout28from swift.common.exceptions import ConnectionTimeout
29from swift.common.ring import Ring29from swift.common.ring import Ring
30from swift.common.utils import get_logger, whataremyips30from swift.common.utils import get_logger, whataremyips
3131from swift.common.daemon import Daemon
3232
33class ContainerUpdater(object):33
34class ContainerUpdater(Daemon):
34 """Update container information in account listings."""35 """Update container information in account listings."""
3536
36 def __init__(self, conf):37 def __init__(self, conf):
38 self.conf = conf
37 self.logger = get_logger(conf, 'container-updater')39 self.logger = get_logger(conf, 'container-updater')
38 self.devices = conf.get('devices', '/srv/node')40 self.devices = conf.get('devices', '/srv/node')
39 self.mount_check = conf.get('mount_check', 'true').lower() in \41 self.mount_check = conf.get('mount_check', 'true').lower() in \
@@ -78,7 +80,7 @@
78 shuffle(paths)80 shuffle(paths)
79 return paths81 return paths
8082
81 def update_forever(self): # pragma: no cover83 def run_forever(self): # pragma: no cover
82 """84 """
83 Run the updator continuously.85 Run the updator continuously.
84 """86 """
@@ -118,7 +120,7 @@
118 if elapsed < self.interval:120 if elapsed < self.interval:
119 time.sleep(self.interval - elapsed)121 time.sleep(self.interval - elapsed)
120122
121 def update_once_single_threaded(self):123 def run_once(self):
122 """124 """
123 Run the updater once.125 Run the updater once.
124 """126 """
125127
=== modified file 'swift/obj/auditor.py'
--- swift/obj/auditor.py 2010-08-20 00:42:38 +0000
+++ swift/obj/auditor.py 2010-09-01 15:57:44 +0000
@@ -28,13 +28,15 @@
28from swift.common.ring import Ring28from swift.common.ring import Ring
29from swift.common.utils import get_logger, renamer29from swift.common.utils import get_logger, renamer
30from swift.common.exceptions import AuditException30from swift.common.exceptions import AuditException
3131from swift.common.daemon import Daemon
3232
33class ObjectAuditor(object):33
34class ObjectAuditor(Daemon):
34 """Audit objects."""35 """Audit objects."""
3536
36 def __init__(self, conf):37 def __init__(self, conf):
37 self.logger = get_logger(conf)38 self.conf = conf
39 self.logger = get_logger(conf, 'object-auditor')
38 self.devices = conf.get('devices', '/srv/node')40 self.devices = conf.get('devices', '/srv/node')
39 self.mount_check = conf.get('mount_check', 'true').lower() in \41 self.mount_check = conf.get('mount_check', 'true').lower() in \
40 ('true', 't', '1', 'on', 'yes', 'y')42 ('true', 't', '1', 'on', 'yes', 'y')
@@ -63,7 +65,7 @@
63 self.container_ring = Ring(self.container_ring_path)65 self.container_ring = Ring(self.container_ring_path)
64 return self.container_ring66 return self.container_ring
6567
66 def audit_forever(self): # pragma: no cover68 def run_forever(self): # pragma: no cover
67 """Run the object audit until stopped."""69 """Run the object audit until stopped."""
68 reported = time.time()70 reported = time.time()
69 time.sleep(random() * self.interval)71 time.sleep(random() * self.interval)
@@ -97,7 +99,7 @@
97 if elapsed < self.interval:99 if elapsed < self.interval:
98 time.sleep(self.interval - elapsed)100 time.sleep(self.interval - elapsed)
99101
100 def audit_once(self):102 def run_once(self):
101 """Run the object audit once."""103 """Run the object audit once."""
102 self.logger.info('Begin object audit "once" mode')104 self.logger.info('Begin object audit "once" mode')
103 begin = time.time()105 begin = time.time()
104106
=== modified file 'swift/obj/replicator.py'
--- swift/obj/replicator.py 2010-08-24 18:27:38 +0000
+++ swift/obj/replicator.py 2010-09-01 15:57:44 +0000
@@ -24,15 +24,17 @@
24import cPickle as pickle24import cPickle as pickle
2525
26import eventlet26import eventlet
27from eventlet import GreenPool, tpool, Timeout, sleep27from eventlet import GreenPool, tpool, Timeout, sleep, hubs
28from eventlet.green import subprocess28from eventlet.green import subprocess
29from eventlet.support.greenlets import GreenletExit29from eventlet.support.greenlets import GreenletExit
3030
31from swift.common.ring import Ring31from swift.common.ring import Ring
32from swift.common.utils import whataremyips, unlink_older_than, lock_path, \32from swift.common.utils import whataremyips, unlink_older_than, lock_path, \
33 renamer, compute_eta33 renamer, compute_eta, get_logger
34from swift.common.bufferedhttp import http_connect34from swift.common.bufferedhttp import http_connect
35from swift.common.daemon import Daemon
3536
37hubs.use_hub('poll')
3638
37PICKLE_PROTOCOL = 239PICKLE_PROTOCOL = 2
38ONE_WEEK = 60480040ONE_WEEK = 604800
@@ -190,22 +192,22 @@
190 return hashed, hashes192 return hashed, hashes
191193
192194
193class ObjectReplicator(object):195class ObjectReplicator(Daemon):
194 """196 """
195 Replicate objects.197 Replicate objects.
196198
197 Encapsulates most logic and data needed by the object replication process.199 Encapsulates most logic and data needed by the object replication process.
198 Each call to .run() performs one replication pass. It's up to the caller200 Each call to .replicate() performs one replication pass. It's up to the
199 to do this in a loop.201 caller to do this in a loop.
200 """202 """
201203
202 def __init__(self, conf, logger):204 def __init__(self, conf):
203 """205 """
204 :param conf: configuration object obtained from ConfigParser206 :param conf: configuration object obtained from ConfigParser
205 :param logger: logging object207 :param logger: logging object
206 """208 """
207 self.conf = conf209 self.conf = conf
208 self.logger = logger210 self.logger = get_logger(conf, 'object-replicator')
209 self.devices_dir = conf.get('devices', '/srv/node')211 self.devices_dir = conf.get('devices', '/srv/node')
210 self.mount_check = conf.get('mount_check', 'true').lower() in \212 self.mount_check = conf.get('mount_check', 'true').lower() in \
211 ('true', 't', '1', 'on', 'yes', 'y')213 ('true', 't', '1', 'on', 'yes', 'y')
@@ -221,6 +223,7 @@
221 self.next_check = time.time() + self.ring_check_interval223 self.next_check = time.time() + self.ring_check_interval
222 self.reclaim_age = int(conf.get('reclaim_age', 86400 * 7))224 self.reclaim_age = int(conf.get('reclaim_age', 86400 * 7))
223 self.partition_times = []225 self.partition_times = []
226 self.run_pause = int(conf.get('run_pause', 30))
224227
225 def _rsync(self, args):228 def _rsync(self, args):
226 """229 """
@@ -450,7 +453,7 @@
450 eventlet.sleep(300)453 eventlet.sleep(300)
451 self.stats_line()454 self.stats_line()
452455
453 def run(self):456 def replicate(self):
454 """Run a replication pass"""457 """Run a replication pass"""
455 self.start = time.time()458 self.start = time.time()
456 self.suffix_count = 0459 self.suffix_count = 0
@@ -506,3 +509,26 @@
506 self.kill_coros()509 self.kill_coros()
507 self.stats_line()510 self.stats_line()
508 stats.kill()511 stats.kill()
512
513 def run_once(self):
514 start = time.time()
515 self.logger.info("Running object replicator in script mode.")
516 self.replicate()
517 total = (time.time() - start)/60
518 self.logger.info(
519 "Object replication complete. (%.02f minutes)" % total)
520
521 def run_forever(self):
522 self.logger.info("Starting object replicator in daemon mode.")
523 # Run the replicator continually
524 while True:
525 start = time.time()
526 self.logger.info("Starting object replication pass.")
527 # Run the replicator
528 self.replicate()
529 total = (time.time() - start)/60
530 self.logger.info(
531 "Object replication complete. (%.02f minutes)" % total)
532 self.logger.debug('Replication sleeping for %s seconds.' %
533 self.run_pause)
534 sleep(self.run_pause)
509535
=== modified file 'swift/obj/updater.py'
--- swift/obj/updater.py 2010-08-20 00:42:38 +0000
+++ swift/obj/updater.py 2010-09-01 15:57:44 +0000
@@ -26,14 +26,16 @@
26from swift.common.exceptions import ConnectionTimeout26from swift.common.exceptions import ConnectionTimeout
27from swift.common.ring import Ring27from swift.common.ring import Ring
28from swift.common.utils import get_logger, renamer28from swift.common.utils import get_logger, renamer
29from swift.common.daemon import Daemon
29from swift.obj.server import ASYNCDIR30from swift.obj.server import ASYNCDIR
3031
3132
32class ObjectUpdater(object):33class ObjectUpdater(Daemon):
33 """Update object information in container listings."""34 """Update object information in container listings."""
3435
35 def __init__(self, conf):36 def __init__(self, conf):
36 self.logger = get_logger(conf)37 self.conf = conf
38 self.logger = get_logger(conf, 'object-updater')
37 self.devices = conf.get('devices', '/srv/node')39 self.devices = conf.get('devices', '/srv/node')
38 self.mount_check = conf.get('mount_check', 'true').lower() in \40 self.mount_check = conf.get('mount_check', 'true').lower() in \
39 ('true', 't', '1', 'on', 'yes', 'y')41 ('true', 't', '1', 'on', 'yes', 'y')
@@ -56,7 +58,7 @@
56 self.container_ring = Ring(self.container_ring_path)58 self.container_ring = Ring(self.container_ring_path)
57 return self.container_ring59 return self.container_ring
5860
59 def update_forever(self): # pragma: no cover61 def run_forever(self): # pragma: no cover
60 """Run the updater continuously."""62 """Run the updater continuously."""
61 time.sleep(random() * self.interval)63 time.sleep(random() * self.interval)
62 while True:64 while True:
@@ -95,7 +97,7 @@
95 if elapsed < self.interval:97 if elapsed < self.interval:
96 time.sleep(self.interval - elapsed)98 time.sleep(self.interval - elapsed)
9799
98 def update_once_single_threaded(self):100 def run_once(self):
99 """Run the updater once"""101 """Run the updater once"""
100 self.logger.info('Begin object update single threaded sweep')102 self.logger.info('Begin object update single threaded sweep')
101 begin = time.time()103 begin = time.time()
102104
=== modified file 'test/unit/common/test_db_replicator.py'
--- test/unit/common/test_db_replicator.py 2010-08-20 00:50:12 +0000
+++ test/unit/common/test_db_replicator.py 2010-09-01 15:57:44 +0000
@@ -170,9 +170,9 @@
170 {'id': 'a', 'point': -1, 'max_row': 10, 'hash': 'd'},170 {'id': 'a', 'point': -1, 'max_row': 10, 'hash': 'd'},
171 FakeBroker(), -1)), False)171 FakeBroker(), -1)), False)
172172
173 def test_replicate_once(self):173 def test_run_once(self):
174 replicator = TestReplicator({})174 replicator = TestReplicator({})
175 replicator.replicate_once()175 replicator.run_once()
176176
177 def test_usync(self):177 def test_usync(self):
178 fake_http = ReplHttp()178 fake_http = ReplHttp()
179179
=== modified file 'test/unit/container/test_updater.py'
--- test/unit/container/test_updater.py 2010-08-20 00:42:38 +0000
+++ test/unit/container/test_updater.py 2010-09-01 15:57:44 +0000
@@ -77,7 +77,7 @@
77 self.assertEquals(cu.node_timeout, 5)77 self.assertEquals(cu.node_timeout, 5)
78 self.assert_(cu.get_account_ring() is not None)78 self.assert_(cu.get_account_ring() is not None)
7979
80 def test_update_once_single_threaded(self):80 def test_run_once(self):
81 cu = container_updater.ContainerUpdater({81 cu = container_updater.ContainerUpdater({
82 'devices': self.devices_dir,82 'devices': self.devices_dir,
83 'mount_check': 'false',83 'mount_check': 'false',
@@ -86,17 +86,17 @@
86 'concurrency': '1',86 'concurrency': '1',
87 'node_timeout': '15',87 'node_timeout': '15',
88 })88 })
89 cu.update_once_single_threaded()89 cu.run_once()
90 containers_dir = os.path.join(self.sda1, container_server.DATADIR)90 containers_dir = os.path.join(self.sda1, container_server.DATADIR)
91 os.mkdir(containers_dir)91 os.mkdir(containers_dir)
92 cu.update_once_single_threaded()92 cu.run_once()
93 self.assert_(os.path.exists(containers_dir))93 self.assert_(os.path.exists(containers_dir))
94 subdir = os.path.join(containers_dir, 'subdir')94 subdir = os.path.join(containers_dir, 'subdir')
95 os.mkdir(subdir)95 os.mkdir(subdir)
96 cb = ContainerBroker(os.path.join(subdir, 'hash.db'), account='a',96 cb = ContainerBroker(os.path.join(subdir, 'hash.db'), account='a',
97 container='c')97 container='c')
98 cb.initialize(normalize_timestamp(1))98 cb.initialize(normalize_timestamp(1))
99 cu.update_once_single_threaded()99 cu.run_once()
100 info = cb.get_info()100 info = cb.get_info()
101 self.assertEquals(info['object_count'], 0)101 self.assertEquals(info['object_count'], 0)
102 self.assertEquals(info['bytes_used'], 0)102 self.assertEquals(info['bytes_used'], 0)
@@ -105,7 +105,7 @@
105105
106 cb.put_object('o', normalize_timestamp(2), 3, 'text/plain',106 cb.put_object('o', normalize_timestamp(2), 3, 'text/plain',
107 '68b329da9893e34099c7d8ad5cb9c940')107 '68b329da9893e34099c7d8ad5cb9c940')
108 cu.update_once_single_threaded()108 cu.run_once()
109 info = cb.get_info()109 info = cb.get_info()
110 self.assertEquals(info['object_count'], 1)110 self.assertEquals(info['object_count'], 1)
111 self.assertEquals(info['bytes_used'], 3)111 self.assertEquals(info['bytes_used'], 3)
@@ -148,7 +148,7 @@
148 for dev in cu.get_account_ring().devs:148 for dev in cu.get_account_ring().devs:
149 if dev is not None:149 if dev is not None:
150 dev['port'] = bindsock.getsockname()[1]150 dev['port'] = bindsock.getsockname()[1]
151 cu.update_once_single_threaded()151 cu.run_once()
152 for event in spawned.wait():152 for event in spawned.wait():
153 err = event.wait()153 err = event.wait()
154 if err:154 if err:
@@ -202,7 +202,7 @@
202 for dev in cu.get_account_ring().devs:202 for dev in cu.get_account_ring().devs:
203 if dev is not None:203 if dev is not None:
204 dev['port'] = bindsock.getsockname()[1]204 dev['port'] = bindsock.getsockname()[1]
205 cu.update_once_single_threaded()205 cu.run_once()
206 for event in spawned.wait():206 for event in spawned.wait():
207 err = event.wait()207 err = event.wait()
208 if err:208 if err:
209209
=== modified file 'test/unit/obj/test_replicator.py'
--- test/unit/obj/test_replicator.py 2010-07-19 16:25:18 +0000
+++ test/unit/obj/test_replicator.py 2010-09-01 15:57:44 +0000
@@ -105,7 +105,7 @@
105 swift_dir=self.testdir, devices=self.devices, mount_check='false',105 swift_dir=self.testdir, devices=self.devices, mount_check='false',
106 timeout='300', stats_interval='1')106 timeout='300', stats_interval='1')
107 self.replicator = object_replicator.ObjectReplicator(107 self.replicator = object_replicator.ObjectReplicator(
108 self.conf, null_logger)108 self.conf)
109109
110# def test_check_ring(self):110# def test_check_ring(self):
111# self.replicator.collect_jobs('sda', 0, self.ring)111# self.replicator.collect_jobs('sda', 0, self.ring)
@@ -184,11 +184,11 @@
184184
185 def test_run(self):185 def test_run(self):
186 with _mock_process([(0,'')]*100):186 with _mock_process([(0,'')]*100):
187 self.replicator.run()187 self.replicator.replicate()
188188
189 def test_run_withlog(self):189 def test_run_withlog(self):
190 with _mock_process([(0,"stuff in log")]*100):190 with _mock_process([(0,"stuff in log")]*100):
191 self.replicator.run()191 self.replicator.replicate()
192192
193if __name__ == '__main__':193if __name__ == '__main__':
194 unittest.main()194 unittest.main()
195195
=== modified file 'test/unit/obj/test_updater.py'
--- test/unit/obj/test_updater.py 2010-08-26 16:03:08 +0000
+++ test/unit/obj/test_updater.py 2010-09-01 15:57:44 +0000
@@ -69,7 +69,7 @@
69 self.assertEquals(cu.node_timeout, 5)69 self.assertEquals(cu.node_timeout, 5)
70 self.assert_(cu.get_container_ring() is not None)70 self.assert_(cu.get_container_ring() is not None)
7171
72 def test_update_once_single_threaded(self):72 def test_run_once(self):
73 cu = object_updater.ObjectUpdater({73 cu = object_updater.ObjectUpdater({
74 'devices': self.devices_dir,74 'devices': self.devices_dir,
75 'mount_check': 'false',75 'mount_check': 'false',
@@ -78,15 +78,15 @@
78 'concurrency': '1',78 'concurrency': '1',
79 'node_timeout': '15',79 'node_timeout': '15',
80 })80 })
81 cu.update_once_single_threaded()81 cu.run_once()
82 async_dir = os.path.join(self.sda1, object_server.ASYNCDIR)82 async_dir = os.path.join(self.sda1, object_server.ASYNCDIR)
83 os.mkdir(async_dir)83 os.mkdir(async_dir)
84 cu.update_once_single_threaded()84 cu.run_once()
85 self.assert_(os.path.exists(async_dir))85 self.assert_(os.path.exists(async_dir))
8686
87 odd_dir = os.path.join(async_dir, 'not really supposed to be here')87 odd_dir = os.path.join(async_dir, 'not really supposed to be here')
88 os.mkdir(odd_dir)88 os.mkdir(odd_dir)
89 cu.update_once_single_threaded()89 cu.run_once()
90 self.assert_(os.path.exists(async_dir))90 self.assert_(os.path.exists(async_dir))
91 self.assert_(not os.path.exists(odd_dir))91 self.assert_(not os.path.exists(odd_dir))
9292
@@ -98,7 +98,7 @@
98 pickle.dump({'op': 'PUT', 'account': 'a', 'container': 'c', 'obj': 'o',98 pickle.dump({'op': 'PUT', 'account': 'a', 'container': 'c', 'obj': 'o',
99 'headers': {'X-Container-Timestamp': normalize_timestamp(0)}},99 'headers': {'X-Container-Timestamp': normalize_timestamp(0)}},
100 open(op_path, 'wb'))100 open(op_path, 'wb'))
101 cu.update_once_single_threaded()101 cu.run_once()
102 self.assert_(os.path.exists(op_path))102 self.assert_(os.path.exists(op_path))
103103
104 bindsock = listen(('127.0.0.1', 0))104 bindsock = listen(('127.0.0.1', 0))
@@ -140,7 +140,7 @@
140 for dev in cu.get_container_ring().devs:140 for dev in cu.get_container_ring().devs:
141 if dev is not None:141 if dev is not None:
142 dev['port'] = bindsock.getsockname()[1]142 dev['port'] = bindsock.getsockname()[1]
143 cu.update_once_single_threaded()143 cu.run_once()
144 err = event.wait()144 err = event.wait()
145 if err:145 if err:
146 raise err146 raise err