Commit 38e9d877 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: fixup slapos_stop_collect_instance tests

parent 0bea52ec
......@@ -599,95 +599,70 @@ class TestSlapOSUpdateComputeNodeCapacityScopeAlarm(SlapOSTestCaseMixin):
class TestSlapOSGarbageCollectStoppedRootTreeAlarm(SlapOSTestCaseMixin):
def afterSetUp(self):
SlapOSTestCaseMixin.afterSetUp(self)
self.project = self.addProject()
def createInstance(self, project):
instance_tree = self.portal.instance_tree_module\
.template_instance_tree.Base_createCloneDocument(batch_mode=1)
instance_tree.edit(
follow_up_value=project
)
instance_tree.validate()
instance_tree.edit(
title=self.generateNewSoftwareTitle(),
reference="TESTHS-%s" % self.generateNewId(),
)
request_kw = dict(
software_release=\
self.generateNewSoftwareReleaseUrl(),
software_type=self.generateNewSoftwareType(),
instance_xml=self.generateSafeXml(),
sla_xml=self.generateSafeXml(),
shared=False,
software_title=instance_tree.getTitle(),
state='started',
project_reference=project.getReference()
#################################################################
# slapos_stop_collect_instance
#################################################################
def test_SoftwareInstance_tryToStopCollect_alarm(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
self._test_alarm(
self.portal.portal_alarms.slapos_stop_collect_instance,
software_instance,
'SoftwareInstance_tryToStopCollect'
)
instance_tree.requestStart(**request_kw)
instance_tree.requestInstance(**request_kw)
instance = instance_tree.getSuccessorValue()
self.tic()
return instance
def test_SoftwareInstance_tryToStopCollect_alarm_invalidated(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
software_instance.invalidate()
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_stop_collect_instance,
software_instance,
'SoftwareInstance_tryToStopCollect'
)
#################################################################
# SoftwareInstance_tryToStopCollect
#################################################################
def test_SoftwareInstance_tryToStopCollect_REQUEST_disallowed(self):
self.assertRaises(
Unauthorized,
self.portal.SoftwareInstance_tryToStopCollect,
REQUEST={})
def test_SoftwareInstance_tryToStopCollect_started_instance(self):
instance = self.createInstance(self.project)
instance_tree = instance.getSpecialiseValue()
def test_SoftwareInstance_tryToStopCollect_script_startedInstance(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
self.portal.portal_workflow._jumpToStateFor(instance_tree,
'stop_requested')
self.assertEqual('start_requested', instance.getSlapState())
self.assertEqual('start_requested', software_instance.getSlapState())
instance.SoftwareInstance_tryToStopCollect()
self.assertEqual('stop_requested', instance.getSlapState())
software_instance.SoftwareInstance_tryToStopCollect()
self.assertEqual('stop_requested', software_instance.getSlapState())
def test_SoftwareInstance_tryToStopCollect_destroyed_instance(self):
instance = self.createInstance(self.project)
instance_tree = instance.getSpecialiseValue()
def test_SoftwareInstance_tryToStopCollect_script_destroyedInstance(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
self.portal.portal_workflow._jumpToStateFor(instance_tree,
'stop_requested')
self.portal.portal_workflow._jumpToStateFor(instance,
self.portal.portal_workflow._jumpToStateFor(software_instance,
'destroy_requested')
instance.SoftwareInstance_tryToStopCollect()
self.assertEqual('destroy_requested', instance.getSlapState())
software_instance.SoftwareInstance_tryToStopCollect()
self.assertEqual('destroy_requested', software_instance.getSlapState())
def test_SoftwareInstance_tryToStopCollect_started_subscription(self):
instance = self.createInstance(self.project)
instance_tree = instance.getSpecialiseValue()
def test_SoftwareInstance_tryToStopCollect_script_startedInstanceTree(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
self.assertEqual('start_requested', instance_tree.getSlapState())
self.assertEqual('start_requested', instance.getSlapState())
instance.SoftwareInstance_tryToStopCollect()
self.assertEqual('start_requested', instance.getSlapState())
self.assertEqual('start_requested', software_instance.getSlapState())
def test_alarm(self):
instance = self.createInstance(self.project)
self._test_alarm(
self.portal.portal_alarms.slapos_stop_collect_instance,
instance,
'SoftwareInstance_tryToStopCollect'
)
software_instance.SoftwareInstance_tryToStopCollect()
self.assertEqual('start_requested', software_instance.getSlapState())
def test_alarm_invalidated(self):
instance = self.createInstance(self.project)
instance.invalidate()
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_stop_collect_instance,
instance,
'SoftwareInstance_tryToStopCollect'
)
class TestSlapOSGarbageCollectNonAllocatedRootTreeAlarm(SlapOSTestCaseMixin):
......
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