Merge "use a context manager to apply --no-auto-shard option"

This commit is contained in:
Zuul
2021-08-20 18:58:43 +00:00
committed by Gerrit Code Review

View File

@@ -25,6 +25,7 @@ import os
import six
from six.moves.urllib.parse import quote
from eventlet import Timeout
from contextlib import contextmanager
from swift.common import internal_client
from swift.common.constraints import check_drive, AUTO_CREATE_ACCOUNT_PREFIX
@@ -2127,14 +2128,20 @@ class ContainerSharder(ContainerSharderConf, ContainerReplicator):
self._report_stats()
@contextmanager
def _set_auto_shard_from_command_line(self, **kwargs):
conf_auto_shard = self.auto_shard
auto_shard = kwargs.get('auto_shard', None)
if auto_shard is not None:
self.auto_shard = config_true_value(auto_shard)
try:
yield
finally:
self.auto_shard = conf_auto_shard
def run_forever(self, *args, **kwargs):
"""Run the container sharder until stopped."""
self._set_auto_shard_from_command_line(**kwargs)
with self._set_auto_shard_from_command_line(**kwargs):
self.reported = time.time()
time.sleep(random() * self.interval)
while True:
@@ -2157,7 +2164,7 @@ class ContainerSharder(ContainerSharderConf, ContainerReplicator):
override_options = parse_override_options(once=True, **kwargs)
devices_to_shard = override_options.devices or Everything()
partitions_to_shard = override_options.partitions or Everything()
self._set_auto_shard_from_command_line(**kwargs)
with self._set_auto_shard_from_command_line(**kwargs):
begin = self.reported = time.time()
self._one_shard_cycle(devices_to_shard=devices_to_shard,
partitions_to_shard=partitions_to_shard)