Commit bb983933 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud: Move _getSoftwareInstallationFromUrl into ComputeNodeMixin

   This prevent us rely on SlapTool implementation to search the Software Installation for a given URL
parent 41e5b43f
...@@ -32,6 +32,7 @@ from AccessControl.Permissions import access_contents_information ...@@ -32,6 +32,7 @@ from AccessControl.Permissions import access_contents_information
from AccessControl import getSecurityManager from AccessControl import getSecurityManager
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from Products.ERP5Type.tests.utils import DummyMailHostMixin from Products.ERP5Type.tests.utils import DummyMailHostMixin
from OFS.Traversable import NotFound
import time import time
from lxml import etree from lxml import etree
...@@ -150,7 +151,6 @@ class SlapOSComputeNodeMixin(object): ...@@ -150,7 +151,6 @@ class SlapOSComputeNodeMixin(object):
# called on site # called on site
pass pass
def _calculateRefreshEtag(self): def _calculateRefreshEtag(self):
# check max indexation timestamp # check max indexation timestamp
# it is unlikely to get an empty catalog # it is unlikely to get an empty catalog
...@@ -326,3 +326,24 @@ class SlapOSComputeNodeMixin(object): ...@@ -326,3 +326,24 @@ class SlapOSComputeNodeMixin(object):
slap_partition._parameter_dict.update(parameter_dict) slap_partition._parameter_dict.update(parameter_dict)
return slap_partition return slap_partition
def _getSoftwareInstallationFromUrl(self, url):
software_installation_list = self.getPortalObject().portal_catalog.unrestrictedSearchResults(
portal_type='Software Installation',
default_aggregate_uid=self.getUid(),
validation_state='validated',
limit=2,
url_string={'query': url, 'key': 'ExactMatch'},
)
l = len(software_installation_list)
if l == 1:
return _assertACI(software_installation_list[0].getObject())
elif l == 0:
raise NotFound('No software release %r found on compute_node %r' % (url,
self.getReference()))
else:
raise ValueError('Wrong list of software releases on %r: %s' % (
self.getReference(), ', '.join([q.getRelativeUrl() for q \
in software_installation_list])
))
...@@ -304,15 +304,11 @@ class SlapTool(BaseTool): ...@@ -304,15 +304,11 @@ class SlapTool(BaseTool):
""" """
Get the connection status of the software installation Get the connection status of the software installation
""" """
compute_node = self.getPortalObject().portal_catalog.unrestrictedSearchResults( compute_node = self._getComputeNodeDocument(computer_id)
portal_type='Compute Node', reference=computer_id,
validation_state="validated")[0].getObject()
# Be sure to prevent accessing information to disallowed users # Be sure to prevent accessing information to disallowed users
compute_node = _assertACI(compute_node) compute_node = _assertACI(compute_node)
try: try:
software_installation = self._getSoftwareInstallationForComputeNode( software_installation = compute_node._getSoftwareInstallationFromUrl(url)
url,
compute_node)
except NotFound: except NotFound:
data_dict = self._getAccessStatus(None) data_dict = self._getAccessStatus(None)
else: else:
...@@ -799,14 +795,17 @@ class SlapTool(BaseTool): ...@@ -799,14 +795,17 @@ class SlapTool(BaseTool):
compute_node_document = self._getComputeNodeDocument(compute_node_id) compute_node_document = self._getComputeNodeDocument(compute_node_id)
compute_node_document.requestSoftwareRelease(software_release_url=url, state=state) compute_node_document.requestSoftwareRelease(software_release_url=url, state=state)
########
@convertToREST @convertToREST
def _buildingSoftwareRelease(self, url, compute_node_id): def _buildingSoftwareRelease(self, url, compute_node_id):
""" """
Log the software release status Log the software release status
""" """
compute_node_document = self._getComputeNodeDocument(compute_node_id) compute_node = self._getComputeNodeDocument(compute_node_id)
software_installation = self._getSoftwareInstallationForComputeNode(url, software_installation = compute_node._getSoftwareInstallationFromUrl(url)
compute_node_document)
software_installation.setBuildingStatus( software_installation.setBuildingStatus(
'software release %s' % url, "building") 'software release %s' % url, "building")
...@@ -815,9 +814,8 @@ class SlapTool(BaseTool): ...@@ -815,9 +814,8 @@ class SlapTool(BaseTool):
""" """
Log the software release status Log the software release status
""" """
compute_node_document = self._getComputeNodeDocument(compute_node_id) compute_node = self._getComputeNodeDocument(compute_node_id)
software_installation = self._getSoftwareInstallationForComputeNode(url, software_installation = compute_node._getSoftwareInstallationFromUrl(url)
compute_node_document)
software_installation.setAccessStatus( software_installation.setAccessStatus(
'software release %s available' % url, "available") 'software release %s available' % url, "available")
...@@ -826,9 +824,8 @@ class SlapTool(BaseTool): ...@@ -826,9 +824,8 @@ class SlapTool(BaseTool):
""" """
Reports that Software Release is destroyed Reports that Software Release is destroyed
""" """
compute_node_document = self._getComputeNodeDocument(compute_node_id) compute_node = self._getComputeNodeDocument(compute_node_id)
software_installation = self._getSoftwareInstallationForComputeNode(url, software_installation = compute_node._getSoftwareInstallationFromUrl(url)
compute_node_document)
if software_installation.getSlapState() != 'destroy_requested': if software_installation.getSlapState() != 'destroy_requested':
raise NotFound raise NotFound
if self.getPortalObject().portal_workflow.isTransitionPossible(software_installation, if self.getPortalObject().portal_workflow.isTransitionPossible(software_installation,
...@@ -1196,31 +1193,6 @@ class SlapTool(BaseTool): ...@@ -1196,31 +1193,6 @@ class SlapTool(BaseTool):
parent_uid=self._getComputeNodeUidByReference( parent_uid=self._getComputeNodeUidByReference(
compute_node_reference)) compute_node_reference))
def _getSoftwareInstallationForComputeNode(self, url, compute_node_document):
software_installation_list = self.getPortalObject().portal_catalog.unrestrictedSearchResults(
portal_type='Software Installation',
default_aggregate_uid=compute_node_document.getUid(),
validation_state='validated',
limit=2,
url_string={'query': url, 'key': 'ExactMatch'},
)
l = len(software_installation_list)
if l == 1:
return _assertACI(software_installation_list[0].getObject())
elif l == 0:
raise NotFound('No software release %r found on compute_node %r' % (url,
compute_node_document.getReference()))
else:
raise ValueError('Wrong list of software releases on %r: %s' % (
compute_node_document.getReference(), ', '.join([q.getRelativeUrl() for q \
in software_installation_list])
))
def _getSoftwareInstallationReference(self, url, compute_node_document):
return self._getSoftwareInstallationForComputeNode(url,
compute_node_document).getReference()
def _getSoftwareInstanceForComputePartition(self, compute_node_id, def _getSoftwareInstanceForComputePartition(self, compute_node_id,
compute_partition_id, slave_reference=None): compute_partition_id, slave_reference=None):
compute_partition_document = self._getComputePartitionDocument( compute_partition_document = self._getComputePartitionDocument(
...@@ -1254,9 +1226,8 @@ class SlapTool(BaseTool): ...@@ -1254,9 +1226,8 @@ class SlapTool(BaseTool):
""" """
Log the compute_node status Log the compute_node status
""" """
compute_node_document = self._getComputeNodeDocument(compute_node_id) compute_node = self._getComputeNodeDocument(compute_node_id)
software_installation = self._getSoftwareInstallationForComputeNode(url, software_installation = compute_node._getSoftwareInstallationFromUrl(url)
compute_node_document)
software_installation.setErrorStatus('while installing %s' % url) software_installation.setErrorStatus('while installing %s' % url)
InitializeClass(SlapTool) InitializeClass(SlapTool)
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