Commit 21ce22fb authored by Jérome Perrin's avatar Jérome Perrin

proxy: remove no longer existing partitions on updateConfiguration

Calling computer.updateConfiguration should remove previously defined
partitions that are no longer part of the configuration.
parent 88d5383f
......@@ -350,11 +350,14 @@ def loadComputerConfigurationFromXML():
computer_dict = loads(xml.encode('utf-8'))
execute_db('computer', 'INSERT OR REPLACE INTO %s values(:reference, :address, :netmask)',
computer_dict)
# remove references to old partitions.
execute_db('partition', 'DELETE FROM %s WHERE computer_reference = :reference', computer_dict)
execute_db('partition_network', 'DELETE FROM %s WHERE computer_reference = :reference', computer_dict)
for partition in computer_dict['partition_list']:
partition['computer_reference'] = computer_dict['reference']
execute_db('partition', 'INSERT OR IGNORE INTO %s (reference, computer_reference) values(:reference, :computer_reference)', partition)
execute_db('partition_network', 'DELETE FROM %s WHERE partition_reference = ? AND computer_reference = ?',
[partition['reference'], partition['computer_reference']])
for address in partition['address_list']:
address['reference'] = partition['tap']['name']
address['partition_reference'] = partition['reference']
......
......@@ -160,6 +160,47 @@ database_uri = %(tempdir)s/lib/proxy.db
views.is_schema_already_executed = False
class TestLoadComputerConfiguration(BasicMixin, unittest.TestCase):
"""tests /loadComputerConfigurationFromXML the endpoint for format
"""
def test_loadComputerConfigurationFromXML_remove_partitions(self):
computer_dict = {
'reference': self.computer_id,
'address': '12.34.56.78',
'netmask': '255.255.255.255',
'partition_list': [
{
'reference': 'slappart1',
'address_list': [
{
'addr': '1.2.3.4',
'netmask': '255.255.255.255'
},
],
'tap': {'name': 'tap0'},
}
],
}
rv = self.app.post('/loadComputerConfigurationFromXML', data={
'computer_id': self.computer_id,
'xml': dumps(computer_dict),
})
self.assertEqual(rv._status_code, 200)
# call again with different partition reference, old partition will be removed
# and a new partition will be used.
computer_dict['partition_list'][0]['reference'] = 'something else'
rv = self.app.post('/loadComputerConfigurationFromXML', data={
'computer_id': self.computer_id,
'xml': dumps(computer_dict),
})
self.assertEqual(rv._status_code, 200)
computer = loads(
self.app.get('/getFullComputerInformation', query_string={'computer_id': self.computer_id}).data)
self.assertEqual(
['something else'],
[p.getId() for p in computer._computer_partition_list])
class TestInformation(BasicMixin, unittest.TestCase):
"""
Test Basic response of slapproxy
......
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