Skip to content
This repository was archived by the owner on Jan 1, 2024. It is now read-only.

Commit bb85d61

Browse files
authored
Add disabled instances to single_instances_for_each_machine variable (#415)
Before this patch, only enabled instances got into the `single_instances_for_each_machine` variable. This prevented updating instances that are disabled. Now, if no enabled instance was found for a machine, a disabled instance is added to this list.
1 parent 9a6d796 commit bb85d61

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ README.md to use the newest tag with new release
2020
- Remove old app configurations before uploading a new one
2121
- Allow downgrading RPM and DEB packages
2222
- Ignore disabled instances when counting disabled instances
23+
- Add disabled instances to `single_instances_for_each_machine` variable
2324

2425
## [1.12.0] - 2022-03-03
2526

library/cartridge_get_facts_for_machines.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def get_facts_for_machines(params):
2727
play_hosts = params['play_hosts']
2828

2929
single_instances_for_each_machine = {}
30+
single_instances_for_each_machine_with_disabled = {}
3031
instances_by_machines = {}
3132
instances_from_same_machine = {}
3233

@@ -41,13 +42,24 @@ def get_facts_for_machines(params):
4142
# Copy link to machine list
4243
instances_from_same_machine[instance_name] = instances_by_machines[machine_id]
4344

44-
# Calculate single not expelled instance for each machine
45+
# Calculate single enabled instance for each machine
4546
if all([
4647
helpers.is_enabled(instance_vars),
4748
instance_name not in cluster_disabled_instances,
4849
machine_id not in single_instances_for_each_machine,
4950
]):
5051
single_instances_for_each_machine[machine_id] = instance_name
52+
# Calculate single not expelled instance for each machine
53+
elif all([
54+
not helpers.is_expelled(instance_vars),
55+
machine_id not in single_instances_for_each_machine_with_disabled,
56+
]):
57+
single_instances_for_each_machine_with_disabled[machine_id] = instance_name
58+
59+
# If there is no enabled instance, then check for the presence of a disabled (not expelled) one
60+
for machine_id, instance_name in single_instances_for_each_machine_with_disabled.items():
61+
if machine_id not in single_instances_for_each_machine:
62+
single_instances_for_each_machine[machine_id] = instance_name
5163

5264
return helpers.ModuleRes(
5365
changed=False,

unit/test_get_facts_for_machines.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def setUp(self):
3333
},
3434
'instance-1-1': {
3535
'ansible_host': 'host-1',
36+
'disabled': True,
3637
},
3738
'instance-1-2': {
3839
'ansible_host': 'host-1',
@@ -69,6 +70,10 @@ def setUp(self):
6970
'ansible_host': 'host-2',
7071
'ansible_port': 44, # one more different port
7172
},
73+
'instance-3-1': {
74+
'ansible_host': 'host-3',
75+
'disabled': True,
76+
},
7277
}
7378

7479
def test_no_instances_in_play_hosts(self):
@@ -105,13 +110,18 @@ def test_all_instances_specified(self):
105110
'stateboard-1', 'stateboard-2',
106111
'instance-1-1', 'instance-1-2', 'instance-1-3', 'instance-1-4',
107112
'instance-2-1', 'instance-2-2', 'instance-2-3', 'instance-2-4',
113+
'instance-3-1',
108114
])
109115
self.assertFalse(res.failed, res.msg)
110116

111117
single_instances_for_each_machine = res.kwargs['single_instances_for_each_machine']
112118
self.assertSetEqual(set(single_instances_for_each_machine), {
113-
'instance-1-1', 'instance-1-3',
114-
'instance-2-1', 'instance-2-3', 'instance-2-4',
119+
'instance-1-2', # host-1:22
120+
'instance-1-3', # host-1:33
121+
'instance-2-1', # host-2:22
122+
'instance-2-3', # host-2:33
123+
'instance-2-4', # host-2:44
124+
'instance-3-1', # host-3:22
115125
})
116126
self.assertEqual(res.kwargs['instances_from_same_machine'], {
117127
# host-1:22
@@ -131,4 +141,6 @@ def test_all_instances_specified(self):
131141
'instance-2-3': ['instance-2-3'],
132142
# host-2:44
133143
'instance-2-4': ['instance-2-4'],
144+
# host-3:22
145+
'instance-3-1': ['instance-3-1'],
134146
})

0 commit comments

Comments
 (0)