From 85d02112795999317c050b9b03aa3736e7ee84bd Mon Sep 17 00:00:00 2001 From: Pete Zaitcev Date: Thu, 30 Sep 2021 00:02:55 -0500 Subject: [PATCH] Get rid of port to node assumptions and their modulo kludges We had get_server_number for many years now, there's no reason to continue using the node_id=port%100//10 thing. Change-Id: I5357a095110e8e4889c0468c154611209c6e8c07 --- test/probe/common.py | 3 +-- test/probe/test_object_failures.py | 2 +- test/probe/test_object_handoff.py | 33 +++++++++++-------------- test/probe/test_reconstructor_revert.py | 4 +-- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/test/probe/common.py b/test/probe/common.py index d2bdfb4dc6..096cc69e58 100644 --- a/test/probe/common.py +++ b/test/probe/common.py @@ -634,10 +634,9 @@ class ReplProbeTest(ProbeTest): def get_container_db_files(self, container): opart, onodes = self.container_ring.get_nodes(self.account, container) - onode = onodes[0] db_files = [] for onode in onodes: - node_id = (onode['port'] % 100) // 10 + node_id = self.config_number(onode) device = onode['device'] hash_str = hash_path(self.account, container) server_conf = readconf(self.configs['container-server'][node_id]) diff --git a/test/probe/test_object_failures.py b/test/probe/test_object_failures.py index 0321473310..ae95096335 100644 --- a/test/probe/test_object_failures.py +++ b/test/probe/test_object_failures.py @@ -63,7 +63,7 @@ class TestObjectFailures(ReplProbeTest): opart, onodes = self.object_ring.get_nodes( self.account, container, obj) onode = onodes[0] - node_id = (onode['port'] % 100) // 10 + node_id = self.config_number(onode) device = onode['device'] hash_str = hash_path(self.account, container, obj) obj_server_conf = readconf(self.configs['object-server'][node_id]) diff --git a/test/probe/test_object_handoff.py b/test/probe/test_object_handoff.py index f4dc21ab3d..30a3a29642 100644 --- a/test/probe/test_object_handoff.py +++ b/test/probe/test_object_handoff.py @@ -30,8 +30,9 @@ from swift.common import direct_client from swift.common.exceptions import ClientException from swift.common.manager import Manager from swift.common.utils import md5 -from test.probe.common import (kill_server, start_server, ReplProbeTest, - ECProbeTest, Body) +from test.probe.common import ( + Body, get_server_number, kill_server, start_server, + ReplProbeTest, ECProbeTest) class TestObjectHandoff(ReplProbeTest): @@ -135,17 +136,14 @@ class TestObjectHandoff(ReplProbeTest): # Run object replication, ensuring we run the handoff node last so it # will remove its extra handoff partition for node in onodes: - try: - port_num = node['replication_port'] - except KeyError: - port_num = node['port'] - node_id = (port_num % 100) // 10 + _, node_id = get_server_number( + (node['ip'], node.get('replication_port', node['port'])), + self.ipport2server) Manager(['object-replicator']).once(number=node_id) - try: - another_port_num = another_onode['replication_port'] - except KeyError: - another_port_num = another_onode['port'] - another_num = (another_port_num % 100) // 10 + another_port_num = another_onode.get( + 'replication_port', another_onode['port']) + _, another_num = get_server_number( + (another_onode['ip'], another_port_num), self.ipport2server) Manager(['object-replicator']).once(number=another_num) # Assert the first container/obj primary server now has container/obj @@ -227,13 +225,12 @@ class TestObjectHandoff(ReplProbeTest): # Run object replication, ensuring we run the handoff node last so it # will remove its extra handoff partition for node in onodes: - try: - port_num = node['replication_port'] - except KeyError: - port_num = node['port'] - node_id = (port_num % 100) // 10 + _, node_id = get_server_number( + (node['ip'], node.get('replication_port', node['port'])), + self.ipport2server) Manager(['object-replicator']).once(number=node_id) - another_node_id = (another_port_num % 100) // 10 + _, another_node_id = get_server_number( + (another_onode['ip'], another_port_num), self.ipport2server) Manager(['object-replicator']).once(number=another_node_id) # Assert primary node no longer has container/obj diff --git a/test/probe/test_reconstructor_revert.py b/test/probe/test_reconstructor_revert.py index 3065e95e98..a86f4b49c0 100644 --- a/test/probe/test_reconstructor_revert.py +++ b/test/probe/test_reconstructor_revert.py @@ -86,7 +86,7 @@ class TestReconstructorRevert(ECProbeTest): # fire up reconstructor on handoff nodes only for hnode in hnodes: - hnode_id = (hnode['port'] % 100) // 10 + hnode_id = self.config_number(hnode) self.reconstructor.once(number=hnode_id) # first three primaries have data again @@ -398,7 +398,7 @@ class TestReconstructorRevert(ECProbeTest): # fire up reconstructor on handoff node only; commit_window is # set to zero to ensure the nondurable handoff frag is purged - hnode_id = (hnodes[0]['port'] % 100) // 10 + hnode_id = self.config_number(hnodes[0]) self.run_custom_daemon( ObjectReconstructor, 'object-reconstructor', hnode_id, {'commit_window': '0'})