Commit e2903c82 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: fixup slapos_garbage_collect_destroy_unlinked_instance tests

parent b5a8c15c
...@@ -880,50 +880,6 @@ class TestSlapOSGarbageCollectNonAllocatedRootTreeAlarm(SlapOSTestCaseMixin): ...@@ -880,50 +880,6 @@ class TestSlapOSGarbageCollectNonAllocatedRootTreeAlarm(SlapOSTestCaseMixin):
class TestSlapOSGarbageCollectUnlinkedInstanceAlarm(SlapOSTestCaseMixin): class TestSlapOSGarbageCollectUnlinkedInstanceAlarm(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()
)
instance_tree.requestStart(**request_kw)
instance_tree.requestInstance(**request_kw)
self.instance_tree = instance_tree
instance = instance_tree.getSuccessorValue()
return instance
def createComputePartition(self):
compute_node = self.portal.compute_node_module\
.template_compute_node.Base_createCloneDocument(batch_mode=1)
compute_node.validate()
compute_node.edit(
title=self.generateNewSoftwareTitle(),
reference="TESTCOMP-%s" % self.generateNewId(),
)
partition = compute_node.newContent(portal_type="Compute Partition")
return partition
def doRequestInstance(self, instance, title, slave=False): def doRequestInstance(self, instance, title, slave=False):
instance_kw = dict(software_release=self.generateNewSoftwareReleaseUrl(), instance_kw = dict(software_release=self.generateNewSoftwareReleaseUrl(),
software_type=self.generateNewSoftwareType(), software_type=self.generateNewSoftwareType(),
...@@ -936,42 +892,86 @@ class TestSlapOSGarbageCollectUnlinkedInstanceAlarm(SlapOSTestCaseMixin): ...@@ -936,42 +892,86 @@ class TestSlapOSGarbageCollectUnlinkedInstanceAlarm(SlapOSTestCaseMixin):
instance.requestInstance(**instance_kw) instance.requestInstance(**instance_kw)
self.tic() self.tic()
sub_instance = instance.getSuccessorValue() sub_instance = instance.getSuccessorValue()
partition = self.createComputePartition() self.assertEqual(instance.getSpecialiseValue().getRelativeUrl(),
sub_instance.edit(aggregate_value=partition)
self.tic()
self.assertEqual(self.instance_tree.getRelativeUrl(),
sub_instance.getSpecialise()) sub_instance.getSpecialise())
return sub_instance return sub_instance
def test_SoftwareInstance_tryToGarbageUnlinkedInstance(self): #################################################################
instance = self.createInstance(self.project) # slapos_garbage_collect_destroy_unlinked_instance
partition = self.createComputePartition() #################################################################
instance.edit(aggregate_value=partition) def test_SoftwareInstance_tryToGarbageUnlinkedInstance_alarm_inlinkedInstance(self):
self.tic() instance_tree = self.addInstanceTree()
instance0 = self.doRequestInstance(instance, 'instance0') software_instance = instance_tree.getSuccessorValue()
self.assertEqual(instance0.getSuccessorRelatedTitle(), instance.getTitle())
instance0 = self.doRequestInstance(software_instance, 'instance0')
self.assertEqual(software_instance.getSuccessorReference(),
instance0.getReference())
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_garbage_collect_destroy_unlinked_instance,
instance0,
'SoftwareInstance_tryToGarbageUnlinkedInstance'
)
# Remove successor link # Remove successor link
instance.edit(successor_list=[]) software_instance.edit(successor_list=[])
self._test_alarm(
self.portal.portal_alarms.slapos_garbage_collect_destroy_unlinked_instance,
instance0,
'SoftwareInstance_tryToGarbageUnlinkedInstance'
)
def test_SoftwareInstance_tryToGarbageUnlinkedInstance_alarm_inlinkedInstanceSlave(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
instance0 = self.doRequestInstance(software_instance, 'instance0', True)
self.assertEqual(software_instance.getSuccessorReference(),
instance0.getReference())
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_garbage_collect_destroy_unlinked_instance,
instance0,
'SoftwareInstance_tryToGarbageUnlinkedInstance'
)
# Remove successor link
software_instance.edit(successor_list=[])
self._test_alarm(
self.portal.portal_alarms.slapos_garbage_collect_destroy_unlinked_instance,
instance0,
'SoftwareInstance_tryToGarbageUnlinkedInstance'
)
#################################################################
# SoftwareInstance_tryToGarbageUnlinkedInstance
#################################################################
def test_SoftwareInstance_tryToGarbageUnlinkedInstance_script(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
instance0 = self.doRequestInstance(software_instance, 'instance0')
self.assertEqual(instance0.getSuccessorRelatedTitle(), software_instance.getTitle())
# Remove successor link
software_instance.edit(successor_list=[])
self.tic() self.tic()
self.assertEqual(instance0.getSuccessorRelatedTitle(), None) self.assertEqual(instance0.getSuccessorRelatedTitle(), None)
instance0.SoftwareInstance_tryToGarbageUnlinkedInstance(delay_time=-1) instance0.SoftwareInstance_tryToGarbageUnlinkedInstance(delay_time=-1)
self.tic() self.tic()
self.assertEqual(instance0.getSlapState(), 'destroy_requested') self.assertEqual(instance0.getSlapState(), 'destroy_requested')
def test_SoftwareInstance_tryToGarbageUnlinkedInstance_hosting_destroyed(self): def test_SoftwareInstance_tryToGarbageUnlinkedInstance_script_hostingDestroyed(self):
instance = self.createInstance(self.project) instance_tree = self.addInstanceTree()
partition = self.createComputePartition() software_instance = instance_tree.getSuccessorValue()
instance.edit(aggregate_value=partition) instance0 = self.doRequestInstance(software_instance, 'instance0')
self.tic() self.assertEqual(instance0.getSuccessorRelatedTitle(), software_instance.getTitle())
instance0 = self.doRequestInstance(instance, 'instance0') # Remove successor link
instance.edit(successor_list=[]) software_instance.edit(successor_list=[])
self.tic() self.tic()
self.assertEqual(instance0.getSuccessorRelatedTitle(), None)
self.instance_tree.archive() instance_tree.archive()
self.portal.portal_workflow._jumpToStateFor(self.instance_tree, self.portal.portal_workflow._jumpToStateFor(instance_tree,
'destroy_requested') 'destroy_requested')
self.portal.portal_workflow._jumpToStateFor(instance, 'destroy_requested') self.portal.portal_workflow._jumpToStateFor(software_instance, 'destroy_requested')
self.tic() self.tic()
instance0.SoftwareInstance_tryToGarbageUnlinkedInstance() instance0.SoftwareInstance_tryToGarbageUnlinkedInstance()
...@@ -979,16 +979,16 @@ class TestSlapOSGarbageCollectUnlinkedInstanceAlarm(SlapOSTestCaseMixin): ...@@ -979,16 +979,16 @@ class TestSlapOSGarbageCollectUnlinkedInstanceAlarm(SlapOSTestCaseMixin):
# Will not be destroyed by this script # Will not be destroyed by this script
self.assertEqual(instance0.getSlapState(), 'start_requested') self.assertEqual(instance0.getSlapState(), 'start_requested')
def test_SoftwareInstance_tryToGarbageUnlinkedInstance_will_unlink_children(self): def test_SoftwareInstance_tryToGarbageUnlinkedInstance_script_willUnlinkChildren(self):
instance = self.createInstance(self.project) instance_tree = self.addInstanceTree()
partition = self.createComputePartition() software_instance = instance_tree.getSuccessorValue()
instance.edit(aggregate_value=partition) instance0 = self.doRequestInstance(software_instance, 'instance0')
self.tic() self.assertEqual(instance0.getSuccessorRelatedTitle(), software_instance.getTitle())
instance0 = self.doRequestInstance(instance, 'instance0')
instance_instance0 = self.doRequestInstance(instance0, 'Subinstance0') instance_instance0 = self.doRequestInstance(instance0, 'Subinstance0')
self.assertEqual(instance_instance0.getSuccessorRelatedTitle(), self.assertEqual(instance_instance0.getSuccessorRelatedTitle(),
'instance0') 'instance0')
instance.edit(successor_list=[]) # Remove successor link
software_instance.edit(successor_list=[])
self.tic() self.tic()
self.assertEqual(instance0.getSuccessorRelatedTitle(), None) self.assertEqual(instance0.getSuccessorRelatedTitle(), None)
...@@ -999,21 +999,22 @@ class TestSlapOSGarbageCollectUnlinkedInstanceAlarm(SlapOSTestCaseMixin): ...@@ -999,21 +999,22 @@ class TestSlapOSGarbageCollectUnlinkedInstanceAlarm(SlapOSTestCaseMixin):
# Link of child removed # Link of child removed
self.assertEqual(instance_instance0.getSuccessorRelatedTitle(), None) self.assertEqual(instance_instance0.getSuccessorRelatedTitle(), None)
def test_SoftwareInstance_tryToGarbageUnlinkedInstance_will_delay(self): def test_SoftwareInstance_tryToGarbageUnlinkedInstance_script_willDelay(self):
instance = self.createInstance(self.project) instance_tree = self.addInstanceTree()
partition = self.createComputePartition() software_instance = instance_tree.getSuccessorValue()
instance.edit(aggregate_value=partition) instance0 = self.doRequestInstance(software_instance, 'instance0')
self.tic() self.assertEqual(instance0.getSuccessorRelatedTitle(), software_instance.getTitle())
instance0 = self.doRequestInstance(instance, 'instance0')
instance_instance0 = self.doRequestInstance(instance0, 'Subinstance0') instance_instance0 = self.doRequestInstance(instance0, 'Subinstance0')
self.assertEqual(instance_instance0.getSuccessorRelatedTitle(), self.assertEqual(instance_instance0.getSuccessorRelatedTitle(),
'instance0') 'instance0')
instance.edit(successor_list=[]) # Remove successor link
software_instance.edit(successor_list=[])
self.tic() self.tic()
self.assertEqual(instance0.getSuccessorRelatedTitle(), None) self.assertEqual(instance0.getSuccessorRelatedTitle(), None)
instance0.SoftwareInstance_tryToGarbageUnlinkedInstance() instance0.SoftwareInstance_tryToGarbageUnlinkedInstance()
self.tic() self.tic()
self.assertEqual(instance0.getSlapState(), 'start_requested') self.assertEqual(instance0.getSlapState(), 'start_requested')
self.assertEqual(instance_instance0.getSlapState(), 'start_requested') self.assertEqual(instance_instance0.getSlapState(), 'start_requested')
...@@ -1028,32 +1029,27 @@ class TestSlapOSGarbageCollectUnlinkedInstanceAlarm(SlapOSTestCaseMixin): ...@@ -1028,32 +1029,27 @@ class TestSlapOSGarbageCollectUnlinkedInstanceAlarm(SlapOSTestCaseMixin):
# Link of child removed # Link of child removed
self.assertEqual(instance_instance0.getSuccessorRelatedTitle(), None) self.assertEqual(instance_instance0.getSuccessorRelatedTitle(), None)
def test_SoftwareInstance_tryToGarbageUnlinkedInstance_unlinked_root(self): def test_SoftwareInstance_tryToGarbageUnlinkedInstance_script_unlinkedRoot(self):
instance = self.createInstance(self.project) instance_tree = self.addInstanceTree()
partition = self.createComputePartition() software_instance = instance_tree.getSuccessorValue()
instance.edit(aggregate_value=partition)
self.tic()
self.assertEqual(self.instance_tree.getTitle(), instance.getTitle())
# Remove successor link # Remove successor link
self.instance_tree.edit(successor_list=[]) instance_tree.edit(successor_list=[])
self.tic() self.tic()
self.assertEqual(instance.getSuccessorRelatedTitle(), None) self.assertEqual(software_instance.getSuccessorRelatedTitle(), None)
# will not destroy # will not destroy
self.assertRaises( self.assertRaises(
ValueError, ValueError,
instance.SoftwareInstance_tryToGarbageUnlinkedInstance, software_instance.SoftwareInstance_tryToGarbageUnlinkedInstance,
delay_time=-10) delay_time=-10)
self.tic() self.tic()
self.assertEqual(instance.getSlapState(), 'start_requested') self.assertEqual(software_instance.getSlapState(), 'start_requested')
def test_SoftwareInstance_tryToGarbageUnlinkedInstance_script_notUnlinked(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
instance0 = self.doRequestInstance(software_instance, 'instance0')
self.assertEqual(instance0.getSuccessorRelatedTitle(), software_instance.getTitle())
def test_SoftwareInstance_tryToGarbageUnlinkedInstance_not_unlinked(self):
instance = self.createInstance(self.project)
partition = self.createComputePartition()
instance.edit(aggregate_value=partition)
self.tic()
instance0 = self.doRequestInstance(instance, 'instance0')
instance_instance0 = self.doRequestInstance(instance0, 'Subinstance0') instance_instance0 = self.doRequestInstance(instance0, 'Subinstance0')
self.assertEqual(instance_instance0.getSuccessorRelatedTitle(), self.assertEqual(instance_instance0.getSuccessorRelatedTitle(),
'instance0') 'instance0')
...@@ -1064,47 +1060,6 @@ class TestSlapOSGarbageCollectUnlinkedInstanceAlarm(SlapOSTestCaseMixin): ...@@ -1064,47 +1060,6 @@ class TestSlapOSGarbageCollectUnlinkedInstanceAlarm(SlapOSTestCaseMixin):
self.tic() self.tic()
self.assertEqual(instance_instance0.getSlapState(), 'start_requested') self.assertEqual(instance_instance0.getSlapState(), 'start_requested')
def test_alarm_search_inlinked_instance(self):
instance = self.createInstance(self.project)
partition = self.createComputePartition()
instance.edit(aggregate_value=partition)
self.tic()
instance0 = self.doRequestInstance(instance, 'instance0')
self.assertEqual(instance.getSuccessorReference(),
instance0.getReference())
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_garbage_collect_destroy_unlinked_instance,
instance0,
'SoftwareInstance_tryToGarbageUnlinkedInstance'
)
# Remove successor link
instance.edit(successor_list=[])
self._test_alarm(
self.portal.portal_alarms.slapos_garbage_collect_destroy_unlinked_instance,
instance0,
'SoftwareInstance_tryToGarbageUnlinkedInstance'
)
def test_alarm_search_inlinked_instance_slave(self):
instance = self.createInstance(self.project)
partition = self.createComputePartition()
instance.edit(aggregate_value=partition)
self.tic()
slave_instance0 = self.doRequestInstance(instance, 'slaveInstance0', True)
self.assertEqual(instance.getSuccessorTitle(), 'slaveInstance0')
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_garbage_collect_destroy_unlinked_instance,
slave_instance0,
'SoftwareInstance_tryToGarbageUnlinkedInstance'
)
instance.edit(successor_list=[])
self._test_alarm(
self.portal.portal_alarms.slapos_garbage_collect_destroy_unlinked_instance,
slave_instance0,
'SoftwareInstance_tryToGarbageUnlinkedInstance'
)
class TestSlapOSInvalidateDestroyedInstance(SlapOSTestCaseMixin): class TestSlapOSInvalidateDestroyedInstance(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