Commit 9fdaa54d authored by Rafael Monnerat's avatar Rafael Monnerat

API Change: Remove available/building API from Computer Partition

  The API that notify availability and building from Computer Partition is unecessary and it's
  implementation overuse resources and cause flaky effect on the state of the Computer Partition.

  At the Software Release, the states can be available/building/error, and this state tens to be
  immutable once the software release is finished (it will be available, where building and error are
  transitory states).

  At Computer Partition, we intent to have started/stopped/destroyed instances, where available and
  building were transitory, but they have no practical function as a second report would come quickly
  after. So we may consider that started is actually same as available, in this case, it is a duplicated
  meaning, as you cannot be available w/o been started/stopped.

  computer_partition.building were never used, as the master knew that a partition is been processed,
  so this API were never used.

  Report transitory states are prevent us to determinate the actuall state, considering that the latest
  actuall state is more relevant (started/stopped/destroyed).
parent e58e8f7c
......@@ -1519,7 +1519,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
<unicode>created_at</unicode>
<unicode>%(created_at)s</unicode>
<unicode>text</unicode>
<unicode>#error while instanciating</unicode>
<unicode>#error while instanciating: The error</unicode>
<unicode>user</unicode>
<unicode>%(instance_guid)s</unicode>
</dictionary>
......@@ -1819,80 +1819,6 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
self.assertEqual([],
self.start_requested_software_instance.getPredecessorTitleList())
def test_availableComputerPartition(self):
self._makeComplexComputer()
partition_id = self.start_requested_software_instance.getAggregateValue(
portal_type='Computer Partition').getReference()
self.login(self.start_requested_software_instance.getUserId())
response = self.portal_slap.availableComputerPartition(self.computer_id,
partition_id)
self.assertEqual('None', response)
created_at = rfc1123_date(DateTime())
response = self.portal_slap.getComputerPartitionStatus(self.computer_id,
partition_id)
# check returned XML
xml_fp = StringIO.StringIO()
xml.dom.ext.PrettyPrint(xml.dom.ext.reader.Sax.FromXml(response.body),
stream=xml_fp)
xml_fp.seek(0)
got_xml = xml_fp.read()
expected_xml = """\
<?xml version='1.0' encoding='UTF-8'?>
<marshal>
<dictionary id='i2'>
<unicode>created_at</unicode>
<unicode>%(created_at)s</unicode>
<unicode>text</unicode>
<unicode>#access instance available</unicode>
<unicode>user</unicode>
<unicode>%(instance_guid)s</unicode>
</dictionary>
</marshal>
""" % dict(
created_at=created_at,
instance_guid=self.start_requested_software_instance.getReference(),
)
self.assertEqual(expected_xml, got_xml,
'\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))]))
def test_buildingComputerPartition(self):
self._makeComplexComputer()
partition_id = self.start_requested_software_instance.getAggregateValue(
portal_type='Computer Partition').getReference()
self.login(self.start_requested_software_instance.getUserId())
response = self.portal_slap.buildingComputerPartition(self.computer_id,
partition_id)
self.assertEqual('None', response)
created_at = rfc1123_date(DateTime())
response = self.portal_slap.getComputerPartitionStatus(self.computer_id,
partition_id)
# check returned XML
xml_fp = StringIO.StringIO()
xml.dom.ext.PrettyPrint(xml.dom.ext.reader.Sax.FromXml(response.body),
stream=xml_fp)
xml_fp.seek(0)
got_xml = xml_fp.read()
expected_xml = """\
<?xml version='1.0' encoding='UTF-8'?>
<marshal>
<dictionary id='i2'>
<unicode>created_at</unicode>
<unicode>%(created_at)s</unicode>
<unicode>text</unicode>
<unicode>building the instance</unicode>
<unicode>user</unicode>
<unicode>%(instance_guid)s</unicode>
</dictionary>
</marshal>
""" % dict(
created_at=created_at,
instance_guid=self.start_requested_software_instance.getReference(),
)
self.assertEqual(expected_xml, got_xml,
'\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))]))
def test_stoppedComputerPartition(self):
self._makeComplexComputer()
partition_id = self.start_requested_software_instance.getAggregateValue(
......@@ -3040,4 +2966,4 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
self.login(self.person_user_id)
response = self.portal_slap.getHateoasUrl()
self.assertEqual(200, response.status)
self.assertEqual('foo', response.body)
self.assertEqual('foo', response.body)
\ No newline at end of file
......@@ -47,21 +47,21 @@
<value>
<tuple>
<string>W: 28, 10: Use of eval (eval-used)</string>
<string>W:516, 13: Use of eval (eval-used)</string>
<string>W:567, 13: Use of eval (eval-used)</string>
<string>W:792, 13: Use of eval (eval-used)</string>
<string>W:1400, 13: Use of eval (eval-used)</string>
<string>W:1513, 13: Use of eval (eval-used)</string>
<string>W:1567, 13: Use of eval (eval-used)</string>
<string>W:1607, 13: Use of eval (eval-used)</string>
<string>W:2229, 13: Use of eval (eval-used)</string>
<string>W:2614, 13: Use of eval (eval-used)</string>
<string>W:2668, 13: Use of eval (eval-used)</string>
<string>W:2695, 13: Use of eval (eval-used)</string>
<string>W:2850, 13: Use of eval (eval-used)</string>
<string>W:2878, 13: Use of eval (eval-used)</string>
<string>W:2927, 13: Use of eval (eval-used)</string>
<string>W:2974, 13: Use of eval (eval-used)</string>
<string>W:529, 13: Use of eval (eval-used)</string>
<string>W:580, 13: Use of eval (eval-used)</string>
<string>W:805, 13: Use of eval (eval-used)</string>
<string>W:1422, 13: Use of eval (eval-used)</string>
<string>W:1535, 13: Use of eval (eval-used)</string>
<string>W:1589, 13: Use of eval (eval-used)</string>
<string>W:1629, 13: Use of eval (eval-used)</string>
<string>W:2177, 13: Use of eval (eval-used)</string>
<string>W:2566, 13: Use of eval (eval-used)</string>
<string>W:2620, 13: Use of eval (eval-used)</string>
<string>W:2647, 13: Use of eval (eval-used)</string>
<string>W:2804, 13: Use of eval (eval-used)</string>
<string>W:2832, 13: Use of eval (eval-used)</string>
<string>W:2881, 13: Use of eval (eval-used)</string>
<string>W:2928, 13: Use of eval (eval-used)</string>
</tuple>
</value>
</item>
......
......@@ -589,22 +589,6 @@ class SlapTool(BaseTool):
"""
return self._softwareReleaseError(url, computer_id, error_log)
security.declareProtected(Permissions.AccessContentsInformation,
'buildingComputerPartition')
def buildingComputerPartition(self, computer_id, computer_partition_id):
"""
Reports that Computer Partition is being build
"""
return self._buildingComputerPartition(computer_id, computer_partition_id)
security.declareProtected(Permissions.AccessContentsInformation,
'availableComputerPartition')
def availableComputerPartition(self, computer_id, computer_partition_id):
"""
Reports that Computer Partition is available
"""
return self._availableComputerPartition(computer_id, computer_partition_id)
security.declareProtected(Permissions.AccessContentsInformation,
'softwareInstanceError')
def softwareInstanceError(self, computer_id,
......@@ -1042,32 +1026,6 @@ class SlapTool(BaseTool):
software_installation.invalidate(
comment="Software Release destroyed report.")
@convertToREST
def _buildingComputerPartition(self, computer_id, computer_partition_id):
"""
Log the computer status
"""
instance = self._getSoftwareInstanceForComputerPartition(
computer_id,
computer_partition_id)
user = self.getPortalObject().portal_membership.getAuthenticatedMember()\
.getUserName()
self._logAccess(user, instance.getReference(),
'building the instance')
@convertToREST
def _availableComputerPartition(self, computer_id, computer_partition_id):
"""
Log the computer status
"""
instance = self._getSoftwareInstanceForComputerPartition(
computer_id,
computer_partition_id)
user = self.getPortalObject().portal_membership.getAuthenticatedMember()\
.getUserName()
self._logAccess(user, instance.getReference(),
'#access instance available')
@convertToREST
def _softwareInstanceError(self, computer_id,
computer_partition_id, error_log=""):
......@@ -1082,7 +1040,7 @@ class SlapTool(BaseTool):
computer_partition_id)
user = self.getPortalObject().portal_membership.getAuthenticatedMember()\
.getUserName()
self._logAccess(user, instance,
self._logAccess(user, instance.getReference(),
'#error while instanciating: %s' % error_log[-80:])
#return instance.reportComputerPartitionError()
......
......@@ -1091,7 +1091,6 @@ stderr_logfile_backups=1
if computer_partition_state == COMPUTER_PARTITION_STARTED_STATE:
local_partition.install()
computer_partition.available()
local_partition.start()
if self.firewall_conf:
self._setupComputerPartitionFirewall(computer_partition,
......@@ -1104,14 +1103,19 @@ stderr_logfile_backups=1
# We want to process the partition, even if stopped, because it should
# propagate the state to children if any.
local_partition.install()
computer_partition.available()
if self.firewall_conf:
self._setupComputerPartitionFirewall(computer_partition,
partition_ip_list)
finally:
# Instance has to be stopped even if buildout/reporting is wrong.
local_partition.stop()
computer_partition.stopped()
try:
computer_partition.stopped()
except (SystemExit, KeyboardInterrupt):
computer_partition.error(traceback.format_exc(), logger=self.logger)
raise
except Exception:
pass
self._endInstallationTransaction(computer_partition)
elif computer_partition_state == COMPUTER_PARTITION_DESTROYED_STATE:
local_partition.stop()
......
......@@ -277,14 +277,6 @@ def availableSoftwareRelease():
def softwareReleaseError():
return 'Ignored'
@app.route('/buildingComputerPartition', methods=['POST'])
def buildingComputerPartition():
return 'Ignored'
@app.route('/availableComputerPartition', methods=['POST'])
def availableComputerPartition():
return 'Ignored'
@app.route('/softwareInstanceError', methods=['POST'])
def softwareInstanceError():
return 'Ignored'
......
......@@ -107,34 +107,7 @@ class IRequester(Interface):
to identify the instances.
"""
class IBuildoutController(Interface):
"""
Classes which implement IBuildoutController can report the buildout run
status to the slapgrid server.
"""
def available():
"""
Notify (to the slapgrid server) that the software instance is
available.
"""
def building():
"""
Notify (to the slapgrid server) that the buildout is not
available and under creation.
"""
def error(error_log):
"""
Notify (to the slapgrid server) that the buildout is not available
and reports an error.
error_log -- a text describing the error
It can be a traceback for example.
"""
class ISoftwareRelease(IBuildoutController):
class ISoftwareRelease(Interface):
"""
Software release interface specification
"""
......@@ -158,12 +131,33 @@ class ISoftwareRelease(IBuildoutController):
The result can be: available, destroyed
"""
def available():
"""
Notify (to the slapgrid server) that the software release is
available.
"""
def building():
"""
Notify (to the slapgrid server) that the software release is not
available and under creation.
"""
def destroyed():
"""
Notify (to the slapgrid server) that the software installation has
been correctly destroyed.
"""
def error(error_log):
"""
Notify (to the slapgrid server) that the software installation is
not available and reports an error.
error_log -- a text describing the error
It can be a traceback for example.
"""
class ISoftwareProductCollection(Interface):
"""
Fake object representing the abstract of all Software Products.
......@@ -181,7 +175,7 @@ class ISoftwareInstance(Interface):
informations about a Software Instance.
"""
class IComputerPartition(IBuildoutController, IRequester):
class IComputerPartition(IRequester):
"""
Computer Partition interface specification
......@@ -208,6 +202,16 @@ class IComputerPartition(IBuildoutController, IRequester):
been correctly destroyed.
"""
def error(error_log):
"""
Notify (to the slapgrid server) that the software instance is
not available and reports an error.
error_log -- a text describing the error
It can be a traceback for example.
"""
def getId():
"""
Returns a string representing the identifier of the computer partition
......
......@@ -475,16 +475,6 @@ class ComputerPartition(SlapRequester):
self._updateTransactionFile(partition_reference)
return self._requestComputerPartition(request_dict)
def building(self):
self._connection_helper.POST('buildingComputerPartition', data={
'computer_id': self._computer_id,
'computer_partition_id': self.getId()})
def available(self):
self._connection_helper.POST('availableComputerPartition', data={
'computer_id': self._computer_id,
'computer_partition_id': self.getId()})
def destroyed(self):
self._connection_helper.POST('destroyedComputerPartition', data={
'computer_id': self._computer_id,
......
......@@ -899,20 +899,6 @@ class TestComputerPartition(SlapMixin):
self.assertRaises(slapos.slap.NotFoundError,
getattr(computer_partition, state))
def test_available_new_ComputerPartition_raises(self):
"""
Asserts that calling ComputerPartition.available on new partition
raises (not defined yet) exception
"""
self._test_new_computer_partition_state('available')
def test_building_new_ComputerPartition_raises(self):
"""
Asserts that calling ComputerPartition.building on new partition raises
(not defined yet) exception
"""
self._test_new_computer_partition_state('building')
def test_started_new_ComputerPartition_raises(self):
"""
Asserts that calling ComputerPartition.started on new partition raises
......
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