Commit f01afc72 authored by Jérome Perrin's avatar Jérome Perrin

Implement Software Destruction in slapos proxy

Slapos proxy was not really deleting the software, just removing it from its database but not telling the node that requester requested deletion.

As a result, node was not destroying the software and leaving the software folder around.

These changes are about telling the node that requester wanted destruction of software, so that node really delete the folder.

/reviewed-on nexedi/slapos.core!76
parents a92ef82b c331767f
--version:11 --version:12
CREATE TABLE IF NOT EXISTS software%(version)s ( CREATE TABLE IF NOT EXISTS software%(version)s (
url VARCHAR(255), url VARCHAR(255),
computer_reference VARCHAR(255) DEFAULT '%(computer)s', computer_reference VARCHAR(255) DEFAULT '%(computer)s',
requested_state VARCHAR(255) DEFAULT 'available',
CONSTRAINT uniq PRIMARY KEY (url, computer_reference) CONSTRAINT uniq PRIMARY KEY (url, computer_reference)
); );
......
...@@ -222,8 +222,11 @@ def getFullComputerInformation(): ...@@ -222,8 +222,11 @@ def getFullComputerInformation():
slap_computer = Computer(computer_id) slap_computer = Computer(computer_id)
slap_computer._software_release_list = [] slap_computer._software_release_list = []
for sr in execute_db('software', 'select * from %s WHERE computer_reference=?', [computer_id]): for sr in execute_db('software', 'select * from %s WHERE computer_reference=?', [computer_id]):
slap_computer._software_release_list.append(SoftwareRelease( software_release = SoftwareRelease(
software_release=sr['url'], computer_guid=computer_id)) software_release=sr['url'],
computer_guid=computer_id)
software_release._requested_state = sr['requested_state']
slap_computer._software_release_list.append(software_release)
slap_computer._computer_partition_list = [] slap_computer._computer_partition_list = []
for partition in execute_db('partition', 'SELECT * FROM %s WHERE computer_reference=?', [computer_id]): for partition in execute_db('partition', 'SELECT * FROM %s WHERE computer_reference=?', [computer_id]):
slap_computer._computer_partition_list.append(partitiondict2partition( slap_computer._computer_partition_list.append(partitiondict2partition(
...@@ -251,6 +254,14 @@ def setComputerPartitionConnectionXml(): ...@@ -251,6 +254,14 @@ def setComputerPartitionConnectionXml():
def buildingSoftwareRelease(): def buildingSoftwareRelease():
return 'Ignored' return 'Ignored'
@app.route('/destroyedSoftwareRelease', methods=['POST'])
def destroyedSoftwareRelease():
execute_db(
'software',
'DELETE FROM %s WHERE url = ? and computer_reference=? ',
[request.form['url'], request.form['computer_id']])
return 'OK'
@app.route('/availableSoftwareRelease', methods=['POST']) @app.route('/availableSoftwareRelease', methods=['POST'])
def availableSoftwareRelease(): def availableSoftwareRelease():
return 'Ignored' return 'Ignored'
...@@ -316,12 +327,16 @@ def registerComputerPartition(): ...@@ -316,12 +327,16 @@ def registerComputerPartition():
def supplySupply(): def supplySupply():
url = request.form['url'] url = request.form['url']
computer_id = request.form['computer_id'] computer_id = request.form['computer_id']
if request.form['state'] == 'destroyed': state = request.form['state']
execute_db('software', 'DELETE FROM %s WHERE url = ? AND computer_reference=?', if state not in ('available', 'destroyed'):
[url, computer_id]) raise ValueError("Wrong state %s" % state)
else:
execute_db('software', 'INSERT OR REPLACE INTO %s VALUES(?, ?)', [url, computer_id]) execute_db(
return '%r added' % url 'software',
'INSERT OR REPLACE INTO %s VALUES(?, ?, ?)',
[url, computer_id, state])
return 'Supplied %r to be %s' % (url, state)
@app.route('/requestComputerPartition', methods=['POST']) @app.route('/requestComputerPartition', methods=['POST'])
......
...@@ -120,7 +120,7 @@ class SoftwareRelease(SlapDocument): ...@@ -120,7 +120,7 @@ class SoftwareRelease(SlapDocument):
Contains Software Release information Contains Software Release information
""" """
def __init__(self, software_release=None, computer_guid=None, **kw): def __init__(self, software_release=None, computer_guid=None, requested_state='available', **kw):
""" """
Makes easy initialisation of class parameters Makes easy initialisation of class parameters
......
...@@ -97,7 +97,7 @@ class TestCliProxyShow(CliMixin): ...@@ -97,7 +97,7 @@ class TestCliProxyShow(CliMixin):
self.conf.logger = self.logger self.conf.logger = self.logger
# load database # load database
schema = bytes2str(pkg_resources.resource_string('slapos.tests.slapproxy', 'database_dump_version_11.sql')) schema = bytes2str(pkg_resources.resource_string('slapos.tests.slapproxy', 'database_dump_version_current.sql'))
db = sqlite_connect(self.db_file.name) db = sqlite_connect(self.db_file.name)
db.cursor().executescript(schema) db.cursor().executescript(schema)
db.commit() db.commit()
...@@ -123,7 +123,7 @@ class TestCliProxyShow(CliMixin): ...@@ -123,7 +123,7 @@ class TestCliProxyShow(CliMixin):
# installed softwares are listed # installed softwares are listed
logger.info.assert_any_call( logger.info.assert_any_call(
' /srv/slapgrid/slappart8/srv/runner/project/slapos/software/erp5/software.cfg slaprunner 287375f0cba269902ba1bc50242839d7 ' ) ' /srv/slapgrid/slappart8/srv/runner/project/slapos/software/erp5/software.cfg available slaprunner 287375f0cba269902ba1bc50242839d7 ' )
# instance parameters are listed # instance parameters are listed
# _ parameter is json formatted # _ parameter is json formatted
......
This diff is collapsed.
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