object-expirer: fix unused _make_internal_client arg

The RelatedChange introduced a _make_internal_client() method with an
unused argument 'is_legacy_conf'. This patch completes the original
intention i.e. for the selection of internal client config path to
also be moved to the new method and use the 'is_legacy_conf' arg.

Change-Id: I5075cb446a15edc7f47e83f6aa038c626bd1dd82
RelatedChange: Ia6e1e6a8b58a8476fa16a3c7d45e620c6d7f88e4
This commit is contained in:
Alistair Coles 2024-09-11 10:13:23 +01:00
parent 6f7687b23c
commit ffdf962598
2 changed files with 77 additions and 10 deletions

View File

@ -167,17 +167,8 @@ class ObjectExpirer(Daemon):
self.dequeue_from_legacy = \
True if is_legacy_conf else \
config_true_value(conf.get('dequeue_from_legacy', 'false'))
if is_legacy_conf:
self.ic_conf_path = self.conf_path
else:
self.ic_conf_path = \
self.conf.get('internal_client_conf_path') or \
'/etc/swift/internal-client.conf'
self.swift = swift or self._make_internal_client(is_legacy_conf)
self.read_conf_for_queue_access()
self.report_interval = float(conf.get('report_interval') or 300)
self.report_first_time = self.report_last_time = time()
self.report_objects = 0
@ -195,9 +186,15 @@ class ObjectExpirer(Daemon):
self.delay_reaping_times = read_conf_for_delay_reaping_times(conf)
def _make_internal_client(self, is_legacy_conf):
if is_legacy_conf:
ic_conf_path = self.conf_path
else:
ic_conf_path = \
self.conf.get('internal_client_conf_path') or \
'/etc/swift/internal-client.conf'
request_tries = int(self.conf.get('request_tries') or 3)
return InternalClient(
self.ic_conf_path, 'Swift Object Expirer', request_tries,
ic_conf_path, 'Swift Object Expirer', request_tries,
use_replication_network=True,
global_conf={'log_name': '%s-ic' % self.conf.get(
'log_name', self.log_route)})

View File

@ -306,6 +306,76 @@ class TestObjectExpirer(TestCase):
self.assertEqual(x.expiring_objects_account, '.expiring_objects')
self.assertIs(x.swift, self.fake_swift)
def test_init_internal_client_path(self):
# default -> /etc/swift/object-expirer.conf
conf = {'internal_client_conf_path': 'ignored'}
with mock.patch.object(expirer, 'InternalClient',
return_value=self.fake_swift) as mock_ic:
x = expirer.ObjectExpirer(conf, logger=self.logger)
self.assertEqual(mock_ic.mock_calls, [mock.call(
'/etc/swift/object-expirer.conf', 'Swift Object Expirer', 3,
use_replication_network=True,
global_conf={'log_name': 'object-expirer-ic'})])
self.assertEqual(self.logger.get_lines_for_level('warning'), [])
self.assertIs(x.swift, self.fake_swift)
# conf read from /etc/swift/object-expirer.conf
# -> /etc/swift/object-expirer.conf
conf = {'__file__': '/etc/swift/object-expirer.conf',
'internal_client_conf_path': 'ignored'}
with mock.patch.object(expirer, 'InternalClient',
return_value=self.fake_swift) as mock_ic:
x = expirer.ObjectExpirer(conf, logger=self.logger)
self.assertEqual(mock_ic.mock_calls, [mock.call(
'/etc/swift/object-expirer.conf', 'Swift Object Expirer', 3,
use_replication_network=True,
global_conf={'log_name': 'object-expirer-ic'})])
self.assertEqual(self.logger.get_lines_for_level('warning'), [])
self.assertIs(x.swift, self.fake_swift)
# conf read from object-server.conf, no internal_client_conf_path
# specified -> /etc/swift/internal-client.conf
conf = {'__file__': '/etc/swift/object-server.conf'}
with mock.patch.object(expirer, 'InternalClient',
return_value=self.fake_swift) as mock_ic:
x = expirer.ObjectExpirer(conf, logger=self.logger)
self.assertEqual(mock_ic.mock_calls, [mock.call(
'/etc/swift/internal-client.conf', 'Swift Object Expirer', 3,
use_replication_network=True,
global_conf={'log_name': 'object-expirer-ic'})])
self.assertEqual(self.logger.get_lines_for_level('warning'), [])
self.assertIs(x.swift, self.fake_swift)
# conf read from object-server.conf, internal_client_conf_path is
# specified -> internal_client_conf_path value
conf = {'__file__': '/etc/swift/object-server.conf',
'internal_client_conf_path':
'/etc/swift/other-internal-client.conf'}
with mock.patch.object(expirer, 'InternalClient',
return_value=self.fake_swift) as mock_ic:
x = expirer.ObjectExpirer(conf, logger=self.logger)
self.assertEqual(mock_ic.mock_calls, [mock.call(
'/etc/swift/other-internal-client.conf', 'Swift Object Expirer', 3,
use_replication_network=True,
global_conf={'log_name': 'object-expirer-ic'})])
self.assertEqual(self.logger.get_lines_for_level('warning'), [])
self.assertIs(x.swift, self.fake_swift)
# conf read from other file, internal_client_conf_path is
# specified -> internal_client_conf_path value
conf = {'__file__': '/etc/swift/other-object-server.conf',
'internal_client_conf_path':
'/etc/swift/other-internal-client.conf'}
with mock.patch.object(expirer, 'InternalClient',
return_value=self.fake_swift) as mock_ic:
x = expirer.ObjectExpirer(conf, logger=self.logger)
self.assertEqual(mock_ic.mock_calls, [mock.call(
'/etc/swift/other-internal-client.conf', 'Swift Object Expirer', 3,
use_replication_network=True,
global_conf={'log_name': 'object-expirer-ic'})])
self.assertEqual(self.logger.get_lines_for_level('warning'), [])
self.assertIs(x.swift, self.fake_swift)
def test_init_internal_client_log_name(self):
def _do_test_init_ic_log_name(conf, exp_internal_client_log_name):
with mock.patch(