Skip to content

Instantly share code, notes, and snippets.

@notmyname
Created April 14, 2015 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notmyname/d3d86c8f46ea01585b9f to your computer and use it in GitHub Desktop.
Save notmyname/d3d86c8f46ea01585b9f to your computer and use it in GitHub Desktop.
diff --cc etc/container-server.conf-sample
index 6e881d9,4d2c724..0000000
--- a/etc/container-server.conf-sample
+++ b/etc/container-server.conf-sample
@@@ -168,8 -168,11 +168,13 @@@ use = egg:swift#reco
# Maximum amount of time to spend syncing each container per pass
# container_time = 60
#
+# Maximum amount of time in seconds for the connection attempt
+# conn_timeout = 5
+ # Server errors from requests will be retried by default
+ # request_tries = 3
+ #
+ # Internal client config file path
+ # internal_client_conf_path = /etc/swift/internal-client.conf
# Note: Put it at the beginning of the pipeline to profile all middleware. But
# it is safer to put this after healthcheck.
diff --cc swift/container/sync.py
index 0f42de6,e6dd6b8..0000000
--- a/swift/container/sync.py
+++ b/swift/container/sync.py
@@@ -158,7 -208,26 +208,27 @@@ class ContainerSync(Daemon)
self._myport = int(conf.get('bind_port', 6001))
swift.common.db.DB_PREALLOCATION = \
config_true_value(conf.get('db_preallocation', 'f'))
+ self.conn_timeout = float(conf.get('conn_timeout', 5))
+ request_tries = int(conf.get('request_tries') or 3)
+
+ internal_client_conf_path = conf.get('internal_client_conf_path')
+ if not internal_client_conf_path:
+ self.logger.warning(
+ _('Configuration option internal_client_conf_path not '
+ 'defined. Using default configuration, See '
+ 'internal-client.conf-sample for options'))
+ internal_client_conf = ConfigString(ic_conf_body)
+ else:
+ internal_client_conf = internal_client_conf_path
+ try:
+ self.swift = InternalClient(
+ internal_client_conf, 'Swift Container Sync', request_tries)
+ except IOError as err:
+ if err.errno != errno.ENOENT:
+ raise
+ raise SystemExit(
+ _('Unable to load internal client from config: %r (%s)') %
+ (internal_client_conf_path, err))
def get_object_ring(self, policy_idx):
"""
diff --cc test/unit/container/test_sync.py
index 3db5c41,b497e10..0000000
--- a/test/unit/container/test_sync.py
+++ b/test/unit/container/test_sync.py
@@@ -649,10 -713,9 +713,9 @@@ class TestContainerSync(unittest.TestCa
hex = 'abcdef'
sync.uuid = FakeUUID
- fake_logger = FakeLogger()
def fake_delete_object(path, name=None, headers=None, proxy=None,
- logger=None):
+ logger=None, timeout=None):
self.assertEquals(path, 'http://sync/to/path')
self.assertEquals(name, 'object')
if realm:
@@@ -665,12 -728,13 +728,14 @@@
headers,
{'x-container-sync-key': 'key', 'x-timestamp': '1.2'})
self.assertEquals(proxy, 'http://proxy')
- self.assertEqual(logger, fake_logger)
+ self.assertEqual(timeout, 5.0)
+ self.assertEqual(logger, self.logger)
sync.delete_object = fake_delete_object
- cs = sync.ContainerSync({}, container_ring=FakeRing())
- cs.logger = fake_logger
+
+ with mock.patch('swift.container.sync.InternalClient'):
+ cs = sync.ContainerSync({}, container_ring=FakeRing(),
+ logger=self.logger)
cs.http_proxies = ['http://proxy']
# Success
self.assertTrue(cs.container_sync_row(
@@@ -757,11 -820,9 +821,10 @@@
sync.uuid = FakeUUID
sync.shuffle = lambda x: x
- fake_logger = FakeLogger()
def fake_put_object(sync_to, name=None, headers=None,
- contents=None, proxy=None, logger=None):
+ contents=None, proxy=None, logger=None,
+ timeout=None):
self.assertEquals(sync_to, 'http://sync/to/path')
self.assertEquals(name, 'object')
if realm:
@@@ -781,8 -842,7 +844,8 @@@
'content-type': 'text/plain'})
self.assertEquals(contents.read(), 'contents')
self.assertEquals(proxy, 'http://proxy')
- self.assertEqual(logger, fake_logger)
+ self.assertEqual(timeout, 5.0)
+ self.assertEqual(logger, self.logger)
sync.put_object = fake_put_object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment