From 57de3c8817c02bb816fcf1dbf1e7ae3237be3f71 Mon Sep 17 00:00:00 2001 From: Andy McCrae Date: Mon, 20 Mar 2017 10:51:05 +0000 Subject: [PATCH] Check if changes have made before attempting a rebalance Utilize the "ringbuilder.devs_changed" option to ensure that the ring needs a rebalance. This will prevent unnecessary rebalances that cause failures due to "min_part_hours" not being passed even though no changes were required. Additionally, we can now return a correct Ansible repsonse when the ring has changed/rebalanced - and return "OK" when it hasn't returned at all. Change-Id: I1fb4b3544a50ab5f566b3846d616107a84ff29c9 --- tasks/swift_rings_build.yml | 8 ++++++-- templates/swift_rings.py.j2 | 3 ++- tests/os_swift-overrides.yml | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tasks/swift_rings_build.yml b/tasks/swift_rings_build.yml index b2ce7e3b..e7d54d88 100644 --- a/tasks/swift_rings_build.yml +++ b/tasks/swift_rings_build.yml @@ -48,9 +48,11 @@ with_nested: - [ 'account', 'container' ] - "{{ swift_managed_regions | default([None]) }}" + register: swift_rings_create become: yes become_user: "{{ swift_system_user_name }}" - changed_when: false + changed_when: "{{ swift_rings_create.rc not in [1, 2, 3] }}" + failed_when: "{{ swift_rings_create.rc in [1, 2] }}" args: chdir: /etc/swift/ring_build_files/ @@ -59,8 +61,10 @@ with_nested: - "{{ swift.storage_policies }}" - "{{ swift_managed_regions | default([None]) }}" + register: swift_object_rings_create become: yes become_user: "{{ swift_system_user_name }}" - changed_when: false + changed_when: "{{ swift_object_rings_create.rc not in [1, 2, 3] }}" + failed_when: "{{ swift_object_rings_create.rc in [1, 2] }}" args: chdir: /etc/swift/ring_build_files/ diff --git a/templates/swift_rings.py.j2 b/templates/swift_rings.py.j2 index 7f190509..5c236029 100644 --- a/templates/swift_rings.py.j2 +++ b/templates/swift_rings.py.j2 @@ -140,11 +140,12 @@ def build_ring(build_name, repl, min_part_hours, part_power, hosts, # Rebalance ring if not validate: - if not hosts: + if not hosts or not ringbuilder.devs_changed: ringdata = ringbuilder.get_ring() ringdata.save(join(backup_folder, '%d.' % ts + basename(ring_file))) ringdata.save(ring_file) + exit(3) else: if reset_mph_clock: ringbuilder.pretend_min_part_hours_passed() diff --git a/tests/os_swift-overrides.yml b/tests/os_swift-overrides.yml index c60e4b8b..62a96347 100644 --- a/tests/os_swift-overrides.yml +++ b/tests/os_swift-overrides.yml @@ -21,6 +21,8 @@ bridges: - name: "br-repl" ip_addr: "10.1.3.1" +swift_pretend_min_part_hours_passed: False + swift: storage_network: "{{ test_swift_storage_network | default('eth2') }}" replication_network: "{{ test_swift_repl_network | default('eth3') }}"