diff --git a/swift/obj/expirer.py b/swift/obj/expirer.py index 06419431b8..58870a9431 100644 --- a/swift/obj/expirer.py +++ b/swift/obj/expirer.py @@ -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)}) diff --git a/test/unit/obj/test_expirer.py b/test/unit/obj/test_expirer.py index 4c154514f3..bba695ff2f 100644 --- a/test/unit/obj/test_expirer.py +++ b/test/unit/obj/test_expirer.py @@ -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(