From a9b5982d525d6b1ed369e780835b5b26a250ad95 Mon Sep 17 00:00:00 2001 From: Samuel Merritt Date: Thu, 12 Feb 2015 09:59:48 -0800 Subject: [PATCH] Fix account-reaper As part of commit efb39a5, the account reaper grew a bind_port attribute, but it wasn't being converted to int, so naturally "6002" != 6002, and it wouldn't reap anything. The bind_port was only used for determining the local devices. Rather than fix the code to call int(), this commit removes the need for bind_port entirely by skipping the port check. If your rings have IPs, this is the same behavior as pre-efb39a5, and if your rings have hostnames, this still works. Change-Id: I7bd18e9952f7b9e0d7ce2dce230ee54c5e23709a --- swift/account/reaper.py | 6 ++---- test/unit/common/ring/test_utils.py | 9 +++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/swift/account/reaper.py b/swift/account/reaper.py index c8d623691a..d33f3514fa 100644 --- a/swift/account/reaper.py +++ b/swift/account/reaper.py @@ -59,7 +59,6 @@ class AccountReaper(Daemon): def __init__(self, conf, logger=None): self.conf = conf self.logger = logger or get_logger(conf, log_route='account-reaper') - self.bind_port = conf.get('bind_port', 6002) self.devices = conf.get('devices', '/srv/node') self.mount_check = config_true_value(conf.get('mount_check', 'true')) self.interval = int(conf.get('interval', 3600)) @@ -161,9 +160,8 @@ class AccountReaper(Daemon): if not partition.isdigit(): continue nodes = self.get_account_ring().get_part_nodes(int(partition)) - if not is_local_device(self.myips, self.bind_port, - nodes[0]['ip'], nodes[0]['port']) or \ - not os.path.isdir(partition_path): + if (not is_local_device(self.myips, None, nodes[0]['ip'], None) + or not os.path.isdir(partition_path)): continue for suffix in os.listdir(partition_path): suffix_path = os.path.join(partition_path, suffix) diff --git a/test/unit/common/ring/test_utils.py b/test/unit/common/ring/test_utils.py index a112547310..bf59a33be1 100644 --- a/test/unit/common/ring/test_utils.py +++ b/test/unit/common/ring/test_utils.py @@ -191,6 +191,15 @@ class TestUtils(unittest.TestCase): self.assertTrue(is_local_device(my_ips, my_port, "localhost", my_port)) + self.assertFalse(is_local_device(my_ips, my_port, + "localhost", + my_port + 1)) + self.assertFalse(is_local_device(my_ips, my_port, + "127.0.0.2", + my_port)) + # for those that don't have a local port + self.assertTrue(is_local_device(my_ips, None, + my_ips[0], None)) def test_validate_and_normalize_ip(self): ipv4 = "10.0.0.1"