Ensure storage hooks observe disable-ring-rebalance

When adding new storage capacity, its desirable to disable ring
rebalancing until all new storage has been added, allowing the
end-user to determing when all new capacity has been added and its
OK to rebalance the rings and re-distribute.

Ensure that storage hook events from swift-storage observe the
'disable-ring-rebalance' configuration option, enabling end users
to perform this type of orchestration storage expansion.

Change-Id: I95727e663b369d5feb28147b19edcc6cab36b905
Closes-Bug: 1638981
This commit is contained in:
James Page 2017-02-02 10:58:20 +00:00
parent 08f81f6a0e
commit 1cf5ea71d0
3 changed files with 16 additions and 4 deletions

View File

@ -171,7 +171,8 @@ def config_changed():
status_set('maintenance', 'Running openstack upgrade')
status_set('maintenance', 'Updating and (maybe) balancing rings')
update_rings(min_part_hours=config('min-hours'))
update_rings(min_part_hours=config('min-hours'),
rebalance=not config('disable-ring-balance'))
if not config('disable-ring-balance') and is_elected_leader(SWIFT_HA_RES):
# Try ring balance. If rings are balanced, no sync will occur.
@ -324,7 +325,11 @@ def storage_changed():
node['device'] = dev
nodes.append(node)
update_rings(nodes)
# NOTE(jamespage): ensure that disable-ring-balance is observed
# whilst new storage is added - rebalance will
# happen when configuration is toggled later
update_rings(nodes, rebalance=not config('disable-ring-balance'))
if not openstack.is_unit_paused_set():
# Restart proxy here in case no config changes made (so
# restart_on_change() ineffective).

View File

@ -861,7 +861,7 @@ def sync_builders_and_rings_if_changed(f):
@sync_builders_and_rings_if_changed
def update_rings(nodes=[], min_part_hours=None):
def update_rings(nodes=[], min_part_hours=None, rebalance=True):
"""Update builder with node settings and balance rings if necessary.
Also update min_part_hours if provided.
@ -899,7 +899,7 @@ def update_rings(nodes=[], min_part_hours=None):
add_to_ring(ring, node)
balance_required = True
if balance_required:
if rebalance and balance_required:
balance_rings()

View File

@ -90,6 +90,13 @@ class SwiftUtilsTestCase(unittest.TestCase):
self.assertTrue(mock_set_min_hours.called)
self.assertTrue(mock_balance_rings.called)
mock_balance_rings.reset_mock()
swift_utils.update_rings(min_part_hours=10,
rebalance=False)
self.assertTrue(mock_get_min_hours.called)
self.assertTrue(mock_set_min_hours.called)
self.assertFalse(mock_balance_rings.called)
@mock.patch('lib.swift_utils.previously_synced')
@mock.patch('lib.swift_utils._load_builder')
@mock.patch('lib.swift_utils.initialize_ring')