From 1cf5ea71d0895556bdfd69ae4302ebcca441289a Mon Sep 17 00:00:00 2001 From: James Page Date: Thu, 2 Feb 2017 10:58:20 +0000 Subject: [PATCH] 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 --- hooks/swift_hooks.py | 9 +++++++-- lib/swift_utils.py | 4 ++-- unit_tests/test_swift_utils.py | 7 +++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/hooks/swift_hooks.py b/hooks/swift_hooks.py index 1cf329f..2ca51e4 100755 --- a/hooks/swift_hooks.py +++ b/hooks/swift_hooks.py @@ -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). diff --git a/lib/swift_utils.py b/lib/swift_utils.py index 3f5ae05..c2aded2 100644 --- a/lib/swift_utils.py +++ b/lib/swift_utils.py @@ -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() diff --git a/unit_tests/test_swift_utils.py b/unit_tests/test_swift_utils.py index 41e6715..a6e8b6d 100644 --- a/unit_tests/test_swift_utils.py +++ b/unit_tests/test_swift_utils.py @@ -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')