Remove account name from being saved in the object

Instead we save the account in the a list, where the
index to the account is the partition number.

Change-Id: Ie4abefee48a3b237306a1e301ffa798e24e3f1db
Signed-off-by: Luis Pabon <lpabon@redhat.com>
Reviewed-on: http://review.gluster.org/5120
Reviewed-by: Peter Portante <pportant@redhat.com>
Tested-by: Peter Portante <pportant@redhat.com>
This commit is contained in:
Luis Pabon 2013-05-30 17:31:26 -04:00 committed by Peter Portante
parent 50e1660f5b
commit 31a2ef1935
2 changed files with 46 additions and 11 deletions

View File

@ -38,12 +38,30 @@ if not reseller_prefix.endswith('_'):
class Ring(ring.Ring):
def __init__(self, *args, **kwargs):
self.false_node = {'zone': 1, 'weight': 100.0, 'ip': '127.0.0.1',
'id': 0, 'meta': '', 'device': 'volume_not_in_ring',
'port': 6012}
self.account_list = []
ring.Ring.__init__(self, *args, **kwargs)
def _get_part_nodes(self, part):
seen_ids = set()
nodes = [dev for dev in self._devs if dev['device'] == self.acc_name
and not (dev['id'] in seen_ids or seen_ids.add(dev['id']))]
if not nodes:
nodes = [self.false_node]
try:
account = self.account_list[part]
except IndexError:
return [self.false_node]
else:
nodes = []
for dev in self._devs:
if dev['device'] == account:
if dev['id'] not in seen_ids:
seen_ids.add(dev['id'])
nodes.append(dev)
if not nodes:
nodes = [self.false_node]
return nodes
def get_part_nodes(self, part):
@ -85,15 +103,18 @@ class Ring(ring.Ring):
hardware description
====== ===============================================================
"""
self.false_node = {'zone': 1, 'weight': 100.0, 'ip': '127.0.0.1',
'id': 0, 'meta': '', 'device': 'volume_not_in_ring',
'port': 6012}
if account.startswith(reseller_prefix):
self.acc_name = account.replace(reseller_prefix, '', 1)
else:
self.acc_name = account
account = account.replace(reseller_prefix, '', 1)
# Save the account name in the table
# This makes part be the index of the location of the account
# in the list
try:
part = self.account_list.index(account)
except ValueError:
self.account_list.append(account)
part = self.account_list.index(account)
part = 0
return part, self._get_part_nodes(part)
def get_more_nodes(self, part):

View File

@ -53,3 +53,17 @@ class TestRing(unittest.TestCase):
def test_second_device_with_reseller_prefix(self):
part, node = self.ring.get_nodes('AUTH_iops')
assert node[0]['device'] == 'iops'
def test_partition_id_for_multiple_accounts(self):
test_part, test_node = self.ring.get_nodes('test')
iops_part, iops_node = self.ring.get_nodes('iops')
self.assertNotEqual(test_part, iops_part)
self.assertEqual(test_node, self.ring.get_part_nodes(test_part))
self.assertEqual(iops_node, self.ring.get_part_nodes(iops_part))
self.assertNotEqual(test_node, self.ring.get_part_nodes(iops_part))
self.assertNotEqual(iops_node, self.ring.get_part_nodes(test_part))
def test_invalid_partition(self):
nodes = self.ring.get_part_nodes(0)
self.assertEqual(nodes[0]['device'], 'volume_not_in_ring')