Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Klaus Wölfel
slapos.core
Commits
c1972a51
Commit
c1972a51
authored
Feb 27, 2013
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up unallocated instance.
parent
5bb173de
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
406 additions
and
1 deletion
+406
-1
master/bt5/slapos_cloud/PathTemplateItem/portal_alarms/slapos_cloud_invalidate_destroyed_instance.xml
...tal_alarms/slapos_cloud_invalidate_destroyed_instance.xml
+103
-0
master/bt5/slapos_cloud/SkinTemplateItem/portal_skins/slapos_cloud/Alarm_invalidateDestroyedInstance.xml
..._skins/slapos_cloud/Alarm_invalidateDestroyedInstance.xml
+80
-0
master/bt5/slapos_cloud/SkinTemplateItem/portal_skins/slapos_cloud/SoftwareInstance_tryToInvalidateIfDestroyed.xml
...pos_cloud/SoftwareInstance_tryToInvalidateIfDestroyed.xml
+78
-0
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudAlarm.py
...bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudAlarm.py
+143
-0
master/bt5/slapos_cloud/bt/revision
master/bt5/slapos_cloud/bt/revision
+1
-1
master/bt5/slapos_cloud/bt/template_path_list
master/bt5/slapos_cloud/bt/template_path_list
+1
-0
No files found.
master/bt5/slapos_cloud/PathTemplateItem/portal_alarms/slapos_cloud_invalidate_destroyed_instance.xml
0 → 100644
View file @
c1972a51
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"Alarm"
module=
"erp5.portal_type"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
active_sense_method_id
</string>
</key>
<value>
<string>
Alarm_invalidateDestroyedInstance
</string>
</value>
</item>
<item>
<key>
<string>
description
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
enabled
</string>
</key>
<value>
<int>
1
</int>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
slapos_cloud_invalidate_destroyed_instance
</string>
</value>
</item>
<item>
<key>
<string>
periodicity_hour
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
periodicity_hour_frequency
</string>
</key>
<value>
<int>
1
</int>
</value>
</item>
<item>
<key>
<string>
periodicity_minute
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
periodicity_minute_frequency
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
periodicity_month
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
periodicity_month_day
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
periodicity_start_date
</string>
</key>
<value>
<object>
<klass>
<global
name=
"DateTime"
module=
"DateTime.DateTime"
/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>
1288051200.0
</float>
<string>
GMT
</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key>
<string>
periodicity_week
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
portal_type
</string>
</key>
<value>
<string>
Alarm
</string>
</value>
</item>
<item>
<key>
<string>
sense_method_id
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
title
</string>
</key>
<value>
<string>
Invalidate destroyed instance
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
master/bt5/slapos_cloud/SkinTemplateItem/portal_skins/slapos_cloud/Alarm_invalidateDestroyedInstance.xml
0 → 100644
View file @
c1972a51
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"PythonScript"
module=
"Products.PythonScripts.PythonScript"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
Script_magic
</string>
</key>
<value>
<int>
3
</int>
</value>
</item>
<item>
<key>
<string>
_bind_names
</string>
</key>
<value>
<object>
<klass>
<global
name=
"NameAssignments"
module=
"Shared.DC.Scripts.Bindings"
/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key>
<string>
_asgns
</string>
</key>
<value>
<dictionary>
<item>
<key>
<string>
name_container
</string>
</key>
<value>
<string>
container
</string>
</value>
</item>
<item>
<key>
<string>
name_context
</string>
</key>
<value>
<string>
context
</string>
</value>
</item>
<item>
<key>
<string>
name_m_self
</string>
</key>
<value>
<string>
script
</string>
</value>
</item>
<item>
<key>
<string>
name_subpath
</string>
</key>
<value>
<string>
traverse_subpath
</string>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key>
<string>
_body
</string>
</key>
<value>
<string>
portal = context.getPortalObject()\n
select_dict= {\'default_aggregate_uid\': None}\n
portal.portal_catalog.searchAndActivate(\n
portal_type=(\'Slave Instance\', \'Software Instance\'),\n
validation_state=\'validated\',\n
default_aggregate_uid=None,\n
select_dict=select_dict,\n
left_join_list=select_dict.keys(),\n
\n
method_id=\'SoftwareInstance_tryToInvalidateIfDestroyed\',\n
activate_kw={\'tag\': tag}\n
)\n
\n
context.activate(after_tag=tag).getId()\n
</string>
</value>
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string>
tag, fixit, params
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
Alarm_invalidateDestroyedInstance
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
master/bt5/slapos_cloud/SkinTemplateItem/portal_skins/slapos_cloud/SoftwareInstance_tryToInvalidateIfDestroyed.xml
0 → 100644
View file @
c1972a51
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"PythonScript"
module=
"Products.PythonScripts.PythonScript"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
Script_magic
</string>
</key>
<value>
<int>
3
</int>
</value>
</item>
<item>
<key>
<string>
_bind_names
</string>
</key>
<value>
<object>
<klass>
<global
name=
"NameAssignments"
module=
"Shared.DC.Scripts.Bindings"
/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key>
<string>
_asgns
</string>
</key>
<value>
<dictionary>
<item>
<key>
<string>
name_container
</string>
</key>
<value>
<string>
container
</string>
</value>
</item>
<item>
<key>
<string>
name_context
</string>
</key>
<value>
<string>
context
</string>
</value>
</item>
<item>
<key>
<string>
name_m_self
</string>
</key>
<value>
<string>
script
</string>
</value>
</item>
<item>
<key>
<string>
name_subpath
</string>
</key>
<value>
<string>
traverse_subpath
</string>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key>
<string>
_body
</string>
</key>
<value>
<string>
from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
\n
if context.getPortalType() not in (\'Software Instance\', \'Slave Instance\'):\n
raise TypeError(\'%s is not supported\' % context.getPortalType())\n
\n
software_instance = context\n
if software_instance.getValidationState() == \'validated\' \\\n
and software_instance.getSlapState() == \'destroy_requested\' \\\n
and software_instance.getAggregateValue(portal_type=\'Computer Partition\') is None:\n
software_instance.invalidate(comment=\'Invalidated as unallocated and destroyed\')\n
</string>
</value>
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string>
REQUEST=None
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
SoftwareInstance_tryToInvalidateIfDestroyed
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudAlarm.py
View file @
c1972a51
...
...
@@ -1528,3 +1528,146 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by I
self
.
assertNotEqual
(
'Visited by Instance_tryToGarbageCollectNonAllocatedRootTree'
,
instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
class
TestSlapOSInvalidateDestroyedInstance
(
testSlapOSMixin
):
def
createSoftwareInstance
(
self
):
new_id
=
self
.
generateNewId
()
return
self
.
portal
.
software_instance_module
.
newContent
(
portal_type
=
'Software Instance'
,
title
=
"Test instance %s"
%
new_id
,
reference
=
"TESTINST-%s"
%
new_id
,
)
def
createComputerPartition
(
self
):
new_id
=
self
.
generateNewId
()
computer
=
self
.
portal
.
computer_module
.
newContent
(
portal_type
=
'Computer'
,
title
=
"Test computer %s"
%
new_id
,
reference
=
"TESTCOMP-%s"
%
new_id
,
)
computer_partition
=
computer
.
newContent
(
portal_type
=
'Computer Partition'
,
)
return
computer_partition
def
test_tryToInvalidateIfDestroyed_REQUEST_disallowed
(
self
):
instance
=
self
.
createSoftwareInstance
()
self
.
assertRaises
(
Unauthorized
,
instance
.
SoftwareInstance_tryToInvalidateIfDestroyed
,
REQUEST
=
{})
def
test_tryToInvalidateIfDestroyed_unexpected_context
(
self
):
self
.
assertRaises
(
TypeError
,
self
.
portal
.
SoftwareInstance_tryToInvalidateIfDestroyed
,
)
def
test_tryToInvalidateIfDestroyed_expected_instance
(
self
):
instance
=
self
.
createSoftwareInstance
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance
,
'validated'
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance
,
'destroy_requested'
)
instance
.
SoftwareInstance_tryToInvalidateIfDestroyed
()
self
.
assertEqual
(
instance
.
getValidationState
(),
"invalidated"
)
self
.
assertEqual
(
instance
.
getSlapState
(),
"destroy_requested"
)
def
test_tryToInvalidateIfDestroyed_invalidated_instance
(
self
):
instance
=
self
.
createSoftwareInstance
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance
,
'invalidated'
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance
,
'destroy_requested'
)
instance
.
SoftwareInstance_tryToInvalidateIfDestroyed
()
self
.
assertEqual
(
instance
.
getValidationState
(),
"invalidated"
)
self
.
assertEqual
(
instance
.
getSlapState
(),
"destroy_requested"
)
def
test_tryToInvalidateIfDestroyed_not_destroyed_instance
(
self
):
instance
=
self
.
createSoftwareInstance
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance
,
'validated'
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance
,
'stop_requested'
)
instance
.
SoftwareInstance_tryToInvalidateIfDestroyed
()
self
.
assertEqual
(
instance
.
getValidationState
(),
"validated"
)
self
.
assertEqual
(
instance
.
getSlapState
(),
"stop_requested"
)
def
test_tryToInvalidateIfDestroyed_allocated_instance
(
self
):
instance
=
self
.
createSoftwareInstance
()
partition
=
self
.
createComputerPartition
()
instance
.
edit
(
aggregate_value
=
partition
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance
,
'validated'
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance
,
'destroy_requested'
)
instance
.
SoftwareInstance_tryToInvalidateIfDestroyed
()
self
.
assertEqual
(
instance
.
getValidationState
(),
"validated"
)
self
.
assertEqual
(
instance
.
getSlapState
(),
"destroy_requested"
)
def
_simulateSoftwareInstance_tryToInvalidateIfDestroyed
(
self
):
script_name
=
'SoftwareInstance_tryToInvalidateIfDestroyed'
if
script_name
in
self
.
portal
.
portal_skins
.
custom
.
objectIds
():
raise
ValueError
(
'Precondition failed: %s exists in custom'
%
script_name
)
createZODBPythonScript
(
self
.
portal
.
portal_skins
.
custom
,
script_name
,
'*args, **kwargs'
,
'# Script body
\
n
'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by SoftwareInstance_tryToInvalidateIfDestroyed') """
)
transaction
.
commit
()
def
_dropSoftwareInstance_tryToInvalidateIfDestroyed
(
self
):
script_name
=
'SoftwareInstance_tryToInvalidateIfDestroyed'
if
script_name
in
self
.
portal
.
portal_skins
.
custom
.
objectIds
():
self
.
portal
.
portal_skins
.
custom
.
manage_delObjects
(
script_name
)
transaction
.
commit
()
def
test_alarm_software_instance_allocated
(
self
):
instance
=
self
.
createSoftwareInstance
()
partition
=
self
.
createComputerPartition
()
instance
.
edit
(
aggregate_value
=
partition
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance
,
'validated'
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance
,
'destroy_requested'
)
self
.
tic
()
self
.
_simulateSoftwareInstance_tryToInvalidateIfDestroyed
()
try
:
self
.
portal
.
portal_alarms
.
slapos_cloud_invalidate_destroyed_instance
.
\
activeSense
()
self
.
tic
()
finally
:
self
.
_dropSoftwareInstance_tryToInvalidateIfDestroyed
()
self
.
assertNotEqual
(
'Visited by SoftwareInstance_tryToInvalidateIfDestroyed'
,
instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_software_instance_invalidated
(
self
):
instance
=
self
.
createSoftwareInstance
()
partition
=
self
.
createComputerPartition
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance
,
'invalidated'
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance
,
'destroy_requested'
)
self
.
tic
()
self
.
_simulateSoftwareInstance_tryToInvalidateIfDestroyed
()
try
:
self
.
portal
.
portal_alarms
.
slapos_cloud_invalidate_destroyed_instance
.
\
activeSense
()
self
.
tic
()
finally
:
self
.
_dropSoftwareInstance_tryToInvalidateIfDestroyed
()
self
.
assertNotEqual
(
'Visited by SoftwareInstance_tryToInvalidateIfDestroyed'
,
instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_software_instance_matching
(
self
):
instance
=
self
.
createSoftwareInstance
()
partition
=
self
.
createComputerPartition
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance
,
'validated'
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
instance
,
'destroy_requested'
)
self
.
tic
()
self
.
_simulateSoftwareInstance_tryToInvalidateIfDestroyed
()
try
:
self
.
portal
.
portal_alarms
.
slapos_cloud_invalidate_destroyed_instance
.
\
activeSense
()
self
.
tic
()
finally
:
self
.
_dropSoftwareInstance_tryToInvalidateIfDestroyed
()
self
.
assertEqual
(
'Visited by SoftwareInstance_tryToInvalidateIfDestroyed'
,
instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
master/bt5/slapos_cloud/bt/revision
View file @
c1972a51
272
\ No newline at end of file
273
\ No newline at end of file
master/bt5/slapos_cloud/bt/template_path_list
View file @
c1972a51
...
...
@@ -9,6 +9,7 @@ portal_alarms/promise_slapos_module_id_generator
portal_alarms/promise_slapos_pas
portal_alarms/slapos_allocate_instance
portal_alarms/slapos_assert_hosting_subscription_predecessor
portal_alarms/slapos_cloud_invalidate_destroyed_instance
portal_alarms/slapos_free_computer_partition
portal_alarms/slapos_garbage_collect_destroyed_root_tree
portal_alarms/slapos_garbage_collect_non_allocated_root_tree
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment