Commit efc319ce authored by Łukasz Nowak's avatar Łukasz Nowak

proxy: Support slave removal

Additionally timestamp is updated on each slave removal.
parent d3b935fc
Pipeline #7527 failed with stage
in 0 seconds
......@@ -758,6 +758,14 @@ def requestSlave(software_release, software_type, partition_reference, partition
# Add slave to partition slave_list if not present else replace information
slave_updated_or_added = False
slave_instance_list = partition['slave_instance_list']
if requested_state == 'destroyed':
if slave_instance_list:
slave_instance_list = loads(slave_instance_list.encode('utf-8'))
before_count = len(slave_instance_list)
slave_instance_list = [x for x in slave_instance_list if x['slave_reference'] != slave_reference]
if before_count != len(slave_instance_list):
slave_updated_or_added = True
else:
if slave_instance_list:
slave_instance_list = loads(slave_instance_list.encode('utf-8'))
for i, x in enumerate(slave_instance_list):
......
......@@ -916,6 +916,29 @@ class TestSlaveRequest(MasterMixin):
self.assertEqual(len(after._parameter_dict['slave_instance_list']), 2)
self.assertEqual(before_timestamp, after_timestamp, 'No-op change of the slave shall not change the timestamp')
def test_slave_request_destroyed(self):
self.format_for_number_of_partitions(1)
# Provide partition
master_partition = self.request('http://sr//', None, 'MyMasterInstance', 'slappart4')
def getPartition():
return self.getFullComputerInformation()._computer_partition_list[0]
def getTimestamp(partition):
return float(partition._parameter_dict['timestamp'])
self.request('http://sr//', None, 'MyFirstSlave', shared=True)
self.request('http://sr//', None, 'MySecondSlave', shared=True)
after = getPartition()
self.assertEqual(len(after._parameter_dict['slave_instance_list']), 2)
before_timestamp = getTimestamp(after)
time.sleep(.1)
self.request('http://sr//', None, 'MyFirstSlave', shared=True, state='destroyed')
after = getPartition()
after_timestamp = getTimestamp(after)
self.assertEqual(len(after._parameter_dict['slave_instance_list']), 1)
self.assertLess(before_timestamp, after_timestamp, 'Slave destroy shall result with timestamp update')
self.assertEqual(after._parameter_dict['slave_instance_list'][0]['slave_reference'], '_MySecondSlave')
def test_slave_request_set_parameters_are_updated(self):
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment