Commit 151bc436 authored by Jérome Perrin's avatar Jérome Perrin

proxy: delete destroyed partitions from forwarded_partition_request

When a forwarded partition is requested in destroyed state, delete
the entry from forwarded_partition_request table (after getting reply
from remote server)
parent 285af41f
......@@ -5,6 +5,7 @@ Changes
------------------
* service list, service info: output json
* request: don't fetch schema for frontend software release, speeding up slapos node instance
* proxy: update forwarded_partition_request table after destroying a forwarded partition
1.8.3 (2022-10-17)
------------------
......
......@@ -667,13 +667,10 @@ def forwardRequestToExternalMaster(master_url, request_form):
filter_kw = loads(request_form['filter_xml'].encode('utf-8'))
partition_parameter_kw = loads(request_form['partition_parameter_xml'].encode('utf-8'))
app.logger.info("Forwarding request of %s to %s", partition_reference, master_url)
state = loads(request_form['state'].encode('utf-8'))
app.logger.info("Forwarding request of %s (state=%s) to %s ", partition_reference, state, master_url)
app.logger.debug("request_form: %s", request_form)
# Store in database
execute_db('forwarded_partition_request', 'INSERT OR REPLACE INTO %s values(:partition_reference, :master_url)',
{'partition_reference':partition_reference, 'master_url': master_url})
if master_entry.get('computer') and master_entry.get('partition'):
app.logger.debug("requesting from partition %s", master_entry)
# XXX ComputerPartition.request and OpenOrder.request have different signatures
......@@ -687,7 +684,7 @@ def forwardRequestToExternalMaster(master_url, request_form):
shared=loads(request_form['shared_xml'].encode('utf-8')),
partition_parameter_kw=partition_parameter_kw,
filter_kw=filter_kw,
state=loads(request_form['state'].encode('utf-8')),
state=state,
)
else:
filter_kw['source_instance_id'] = partition_reference
......@@ -697,10 +694,22 @@ def forwardRequestToExternalMaster(master_url, request_form):
partition_parameter_kw=partition_parameter_kw,
software_type=request_form.get('software_type', ''),
filter_kw=filter_kw,
state=loads(request_form['state'].encode('utf-8')),
state=state,
shared=loads(request_form['shared_xml'].encode('utf-8')),
)
# Store in database
if state == 'destroyed':
execute_db(
'forwarded_partition_request',
'DELETE FROM %s WHERE partition_reference = :partition_reference and master_url = :master_url',
{'partition_reference':partition_reference, 'master_url': master_url})
else:
execute_db(
'forwarded_partition_request',
'INSERT OR REPLACE INTO %s values(:partition_reference, :master_url)',
{'partition_reference':partition_reference, 'master_url': master_url})
# XXX move to other end
partition._master_url = master_url # type: ignore
partition._connection_helper = None
......
......@@ -1988,6 +1988,26 @@ database_uri = %(rootdir)s/lib/external_proxy.db
'requested_by': 'slappart0'
}], requested_by)
def testForwardToMasterAndDestroy(self):
instance_reference = 'MyFirstInstance'
self.format_for_number_of_partitions(1)
self.external_proxy_format_for_number_of_partitions(1)
self.request(self.external_software_release, None, instance_reference, 'slappart0')
self._checkInstanceIsForwarded(instance_reference, 'slappart0', {}, self.external_software_release)
self.request(self.external_software_release, None, instance_reference, 'slappart0', state='destroyed')
# partition is destroyed in the external slapos
external_slap = slapos.slap.slap()
external_slap.initializeConnection(self.external_master_url)
external_computer = external_slap.registerComputer(self.external_computer_id)
external_partition = external_computer.getComputerPartitionList()[0]
self.assertEqual(external_partition.getState(), 'destroyed')
# and no longer referenced in forwarded_partition_request
self.assertFalse(slapos.proxy.views.execute_db('forwarded_partition_request', 'SELECT * from %s', db=self.db))
def testRequestToCurrentMaster(self):
"""
Explicitely ask deployment of an instance to current master
......
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