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
Łukasz Nowak
slapos.core
Commits
89a6f1c2
Commit
89a6f1c2
authored
Nov 20, 2012
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge tests per functionality.
parent
a35da019
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
4150 additions
and
2506 deletions
+4150
-2506
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudAlarm.py
...bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudAlarm.py
+1168
-0
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudComputerPartitionSlapInterfaceWorkflow.py
.../testSlapOSCloudComputerPartitionSlapInterfaceWorkflow.py
+0
-94
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudComputerSlapInterfaceWorkflow.py
...plateItem/testSlapOSCloudComputerSlapInterfaceWorkflow.py
+0
-607
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudPersonSlapInterfaceWorkflow.py
...emplateItem/testSlapOSCloudPersonSlapInterfaceWorkflow.py
+0
-780
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudPromiseSlapOSModuleIdGeneratorAlarm.py
...tem/testSlapOSCloudPromiseSlapOSModuleIdGeneratorAlarm.py
+0
-150
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudSlapOSAssertHostingSubscriptionPredecessorAlarm.py
...OSCloudSlapOSAssertHostingSubscriptionPredecessorAlarm.py
+0
-108
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudSlapOSCloudInteractionWorkflow.py
...lateItem/testSlapOSCloudSlapOSCloudInteractionWorkflow.py
+0
-325
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudSlapOSFreeComputerPartitionAlarm.py
...teItem/testSlapOSCloudSlapOSFreeComputerPartitionAlarm.py
+0
-175
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudSlapOSGarbageCollectDestroyedRootTreeAlarm.py
...tSlapOSCloudSlapOSGarbageCollectDestroyedRootTreeAlarm.py
+0
-118
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudSlapOSUpdateComputerCapacityScopeAlarm.py
.../testSlapOSCloudSlapOSUpdateComputerCapacityScopeAlarm.py
+0
-136
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudWorkflow.py
.../slapos_cloud/TestTemplateItem/testSlapOSCloudWorkflow.py
+2978
-0
master/bt5/slapos_cloud/bt/revision
master/bt5/slapos_cloud/bt/revision
+1
-1
master/bt5/slapos_cloud/bt/template_test_id_list
master/bt5/slapos_cloud/bt/template_test_id_list
+3
-12
No files found.
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloud
SlapOSAllocateInstance
Alarm.py
→
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudAlarm.py
View file @
89a6f1c2
# Copyright (c) 2002-2012 Nexedi SA and Contributors. All Rights Reserved.
import
transaction
from
Products.SlapOS.tests.testSlapOSMixin
import
\
testSlapOSMixin
import
transaction
from
Products.ERP5Type.tests.utils
import
createZODBPythonScript
from
Products.ERP5Type.tests.backportUnittest
import
skip
import
json
class
TestSlapOSCorePromiseSlapOSModuleIdGeneratorAlarm
(
testSlapOSMixin
):
def
test_Module_assertIdGenerator
(
self
):
module
=
self
.
portal
.
newContent
(
portal_type
=
'Person Module'
,
id
=
str
(
self
.
generateNewId
()),
id_generator
=
'bad_id_generator'
)
self
.
assertEqual
(
'bad_id_generator'
,
module
.
getIdGenerator
())
# check positive response
self
.
assertTrue
(
module
.
Module_assertIdGenerator
(
'bad_id_generator'
,
False
))
self
.
assertEqual
(
'bad_id_generator'
,
module
.
getIdGenerator
())
self
.
assertTrue
(
module
.
Module_assertIdGenerator
(
'bad_id_generator'
,
True
))
self
.
assertEqual
(
'bad_id_generator'
,
module
.
getIdGenerator
())
# check negative response and that no-op run does not modify
self
.
assertFalse
(
module
.
Module_assertIdGenerator
(
'good_id_generator'
,
False
))
self
.
assertEqual
(
'bad_id_generator'
,
module
.
getIdGenerator
())
# check negative response with fixit request
self
.
assertFalse
(
module
.
Module_assertIdGenerator
(
'good_id_generator'
,
True
))
self
.
assertEqual
(
'good_id_generator'
,
module
.
getIdGenerator
())
self
.
assertTrue
(
module
.
Module_assertIdGenerator
(
'good_id_generator'
,
False
))
self
.
assertEqual
(
'good_id_generator'
,
module
.
getIdGenerator
())
transaction
.
abort
()
def
_simulateModule_assertIdGenerator
(
self
):
script_name
=
'Module_assertIdGenerator'
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
,
'id_generator, fixit, active_process=None'
,
'# Script body
\
n
'
"""from Products.CMFActivity.ActiveResult import ActiveResult
active_result = ActiveResult()
active_result.edit(
summary='Module_assertIdGenerator simulation',
severity=0,
detail=context.getRelativeUrl())
active_process.postResult(active_result)
"""
)
transaction
.
commit
()
def
_dropModule_assertIdGenerator
(
self
):
script_name
=
'Module_assertIdGenerator'
if
script_name
in
self
.
portal
.
portal_skins
.
custom
.
objectIds
():
self
.
portal
.
portal_skins
.
custom
.
manage_delObjects
(
script_name
)
transaction
.
commit
()
def
test_alarm
(
self
):
alarm
=
self
.
portal
.
portal_alarms
.
promise_slapos_module_id_generator
previous_active_process
=
self
.
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Active Process'
,
causality_uid
=
alarm
.
getUid
(),
sort_on
=
((
'creation_date'
,
'DESC'
),)
)
self
.
_simulateModule_assertIdGenerator
()
try
:
alarm
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropModule_assertIdGenerator
()
active_process
=
self
.
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Active Process'
,
causality_uid
=
alarm
.
getUid
(),
sort_on
=
((
'creation_date'
,
'DESC'
),)
)
self
.
assertNotEqual
(
previous_active_process
.
getPath
(),
active_process
.
getPath
())
visited_list
=
sorted
([
q
.
detail
for
q
in
active_process
.
getResultList
()
\
if
q
.
summary
==
'Module_assertIdGenerator simulation'
])
expected_list
=
sorted
([
'account_module'
,
'accounting_module'
,
'bug_module'
,
'business_configuration_module'
,
'business_process_module'
,
'campaign_module'
,
'component_module'
,
'computer_model_module'
,
'computer_module'
,
'computer_network_module'
,
'credential_recovery_module'
,
'credential_request_module'
,
'credential_update_module'
,
'currency_module'
,
'data_set_module'
,
'document_ingestion_module'
,
'document_module'
,
'event_module'
,
'external_source_module'
,
'glossary_module'
,
'hosting_subscription_module'
,
'image_module'
,
'internal_order_module'
,
'internal_packing_list_module'
,
'internal_supply_module'
,
'internal_trade_condition_module'
,
'inventory_module'
,
'item_module'
,
'knowledge_pad_module'
,
'meeting_module'
,
'notification_message_module'
,
'open_internal_order_module'
,
'open_purchase_order_module'
,
'open_sale_order_module'
,
'organisation_module'
,
'person_module'
,
'portal_activities'
,
'portal_simulation'
,
'product_module'
,
'purchase_order_module'
,
'purchase_packing_list_module'
,
'purchase_supply_module'
,
'purchase_trade_condition_module'
,
'quantity_unit_conversion_module'
,
'query_module'
,
'returned_purchase_packing_list_module'
,
'returned_sale_packing_list_module'
,
'sale_opportunity_module'
,
'sale_order_module'
,
'sale_packing_list_module'
,
'sale_supply_module'
,
'sale_trade_condition_module'
,
'service_module'
,
'service_report_module'
,
'software_installation_module'
,
'software_instance_module'
,
'software_licence_module'
,
'software_product_module'
,
'software_publication_module'
,
'software_release_module'
,
'support_request_module'
,
'transformation_module'
,
'web_page_module'
,
'web_site_module'
,
'workflow_module'
,
])
self
.
assertSameSet
(
expected_list
,
visited_list
)
class
TestSlapOSAllocation
(
testSlapOSMixin
):
...
...
@@ -505,3 +651,518 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by S
def
test_allocation_storage_redundancy_sla
(
self
):
return
self
.
check_allocation_category_sla
(
'storage_redundancy'
,
'dht'
,
'raid'
)
class
TestSlapOSCoreSlapOSAssertHostingSubscriptionPredecessorAlarm
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSCoreSlapOSAssertHostingSubscriptionPredecessorAlarm
,
self
).
afterSetUp
()
self
.
_makeTree
()
def
test_HostingSubscription_assertPredecessor
(
self
):
self
.
software_instance
.
rename
(
new_name
=
self
.
generateNewSoftwareTitle
())
self
.
tic
()
# check that no interaction has recreated the instance
self
.
assertFalse
(
self
.
hosting_subscription
.
getTitle
()
in
self
.
hosting_subscription
.
getPredecessorTitleList
())
self
.
hosting_subscription
.
HostingSubscription_assertPredecessor
()
self
.
assertTrue
(
self
.
hosting_subscription
.
getTitle
()
in
self
.
hosting_subscription
.
getPredecessorTitleList
())
def
test_HostingSubscription_assertPredecessor_stop_requested
(
self
):
self
.
software_instance
.
rename
(
new_name
=
self
.
generateNewSoftwareTitle
())
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
hosting_subscription
,
'stop_requested'
)
self
.
tic
()
# check that no interaction has recreated the instance
self
.
assertFalse
(
self
.
hosting_subscription
.
getTitle
()
in
self
.
hosting_subscription
.
getPredecessorTitleList
())
self
.
hosting_subscription
.
HostingSubscription_assertPredecessor
()
self
.
assertTrue
(
self
.
hosting_subscription
.
getTitle
()
in
self
.
hosting_subscription
.
getPredecessorTitleList
())
def
test_HostingSubscription_assertPredecessor_destroy_requested
(
self
):
self
.
software_instance
.
rename
(
new_name
=
self
.
generateNewSoftwareTitle
())
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
hosting_subscription
,
'destroy_requested'
)
self
.
tic
()
# check that no interaction has recreated the instance
self
.
assertFalse
(
self
.
hosting_subscription
.
getTitle
()
in
self
.
hosting_subscription
.
getPredecessorTitleList
())
self
.
hosting_subscription
.
HostingSubscription_assertPredecessor
()
self
.
assertFalse
(
self
.
hosting_subscription
.
getTitle
()
in
self
.
hosting_subscription
.
getPredecessorTitleList
())
def
test_HostingSubscription_assertPredecessor_archived
(
self
):
self
.
software_instance
.
rename
(
new_name
=
self
.
generateNewSoftwareTitle
())
self
.
hosting_subscription
.
archive
()
self
.
tic
()
# check that no interaction has recreated the instance
self
.
assertFalse
(
self
.
hosting_subscription
.
getTitle
()
in
self
.
hosting_subscription
.
getPredecessorTitleList
())
self
.
hosting_subscription
.
HostingSubscription_assertPredecessor
()
self
.
assertFalse
(
self
.
hosting_subscription
.
getTitle
()
in
self
.
hosting_subscription
.
getPredecessorTitleList
())
def
_simulateHostingSubscription_assertPredecessor
(
self
):
script_name
=
'HostingSubscription_assertPredecessor'
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 HostingSubscription_assertPredecessor') """
)
transaction
.
commit
()
def
_dropHostingSubscription_assertPredecessor
(
self
):
script_name
=
'HostingSubscription_assertPredecessor'
if
script_name
in
self
.
portal
.
portal_skins
.
custom
.
objectIds
():
self
.
portal
.
portal_skins
.
custom
.
manage_delObjects
(
script_name
)
transaction
.
commit
()
def
test_alarm_renamed
(
self
):
self
.
software_instance
.
edit
(
title
=
self
.
generateNewSoftwareTitle
())
self
.
tic
()
self
.
_simulateHostingSubscription_assertPredecessor
()
try
:
self
.
portal
.
portal_alarms
.
slapos_assert_hosting_subscription_predecessor
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropHostingSubscription_assertPredecessor
()
self
.
assertEqual
(
'Visited by HostingSubscription_assertPredecessor'
,
self
.
hosting_subscription
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_not_renamed
(
self
):
self
.
_simulateHostingSubscription_assertPredecessor
()
try
:
self
.
portal
.
portal_alarms
.
slapos_assert_hosting_subscription_predecessor
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropHostingSubscription_assertPredecessor
()
self
.
assertNotEqual
(
'Visited by HostingSubscription_assertPredecessor'
,
self
.
hosting_subscription
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
class
TestSlapOSFreeComputerPartitionAlarm
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSFreeComputerPartitionAlarm
,
self
).
afterSetUp
()
self
.
_makeTree
()
def
test_Instance_tryToUnallocatePartition
(
self
):
self
.
_makeComputer
()
self
.
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
self
.
partition
.
markBusy
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
tic
()
self
.
software_instance
.
Instance_tryToUnallocatePartition
()
self
.
tic
()
self
.
assertEqual
(
None
,
self
.
software_instance
.
getAggregate
())
self
.
assertEqual
(
'free'
,
self
.
partition
.
getSlapState
())
def
test_Instance_tryToUnallocatePartition_concurrency
(
self
):
self
.
_makeComputer
()
self
.
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
self
.
partition
.
markBusy
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
tic
()
self
.
partition
.
activate
(
tag
=
"allocate_%s"
%
self
.
partition
.
getRelativeUrl
()
\
).
getId
()
transaction
.
commit
()
self
.
software_instance
.
Instance_tryToUnallocatePartition
()
self
.
tic
()
self
.
assertEqual
(
self
.
partition
.
getRelativeUrl
(),
self
.
software_instance
.
getAggregate
())
self
.
assertEqual
(
'busy'
,
self
.
partition
.
getSlapState
())
def
test_Instance_tryToUnallocatePartition_twoInstances
(
self
):
software_instance
=
self
.
portal
.
software_instance_module
\
.
template_software_instance
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
_makeComputer
()
self
.
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
self
.
partition
.
markBusy
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
tic
()
self
.
software_instance
.
Instance_tryToUnallocatePartition
()
self
.
tic
()
self
.
assertEqual
(
None
,
self
.
software_instance
.
getAggregate
())
self
.
assertEqual
(
'busy'
,
self
.
partition
.
getSlapState
())
self
.
assertEqual
(
self
.
partition
.
getRelativeUrl
(),
software_instance
.
getAggregate
())
def
_simulateInstance_tryToUnallocatePartition
(
self
):
script_name
=
'Instance_tryToUnallocatePartition'
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 Instance_tryToUnallocatePartition') """
)
transaction
.
commit
()
def
_dropInstance_tryToUnallocatePartition
(
self
):
script_name
=
'Instance_tryToUnallocatePartition'
if
script_name
in
self
.
portal
.
portal_skins
.
custom
.
objectIds
():
self
.
portal
.
portal_skins
.
custom
.
manage_delObjects
(
script_name
)
transaction
.
commit
()
def
test_alarm_allocated
(
self
):
self
.
_makeComputer
()
self
.
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
self
.
partition
.
markBusy
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
software_instance
.
invalidate
()
self
.
tic
()
self
.
_simulateInstance_tryToUnallocatePartition
()
try
:
self
.
portal
.
portal_alarms
.
slapos_free_computer_partition
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropInstance_tryToUnallocatePartition
()
self
.
assertEqual
(
'Visited by Instance_tryToUnallocatePartition'
,
self
.
software_instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_unallocated
(
self
):
self
.
_makeComputer
()
self
.
partition
.
markBusy
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
software_instance
.
invalidate
()
self
.
tic
()
self
.
_simulateInstance_tryToUnallocatePartition
()
try
:
self
.
portal
.
portal_alarms
.
slapos_free_computer_partition
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropInstance_tryToUnallocatePartition
()
self
.
assertNotEqual
(
'Visited by Instance_tryToUnallocatePartition'
,
self
.
software_instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_validated
(
self
):
self
.
_makeComputer
()
self
.
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
self
.
partition
.
markBusy
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
tic
()
self
.
_simulateInstance_tryToUnallocatePartition
()
try
:
self
.
portal
.
portal_alarms
.
slapos_free_computer_partition
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropInstance_tryToUnallocatePartition
()
self
.
assertNotEqual
(
'Visited by Instance_tryToUnallocatePartition'
,
self
.
software_instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_start_requested
(
self
):
self
.
_makeComputer
()
self
.
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
self
.
partition
.
markBusy
()
self
.
tic
()
self
.
_simulateInstance_tryToUnallocatePartition
()
try
:
self
.
portal
.
portal_alarms
.
slapos_free_computer_partition
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropInstance_tryToUnallocatePartition
()
self
.
assertNotEqual
(
'Visited by Instance_tryToUnallocatePartition'
,
self
.
software_instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
class
TestSlapOSFreeComputerPartitionAlarmWithSlave
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSFreeComputerPartitionAlarmWithSlave
,
self
).
afterSetUp
()
self
.
_makeTree
(
requested_template_id
=
'template_slave_instance'
)
def
test_Instance_tryToUnallocatePartition
(
self
):
self
.
_makeComputer
()
self
.
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
self
.
partition
.
markBusy
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
tic
()
self
.
software_instance
.
Instance_tryToUnallocatePartition
()
self
.
tic
()
self
.
assertEqual
(
None
,
self
.
software_instance
.
getAggregate
())
self
.
assertEqual
(
'free'
,
self
.
partition
.
getSlapState
())
def
test_Instance_tryToUnallocatePartition_nonDestroyed
(
self
):
self
.
_makeComputer
()
self
.
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
self
.
partition
.
markBusy
()
self
.
tic
()
self
.
software_instance
.
Instance_tryToUnallocatePartition
()
self
.
tic
()
self
.
assertEqual
(
self
.
partition
.
getRelativeUrl
(),
self
.
software_instance
.
getAggregate
())
self
.
assertEqual
(
'busy'
,
self
.
partition
.
getSlapState
())
class
TestSlapOSGarbageCollectDestroyedRootTreeAlarm
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSGarbageCollectDestroyedRootTreeAlarm
,
self
).
afterSetUp
()
self
.
_makeTree
()
def
test_Instance_tryToGarbageCollect
(
self
):
self
.
hosting_subscription
.
archive
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
tic
()
self
.
requested_software_instance
.
Instance_tryToGarbageCollect
()
self
.
tic
()
self
.
assertEqual
(
'destroy_requested'
,
self
.
requested_software_instance
.
getSlapState
())
self
.
assertEqual
(
'validated'
,
self
.
requested_software_instance
.
getValidationState
())
def
test_Instance_tryToGarbageCollect_not_destroy_requested
(
self
):
self
.
requested_software_instance
.
Instance_tryToGarbageCollect
()
self
.
tic
()
self
.
assertEqual
(
'start_requested'
,
self
.
requested_software_instance
.
getSlapState
())
self
.
assertEqual
(
'validated'
,
self
.
requested_software_instance
.
getValidationState
())
def
test_Instance_tryToGarbageCollect_not_archived
(
self
):
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
tic
()
self
.
requested_software_instance
.
Instance_tryToGarbageCollect
()
self
.
tic
()
self
.
assertEqual
(
'start_requested'
,
self
.
requested_software_instance
.
getSlapState
())
self
.
assertEqual
(
'validated'
,
self
.
requested_software_instance
.
getValidationState
())
def
test_Instance_tryToGarbageCollect_only_instance_destroy_requested
(
self
):
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
tic
()
self
.
requested_software_instance
.
Instance_tryToGarbageCollect
()
self
.
tic
()
self
.
assertEqual
(
'start_requested'
,
self
.
requested_software_instance
.
getSlapState
())
self
.
assertEqual
(
'validated'
,
self
.
requested_software_instance
.
getValidationState
())
def
_simulateInstance_tryToGarbageCollect
(
self
):
script_name
=
'Instance_tryToGarbageCollect'
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 Instance_tryToGarbageCollect') """
)
transaction
.
commit
()
def
_dropInstance_tryToGarbageCollect
(
self
):
script_name
=
'Instance_tryToGarbageCollect'
if
script_name
in
self
.
portal
.
portal_skins
.
custom
.
objectIds
():
self
.
portal
.
portal_skins
.
custom
.
manage_delObjects
(
script_name
)
transaction
.
commit
()
def
test_alarm
(
self
):
self
.
hosting_subscription
.
archive
()
self
.
tic
()
self
.
_simulateInstance_tryToGarbageCollect
()
try
:
self
.
portal
.
portal_alarms
.
slapos_garbage_collect_destroyed_root_tree
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropInstance_tryToGarbageCollect
()
self
.
assertEqual
(
'Visited by Instance_tryToGarbageCollect'
,
self
.
software_instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_invalidated
(
self
):
self
.
hosting_subscription
.
archive
()
self
.
software_instance
.
invalidate
()
self
.
tic
()
self
.
_simulateInstance_tryToGarbageCollect
()
try
:
self
.
portal
.
portal_alarms
.
slapos_garbage_collect_destroyed_root_tree
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropInstance_tryToGarbageCollect
()
self
.
assertNotEqual
(
'Visited by Instance_tryToGarbageCollect'
,
self
.
software_instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_not_archived
(
self
):
self
.
tic
()
self
.
_simulateInstance_tryToGarbageCollect
()
try
:
self
.
portal
.
portal_alarms
.
slapos_garbage_collect_destroyed_root_tree
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropInstance_tryToGarbageCollect
()
self
.
assertNotEqual
(
'Visited by Instance_tryToGarbageCollect'
,
self
.
software_instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
class
TestSlapOSGarbageCollectDestroyedRootTreeAlarm
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSGarbageCollectDestroyedRootTreeAlarm
,
self
).
afterSetUp
()
self
.
computer
=
self
.
portal
.
computer_module
.
template_computer
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
computer
.
edit
(
allocation_scope
=
'open/public'
,
capacity_scope
=
'open'
,
reference
=
'TESTC-%s'
%
self
.
generateNewId
(),
)
self
.
computer
.
validate
()
memcached_dict
=
self
.
portal
.
portal_memcached
.
getMemcachedDict
(
key_prefix
=
'slap_tool'
,
plugin_path
=
'portal_memcached/default_memcached_plugin'
)
memcached_dict
[
self
.
computer
.
getReference
()]
=
json
.
dumps
({
'text'
:
'#access ok'
})
transaction
.
commit
()
def
test_Computer_checkAndUpdateCapacityScope
(
self
):
self
.
computer
.
Computer_checkAndUpdateCapacityScope
()
self
.
assertEqual
(
'open'
,
self
.
computer
.
getCapacityScope
())
def
test_Computer_checkAndUpdateCapacityScope_no_capacity_quantity
(
self
):
self
.
_makeTree
()
self
.
computer
.
edit
(
capacity_quantity
=
1
)
partition
=
self
.
computer
.
newContent
(
portal_type
=
'Computer Partition'
,
reference
=
'part1'
)
partition
.
markFree
()
partition
.
markBusy
()
partition
.
validate
()
self
.
software_instance
.
setAggregate
(
partition
.
getRelativeUrl
())
self
.
tic
()
self
.
computer
.
Computer_checkAndUpdateCapacityScope
()
self
.
assertEqual
(
'close'
,
self
.
computer
.
getCapacityScope
())
self
.
assertEqual
(
'Computer capacity limit exceeded'
,
self
.
computer
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_Computer_checkAndUpdateCapacityScope_no_access
(
self
):
self
.
computer
.
edit
(
reference
=
'TESTC-%s'
%
self
.
generateNewId
())
self
.
computer
.
Computer_checkAndUpdateCapacityScope
()
self
.
assertEqual
(
'close'
,
self
.
computer
.
getCapacityScope
())
self
.
assertEqual
(
"Computer didn't contact the server"
,
self
.
computer
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_Computer_checkAndUpdateCapacityScope_close
(
self
):
self
.
computer
.
edit
(
capacity_scope
=
'close'
)
self
.
computer
.
Computer_checkAndUpdateCapacityScope
()
self
.
assertEqual
(
'open'
,
self
.
computer
.
getCapacityScope
())
def
test_Computer_checkAndUpdateCapacityScope_with_error
(
self
):
memcached_dict
=
self
.
portal
.
portal_memcached
.
getMemcachedDict
(
key_prefix
=
'slap_tool'
,
plugin_path
=
'portal_memcached/default_memcached_plugin'
)
memcached_dict
[
self
.
computer
.
getReference
()]
=
json
.
dumps
({
'text'
:
'#error not ok'
})
self
.
computer
.
Computer_checkAndUpdateCapacityScope
()
self
.
assertEqual
(
'close'
,
self
.
computer
.
getCapacityScope
())
self
.
assertEqual
(
"Computer reported an error"
,
self
.
computer
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_Computer_checkAndUpdateCapacityScope_with_error_non_public
(
self
):
memcached_dict
=
self
.
portal
.
portal_memcached
.
getMemcachedDict
(
key_prefix
=
'slap_tool'
,
plugin_path
=
'portal_memcached/default_memcached_plugin'
)
memcached_dict
[
self
.
computer
.
getReference
()]
=
json
.
dumps
({
'text'
:
'#error not ok'
})
self
.
computer
.
edit
(
allocation_scope
=
'open/personal'
)
self
.
computer
.
Computer_checkAndUpdateCapacityScope
()
self
.
assertEqual
(
'open'
,
self
.
computer
.
getCapacityScope
())
def
_simulateComputer_checkAndUpdateCapacityScope
(
self
):
script_name
=
'Computer_checkAndUpdateCapacityScope'
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 Computer_checkAndUpdateCapacityScope') """
)
transaction
.
commit
()
def
_dropComputer_checkAndUpdateCapacityScope
(
self
):
script_name
=
'Computer_checkAndUpdateCapacityScope'
if
script_name
in
self
.
portal
.
portal_skins
.
custom
.
objectIds
():
self
.
portal
.
portal_skins
.
custom
.
manage_delObjects
(
script_name
)
transaction
.
commit
()
def
test_alarm
(
self
):
self
.
_simulateComputer_checkAndUpdateCapacityScope
()
try
:
self
.
portal
.
portal_alarms
.
slapos_update_computer_capacity_scope
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropComputer_checkAndUpdateCapacityScope
()
self
.
assertEqual
(
'Visited by Computer_checkAndUpdateCapacityScope'
,
self
.
computer
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_non_public
(
self
):
self
.
computer
.
edit
(
allocation_scope
=
'open/personal'
)
self
.
tic
()
self
.
_simulateComputer_checkAndUpdateCapacityScope
()
try
:
self
.
portal
.
portal_alarms
.
slapos_update_computer_capacity_scope
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropComputer_checkAndUpdateCapacityScope
()
self
.
assertNotEqual
(
'Visited by Computer_checkAndUpdateCapacityScope'
,
self
.
computer
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_invalidated
(
self
):
self
.
computer
.
invalidate
()
self
.
tic
()
self
.
_simulateComputer_checkAndUpdateCapacityScope
()
try
:
self
.
portal
.
portal_alarms
.
slapos_update_computer_capacity_scope
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropComputer_checkAndUpdateCapacityScope
()
self
.
assertNotEqual
(
'Visited by Computer_checkAndUpdateCapacityScope'
,
self
.
computer
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudComputerPartitionSlapInterfaceWorkflow.py
deleted
100644 → 0
View file @
a35da019
# Copyright (c) 2002-2012 Nexedi SA and Contributors. All Rights Reserved.
from
Products.SlapOS.tests.testSlapOSMixin
import
\
testSlapOSMixin
class
TestSlapOSCoreComputerPartitionSlapInterfaceWorkflow
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSCoreComputerPartitionSlapInterfaceWorkflow
,
self
).
afterSetUp
()
# Clone computer document
self
.
computer
=
self
.
portal
.
computer_module
.
template_computer
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
new_id
=
self
.
generateNewId
()
self
.
computer
.
edit
(
title
=
"computer %s"
%
(
new_id
,
),
reference
=
"TESTCOMP-%s"
%
(
new_id
,
),
allocation_scope
=
'open/personal'
,
capacity_scope
=
'open'
,
)
self
.
computer
.
validate
()
# install an software release
self
.
software_installation
=
self
.
portal
.
software_installation_module
\
.
newContent
(
portal_type
=
'Software Installation'
,
url_string
=
self
.
generateNewSoftwareReleaseUrl
(),
aggregate
=
self
.
computer
.
getRelativeUrl
())
self
.
software_installation
.
validate
()
self
.
software_installation
.
requestStart
()
self
.
tic
()
def
test_markFree
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
partition
=
self
.
computer
.
newContent
(
portal_type
=
'Computer Partition'
,
reference
=
'PART-%s'
%
self
.
generateNewId
())
partition
.
validate
()
partition
.
markFree
()
self
.
tic
()
self
.
assertEqual
(
1
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
def
test_markFree_markBusy
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
partition
=
self
.
computer
.
newContent
(
portal_type
=
'Computer Partition'
,
reference
=
'PART-%s'
%
self
.
generateNewId
())
partition
.
validate
()
partition
.
markFree
()
self
.
tic
()
self
.
assertEqual
(
1
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
partition
.
markBusy
()
self
.
tic
()
self
.
assertEqual
(
0
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
def
test_markFree_markBusy_markFree
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
partition
=
self
.
computer
.
newContent
(
portal_type
=
'Computer Partition'
,
reference
=
'PART-%s'
%
self
.
generateNewId
())
partition
.
validate
()
partition
.
markFree
()
self
.
tic
()
self
.
assertEqual
(
1
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
partition
.
markBusy
()
self
.
tic
()
self
.
assertEqual
(
0
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
partition
.
markFree
()
self
.
tic
()
self
.
assertEqual
(
1
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
def
test_markInactive
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
partition
=
self
.
computer
.
newContent
(
portal_type
=
'Computer Partition'
,
reference
=
'PART-%s'
%
self
.
generateNewId
())
partition
.
validate
()
partition
.
markInactive
()
self
.
tic
()
self
.
assertEqual
(
0
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
def
test_markInactive_markFree
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
partition
=
self
.
computer
.
newContent
(
portal_type
=
'Computer Partition'
,
reference
=
'PART-%s'
%
self
.
generateNewId
())
partition
.
validate
()
partition
.
markInactive
()
self
.
tic
()
self
.
assertEqual
(
0
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
partition
.
markFree
()
self
.
tic
()
self
.
assertEqual
(
1
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudComputerSlapInterfaceWorkflow.py
deleted
100644 → 0
View file @
a35da019
# Copyright (c) 2002-2012 Nexedi SA and Contributors. All Rights Reserved.
from
Products.SlapOS.tests.testSlapOSMixin
import
\
testSlapOSMixin
import
transaction
from
Products.ERP5Type.tests.backportUnittest
import
expectedFailure
from
Products.ERP5Type.Errors
import
UnsupportedWorkflowMethod
class
TestSlapOSCoreComputerSlapInterfaceWorkflow
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSCoreComputerSlapInterfaceWorkflow
,
self
).
afterSetUp
()
# Clone computer document
self
.
computer
=
self
.
portal
.
computer_module
.
template_computer
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
new_id
=
self
.
generateNewId
()
self
.
computer
.
edit
(
title
=
"computer %s"
%
(
new_id
,
),
reference
=
"TESTCOMP-%s"
%
(
new_id
,
)
)
self
.
computer
.
validate
()
self
.
tic
()
def
_makePerson
(
self
):
new_id
=
self
.
generateNewId
()
self
.
person_user
=
self
.
portal
.
person_module
.
template_member
.
\
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
person_user
.
edit
(
title
=
"live_test_%s"
%
new_id
,
reference
=
"live_test_%s"
%
new_id
,
default_email_text
=
"live_test_%s@example.org"
%
new_id
,
)
self
.
person_user
.
validate
()
for
assignment
in
self
.
person_user
.
contentValues
(
portal_type
=
"Assignment"
):
assignment
.
open
()
self
.
tic
()
def
beforeTearDown
(
self
):
super
(
TestSlapOSCoreComputerSlapInterfaceWorkflow
,
self
).
beforeTearDown
()
self
.
portal
.
REQUEST
[
'computer_key'
]
=
None
self
.
portal
.
REQUEST
[
'computer_certificate'
]
=
None
def
test_generateCertificate
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
self
.
computer
.
generateCertificate
()
computer_key
=
self
.
portal
.
REQUEST
.
get
(
'computer_key'
)
computer_certificate
=
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
)
self
.
assertNotEqual
(
None
,
computer_key
)
self
.
assertNotEqual
(
None
,
computer_certificate
)
self
.
assertNotEqual
(
None
,
self
.
computer
.
getDestinationReference
())
serial
=
'0x%x'
%
int
(
self
.
computer
.
getDestinationReference
(),
16
)
self
.
assertTrue
(
serial
in
computer_certificate
)
self
.
assertTrue
(
self
.
computer
.
getReference
()
in
computer_certificate
)
def
test_generateCertificate_twice
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
self
.
computer
.
generateCertificate
()
computer_key
=
self
.
portal
.
REQUEST
.
get
(
'computer_key'
)
computer_certificate
=
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
)
self
.
assertNotEqual
(
None
,
computer_key
)
self
.
assertNotEqual
(
None
,
computer_certificate
)
self
.
assertNotEqual
(
None
,
self
.
computer
.
getDestinationReference
())
serial
=
'0x%x'
%
int
(
self
.
computer
.
getDestinationReference
(),
16
)
self
.
assertTrue
(
serial
in
computer_certificate
)
self
.
assertTrue
(
self
.
computer
.
getReference
()
in
computer_certificate
)
self
.
assertRaises
(
ValueError
,
self
.
computer
.
generateCertificate
)
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_key'
))
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
))
def
test_approveComputerRegistration
(
self
):
self
.
_makePerson
()
self
.
login
(
self
.
person_user
.
getReference
())
new_id
=
self
.
generateNewId
()
computer
=
self
.
portal
.
computer_module
.
newContent
(
portal_type
=
'Computer'
,
title
=
"Computer %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTCOMP-%s"
%
new_id
)
computer
.
requestComputerRegistration
()
computer
.
approveComputerRegistration
()
self
.
assertEqual
(
'open/personal'
,
computer
.
getAllocationScope
())
self
.
assertEqual
(
self
.
person_user
.
getRelativeUrl
(),
computer
.
getSourceAdministration
())
self
.
assertEqual
(
'validated'
,
computer
.
getValidationState
())
def
_countInstanceBang
(
self
,
instance
,
comment
):
return
len
([
q
for
q
in
instance
.
workflow_history
[
'instance_slap_interface_workflow'
]
if
q
[
'action'
]
==
'bang'
and
\
q
[
'comment'
]
==
comment
])
def
_countComputereBang
(
self
,
computer
,
comment
):
return
len
([
q
for
q
in
computer
.
workflow_history
[
'computer_slap_interface_workflow'
]
if
q
[
'action'
]
==
\
'report_computer_bang'
and
q
[
'comment'
]
==
comment
])
def
test_reportComputerBang
(
self
):
self
.
_makeComplexComputer
()
self
.
login
(
self
.
computer
.
getReference
())
comment
=
'Bang from computer'
started_instance
=
self
.
computer
.
partition1
.
getAggregateRelatedValue
(
portal_type
=
'Software Instance'
)
stopped_instance
=
self
.
computer
.
partition2
.
getAggregateRelatedValue
(
portal_type
=
'Software Instance'
)
destroyed_instance1
=
self
.
computer
.
partition3
.
getAggregateRelatedValue
(
portal_type
=
'Software Instance'
)
destroyed_instance2
=
self
.
computer
.
partition4
.
getAggregateRelatedValue
(
portal_type
=
'Software Instance'
)
# test sanity check -- do not trust _makeComplexComputer
self
.
assertEqual
(
'start_requested'
,
started_instance
.
getSlapState
())
self
.
assertEqual
(
'stop_requested'
,
stopped_instance
.
getSlapState
())
self
.
assertEqual
(
'destroy_requested'
,
destroyed_instance1
.
getSlapState
())
self
.
assertEqual
(
'destroy_requested'
,
destroyed_instance2
.
getSlapState
())
# store counts before bang
computer_bang_count
=
self
.
_countComputereBang
(
self
.
computer
,
comment
)
started_instance_bang_count
=
self
.
_countInstanceBang
(
started_instance
,
comment
)
stopped_instance_bang_count
=
self
.
_countInstanceBang
(
stopped_instance
,
comment
)
destroyed_instance1_bang_count
=
self
.
_countInstanceBang
(
destroyed_instance1
,
comment
)
destroyed_instance2_bang_count
=
self
.
_countInstanceBang
(
destroyed_instance2
,
comment
)
self
.
computer
.
reportComputerBang
(
comment
=
comment
)
self
.
tic
()
self
.
assertEqual
(
1
+
computer_bang_count
,
self
.
_countComputereBang
(
self
.
computer
,
comment
))
self
.
assertEqual
(
1
+
started_instance_bang_count
,
self
.
_countInstanceBang
(
started_instance
,
comment
))
self
.
assertEqual
(
1
+
stopped_instance_bang_count
,
self
.
_countInstanceBang
(
stopped_instance
,
comment
))
self
.
assertEqual
(
destroyed_instance1_bang_count
,
self
.
_countInstanceBang
(
destroyed_instance1
,
comment
))
self
.
assertEqual
(
destroyed_instance2_bang_count
,
self
.
_countInstanceBang
(
destroyed_instance2
,
comment
))
def
test_requestSoftwareRelease_software_release_url_required
(
self
):
self
.
_makePerson
()
self
.
computer
.
edit
(
source_administration
=
self
.
person_user
.
getRelativeUrl
())
self
.
tic
()
self
.
login
(
self
.
person_user
.
getReference
())
self
.
assertRaises
(
TypeError
,
self
.
computer
.
requestSoftwareRelease
,
state
=
'available'
)
transaction
.
abort
()
def
test_requestSoftwareRelease_state_required
(
self
):
self
.
_makePerson
()
self
.
computer
.
edit
(
source_administration
=
self
.
person_user
.
getRelativeUrl
())
self
.
tic
()
self
.
login
(
self
.
person_user
.
getReference
())
url
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
assertRaises
(
TypeError
,
self
.
computer
.
requestSoftwareRelease
,
software_release_url
=
url
)
transaction
.
abort
()
def
test_requestSoftwareRelease_available
(
self
):
self
.
_makePerson
()
self
.
computer
.
edit
(
source_administration
=
self
.
person_user
.
getRelativeUrl
())
self
.
tic
()
self
.
login
(
self
.
person_user
.
getReference
())
url
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
software_release_url
=
url
,
state
=
'available'
)
self
.
tic
()
self
.
login
()
software_installation
=
self
.
computer
.
getAggregateRelatedValue
(
portal_type
=
'Software Installation'
)
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
url
,
software_installation
.
getUrlString
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
def
test_requestSoftwareRelease_destroyed
(
self
):
self
.
_makePerson
()
self
.
computer
.
edit
(
source_administration
=
self
.
person_user
.
getRelativeUrl
())
self
.
tic
()
self
.
login
(
self
.
person_user
.
getReference
())
url
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
software_release_url
=
url
,
state
=
'destroyed'
)
self
.
tic
()
self
.
login
()
software_installation
=
self
.
computer
.
getAggregateRelatedValue
(
portal_type
=
'Software Installation'
)
self
.
assertEqual
(
None
,
software_installation
)
def
test_requestSoftwareRelease_available_destroyed
(
self
):
self
.
_makePerson
()
self
.
computer
.
edit
(
source_administration
=
self
.
person_user
.
getRelativeUrl
())
self
.
tic
()
self
.
login
(
self
.
person_user
.
getReference
())
url
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
software_release_url
=
url
,
state
=
'available'
)
self
.
tic
()
self
.
login
()
software_installation
=
self
.
computer
.
getAggregateRelatedValue
(
portal_type
=
'Software Installation'
)
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
url
,
software_installation
.
getUrlString
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
login
(
self
.
person_user
.
getReference
())
self
.
computer
.
requestSoftwareRelease
(
software_release_url
=
url
,
state
=
'destroyed'
)
self
.
tic
()
self
.
login
()
software_installation
=
self
.
computer
.
getAggregateRelatedValue
(
portal_type
=
'Software Installation'
)
self
.
assertEqual
(
'destroy_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
url
,
software_installation
.
getUrlString
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
def
test_requestSoftwareRelease_not_indexed
(
self
):
self
.
_makePerson
()
self
.
computer
.
edit
(
source_administration
=
self
.
person_user
.
getRelativeUrl
())
self
.
tic
()
self
.
login
(
self
.
person_user
.
getReference
())
url
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
software_release_url
=
url
,
state
=
'available'
)
transaction
.
commit
()
self
.
assertRaises
(
NotImplementedError
,
self
.
computer
.
requestSoftwareRelease
,
software_release_url
=
url
,
state
=
'available'
)
transaction
.
abort
()
@
expectedFailure
def
test_requestSoftwareRelease_same_transaction
(
self
):
self
.
_makePerson
()
self
.
computer
.
edit
(
source_administration
=
self
.
person_user
.
getRelativeUrl
())
self
.
tic
()
self
.
login
(
self
.
person_user
.
getReference
())
url
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
software_release_url
=
url
,
state
=
'available'
)
self
.
assertRaises
(
NotImplementedError
,
self
.
computer
.
requestSoftwareRelease
,
software_release_url
=
url
,
state
=
'available'
)
transaction
.
abort
()
def
test_revokeCertificate
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
self
.
computer
.
generateCertificate
()
computer_key
=
self
.
portal
.
REQUEST
.
get
(
'computer_key'
)
computer_certificate
=
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
)
self
.
assertNotEqual
(
None
,
computer_key
)
self
.
assertNotEqual
(
None
,
computer_certificate
)
self
.
assertNotEqual
(
None
,
self
.
computer
.
getDestinationReference
())
serial
=
'0x%x'
%
int
(
self
.
computer
.
getDestinationReference
(),
16
)
self
.
assertTrue
(
serial
in
computer_certificate
)
self
.
assertTrue
(
self
.
computer
.
getReference
()
in
computer_certificate
)
self
.
computer
.
revokeCertificate
()
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_key'
))
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
))
self
.
assertEqual
(
None
,
self
.
computer
.
getDestinationReference
())
def
test_revokeCertificateNoCertificate
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
self
.
assertRaises
(
ValueError
,
self
.
computer
.
revokeCertificate
)
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_key'
))
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
))
self
.
assertEqual
(
None
,
self
.
computer
.
getDestinationReference
())
def
test_revokeCertificate_twice
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
self
.
computer
.
generateCertificate
()
computer_key
=
self
.
portal
.
REQUEST
.
get
(
'computer_key'
)
computer_certificate
=
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
)
self
.
assertNotEqual
(
None
,
computer_key
)
self
.
assertNotEqual
(
None
,
computer_certificate
)
self
.
assertNotEqual
(
None
,
self
.
computer
.
getDestinationReference
())
serial
=
'0x%x'
%
int
(
self
.
computer
.
getDestinationReference
(),
16
)
self
.
assertTrue
(
serial
in
computer_certificate
)
self
.
assertTrue
(
self
.
computer
.
getReference
()
in
computer_certificate
)
self
.
computer
.
revokeCertificate
()
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_key'
))
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
))
self
.
assertEqual
(
None
,
self
.
computer
.
getDestinationReference
())
self
.
assertRaises
(
ValueError
,
self
.
computer
.
revokeCertificate
)
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_key'
))
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
))
self
.
assertEqual
(
None
,
self
.
computer
.
getDestinationReference
())
class
TestSlapOSCorePersonComputerSupply
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSCorePersonComputerSupply
,
self
).
afterSetUp
()
portal
=
self
.
getPortalObject
()
new_id
=
self
.
generateNewId
()
# Clone computer document
computer
=
portal
.
computer_module
.
template_computer
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
# Clone person document
person_user
=
portal
.
person_module
.
template_member
.
\
Base_createCloneDocument
(
batch_mode
=
1
)
person_user
.
edit
(
title
=
"live_test_%s"
%
new_id
,
reference
=
"live_test_%s"
%
new_id
,
default_email_text
=
"live_test_%s@example.org"
%
new_id
,
)
computer
.
edit
(
title
=
"Computer %s for %s"
%
(
new_id
,
person_user
.
getReference
()),
reference
=
"TESTCOMP-%s"
%
new_id
,
source_administration
=
person_user
.
getRelativeUrl
()
)
computer
.
validate
()
self
.
computer
=
computer
person_user
.
validate
()
for
assignment
in
person_user
.
contentValues
(
portal_type
=
"Assignment"
):
assignment
.
open
()
transaction
.
commit
()
# XXX Tic is needed to reindex the created open order
self
.
tic
()
# Login as new user
self
.
login
(
person_user
.
getReference
())
new_person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
self
.
assertEquals
(
person_user
.
getRelativeUrl
(),
new_person
.
getRelativeUrl
())
def
beforeTearDown
(
self
):
if
'software_installation_url'
in
self
.
computer
.
REQUEST
:
self
.
computer
.
REQUEST
[
'software_installation_url'
]
=
None
def
test_supply_requiredParameter
(
self
):
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
assertRaises
(
TypeError
,
self
.
computer
.
requestSoftwareRelease
)
self
.
assertRaises
(
TypeError
,
self
.
computer
.
requestSoftwareRelease
,
state
=
"available"
)
self
.
assertRaises
(
TypeError
,
self
.
computer
.
requestSoftwareRelease
,
software_release_url
=
software_release
)
self
.
assertRaises
(
ValueError
,
self
.
computer
.
requestSoftwareRelease
,
state
=
"mana"
,
software_release_url
=
software_release
)
def
test_supply_available
(
self
):
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
None
,
software_installation_url
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url
)
self
.
assertEqual
(
software_release
,
software_installation
.
getUrlString
())
def
test_supply_destroyed
(
self
):
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"destroyed"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertEqual
(
None
,
software_installation_url
)
def
test_supply_available_nonIndexed
(
self
):
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
None
,
software_installation_url
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url
)
self
.
assertEqual
(
software_release
,
software_installation
.
getUrlString
())
transaction
.
commit
()
self
.
assertRaises
(
NotImplementedError
,
self
.
computer
.
requestSoftwareRelease
,
state
=
"available"
,
software_release_url
=
software_release
)
def
test_supply_available_destroyed_nonIndexed
(
self
):
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
None
,
software_installation_url
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url
)
self
.
assertEqual
(
software_release
,
software_installation
.
getUrlString
())
transaction
.
commit
()
self
.
assertRaises
(
NotImplementedError
,
self
.
computer
.
requestSoftwareRelease
,
state
=
"destroyed"
,
software_release_url
=
software_release
)
def
test_supply_available_createdSoftwareInstallation
(
self
):
previous_id
=
self
.
getPortalObject
().
portal_ids
\
.
generateNewId
(
id_group
=
'slap_software_installation_reference'
,
id_generator
=
'uid'
)
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
None
,
software_installation_url
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url
)
self
.
assertEqual
(
software_release
,
software_installation
.
getUrlString
())
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
1
),
software_installation
.
getReference
())
def
test_multiple_supply_available_createdSoftwareInstallation
(
self
):
previous_id
=
self
.
getPortalObject
().
portal_ids
\
.
generateNewId
(
id_group
=
'slap_software_installation_reference'
,
id_generator
=
'uid'
)
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
None
,
software_installation_url
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url
)
self
.
assertEqual
(
software_release
,
software_installation
.
getUrlString
())
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
1
),
software_installation
.
getReference
())
self
.
tic
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url2
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertEqual
(
software_installation_url
,
software_installation_url2
)
def
test_supply_available_destroyed
(
self
):
previous_id
=
self
.
getPortalObject
().
portal_ids
\
.
generateNewId
(
id_group
=
'slap_software_installation_reference'
,
id_generator
=
'uid'
)
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
None
,
software_installation_url
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url
)
self
.
assertEqual
(
software_release
,
software_installation
.
getUrlString
())
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
1
),
software_installation
.
getReference
())
self
.
tic
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"destroyed"
,
software_release_url
=
software_release
)
software_installation_url2
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertEqual
(
software_installation_url
,
software_installation_url2
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url2
)
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'destroy_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
1
),
software_installation
.
getReference
())
def
test_supply_available_destroyed_available
(
self
):
previous_id
=
self
.
getPortalObject
().
portal_ids
\
.
generateNewId
(
id_group
=
'slap_software_installation_reference'
,
id_generator
=
'uid'
)
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
None
,
software_installation_url
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url
)
self
.
assertEqual
(
software_release
,
software_installation
.
getUrlString
())
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
1
),
software_installation
.
getReference
())
self
.
tic
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"destroyed"
,
software_release_url
=
software_release
)
software_installation_url2
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertEqual
(
software_installation_url
,
software_installation_url2
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url2
)
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'destroy_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
1
),
software_installation
.
getReference
())
self
.
tic
()
# XXX: This scenario shall be discussed...
self
.
assertRaises
(
UnsupportedWorkflowMethod
,
self
.
computer
.
requestSoftwareRelease
,
state
=
"available"
,
software_release_url
=
software_release
)
def
test_supply_available_destroyed_finalised_available
(
self
):
previous_id
=
self
.
getPortalObject
().
portal_ids
\
.
generateNewId
(
id_group
=
'slap_software_installation_reference'
,
id_generator
=
'uid'
)
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
None
,
software_installation_url
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url
)
self
.
assertEqual
(
software_release
,
software_installation
.
getUrlString
())
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
1
),
software_installation
.
getReference
())
self
.
tic
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"destroyed"
,
software_release_url
=
software_release
)
software_installation_url2
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertEqual
(
software_installation_url
,
software_installation_url2
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url2
)
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'destroy_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
1
),
software_installation
.
getReference
())
software_installation
.
invalidate
()
self
.
tic
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url3
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
software_installation_url
,
software_installation_url3
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url3
)
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
2
),
software_installation
.
getReference
())
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudPersonSlapInterfaceWorkflow.py
deleted
100644 → 0
View file @
a35da019
# Copyright (c) 2002-2012 Nexedi SA and Contributors. All Rights Reserved.
from
Products.SlapOS.tests.testSlapOSMixin
import
\
testSlapOSMixin
import
transaction
from
Products.ERP5Type.tests.backportUnittest
import
expectedFailure
from
AccessControl.SecurityManagement
import
getSecurityManager
,
\
setSecurityManager
class
TestSlapOSCorePersonRequest
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSCorePersonRequest
,
self
).
afterSetUp
()
portal
=
self
.
getPortalObject
()
new_id
=
self
.
generateNewId
()
# Clone person document
person_user
=
portal
.
person_module
.
template_member
.
\
Base_createCloneDocument
(
batch_mode
=
1
)
person_user
.
edit
(
title
=
"live_test_%s"
%
new_id
,
reference
=
"live_test_%s"
%
new_id
,
default_email_text
=
"live_test_%s@example.org"
%
new_id
,
)
person_user
.
validate
()
for
assignment
in
person_user
.
contentValues
(
portal_type
=
"Assignment"
):
assignment
.
open
()
transaction
.
commit
()
# XXX Tic is needed to reindex the created open order
self
.
tic
()
# Login as new user
self
.
login
(
person_user
.
getReference
())
new_person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
self
.
assertEquals
(
person_user
.
getRelativeUrl
(),
new_person
.
getRelativeUrl
())
def
beforeTearDown
(
self
):
pass
def
test_Person_requestSoftwareInstance_requiredParameter
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
state
=
"started"
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
)
# software_release is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
# software_title is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
# software_type is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
# instance_xml is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
# instance_xml is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
# sla_xml is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
shared
=
shared
,
state
=
state
,
)
# shared is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
state
=
state
,
)
# state is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
)
def
test_Person_requestSoftwareInstance_acceptedState
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
# Only started, stopped, destroyed
self
.
assertRaises
(
ValueError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"foo"
,
)
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
"started"
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"started"
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertEquals
(
"start_requested"
,
hosting_subscription
.
getSlapState
())
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
"stopped"
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"stopped"
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertEquals
(
"stop_requested"
,
hosting_subscription
.
getSlapState
())
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
"destroyed"
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"destroyed"
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertEquals
(
None
,
hosting_subscription
)
def
test_Person_requestSoftwareInstance_returnHostingSubscriptionUrl
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
state
=
"started"
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertEquals
(
"Hosting Subscription"
,
hosting_subscription
.
getPortalType
())
def
test_Person_requestSoftwareInstance_createHostingSubscription
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
state
=
"started"
previous_id
=
self
.
getPortalObject
().
portal_ids
\
.
generateNewId
(
id_group
=
'slap_hosting_subscription_reference'
,
id_generator
=
'uid'
)
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertEquals
(
software_release
,
hosting_subscription
.
getUrlString
())
self
.
assertEquals
(
software_title
,
hosting_subscription
.
getTitle
())
self
.
assertEquals
(
software_type
,
hosting_subscription
.
getSourceReference
())
self
.
assertEquals
(
instance_xml
,
hosting_subscription
.
getTextContent
())
self
.
assertEquals
(
sla_xml
,
hosting_subscription
.
getSlaXml
())
self
.
assertEquals
(
shared
,
hosting_subscription
.
getRootSlave
())
self
.
assertEquals
(
"start_requested"
,
hosting_subscription
.
getSlapState
())
self
.
assertEquals
(
"HOSTSUBS-%s"
%
(
previous_id
+
1
),
hosting_subscription
.
getReference
())
self
.
assertEquals
(
"validated"
,
hosting_subscription
.
getValidationState
())
def
test_Person_requestSoftwareInstance_HostingSubscriptionNotReindexed
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
state
=
"started"
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
transaction
.
commit
()
self
.
assertRaises
(
NotImplementedError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
@
expectedFailure
def
test_Person_requestSoftwareInstance_updateHostingSubscription
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
state
=
"started"
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
hosting_subscription_reference
=
hosting_subscription
.
getReference
()
transaction
.
commit
()
self
.
tic
()
software_release2
=
self
.
generateNewSoftwareReleaseUrl
()
software_type2
=
"test2"
instance_xml2
=
"""<?xml version='1.0' encoding='utf-8'?>
<instance>
</instance>"""
sla_xml2
=
"""<?xml version='1.0' encoding='utf-8'?>
<instance>
</instance>"""
shared2
=
False
state2
=
"stopped"
person
.
requestSoftwareInstance
(
software_release
=
software_release2
,
software_title
=
software_title
,
software_type
=
software_type2
,
instance_xml
=
instance_xml2
,
sla_xml
=
sla_xml2
,
shared
=
shared2
,
state
=
state2
,
)
hosting_subscription2
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertEquals
(
hosting_subscription
.
getRelativeUrl
(),
hosting_subscription2
.
getRelativeUrl
())
self
.
assertEquals
(
hosting_subscription_reference
,
hosting_subscription2
.
getReference
())
self
.
assertEquals
(
software_release2
,
hosting_subscription
.
getUrlString
())
self
.
assertEquals
(
software_title
,
hosting_subscription
.
getTitle
())
self
.
assertEquals
(
software_type2
,
hosting_subscription
.
getSourceReference
())
self
.
assertEquals
(
instance_xml2
,
hosting_subscription
.
getTextContent
())
self
.
assertEquals
(
sla_xml2
,
hosting_subscription
.
getSlaXml
())
self
.
assertEquals
(
shared2
,
hosting_subscription
.
getRootSlave
())
self
.
assertEquals
(
"stop_requested"
,
hosting_subscription
.
getSlapState
())
self
.
assertEquals
(
"validated"
,
hosting_subscription
.
getValidationState
())
def
test_Person_requestSoftwareInstance_duplicatedHostingSubscription
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
state
=
"started"
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
transaction
.
commit
()
hosting_subscription2
=
hosting_subscription
.
Base_createCloneDocument
(
batch_mode
=
1
)
hosting_subscription2
.
validate
()
transaction
.
commit
()
self
.
tic
()
self
.
assertRaises
(
NotImplementedError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
def
test_Person_requestSoftwareInstance_HostingSubscriptionNewTitle
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version='1.0' encoding='utf-8'?>
<instance>
</instance>"""
sla_xml
=
"""<?xml version='1.0' encoding='utf-8'?>
<instance>
</instance>"""
shared
=
True
state
=
"started"
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
transaction
.
commit
()
software_release2
=
self
.
generateNewSoftwareReleaseUrl
()
software_title2
=
"test2"
software_type2
=
"test2"
instance_xml2
=
"""<?xml version='1.0' encoding='utf-8'?>
<instance>
</instance>"""
sla_xml2
=
"""<?xml version='1.0' encoding='utf-8'?>
<instance>
</instance>"""
shared2
=
False
state2
=
"stopped"
person
.
requestSoftwareInstance
(
software_release
=
software_release2
,
software_title
=
software_title2
,
software_type
=
software_type2
,
instance_xml
=
instance_xml2
,
sla_xml
=
sla_xml2
,
shared
=
shared2
,
state
=
state2
,
)
hosting_subscription2
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertNotEquals
(
hosting_subscription
.
getRelativeUrl
(),
hosting_subscription2
.
getRelativeUrl
())
self
.
assertNotEquals
(
hosting_subscription
.
getReference
(),
hosting_subscription2
.
getReference
())
self
.
assertEquals
(
software_release2
,
hosting_subscription2
.
getUrlString
())
self
.
assertEquals
(
software_title2
,
hosting_subscription2
.
getTitle
())
self
.
assertEquals
(
software_type2
,
hosting_subscription2
.
getSourceReference
())
self
.
assertEquals
(
instance_xml2
,
hosting_subscription2
.
getTextContent
())
self
.
assertEquals
(
sla_xml2
,
hosting_subscription2
.
getSlaXml
())
self
.
assertEquals
(
shared2
,
hosting_subscription2
.
getRootSlave
())
self
.
assertEquals
(
"stop_requested"
,
hosting_subscription2
.
getSlapState
())
self
.
assertEquals
(
"validated"
,
hosting_subscription2
.
getValidationState
())
def
test_Person_requestSoftwareInstance_deletedHostingSubscription
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"stopped"
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
transaction
.
commit
()
self
.
tic
()
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"destroyed"
,
)
hosting_subscription2
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertEquals
(
None
,
hosting_subscription2
)
self
.
assertEquals
(
"destroy_requested"
,
hosting_subscription
.
getSlapState
())
def
test_Person_requestSoftwareInstance_noConflictWithDeletedHostingSubscription
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"stopped"
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
transaction
.
commit
()
self
.
tic
()
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"destroyed"
,
)
self
.
assertEquals
(
"destroy_requested"
,
hosting_subscription
.
getSlapState
())
transaction
.
commit
()
self
.
tic
()
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"started"
,
)
hosting_subscription2
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertEquals
(
"start_requested"
,
hosting_subscription2
.
getSlapState
())
self
.
assertNotEquals
(
hosting_subscription
.
getRelativeUrl
(),
hosting_subscription2
.
getRelativeUrl
())
class
TestSlapOSCorePersonRequestComputer
(
testSlapOSMixin
):
def
generateNewComputerTitle
(
self
):
return
'My Comp %s'
%
self
.
generateNewId
()
def
afterSetUp
(
self
):
super
(
TestSlapOSCorePersonRequestComputer
,
self
).
afterSetUp
()
portal
=
self
.
getPortalObject
()
new_id
=
self
.
generateNewId
()
# Clone person document
person_user
=
portal
.
person_module
.
template_member
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
person_user
.
edit
(
title
=
"live_test_%s"
%
new_id
,
reference
=
"live_test_%s"
%
new_id
,
default_email_text
=
"live_test_%s@example.org"
%
new_id
,
)
person_user
.
validate
()
for
assignment
in
person_user
.
contentValues
(
portal_type
=
"Assignment"
):
assignment
.
open
()
transaction
.
commit
()
# XXX Tic is needed to reindex the created open order
self
.
tic
()
# Login as new user
self
.
login
(
person_user
.
getReference
())
new_person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
self
.
assertEquals
(
person_user
.
getRelativeUrl
(),
new_person
.
getRelativeUrl
())
def
beforeTearDown
(
self
):
pass
def
test_request_requiredParameter
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
# computer_title is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestComputer
)
# if provided does not raise
computer_title
=
self
.
generateNewComputerTitle
()
person
.
requestComputer
(
computer_title
=
computer_title
)
def
test_request
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
computer_title
=
self
.
generateNewComputerTitle
()
person
.
requestComputer
(
computer_title
=
computer_title
)
# check what is returned via request
computer_url
=
person
.
REQUEST
.
get
(
'computer'
)
computer_absolute_url
=
person
.
REQUEST
.
get
(
'computer_url'
)
computer_reference
=
person
.
REQUEST
.
get
(
'computer_reference'
)
self
.
assertNotEqual
(
None
,
computer_url
)
self
.
assertNotEqual
(
None
,
computer_absolute_url
)
self
.
assertNotEqual
(
None
,
computer_reference
)
def
test_request_createdComputer
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
previous_id
=
self
.
getPortalObject
().
portal_ids
\
.
generateNewId
(
id_group
=
'slap_computer_reference'
,
id_generator
=
'uid'
)
computer_title
=
self
.
generateNewComputerTitle
()
person
.
requestComputer
(
computer_title
=
computer_title
)
# check what is returned via request
computer_url
=
person
.
REQUEST
.
get
(
'computer'
)
computer_absolute_url
=
person
.
REQUEST
.
get
(
'computer_url'
)
computer_reference
=
person
.
REQUEST
.
get
(
'computer_reference'
)
self
.
assertNotEqual
(
None
,
computer_url
)
self
.
assertNotEqual
(
None
,
computer_absolute_url
)
self
.
assertNotEqual
(
None
,
computer_reference
)
# check that title is ok
computer
=
person
.
restrictedTraverse
(
computer_url
)
self
.
assertEqual
(
computer_title
,
computer
.
getTitle
())
# check that data are sane
self
.
assertEqual
(
computer_absolute_url
,
computer
.
absolute_url
())
self
.
assertEqual
(
computer_reference
,
computer
.
getReference
())
self
.
assertEqual
(
'COMP-%s'
%
(
previous_id
+
1
),
computer
.
getReference
())
self
.
assertEqual
(
'validated'
,
computer
.
getValidationState
())
self
.
assertEqual
(
'open/personal'
,
computer
.
getAllocationScope
())
self
.
assertEqual
(
'open'
,
computer
.
getCapacityScope
())
def
test_request_notReindexedCompute
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
computer_title
=
self
.
generateNewComputerTitle
()
person
.
requestComputer
(
computer_title
=
computer_title
)
transaction
.
commit
()
self
.
assertRaises
(
NotImplementedError
,
person
.
requestComputer
,
computer_title
=
computer_title
)
def
test_multiple_request_createdComputer
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
previous_id
=
self
.
getPortalObject
().
portal_ids
\
.
generateNewId
(
id_group
=
'slap_computer_reference'
,
id_generator
=
'uid'
)
computer_title
=
self
.
generateNewComputerTitle
()
computer_title2
=
self
.
generateNewComputerTitle
()
person
.
requestComputer
(
computer_title
=
computer_title
)
# check what is returned via request
computer_url
=
person
.
REQUEST
.
get
(
'computer'
)
computer_absolute_url
=
person
.
REQUEST
.
get
(
'computer_url'
)
computer_reference
=
person
.
REQUEST
.
get
(
'computer_reference'
)
self
.
assertNotEqual
(
None
,
computer_url
)
self
.
assertNotEqual
(
None
,
computer_absolute_url
)
self
.
assertNotEqual
(
None
,
computer_reference
)
# check that title is ok
computer
=
person
.
restrictedTraverse
(
computer_url
)
self
.
assertEqual
(
computer_title
,
computer
.
getTitle
())
# check that data are sane
self
.
assertEqual
(
computer_absolute_url
,
computer
.
absolute_url
())
self
.
assertEqual
(
computer_reference
,
computer
.
getReference
())
self
.
assertEqual
(
'COMP-%s'
%
(
previous_id
+
1
),
computer
.
getReference
())
self
.
assertEqual
(
'validated'
,
computer
.
getValidationState
())
self
.
assertEqual
(
'open/personal'
,
computer
.
getAllocationScope
())
self
.
assertEqual
(
'open'
,
computer
.
getCapacityScope
())
self
.
tic
()
# request again the same computer
person
.
requestComputer
(
computer_title
=
computer_title
)
# check what is returned via request
computer_url
=
person
.
REQUEST
.
get
(
'computer'
)
computer_absolute_url
=
person
.
REQUEST
.
get
(
'computer_url'
)
computer_reference
=
person
.
REQUEST
.
get
(
'computer_reference'
)
self
.
assertNotEqual
(
None
,
computer_url
)
self
.
assertNotEqual
(
None
,
computer_absolute_url
)
self
.
assertNotEqual
(
None
,
computer_reference
)
# check that title is ok
computer
=
person
.
restrictedTraverse
(
computer_url
)
self
.
assertEqual
(
computer_title
,
computer
.
getTitle
())
# check that data are sane
self
.
assertEqual
(
computer_absolute_url
,
computer
.
absolute_url
())
self
.
assertEqual
(
computer_reference
,
computer
.
getReference
())
self
.
assertEqual
(
'COMP-%s'
%
(
previous_id
+
1
),
computer
.
getReference
())
self
.
assertEqual
(
'validated'
,
computer
.
getValidationState
())
self
.
assertEqual
(
'open/personal'
,
computer
.
getAllocationScope
())
self
.
assertEqual
(
'open'
,
computer
.
getCapacityScope
())
# and now another one
person
.
requestComputer
(
computer_title
=
computer_title2
)
# check what is returned via request
computer_url2
=
person
.
REQUEST
.
get
(
'computer'
)
computer_absolute_url2
=
person
.
REQUEST
.
get
(
'computer_url'
)
computer_reference2
=
person
.
REQUEST
.
get
(
'computer_reference'
)
self
.
assertNotEqual
(
None
,
computer_url2
)
self
.
assertNotEqual
(
None
,
computer_absolute_url2
)
self
.
assertNotEqual
(
None
,
computer_reference2
)
# check that computers are really different objects
self
.
assertNotEqual
(
computer_url2
,
computer_url
)
# check that title is ok
computer2
=
person
.
restrictedTraverse
(
computer_url2
)
self
.
assertEqual
(
computer_title2
,
computer2
.
getTitle
())
# check that data are sane
self
.
assertEqual
(
computer_absolute_url2
,
computer2
.
absolute_url
())
self
.
assertEqual
(
computer_reference2
,
computer2
.
getReference
())
self
.
assertEqual
(
'COMP-%s'
%
(
previous_id
+
2
),
computer2
.
getReference
())
self
.
assertEqual
(
'validated'
,
computer2
.
getValidationState
())
self
.
assertEqual
(
'open/personal'
,
computer2
.
getAllocationScope
())
self
.
assertEqual
(
'open'
,
computer2
.
getCapacityScope
())
def
test_request_duplicatedComputer
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
computer_title
=
self
.
generateNewComputerTitle
()
person
.
requestComputer
(
computer_title
=
computer_title
)
# check what is returned via request
computer_url
=
person
.
REQUEST
.
get
(
'computer'
)
computer_absolute_url
=
person
.
REQUEST
.
get
(
'computer_url'
)
computer_reference
=
person
.
REQUEST
.
get
(
'computer_reference'
)
self
.
assertNotEqual
(
None
,
computer_url
)
self
.
assertNotEqual
(
None
,
computer_absolute_url
)
self
.
assertNotEqual
(
None
,
computer_reference
)
# check that title is ok
computer
=
person
.
restrictedTraverse
(
computer_url
)
sm
=
getSecurityManager
()
try
:
self
.
login
()
computer2
=
computer
.
Base_createCloneDocument
(
batch_mode
=
1
)
computer2
.
validate
()
finally
:
setSecurityManager
(
sm
)
self
.
tic
()
self
.
assertRaises
(
NotImplementedError
,
person
.
requestComputer
,
computer_title
=
computer_title
)
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudPromiseSlapOSModuleIdGeneratorAlarm.py
deleted
100644 → 0
View file @
a35da019
# Copyright (c) 2002-2012 Nexedi SA and Contributors. All Rights Reserved.
import
transaction
from
Products.SlapOS.tests.testSlapOSMixin
import
\
testSlapOSMixin
from
Products.ERP5Type.tests.utils
import
createZODBPythonScript
class
TestSlapOSCorePromiseSlapOSModuleIdGeneratorAlarm
(
testSlapOSMixin
):
def
test_Module_assertIdGenerator
(
self
):
module
=
self
.
portal
.
newContent
(
portal_type
=
'Person Module'
,
id
=
str
(
self
.
generateNewId
()),
id_generator
=
'bad_id_generator'
)
self
.
assertEqual
(
'bad_id_generator'
,
module
.
getIdGenerator
())
# check positive response
self
.
assertTrue
(
module
.
Module_assertIdGenerator
(
'bad_id_generator'
,
False
))
self
.
assertEqual
(
'bad_id_generator'
,
module
.
getIdGenerator
())
self
.
assertTrue
(
module
.
Module_assertIdGenerator
(
'bad_id_generator'
,
True
))
self
.
assertEqual
(
'bad_id_generator'
,
module
.
getIdGenerator
())
# check negative response and that no-op run does not modify
self
.
assertFalse
(
module
.
Module_assertIdGenerator
(
'good_id_generator'
,
False
))
self
.
assertEqual
(
'bad_id_generator'
,
module
.
getIdGenerator
())
# check negative response with fixit request
self
.
assertFalse
(
module
.
Module_assertIdGenerator
(
'good_id_generator'
,
True
))
self
.
assertEqual
(
'good_id_generator'
,
module
.
getIdGenerator
())
self
.
assertTrue
(
module
.
Module_assertIdGenerator
(
'good_id_generator'
,
False
))
self
.
assertEqual
(
'good_id_generator'
,
module
.
getIdGenerator
())
transaction
.
abort
()
def
_simulateModule_assertIdGenerator
(
self
):
script_name
=
'Module_assertIdGenerator'
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
,
'id_generator, fixit, active_process=None'
,
'# Script body
\
n
'
"""from Products.CMFActivity.ActiveResult import ActiveResult
active_result = ActiveResult()
active_result.edit(
summary='Module_assertIdGenerator simulation',
severity=0,
detail=context.getRelativeUrl())
active_process.postResult(active_result)
"""
)
transaction
.
commit
()
def
_dropModule_assertIdGenerator
(
self
):
script_name
=
'Module_assertIdGenerator'
if
script_name
in
self
.
portal
.
portal_skins
.
custom
.
objectIds
():
self
.
portal
.
portal_skins
.
custom
.
manage_delObjects
(
script_name
)
transaction
.
commit
()
def
test_alarm
(
self
):
alarm
=
self
.
portal
.
portal_alarms
.
promise_slapos_module_id_generator
previous_active_process
=
self
.
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Active Process'
,
causality_uid
=
alarm
.
getUid
(),
sort_on
=
((
'creation_date'
,
'DESC'
),)
)
self
.
_simulateModule_assertIdGenerator
()
try
:
alarm
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropModule_assertIdGenerator
()
active_process
=
self
.
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Active Process'
,
causality_uid
=
alarm
.
getUid
(),
sort_on
=
((
'creation_date'
,
'DESC'
),)
)
self
.
assertNotEqual
(
previous_active_process
.
getPath
(),
active_process
.
getPath
())
visited_list
=
sorted
([
q
.
detail
for
q
in
active_process
.
getResultList
()
\
if
q
.
summary
==
'Module_assertIdGenerator simulation'
])
expected_list
=
sorted
([
'account_module'
,
'accounting_module'
,
'bug_module'
,
'business_configuration_module'
,
'business_process_module'
,
'campaign_module'
,
'component_module'
,
'computer_model_module'
,
'computer_module'
,
'computer_network_module'
,
'credential_recovery_module'
,
'credential_request_module'
,
'credential_update_module'
,
'currency_module'
,
'data_set_module'
,
'document_ingestion_module'
,
'document_module'
,
'event_module'
,
'external_source_module'
,
'glossary_module'
,
'hosting_subscription_module'
,
'image_module'
,
'internal_order_module'
,
'internal_packing_list_module'
,
'internal_supply_module'
,
'internal_trade_condition_module'
,
'inventory_module'
,
'item_module'
,
'knowledge_pad_module'
,
'meeting_module'
,
'notification_message_module'
,
'open_internal_order_module'
,
'open_purchase_order_module'
,
'open_sale_order_module'
,
'organisation_module'
,
'person_module'
,
'portal_activities'
,
'portal_simulation'
,
'product_module'
,
'purchase_order_module'
,
'purchase_packing_list_module'
,
'purchase_supply_module'
,
'purchase_trade_condition_module'
,
'quantity_unit_conversion_module'
,
'query_module'
,
'returned_purchase_packing_list_module'
,
'returned_sale_packing_list_module'
,
'sale_opportunity_module'
,
'sale_order_module'
,
'sale_packing_list_module'
,
'sale_supply_module'
,
'sale_trade_condition_module'
,
'service_module'
,
'service_report_module'
,
'software_installation_module'
,
'software_instance_module'
,
'software_licence_module'
,
'software_product_module'
,
'software_publication_module'
,
'software_release_module'
,
'support_request_module'
,
'transformation_module'
,
'web_page_module'
,
'web_site_module'
,
'workflow_module'
,
])
self
.
assertSameSet
(
expected_list
,
visited_list
)
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudSlapOSAssertHostingSubscriptionPredecessorAlarm.py
deleted
100644 → 0
View file @
a35da019
# Copyright (c) 2002-2012 Nexedi SA and Contributors. All Rights Reserved.
from
Products.SlapOS.tests.testSlapOSMixin
import
\
testSlapOSMixin
import
transaction
from
Products.ERP5Type.tests.utils
import
createZODBPythonScript
class
TestSlapOSCoreSlapOSAssertHostingSubscriptionPredecessorAlarm
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSCoreSlapOSAssertHostingSubscriptionPredecessorAlarm
,
self
).
afterSetUp
()
self
.
_makeTree
()
def
test_HostingSubscription_assertPredecessor
(
self
):
self
.
software_instance
.
rename
(
new_name
=
self
.
generateNewSoftwareTitle
())
self
.
tic
()
# check that no interaction has recreated the instance
self
.
assertFalse
(
self
.
hosting_subscription
.
getTitle
()
in
self
.
hosting_subscription
.
getPredecessorTitleList
())
self
.
hosting_subscription
.
HostingSubscription_assertPredecessor
()
self
.
assertTrue
(
self
.
hosting_subscription
.
getTitle
()
in
self
.
hosting_subscription
.
getPredecessorTitleList
())
def
test_HostingSubscription_assertPredecessor_stop_requested
(
self
):
self
.
software_instance
.
rename
(
new_name
=
self
.
generateNewSoftwareTitle
())
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
hosting_subscription
,
'stop_requested'
)
self
.
tic
()
# check that no interaction has recreated the instance
self
.
assertFalse
(
self
.
hosting_subscription
.
getTitle
()
in
self
.
hosting_subscription
.
getPredecessorTitleList
())
self
.
hosting_subscription
.
HostingSubscription_assertPredecessor
()
self
.
assertTrue
(
self
.
hosting_subscription
.
getTitle
()
in
self
.
hosting_subscription
.
getPredecessorTitleList
())
def
test_HostingSubscription_assertPredecessor_destroy_requested
(
self
):
self
.
software_instance
.
rename
(
new_name
=
self
.
generateNewSoftwareTitle
())
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
hosting_subscription
,
'destroy_requested'
)
self
.
tic
()
# check that no interaction has recreated the instance
self
.
assertFalse
(
self
.
hosting_subscription
.
getTitle
()
in
self
.
hosting_subscription
.
getPredecessorTitleList
())
self
.
hosting_subscription
.
HostingSubscription_assertPredecessor
()
self
.
assertFalse
(
self
.
hosting_subscription
.
getTitle
()
in
self
.
hosting_subscription
.
getPredecessorTitleList
())
def
test_HostingSubscription_assertPredecessor_archived
(
self
):
self
.
software_instance
.
rename
(
new_name
=
self
.
generateNewSoftwareTitle
())
self
.
hosting_subscription
.
archive
()
self
.
tic
()
# check that no interaction has recreated the instance
self
.
assertFalse
(
self
.
hosting_subscription
.
getTitle
()
in
self
.
hosting_subscription
.
getPredecessorTitleList
())
self
.
hosting_subscription
.
HostingSubscription_assertPredecessor
()
self
.
assertFalse
(
self
.
hosting_subscription
.
getTitle
()
in
self
.
hosting_subscription
.
getPredecessorTitleList
())
def
_simulateHostingSubscription_assertPredecessor
(
self
):
script_name
=
'HostingSubscription_assertPredecessor'
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 HostingSubscription_assertPredecessor') """
)
transaction
.
commit
()
def
_dropHostingSubscription_assertPredecessor
(
self
):
script_name
=
'HostingSubscription_assertPredecessor'
if
script_name
in
self
.
portal
.
portal_skins
.
custom
.
objectIds
():
self
.
portal
.
portal_skins
.
custom
.
manage_delObjects
(
script_name
)
transaction
.
commit
()
def
test_alarm_renamed
(
self
):
self
.
software_instance
.
edit
(
title
=
self
.
generateNewSoftwareTitle
())
self
.
tic
()
self
.
_simulateHostingSubscription_assertPredecessor
()
try
:
self
.
portal
.
portal_alarms
.
slapos_assert_hosting_subscription_predecessor
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropHostingSubscription_assertPredecessor
()
self
.
assertEqual
(
'Visited by HostingSubscription_assertPredecessor'
,
self
.
hosting_subscription
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_not_renamed
(
self
):
self
.
_simulateHostingSubscription_assertPredecessor
()
try
:
self
.
portal
.
portal_alarms
.
slapos_assert_hosting_subscription_predecessor
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropHostingSubscription_assertPredecessor
()
self
.
assertNotEqual
(
'Visited by HostingSubscription_assertPredecessor'
,
self
.
hosting_subscription
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudSlapOSCloudInteractionWorkflow.py
deleted
100644 → 0
View file @
a35da019
# Copyright (c) 2002-2012 Nexedi SA and Contributors. All Rights Reserved.
from
Products.SlapOS.tests.testSlapOSMixin
import
\
testSlapOSMixin
class
TestSlapOSCoreSlapOSCloudInteractionWorkflow
(
testSlapOSMixin
):
def
_makePerson
(
self
):
new_id
=
self
.
generateNewId
()
self
.
person_user
=
self
.
portal
.
person_module
.
template_member
.
\
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
person_user
.
edit
(
title
=
"live_test_%s"
%
new_id
,
reference
=
"live_test_%s"
%
new_id
,
default_email_text
=
"live_test_%s@example.org"
%
new_id
,
)
self
.
person_user
.
validate
()
for
assignment
in
self
.
person_user
.
contentValues
(
portal_type
=
"Assignment"
):
assignment
.
open
()
self
.
tic
()
def
test_Computer_setSubjectList
(
self
):
self
.
_makePerson
()
self
.
login
(
self
.
person_user
.
getReference
())
new_id
=
self
.
generateNewId
()
computer
=
self
.
portal
.
computer_module
.
newContent
(
portal_type
=
'Computer'
,
title
=
"Computer %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTCOMP-%s"
%
new_id
)
self
.
tic
()
assert
computer
.
getDestinationSectionValue
()
is
None
computer
.
edit
(
subject_list
=
[
self
.
person_user
.
getDefaultEmailText
()])
self
.
tic
()
assert
computer
.
getDestinationSection
()
==
\
self
.
person_user
.
getRelativeUrl
()
def
check_Instance_validate
(
self
,
portal_type
):
self
.
_makePerson
()
self
.
login
(
self
.
person_user
.
getReference
())
new_id
=
self
.
generateNewId
()
instance
=
self
.
portal
.
software_instance_module
.
newContent
(
portal_type
=
portal_type
,
title
=
"Instance %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTINST-%s"
%
new_id
)
def
verify_activeSense_call
(
self
):
if
self
.
getRelativeUrl
()
==
'portal_alarms/slapos_allocate_instance'
:
instance
.
portal_workflow
.
doActionFor
(
instance
,
action
=
'edit_action'
,
comment
=
'activeSense triggered'
)
else
:
return
self
.
activeSense_call
()
# Replace activeSense by a dummy method
from
Products.ERP5Type.Document.Alarm
import
Alarm
Alarm
.
activeSense_call
=
Alarm
.
activeSense
Alarm
.
activeSense
=
verify_activeSense_call
try
:
instance
.
validate
()
# instance.portal_alarms.slapos_allocate_instance.activeSense()
self
.
tic
()
finally
:
Alarm
.
activeSense
=
Alarm
.
activeSense_call
self
.
assertEqual
(
'activeSense triggered'
,
instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_SoftwareInstance_validate
(
self
):
return
self
.
check_Instance_validate
(
"Software Instance"
)
def
test_SlaveInstance_validate
(
self
):
return
self
.
check_Instance_validate
(
"Slave Instance"
)
def
test_SlaveInstance_requestDestroy
(
self
):
self
.
_makePerson
()
self
.
login
(
self
.
person_user
.
getReference
())
new_id
=
self
.
generateNewId
()
instance
=
self
.
portal
.
software_instance_module
.
newContent
(
portal_type
=
'Slave Instance'
,
title
=
"Instance %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTINST-%s"
%
new_id
,
destination_reference
=
"TESTINST-%s"
%
new_id
,
)
request_kw
=
dict
(
software_release
=
'http://example.org'
,
software_type
=
'http://example.org'
,
instance_xml
=
self
.
generateSafeXml
(),
sla_xml
=
self
.
generateSafeXml
(),
shared
=
True
,
)
instance
.
requestStop
(
**
request_kw
)
self
.
assertEqual
(
instance
.
getValidationState
(),
'draft'
)
instance
.
validate
()
self
.
assertEqual
(
instance
.
getValidationState
(),
'validated'
)
instance
.
requestDestroy
(
**
request_kw
)
self
.
assertEqual
(
instance
.
getValidationState
(),
'invalidated'
)
def
check_SoftwareInstallation_changeState
(
self
,
method_id
):
self
.
_makePerson
()
self
.
login
(
self
.
person_user
.
getReference
())
new_id
=
self
.
generateNewId
()
computer
=
self
.
portal
.
computer_module
.
newContent
(
portal_type
=
'Computer'
,
title
=
"Computer %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTCOMP-%s"
%
new_id
)
installation
=
self
.
portal
.
software_installation_module
.
newContent
(
portal_type
=
'Software Installation'
,
title
=
"Installation %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
aggregate_value
=
computer
,
)
self
.
tic
()
def
verify_reindexObject_call
(
self
,
*
args
,
**
kw
):
if
self
.
getRelativeUrl
()
==
computer
.
getRelativeUrl
():
computer
.
portal_workflow
.
doActionFor
(
computer
,
action
=
'edit_action'
,
comment
=
'reindexObject triggered on %s'
%
method_id
)
else
:
return
self
.
reindexObject_call
(
*
args
,
**
kw
)
# Replace activeSense by a dummy method
from
Products.ERP5Type.Base
import
Base
Base
.
reindexObject_call
=
Base
.
reindexObject
Base
.
reindexObject
=
verify_reindexObject_call
try
:
getattr
(
installation
,
method_id
)()
self
.
tic
()
finally
:
Base
.
reindexObject
=
Base
.
reindexObject_call
self
.
assertEqual
(
'reindexObject triggered on %s'
%
method_id
,
computer
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_SoftwareInstallation_changeState_onStart
(
self
):
return
self
.
check_SoftwareInstallation_changeState
(
'requestStart'
)
def
test_SoftwareInstallation_changeState_onDestroy
(
self
):
return
self
.
check_SoftwareInstallation_changeState
(
'requestDestroy'
)
def
check_SoftwareInstance_changeState
(
self
,
method_id
):
self
.
_makePerson
()
self
.
login
(
self
.
person_user
.
getReference
())
new_id
=
self
.
generateNewId
()
computer
=
self
.
portal
.
computer_module
.
newContent
(
portal_type
=
'Computer'
,
title
=
"Computer %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTCOMP-%s"
%
new_id
)
partition
=
computer
.
newContent
(
portal_type
=
'Computer Partition'
,
title
=
"Partition Computer %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTPART-%s"
%
new_id
)
instance
=
self
.
portal
.
software_instance_module
.
newContent
(
portal_type
=
"Software Instance"
,
title
=
"Instance %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTINST-%s"
%
new_id
,
aggregate_value
=
partition
,
destination_reference
=
"TESTINST-%s"
%
new_id
,
ssl_certificate
=
"foo"
,
ssl_key
=
"bar"
,
)
request_kw
=
dict
(
software_release
=
'http://example.org'
,
software_type
=
'http://example.org'
,
instance_xml
=
self
.
generateSafeXml
(),
sla_xml
=
self
.
generateSafeXml
(),
shared
=
False
,
)
if
method_id
==
'requestDestroy'
:
instance
.
requestStop
(
**
request_kw
)
self
.
tic
()
def
verify_reindexObject_call
(
self
,
*
args
,
**
kw
):
if
self
.
getRelativeUrl
()
==
partition
.
getRelativeUrl
():
partition
.
portal_workflow
.
doActionFor
(
partition
,
action
=
'edit_action'
,
comment
=
'reindexObject triggered on %s'
%
method_id
)
else
:
return
self
.
reindexObject_call
(
*
args
,
**
kw
)
# Replace activeSense by a dummy method
from
Products.ERP5Type.Base
import
Base
Base
.
reindexObject_call
=
Base
.
reindexObject
Base
.
reindexObject
=
verify_reindexObject_call
try
:
getattr
(
instance
,
method_id
)(
**
request_kw
)
self
.
tic
()
finally
:
Base
.
reindexObject
=
Base
.
reindexObject_call
self
.
assertEqual
(
'reindexObject triggered on %s'
%
method_id
,
partition
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_SoftwareInstance_changeState_onStart
(
self
):
return
self
.
check_SoftwareInstance_changeState
(
"requestStart"
)
def
test_SoftwareInstance_changeState_onStop
(
self
):
return
self
.
check_SoftwareInstance_changeState
(
"requestStop"
)
def
test_SoftwareInstance_changeState_onDestroy
(
self
):
return
self
.
check_SoftwareInstance_changeState
(
"requestDestroy"
)
def
check_change_instance_parameter
(
self
,
portal_type
,
method_id
):
self
.
_makePerson
()
self
.
login
(
self
.
person_user
.
getReference
())
new_id
=
self
.
generateNewId
()
instance
=
self
.
portal
.
software_instance_module
.
newContent
(
portal_type
=
portal_type
,
title
=
"Instance %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTINST-%s"
%
new_id
,
destination_reference
=
"TESTINST-%s"
%
new_id
,
ssl_certificate
=
"foo"
,
ssl_key
=
"bar"
,
)
self
.
tic
()
self
.
assertEqual
(
None
,
instance
.
workflow_history
[
'instance_slap_interface_workflow'
][
-
1
][
'action'
])
instance
.
edit
(
**
{
method_id
:
self
.
generateSafeXml
()})
self
.
tic
()
self
.
assertEqual
(
'bang'
,
instance
.
workflow_history
[
'instance_slap_interface_workflow'
][
-
1
][
'action'
])
def
test_change_instance_parameter_onInstanceUrlString
(
self
):
return
self
.
check_change_instance_parameter
(
"Software Instance"
,
'url_string'
)
def
test_change_instance_parameter_onInstanceTextContent
(
self
):
return
self
.
check_change_instance_parameter
(
"Software Instance"
,
'text_content'
)
def
test_change_instance_parameter_onInstanceSourceReference
(
self
):
return
self
.
check_change_instance_parameter
(
"Software Instance"
,
'source_reference'
)
def
test_change_instance_parameter_onInstanceSlaXML
(
self
):
return
self
.
check_change_instance_parameter
(
"Software Instance"
,
'sla_xml'
)
def
test_change_instance_parameter_onSlaveUrlString
(
self
):
return
self
.
check_change_instance_parameter
(
"Slave Instance"
,
'url_string'
)
def
test_change_instance_parameter_onSlaveTextContent
(
self
):
return
self
.
check_change_instance_parameter
(
"Slave Instance"
,
'text_content'
)
def
test_change_instance_parameter_onSlaveSourceReference
(
self
):
return
self
.
check_change_instance_parameter
(
"Slave Instance"
,
'source_reference'
)
def
test_change_instance_parameter_onSlaveSlaXML
(
self
):
return
self
.
check_change_instance_parameter
(
"Slave Instance"
,
'sla_xml'
)
def
test_SoftwareInstance_setPredecessorList
(
self
):
portal_type
=
"Software Instance"
self
.
_makePerson
()
self
.
login
(
self
.
person_user
.
getReference
())
new_id
=
self
.
generateNewId
()
instance3
=
self
.
portal
.
software_instance_module
.
newContent
(
portal_type
=
portal_type
,
title
=
"Instance %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTINST-%s"
%
new_id
,
destination_reference
=
"TESTINST-%s"
%
new_id
,
ssl_certificate
=
"foo"
,
ssl_key
=
"bar"
,
)
new_id
=
self
.
generateNewId
()
instance2
=
self
.
portal
.
software_instance_module
.
newContent
(
portal_type
=
portal_type
,
title
=
"Instance %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTINST-%s"
%
new_id
,
destination_reference
=
"TESTINST-%s"
%
new_id
,
ssl_certificate
=
"foo"
,
ssl_key
=
"bar"
,
predecessor_value
=
instance3
,
)
new_id
=
self
.
generateNewId
()
instance1
=
self
.
portal
.
software_instance_module
.
newContent
(
portal_type
=
portal_type
,
title
=
"Instance %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTINST-%s"
%
new_id
,
destination_reference
=
"TESTINST-%s"
%
new_id
,
ssl_certificate
=
"foo"
,
ssl_key
=
"bar"
,
predecessor_value
=
instance2
,
)
self
.
tic
()
def
verify_reindexObject_call
(
self
,
*
args
,
**
kw
):
if
self
.
getRelativeUrl
()
in
(
instance2
.
getRelativeUrl
(),
instance3
.
getRelativeUrl
()):
self
.
portal_workflow
.
doActionFor
(
instance1
,
action
=
'edit_action'
,
comment
=
'reindexObject triggered'
)
else
:
return
self
.
reindexObject_call
(
*
args
,
**
kw
)
# Replace activeSense by a dummy method
from
Products.ERP5Type.Base
import
Base
Base
.
reindexObject_call
=
Base
.
reindexObject
Base
.
reindexObject
=
verify_reindexObject_call
try
:
instance1
.
edit
(
predecessor_value
=
instance3
)
self
.
tic
()
finally
:
Base
.
reindexObject
=
Base
.
reindexObject_call
self
.
assertEqual
(
'reindexObject triggered'
,
instance1
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
self
.
assertEqual
(
'reindexObject triggered'
,
instance1
.
workflow_history
[
'edit_workflow'
][
-
2
][
'comment'
])
self
.
assertEqual
(
None
,
instance1
.
workflow_history
[
'edit_workflow'
][
-
3
][
'comment'
])
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudSlapOSFreeComputerPartitionAlarm.py
deleted
100644 → 0
View file @
a35da019
# Copyright (c) 2002-2012 Nexedi SA and Contributors. All Rights Reserved.
from
Products.SlapOS.tests.testSlapOSMixin
import
\
testSlapOSMixin
import
transaction
from
Products.ERP5Type.tests.utils
import
createZODBPythonScript
class
TestSlapOSFreeComputerPartitionAlarm
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSFreeComputerPartitionAlarm
,
self
).
afterSetUp
()
self
.
_makeTree
()
def
test_Instance_tryToUnallocatePartition
(
self
):
self
.
_makeComputer
()
self
.
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
self
.
partition
.
markBusy
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
tic
()
self
.
software_instance
.
Instance_tryToUnallocatePartition
()
self
.
tic
()
self
.
assertEqual
(
None
,
self
.
software_instance
.
getAggregate
())
self
.
assertEqual
(
'free'
,
self
.
partition
.
getSlapState
())
def
test_Instance_tryToUnallocatePartition_concurrency
(
self
):
self
.
_makeComputer
()
self
.
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
self
.
partition
.
markBusy
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
tic
()
self
.
partition
.
activate
(
tag
=
"allocate_%s"
%
self
.
partition
.
getRelativeUrl
()
\
).
getId
()
transaction
.
commit
()
self
.
software_instance
.
Instance_tryToUnallocatePartition
()
self
.
tic
()
self
.
assertEqual
(
self
.
partition
.
getRelativeUrl
(),
self
.
software_instance
.
getAggregate
())
self
.
assertEqual
(
'busy'
,
self
.
partition
.
getSlapState
())
def
test_Instance_tryToUnallocatePartition_twoInstances
(
self
):
software_instance
=
self
.
portal
.
software_instance_module
\
.
template_software_instance
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
_makeComputer
()
self
.
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
self
.
partition
.
markBusy
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
tic
()
self
.
software_instance
.
Instance_tryToUnallocatePartition
()
self
.
tic
()
self
.
assertEqual
(
None
,
self
.
software_instance
.
getAggregate
())
self
.
assertEqual
(
'busy'
,
self
.
partition
.
getSlapState
())
self
.
assertEqual
(
self
.
partition
.
getRelativeUrl
(),
software_instance
.
getAggregate
())
def
_simulateInstance_tryToUnallocatePartition
(
self
):
script_name
=
'Instance_tryToUnallocatePartition'
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 Instance_tryToUnallocatePartition') """
)
transaction
.
commit
()
def
_dropInstance_tryToUnallocatePartition
(
self
):
script_name
=
'Instance_tryToUnallocatePartition'
if
script_name
in
self
.
portal
.
portal_skins
.
custom
.
objectIds
():
self
.
portal
.
portal_skins
.
custom
.
manage_delObjects
(
script_name
)
transaction
.
commit
()
def
test_alarm_allocated
(
self
):
self
.
_makeComputer
()
self
.
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
self
.
partition
.
markBusy
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
software_instance
.
invalidate
()
self
.
tic
()
self
.
_simulateInstance_tryToUnallocatePartition
()
try
:
self
.
portal
.
portal_alarms
.
slapos_free_computer_partition
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropInstance_tryToUnallocatePartition
()
self
.
assertEqual
(
'Visited by Instance_tryToUnallocatePartition'
,
self
.
software_instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_unallocated
(
self
):
self
.
_makeComputer
()
self
.
partition
.
markBusy
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
software_instance
.
invalidate
()
self
.
tic
()
self
.
_simulateInstance_tryToUnallocatePartition
()
try
:
self
.
portal
.
portal_alarms
.
slapos_free_computer_partition
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropInstance_tryToUnallocatePartition
()
self
.
assertNotEqual
(
'Visited by Instance_tryToUnallocatePartition'
,
self
.
software_instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_validated
(
self
):
self
.
_makeComputer
()
self
.
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
self
.
partition
.
markBusy
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
tic
()
self
.
_simulateInstance_tryToUnallocatePartition
()
try
:
self
.
portal
.
portal_alarms
.
slapos_free_computer_partition
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropInstance_tryToUnallocatePartition
()
self
.
assertNotEqual
(
'Visited by Instance_tryToUnallocatePartition'
,
self
.
software_instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_start_requested
(
self
):
self
.
_makeComputer
()
self
.
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
self
.
partition
.
markBusy
()
self
.
tic
()
self
.
_simulateInstance_tryToUnallocatePartition
()
try
:
self
.
portal
.
portal_alarms
.
slapos_free_computer_partition
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropInstance_tryToUnallocatePartition
()
self
.
assertNotEqual
(
'Visited by Instance_tryToUnallocatePartition'
,
self
.
software_instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
class
TestSlapOSFreeComputerPartitionAlarmWithSlave
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSFreeComputerPartitionAlarmWithSlave
,
self
).
afterSetUp
()
self
.
_makeTree
(
requested_template_id
=
'template_slave_instance'
)
def
test_Instance_tryToUnallocatePartition
(
self
):
self
.
_makeComputer
()
self
.
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
self
.
partition
.
markBusy
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
tic
()
self
.
software_instance
.
Instance_tryToUnallocatePartition
()
self
.
tic
()
self
.
assertEqual
(
None
,
self
.
software_instance
.
getAggregate
())
self
.
assertEqual
(
'free'
,
self
.
partition
.
getSlapState
())
def
test_Instance_tryToUnallocatePartition_nonDestroyed
(
self
):
self
.
_makeComputer
()
self
.
software_instance
.
setAggregate
(
self
.
partition
.
getRelativeUrl
())
self
.
partition
.
markBusy
()
self
.
tic
()
self
.
software_instance
.
Instance_tryToUnallocatePartition
()
self
.
tic
()
self
.
assertEqual
(
self
.
partition
.
getRelativeUrl
(),
self
.
software_instance
.
getAggregate
())
self
.
assertEqual
(
'busy'
,
self
.
partition
.
getSlapState
())
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudSlapOSGarbageCollectDestroyedRootTreeAlarm.py
deleted
100644 → 0
View file @
a35da019
# Copyright (c) 2002-2012 Nexedi SA and Contributors. All Rights Reserved.
from
Products.SlapOS.tests.testSlapOSMixin
import
\
testSlapOSMixin
import
transaction
from
Products.ERP5Type.tests.utils
import
createZODBPythonScript
class
TestSlapOSGarbageCollectDestroyedRootTreeAlarm
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSGarbageCollectDestroyedRootTreeAlarm
,
self
).
afterSetUp
()
self
.
_makeTree
()
def
test_Instance_tryToGarbageCollect
(
self
):
self
.
hosting_subscription
.
archive
()
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
tic
()
self
.
requested_software_instance
.
Instance_tryToGarbageCollect
()
self
.
tic
()
self
.
assertEqual
(
'destroy_requested'
,
self
.
requested_software_instance
.
getSlapState
())
self
.
assertEqual
(
'validated'
,
self
.
requested_software_instance
.
getValidationState
())
def
test_Instance_tryToGarbageCollect_not_destroy_requested
(
self
):
self
.
requested_software_instance
.
Instance_tryToGarbageCollect
()
self
.
tic
()
self
.
assertEqual
(
'start_requested'
,
self
.
requested_software_instance
.
getSlapState
())
self
.
assertEqual
(
'validated'
,
self
.
requested_software_instance
.
getValidationState
())
def
test_Instance_tryToGarbageCollect_not_archived
(
self
):
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
tic
()
self
.
requested_software_instance
.
Instance_tryToGarbageCollect
()
self
.
tic
()
self
.
assertEqual
(
'start_requested'
,
self
.
requested_software_instance
.
getSlapState
())
self
.
assertEqual
(
'validated'
,
self
.
requested_software_instance
.
getValidationState
())
def
test_Instance_tryToGarbageCollect_only_instance_destroy_requested
(
self
):
self
.
portal
.
portal_workflow
.
_jumpToStateFor
(
self
.
software_instance
,
'destroy_requested'
)
self
.
tic
()
self
.
requested_software_instance
.
Instance_tryToGarbageCollect
()
self
.
tic
()
self
.
assertEqual
(
'start_requested'
,
self
.
requested_software_instance
.
getSlapState
())
self
.
assertEqual
(
'validated'
,
self
.
requested_software_instance
.
getValidationState
())
def
_simulateInstance_tryToGarbageCollect
(
self
):
script_name
=
'Instance_tryToGarbageCollect'
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 Instance_tryToGarbageCollect') """
)
transaction
.
commit
()
def
_dropInstance_tryToGarbageCollect
(
self
):
script_name
=
'Instance_tryToGarbageCollect'
if
script_name
in
self
.
portal
.
portal_skins
.
custom
.
objectIds
():
self
.
portal
.
portal_skins
.
custom
.
manage_delObjects
(
script_name
)
transaction
.
commit
()
def
test_alarm
(
self
):
self
.
hosting_subscription
.
archive
()
self
.
tic
()
self
.
_simulateInstance_tryToGarbageCollect
()
try
:
self
.
portal
.
portal_alarms
.
slapos_garbage_collect_destroyed_root_tree
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropInstance_tryToGarbageCollect
()
self
.
assertEqual
(
'Visited by Instance_tryToGarbageCollect'
,
self
.
software_instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_invalidated
(
self
):
self
.
hosting_subscription
.
archive
()
self
.
software_instance
.
invalidate
()
self
.
tic
()
self
.
_simulateInstance_tryToGarbageCollect
()
try
:
self
.
portal
.
portal_alarms
.
slapos_garbage_collect_destroyed_root_tree
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropInstance_tryToGarbageCollect
()
self
.
assertNotEqual
(
'Visited by Instance_tryToGarbageCollect'
,
self
.
software_instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_not_archived
(
self
):
self
.
tic
()
self
.
_simulateInstance_tryToGarbageCollect
()
try
:
self
.
portal
.
portal_alarms
.
slapos_garbage_collect_destroyed_root_tree
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropInstance_tryToGarbageCollect
()
self
.
assertNotEqual
(
'Visited by Instance_tryToGarbageCollect'
,
self
.
software_instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudSlapOSUpdateComputerCapacityScopeAlarm.py
deleted
100644 → 0
View file @
a35da019
# Copyright (c) 2002-2012 Nexedi SA and Contributors. All Rights Reserved.
from
Products.SlapOS.tests.testSlapOSMixin
import
\
testSlapOSMixin
import
transaction
from
Products.ERP5Type.tests.utils
import
createZODBPythonScript
import
json
class
TestSlapOSGarbageCollectDestroyedRootTreeAlarm
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSGarbageCollectDestroyedRootTreeAlarm
,
self
).
afterSetUp
()
self
.
computer
=
self
.
portal
.
computer_module
.
template_computer
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
computer
.
edit
(
allocation_scope
=
'open/public'
,
capacity_scope
=
'open'
,
reference
=
'TESTC-%s'
%
self
.
generateNewId
(),
)
self
.
computer
.
validate
()
memcached_dict
=
self
.
portal
.
portal_memcached
.
getMemcachedDict
(
key_prefix
=
'slap_tool'
,
plugin_path
=
'portal_memcached/default_memcached_plugin'
)
memcached_dict
[
self
.
computer
.
getReference
()]
=
json
.
dumps
({
'text'
:
'#access ok'
})
transaction
.
commit
()
def
test_Computer_checkAndUpdateCapacityScope
(
self
):
self
.
computer
.
Computer_checkAndUpdateCapacityScope
()
self
.
assertEqual
(
'open'
,
self
.
computer
.
getCapacityScope
())
def
test_Computer_checkAndUpdateCapacityScope_no_capacity_quantity
(
self
):
self
.
_makeTree
()
self
.
computer
.
edit
(
capacity_quantity
=
1
)
partition
=
self
.
computer
.
newContent
(
portal_type
=
'Computer Partition'
,
reference
=
'part1'
)
partition
.
markFree
()
partition
.
markBusy
()
partition
.
validate
()
self
.
software_instance
.
setAggregate
(
partition
.
getRelativeUrl
())
self
.
tic
()
self
.
computer
.
Computer_checkAndUpdateCapacityScope
()
self
.
assertEqual
(
'close'
,
self
.
computer
.
getCapacityScope
())
self
.
assertEqual
(
'Computer capacity limit exceeded'
,
self
.
computer
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_Computer_checkAndUpdateCapacityScope_no_access
(
self
):
self
.
computer
.
edit
(
reference
=
'TESTC-%s'
%
self
.
generateNewId
())
self
.
computer
.
Computer_checkAndUpdateCapacityScope
()
self
.
assertEqual
(
'close'
,
self
.
computer
.
getCapacityScope
())
self
.
assertEqual
(
"Computer didn't contact the server"
,
self
.
computer
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_Computer_checkAndUpdateCapacityScope_close
(
self
):
self
.
computer
.
edit
(
capacity_scope
=
'close'
)
self
.
computer
.
Computer_checkAndUpdateCapacityScope
()
self
.
assertEqual
(
'open'
,
self
.
computer
.
getCapacityScope
())
def
test_Computer_checkAndUpdateCapacityScope_with_error
(
self
):
memcached_dict
=
self
.
portal
.
portal_memcached
.
getMemcachedDict
(
key_prefix
=
'slap_tool'
,
plugin_path
=
'portal_memcached/default_memcached_plugin'
)
memcached_dict
[
self
.
computer
.
getReference
()]
=
json
.
dumps
({
'text'
:
'#error not ok'
})
self
.
computer
.
Computer_checkAndUpdateCapacityScope
()
self
.
assertEqual
(
'close'
,
self
.
computer
.
getCapacityScope
())
self
.
assertEqual
(
"Computer reported an error"
,
self
.
computer
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_Computer_checkAndUpdateCapacityScope_with_error_non_public
(
self
):
memcached_dict
=
self
.
portal
.
portal_memcached
.
getMemcachedDict
(
key_prefix
=
'slap_tool'
,
plugin_path
=
'portal_memcached/default_memcached_plugin'
)
memcached_dict
[
self
.
computer
.
getReference
()]
=
json
.
dumps
({
'text'
:
'#error not ok'
})
self
.
computer
.
edit
(
allocation_scope
=
'open/personal'
)
self
.
computer
.
Computer_checkAndUpdateCapacityScope
()
self
.
assertEqual
(
'open'
,
self
.
computer
.
getCapacityScope
())
def
_simulateComputer_checkAndUpdateCapacityScope
(
self
):
script_name
=
'Computer_checkAndUpdateCapacityScope'
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 Computer_checkAndUpdateCapacityScope') """
)
transaction
.
commit
()
def
_dropComputer_checkAndUpdateCapacityScope
(
self
):
script_name
=
'Computer_checkAndUpdateCapacityScope'
if
script_name
in
self
.
portal
.
portal_skins
.
custom
.
objectIds
():
self
.
portal
.
portal_skins
.
custom
.
manage_delObjects
(
script_name
)
transaction
.
commit
()
def
test_alarm
(
self
):
self
.
_simulateComputer_checkAndUpdateCapacityScope
()
try
:
self
.
portal
.
portal_alarms
.
slapos_update_computer_capacity_scope
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropComputer_checkAndUpdateCapacityScope
()
self
.
assertEqual
(
'Visited by Computer_checkAndUpdateCapacityScope'
,
self
.
computer
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_non_public
(
self
):
self
.
computer
.
edit
(
allocation_scope
=
'open/personal'
)
self
.
tic
()
self
.
_simulateComputer_checkAndUpdateCapacityScope
()
try
:
self
.
portal
.
portal_alarms
.
slapos_update_computer_capacity_scope
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropComputer_checkAndUpdateCapacityScope
()
self
.
assertNotEqual
(
'Visited by Computer_checkAndUpdateCapacityScope'
,
self
.
computer
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_alarm_invalidated
(
self
):
self
.
computer
.
invalidate
()
self
.
tic
()
self
.
_simulateComputer_checkAndUpdateCapacityScope
()
try
:
self
.
portal
.
portal_alarms
.
slapos_update_computer_capacity_scope
.
activeSense
()
self
.
tic
()
finally
:
self
.
_dropComputer_checkAndUpdateCapacityScope
()
self
.
assertNotEqual
(
'Visited by Computer_checkAndUpdateCapacityScope'
,
self
.
computer
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloud
InstanceSlapInterface
Workflow.py
→
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSCloudWorkflow.py
View file @
89a6f1c2
...
...
@@ -3,6 +3,701 @@ from Products.SlapOS.tests.testSlapOSMixin import \
testSlapOSMixin
import
transaction
from
Products.ERP5Type.tests.backportUnittest
import
expectedFailure
from
Products.ERP5Type.Errors
import
UnsupportedWorkflowMethod
from
AccessControl.SecurityManagement
import
getSecurityManager
,
\
setSecurityManager
class
TestSlapOSCoreComputerPartitionSlapInterfaceWorkflow
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSCoreComputerPartitionSlapInterfaceWorkflow
,
self
).
afterSetUp
()
# Clone computer document
self
.
computer
=
self
.
portal
.
computer_module
.
template_computer
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
new_id
=
self
.
generateNewId
()
self
.
computer
.
edit
(
title
=
"computer %s"
%
(
new_id
,
),
reference
=
"TESTCOMP-%s"
%
(
new_id
,
),
allocation_scope
=
'open/personal'
,
capacity_scope
=
'open'
,
)
self
.
computer
.
validate
()
# install an software release
self
.
software_installation
=
self
.
portal
.
software_installation_module
\
.
newContent
(
portal_type
=
'Software Installation'
,
url_string
=
self
.
generateNewSoftwareReleaseUrl
(),
aggregate
=
self
.
computer
.
getRelativeUrl
())
self
.
software_installation
.
validate
()
self
.
software_installation
.
requestStart
()
self
.
tic
()
def
test_markFree
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
partition
=
self
.
computer
.
newContent
(
portal_type
=
'Computer Partition'
,
reference
=
'PART-%s'
%
self
.
generateNewId
())
partition
.
validate
()
partition
.
markFree
()
self
.
tic
()
self
.
assertEqual
(
1
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
def
test_markFree_markBusy
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
partition
=
self
.
computer
.
newContent
(
portal_type
=
'Computer Partition'
,
reference
=
'PART-%s'
%
self
.
generateNewId
())
partition
.
validate
()
partition
.
markFree
()
self
.
tic
()
self
.
assertEqual
(
1
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
partition
.
markBusy
()
self
.
tic
()
self
.
assertEqual
(
0
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
def
test_markFree_markBusy_markFree
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
partition
=
self
.
computer
.
newContent
(
portal_type
=
'Computer Partition'
,
reference
=
'PART-%s'
%
self
.
generateNewId
())
partition
.
validate
()
partition
.
markFree
()
self
.
tic
()
self
.
assertEqual
(
1
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
partition
.
markBusy
()
self
.
tic
()
self
.
assertEqual
(
0
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
partition
.
markFree
()
self
.
tic
()
self
.
assertEqual
(
1
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
def
test_markInactive
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
partition
=
self
.
computer
.
newContent
(
portal_type
=
'Computer Partition'
,
reference
=
'PART-%s'
%
self
.
generateNewId
())
partition
.
validate
()
partition
.
markInactive
()
self
.
tic
()
self
.
assertEqual
(
0
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
def
test_markInactive_markFree
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
partition
=
self
.
computer
.
newContent
(
portal_type
=
'Computer Partition'
,
reference
=
'PART-%s'
%
self
.
generateNewId
())
partition
.
validate
()
partition
.
markInactive
()
self
.
tic
()
self
.
assertEqual
(
0
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
partition
.
markFree
()
self
.
tic
()
self
.
assertEqual
(
1
,
self
.
portal
.
portal_catalog
.
countResults
(
parent_uid
=
self
.
computer
.
getUid
(),
free_for_request
=
1
)[
0
][
0
])
class
TestSlapOSCoreComputerSlapInterfaceWorkflow
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSCoreComputerSlapInterfaceWorkflow
,
self
).
afterSetUp
()
# Clone computer document
self
.
computer
=
self
.
portal
.
computer_module
.
template_computer
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
new_id
=
self
.
generateNewId
()
self
.
computer
.
edit
(
title
=
"computer %s"
%
(
new_id
,
),
reference
=
"TESTCOMP-%s"
%
(
new_id
,
)
)
self
.
computer
.
validate
()
self
.
tic
()
def
_makePerson
(
self
):
new_id
=
self
.
generateNewId
()
self
.
person_user
=
self
.
portal
.
person_module
.
template_member
.
\
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
person_user
.
edit
(
title
=
"live_test_%s"
%
new_id
,
reference
=
"live_test_%s"
%
new_id
,
default_email_text
=
"live_test_%s@example.org"
%
new_id
,
)
self
.
person_user
.
validate
()
for
assignment
in
self
.
person_user
.
contentValues
(
portal_type
=
"Assignment"
):
assignment
.
open
()
self
.
tic
()
def
beforeTearDown
(
self
):
super
(
TestSlapOSCoreComputerSlapInterfaceWorkflow
,
self
).
beforeTearDown
()
self
.
portal
.
REQUEST
[
'computer_key'
]
=
None
self
.
portal
.
REQUEST
[
'computer_certificate'
]
=
None
def
test_generateCertificate
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
self
.
computer
.
generateCertificate
()
computer_key
=
self
.
portal
.
REQUEST
.
get
(
'computer_key'
)
computer_certificate
=
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
)
self
.
assertNotEqual
(
None
,
computer_key
)
self
.
assertNotEqual
(
None
,
computer_certificate
)
self
.
assertNotEqual
(
None
,
self
.
computer
.
getDestinationReference
())
serial
=
'0x%x'
%
int
(
self
.
computer
.
getDestinationReference
(),
16
)
self
.
assertTrue
(
serial
in
computer_certificate
)
self
.
assertTrue
(
self
.
computer
.
getReference
()
in
computer_certificate
)
def
test_generateCertificate_twice
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
self
.
computer
.
generateCertificate
()
computer_key
=
self
.
portal
.
REQUEST
.
get
(
'computer_key'
)
computer_certificate
=
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
)
self
.
assertNotEqual
(
None
,
computer_key
)
self
.
assertNotEqual
(
None
,
computer_certificate
)
self
.
assertNotEqual
(
None
,
self
.
computer
.
getDestinationReference
())
serial
=
'0x%x'
%
int
(
self
.
computer
.
getDestinationReference
(),
16
)
self
.
assertTrue
(
serial
in
computer_certificate
)
self
.
assertTrue
(
self
.
computer
.
getReference
()
in
computer_certificate
)
self
.
assertRaises
(
ValueError
,
self
.
computer
.
generateCertificate
)
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_key'
))
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
))
def
test_approveComputerRegistration
(
self
):
self
.
_makePerson
()
self
.
login
(
self
.
person_user
.
getReference
())
new_id
=
self
.
generateNewId
()
computer
=
self
.
portal
.
computer_module
.
newContent
(
portal_type
=
'Computer'
,
title
=
"Computer %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTCOMP-%s"
%
new_id
)
computer
.
requestComputerRegistration
()
computer
.
approveComputerRegistration
()
self
.
assertEqual
(
'open/personal'
,
computer
.
getAllocationScope
())
self
.
assertEqual
(
self
.
person_user
.
getRelativeUrl
(),
computer
.
getSourceAdministration
())
self
.
assertEqual
(
'validated'
,
computer
.
getValidationState
())
def
_countInstanceBang
(
self
,
instance
,
comment
):
return
len
([
q
for
q
in
instance
.
workflow_history
[
'instance_slap_interface_workflow'
]
if
q
[
'action'
]
==
'bang'
and
\
q
[
'comment'
]
==
comment
])
def
_countComputereBang
(
self
,
computer
,
comment
):
return
len
([
q
for
q
in
computer
.
workflow_history
[
'computer_slap_interface_workflow'
]
if
q
[
'action'
]
==
\
'report_computer_bang'
and
q
[
'comment'
]
==
comment
])
def
test_reportComputerBang
(
self
):
self
.
_makeComplexComputer
()
self
.
login
(
self
.
computer
.
getReference
())
comment
=
'Bang from computer'
started_instance
=
self
.
computer
.
partition1
.
getAggregateRelatedValue
(
portal_type
=
'Software Instance'
)
stopped_instance
=
self
.
computer
.
partition2
.
getAggregateRelatedValue
(
portal_type
=
'Software Instance'
)
destroyed_instance1
=
self
.
computer
.
partition3
.
getAggregateRelatedValue
(
portal_type
=
'Software Instance'
)
destroyed_instance2
=
self
.
computer
.
partition4
.
getAggregateRelatedValue
(
portal_type
=
'Software Instance'
)
# test sanity check -- do not trust _makeComplexComputer
self
.
assertEqual
(
'start_requested'
,
started_instance
.
getSlapState
())
self
.
assertEqual
(
'stop_requested'
,
stopped_instance
.
getSlapState
())
self
.
assertEqual
(
'destroy_requested'
,
destroyed_instance1
.
getSlapState
())
self
.
assertEqual
(
'destroy_requested'
,
destroyed_instance2
.
getSlapState
())
# store counts before bang
computer_bang_count
=
self
.
_countComputereBang
(
self
.
computer
,
comment
)
started_instance_bang_count
=
self
.
_countInstanceBang
(
started_instance
,
comment
)
stopped_instance_bang_count
=
self
.
_countInstanceBang
(
stopped_instance
,
comment
)
destroyed_instance1_bang_count
=
self
.
_countInstanceBang
(
destroyed_instance1
,
comment
)
destroyed_instance2_bang_count
=
self
.
_countInstanceBang
(
destroyed_instance2
,
comment
)
self
.
computer
.
reportComputerBang
(
comment
=
comment
)
self
.
tic
()
self
.
assertEqual
(
1
+
computer_bang_count
,
self
.
_countComputereBang
(
self
.
computer
,
comment
))
self
.
assertEqual
(
1
+
started_instance_bang_count
,
self
.
_countInstanceBang
(
started_instance
,
comment
))
self
.
assertEqual
(
1
+
stopped_instance_bang_count
,
self
.
_countInstanceBang
(
stopped_instance
,
comment
))
self
.
assertEqual
(
destroyed_instance1_bang_count
,
self
.
_countInstanceBang
(
destroyed_instance1
,
comment
))
self
.
assertEqual
(
destroyed_instance2_bang_count
,
self
.
_countInstanceBang
(
destroyed_instance2
,
comment
))
def
test_requestSoftwareRelease_software_release_url_required
(
self
):
self
.
_makePerson
()
self
.
computer
.
edit
(
source_administration
=
self
.
person_user
.
getRelativeUrl
())
self
.
tic
()
self
.
login
(
self
.
person_user
.
getReference
())
self
.
assertRaises
(
TypeError
,
self
.
computer
.
requestSoftwareRelease
,
state
=
'available'
)
transaction
.
abort
()
def
test_requestSoftwareRelease_state_required
(
self
):
self
.
_makePerson
()
self
.
computer
.
edit
(
source_administration
=
self
.
person_user
.
getRelativeUrl
())
self
.
tic
()
self
.
login
(
self
.
person_user
.
getReference
())
url
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
assertRaises
(
TypeError
,
self
.
computer
.
requestSoftwareRelease
,
software_release_url
=
url
)
transaction
.
abort
()
def
test_requestSoftwareRelease_available
(
self
):
self
.
_makePerson
()
self
.
computer
.
edit
(
source_administration
=
self
.
person_user
.
getRelativeUrl
())
self
.
tic
()
self
.
login
(
self
.
person_user
.
getReference
())
url
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
software_release_url
=
url
,
state
=
'available'
)
self
.
tic
()
self
.
login
()
software_installation
=
self
.
computer
.
getAggregateRelatedValue
(
portal_type
=
'Software Installation'
)
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
url
,
software_installation
.
getUrlString
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
def
test_requestSoftwareRelease_destroyed
(
self
):
self
.
_makePerson
()
self
.
computer
.
edit
(
source_administration
=
self
.
person_user
.
getRelativeUrl
())
self
.
tic
()
self
.
login
(
self
.
person_user
.
getReference
())
url
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
software_release_url
=
url
,
state
=
'destroyed'
)
self
.
tic
()
self
.
login
()
software_installation
=
self
.
computer
.
getAggregateRelatedValue
(
portal_type
=
'Software Installation'
)
self
.
assertEqual
(
None
,
software_installation
)
def
test_requestSoftwareRelease_available_destroyed
(
self
):
self
.
_makePerson
()
self
.
computer
.
edit
(
source_administration
=
self
.
person_user
.
getRelativeUrl
())
self
.
tic
()
self
.
login
(
self
.
person_user
.
getReference
())
url
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
software_release_url
=
url
,
state
=
'available'
)
self
.
tic
()
self
.
login
()
software_installation
=
self
.
computer
.
getAggregateRelatedValue
(
portal_type
=
'Software Installation'
)
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
url
,
software_installation
.
getUrlString
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
login
(
self
.
person_user
.
getReference
())
self
.
computer
.
requestSoftwareRelease
(
software_release_url
=
url
,
state
=
'destroyed'
)
self
.
tic
()
self
.
login
()
software_installation
=
self
.
computer
.
getAggregateRelatedValue
(
portal_type
=
'Software Installation'
)
self
.
assertEqual
(
'destroy_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
url
,
software_installation
.
getUrlString
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
def
test_requestSoftwareRelease_not_indexed
(
self
):
self
.
_makePerson
()
self
.
computer
.
edit
(
source_administration
=
self
.
person_user
.
getRelativeUrl
())
self
.
tic
()
self
.
login
(
self
.
person_user
.
getReference
())
url
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
software_release_url
=
url
,
state
=
'available'
)
transaction
.
commit
()
self
.
assertRaises
(
NotImplementedError
,
self
.
computer
.
requestSoftwareRelease
,
software_release_url
=
url
,
state
=
'available'
)
transaction
.
abort
()
@
expectedFailure
def
test_requestSoftwareRelease_same_transaction
(
self
):
self
.
_makePerson
()
self
.
computer
.
edit
(
source_administration
=
self
.
person_user
.
getRelativeUrl
())
self
.
tic
()
self
.
login
(
self
.
person_user
.
getReference
())
url
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
software_release_url
=
url
,
state
=
'available'
)
self
.
assertRaises
(
NotImplementedError
,
self
.
computer
.
requestSoftwareRelease
,
software_release_url
=
url
,
state
=
'available'
)
transaction
.
abort
()
def
test_revokeCertificate
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
self
.
computer
.
generateCertificate
()
computer_key
=
self
.
portal
.
REQUEST
.
get
(
'computer_key'
)
computer_certificate
=
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
)
self
.
assertNotEqual
(
None
,
computer_key
)
self
.
assertNotEqual
(
None
,
computer_certificate
)
self
.
assertNotEqual
(
None
,
self
.
computer
.
getDestinationReference
())
serial
=
'0x%x'
%
int
(
self
.
computer
.
getDestinationReference
(),
16
)
self
.
assertTrue
(
serial
in
computer_certificate
)
self
.
assertTrue
(
self
.
computer
.
getReference
()
in
computer_certificate
)
self
.
computer
.
revokeCertificate
()
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_key'
))
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
))
self
.
assertEqual
(
None
,
self
.
computer
.
getDestinationReference
())
def
test_revokeCertificateNoCertificate
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
self
.
assertRaises
(
ValueError
,
self
.
computer
.
revokeCertificate
)
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_key'
))
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
))
self
.
assertEqual
(
None
,
self
.
computer
.
getDestinationReference
())
def
test_revokeCertificate_twice
(
self
):
self
.
login
(
self
.
computer
.
getReference
())
self
.
computer
.
generateCertificate
()
computer_key
=
self
.
portal
.
REQUEST
.
get
(
'computer_key'
)
computer_certificate
=
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
)
self
.
assertNotEqual
(
None
,
computer_key
)
self
.
assertNotEqual
(
None
,
computer_certificate
)
self
.
assertNotEqual
(
None
,
self
.
computer
.
getDestinationReference
())
serial
=
'0x%x'
%
int
(
self
.
computer
.
getDestinationReference
(),
16
)
self
.
assertTrue
(
serial
in
computer_certificate
)
self
.
assertTrue
(
self
.
computer
.
getReference
()
in
computer_certificate
)
self
.
computer
.
revokeCertificate
()
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_key'
))
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
))
self
.
assertEqual
(
None
,
self
.
computer
.
getDestinationReference
())
self
.
assertRaises
(
ValueError
,
self
.
computer
.
revokeCertificate
)
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_key'
))
self
.
assertEqual
(
None
,
self
.
portal
.
REQUEST
.
get
(
'computer_certificate'
))
self
.
assertEqual
(
None
,
self
.
computer
.
getDestinationReference
())
class
TestSlapOSCorePersonComputerSupply
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSCorePersonComputerSupply
,
self
).
afterSetUp
()
portal
=
self
.
getPortalObject
()
new_id
=
self
.
generateNewId
()
# Clone computer document
computer
=
portal
.
computer_module
.
template_computer
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
# Clone person document
person_user
=
portal
.
person_module
.
template_member
.
\
Base_createCloneDocument
(
batch_mode
=
1
)
person_user
.
edit
(
title
=
"live_test_%s"
%
new_id
,
reference
=
"live_test_%s"
%
new_id
,
default_email_text
=
"live_test_%s@example.org"
%
new_id
,
)
computer
.
edit
(
title
=
"Computer %s for %s"
%
(
new_id
,
person_user
.
getReference
()),
reference
=
"TESTCOMP-%s"
%
new_id
,
source_administration
=
person_user
.
getRelativeUrl
()
)
computer
.
validate
()
self
.
computer
=
computer
person_user
.
validate
()
for
assignment
in
person_user
.
contentValues
(
portal_type
=
"Assignment"
):
assignment
.
open
()
transaction
.
commit
()
# XXX Tic is needed to reindex the created open order
self
.
tic
()
# Login as new user
self
.
login
(
person_user
.
getReference
())
new_person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
self
.
assertEquals
(
person_user
.
getRelativeUrl
(),
new_person
.
getRelativeUrl
())
def
beforeTearDown
(
self
):
if
'software_installation_url'
in
self
.
computer
.
REQUEST
:
self
.
computer
.
REQUEST
[
'software_installation_url'
]
=
None
def
test_supply_requiredParameter
(
self
):
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
assertRaises
(
TypeError
,
self
.
computer
.
requestSoftwareRelease
)
self
.
assertRaises
(
TypeError
,
self
.
computer
.
requestSoftwareRelease
,
state
=
"available"
)
self
.
assertRaises
(
TypeError
,
self
.
computer
.
requestSoftwareRelease
,
software_release_url
=
software_release
)
self
.
assertRaises
(
ValueError
,
self
.
computer
.
requestSoftwareRelease
,
state
=
"mana"
,
software_release_url
=
software_release
)
def
test_supply_available
(
self
):
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
None
,
software_installation_url
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url
)
self
.
assertEqual
(
software_release
,
software_installation
.
getUrlString
())
def
test_supply_destroyed
(
self
):
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"destroyed"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertEqual
(
None
,
software_installation_url
)
def
test_supply_available_nonIndexed
(
self
):
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
None
,
software_installation_url
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url
)
self
.
assertEqual
(
software_release
,
software_installation
.
getUrlString
())
transaction
.
commit
()
self
.
assertRaises
(
NotImplementedError
,
self
.
computer
.
requestSoftwareRelease
,
state
=
"available"
,
software_release_url
=
software_release
)
def
test_supply_available_destroyed_nonIndexed
(
self
):
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
None
,
software_installation_url
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url
)
self
.
assertEqual
(
software_release
,
software_installation
.
getUrlString
())
transaction
.
commit
()
self
.
assertRaises
(
NotImplementedError
,
self
.
computer
.
requestSoftwareRelease
,
state
=
"destroyed"
,
software_release_url
=
software_release
)
def
test_supply_available_createdSoftwareInstallation
(
self
):
previous_id
=
self
.
getPortalObject
().
portal_ids
\
.
generateNewId
(
id_group
=
'slap_software_installation_reference'
,
id_generator
=
'uid'
)
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
None
,
software_installation_url
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url
)
self
.
assertEqual
(
software_release
,
software_installation
.
getUrlString
())
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
1
),
software_installation
.
getReference
())
def
test_multiple_supply_available_createdSoftwareInstallation
(
self
):
previous_id
=
self
.
getPortalObject
().
portal_ids
\
.
generateNewId
(
id_group
=
'slap_software_installation_reference'
,
id_generator
=
'uid'
)
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
None
,
software_installation_url
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url
)
self
.
assertEqual
(
software_release
,
software_installation
.
getUrlString
())
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
1
),
software_installation
.
getReference
())
self
.
tic
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url2
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertEqual
(
software_installation_url
,
software_installation_url2
)
def
test_supply_available_destroyed
(
self
):
previous_id
=
self
.
getPortalObject
().
portal_ids
\
.
generateNewId
(
id_group
=
'slap_software_installation_reference'
,
id_generator
=
'uid'
)
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
None
,
software_installation_url
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url
)
self
.
assertEqual
(
software_release
,
software_installation
.
getUrlString
())
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
1
),
software_installation
.
getReference
())
self
.
tic
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"destroyed"
,
software_release_url
=
software_release
)
software_installation_url2
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertEqual
(
software_installation_url
,
software_installation_url2
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url2
)
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'destroy_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
1
),
software_installation
.
getReference
())
def
test_supply_available_destroyed_available
(
self
):
previous_id
=
self
.
getPortalObject
().
portal_ids
\
.
generateNewId
(
id_group
=
'slap_software_installation_reference'
,
id_generator
=
'uid'
)
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
None
,
software_installation_url
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url
)
self
.
assertEqual
(
software_release
,
software_installation
.
getUrlString
())
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
1
),
software_installation
.
getReference
())
self
.
tic
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"destroyed"
,
software_release_url
=
software_release
)
software_installation_url2
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertEqual
(
software_installation_url
,
software_installation_url2
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url2
)
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'destroy_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
1
),
software_installation
.
getReference
())
self
.
tic
()
# XXX: This scenario shall be discussed...
self
.
assertRaises
(
UnsupportedWorkflowMethod
,
self
.
computer
.
requestSoftwareRelease
,
state
=
"available"
,
software_release_url
=
software_release
)
def
test_supply_available_destroyed_finalised_available
(
self
):
previous_id
=
self
.
getPortalObject
().
portal_ids
\
.
generateNewId
(
id_group
=
'slap_software_installation_reference'
,
id_generator
=
'uid'
)
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
None
,
software_installation_url
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url
)
self
.
assertEqual
(
software_release
,
software_installation
.
getUrlString
())
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
1
),
software_installation
.
getReference
())
self
.
tic
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"destroyed"
,
software_release_url
=
software_release
)
software_installation_url2
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertEqual
(
software_installation_url
,
software_installation_url2
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url2
)
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'destroy_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
1
),
software_installation
.
getReference
())
software_installation
.
invalidate
()
self
.
tic
()
self
.
computer
.
requestSoftwareRelease
(
state
=
"available"
,
software_release_url
=
software_release
)
software_installation_url3
=
self
.
computer
.
REQUEST
.
get
(
'software_installation_url'
)
self
.
assertNotEqual
(
software_installation_url
,
software_installation_url3
)
software_installation
=
self
.
computer
.
restrictedTraverse
(
software_installation_url3
)
self
.
assertEqual
(
'Software Installation'
,
software_installation
.
getPortalType
())
self
.
assertEqual
(
'validated'
,
software_installation
.
getValidationState
())
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
self
.
assertEqual
(
'SOFTINSTALL-%s'
%
(
previous_id
+
2
),
software_installation
.
getReference
())
class
TestSlapOSCoreInstanceSlapInterfaceWorkflow
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
...
...
@@ -1186,3 +1881,1098 @@ class TestSlapOSCoreSoftwareInstanceRequest(testSlapOSMixin):
self
.
assertEqual
(
request_kw
[
'sla_xml'
],
requested_instance2
.
getSlaXml
())
self
.
assertEqual
(
bang_amount
+
1
,
self
.
_countBang
(
requested_instance
))
class
TestSlapOSCorePersonRequest
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestSlapOSCorePersonRequest
,
self
).
afterSetUp
()
portal
=
self
.
getPortalObject
()
new_id
=
self
.
generateNewId
()
# Clone person document
person_user
=
portal
.
person_module
.
template_member
.
\
Base_createCloneDocument
(
batch_mode
=
1
)
person_user
.
edit
(
title
=
"live_test_%s"
%
new_id
,
reference
=
"live_test_%s"
%
new_id
,
default_email_text
=
"live_test_%s@example.org"
%
new_id
,
)
person_user
.
validate
()
for
assignment
in
person_user
.
contentValues
(
portal_type
=
"Assignment"
):
assignment
.
open
()
transaction
.
commit
()
# XXX Tic is needed to reindex the created open order
self
.
tic
()
# Login as new user
self
.
login
(
person_user
.
getReference
())
new_person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
self
.
assertEquals
(
person_user
.
getRelativeUrl
(),
new_person
.
getRelativeUrl
())
def
beforeTearDown
(
self
):
pass
def
test_Person_requestSoftwareInstance_requiredParameter
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
state
=
"started"
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
)
# software_release is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
# software_title is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
# software_type is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
# instance_xml is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
# instance_xml is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
# sla_xml is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
shared
=
shared
,
state
=
state
,
)
# shared is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
state
=
state
,
)
# state is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
)
def
test_Person_requestSoftwareInstance_acceptedState
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
# Only started, stopped, destroyed
self
.
assertRaises
(
ValueError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"foo"
,
)
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
"started"
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"started"
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertEquals
(
"start_requested"
,
hosting_subscription
.
getSlapState
())
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
"stopped"
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"stopped"
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertEquals
(
"stop_requested"
,
hosting_subscription
.
getSlapState
())
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
"destroyed"
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"destroyed"
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertEquals
(
None
,
hosting_subscription
)
def
test_Person_requestSoftwareInstance_returnHostingSubscriptionUrl
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
state
=
"started"
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertEquals
(
"Hosting Subscription"
,
hosting_subscription
.
getPortalType
())
def
test_Person_requestSoftwareInstance_createHostingSubscription
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
state
=
"started"
previous_id
=
self
.
getPortalObject
().
portal_ids
\
.
generateNewId
(
id_group
=
'slap_hosting_subscription_reference'
,
id_generator
=
'uid'
)
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertEquals
(
software_release
,
hosting_subscription
.
getUrlString
())
self
.
assertEquals
(
software_title
,
hosting_subscription
.
getTitle
())
self
.
assertEquals
(
software_type
,
hosting_subscription
.
getSourceReference
())
self
.
assertEquals
(
instance_xml
,
hosting_subscription
.
getTextContent
())
self
.
assertEquals
(
sla_xml
,
hosting_subscription
.
getSlaXml
())
self
.
assertEquals
(
shared
,
hosting_subscription
.
getRootSlave
())
self
.
assertEquals
(
"start_requested"
,
hosting_subscription
.
getSlapState
())
self
.
assertEquals
(
"HOSTSUBS-%s"
%
(
previous_id
+
1
),
hosting_subscription
.
getReference
())
self
.
assertEquals
(
"validated"
,
hosting_subscription
.
getValidationState
())
def
test_Person_requestSoftwareInstance_HostingSubscriptionNotReindexed
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
state
=
"started"
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
transaction
.
commit
()
self
.
assertRaises
(
NotImplementedError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
@
expectedFailure
def
test_Person_requestSoftwareInstance_updateHostingSubscription
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
state
=
"started"
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
hosting_subscription_reference
=
hosting_subscription
.
getReference
()
transaction
.
commit
()
self
.
tic
()
software_release2
=
self
.
generateNewSoftwareReleaseUrl
()
software_type2
=
"test2"
instance_xml2
=
"""<?xml version='1.0' encoding='utf-8'?>
<instance>
</instance>"""
sla_xml2
=
"""<?xml version='1.0' encoding='utf-8'?>
<instance>
</instance>"""
shared2
=
False
state2
=
"stopped"
person
.
requestSoftwareInstance
(
software_release
=
software_release2
,
software_title
=
software_title
,
software_type
=
software_type2
,
instance_xml
=
instance_xml2
,
sla_xml
=
sla_xml2
,
shared
=
shared2
,
state
=
state2
,
)
hosting_subscription2
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertEquals
(
hosting_subscription
.
getRelativeUrl
(),
hosting_subscription2
.
getRelativeUrl
())
self
.
assertEquals
(
hosting_subscription_reference
,
hosting_subscription2
.
getReference
())
self
.
assertEquals
(
software_release2
,
hosting_subscription
.
getUrlString
())
self
.
assertEquals
(
software_title
,
hosting_subscription
.
getTitle
())
self
.
assertEquals
(
software_type2
,
hosting_subscription
.
getSourceReference
())
self
.
assertEquals
(
instance_xml2
,
hosting_subscription
.
getTextContent
())
self
.
assertEquals
(
sla_xml2
,
hosting_subscription
.
getSlaXml
())
self
.
assertEquals
(
shared2
,
hosting_subscription
.
getRootSlave
())
self
.
assertEquals
(
"stop_requested"
,
hosting_subscription
.
getSlapState
())
self
.
assertEquals
(
"validated"
,
hosting_subscription
.
getValidationState
())
def
test_Person_requestSoftwareInstance_duplicatedHostingSubscription
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
state
=
"started"
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
transaction
.
commit
()
hosting_subscription2
=
hosting_subscription
.
Base_createCloneDocument
(
batch_mode
=
1
)
hosting_subscription2
.
validate
()
transaction
.
commit
()
self
.
tic
()
self
.
assertRaises
(
NotImplementedError
,
person
.
requestSoftwareInstance
,
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
def
test_Person_requestSoftwareInstance_HostingSubscriptionNewTitle
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version='1.0' encoding='utf-8'?>
<instance>
</instance>"""
sla_xml
=
"""<?xml version='1.0' encoding='utf-8'?>
<instance>
</instance>"""
shared
=
True
state
=
"started"
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
state
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
transaction
.
commit
()
software_release2
=
self
.
generateNewSoftwareReleaseUrl
()
software_title2
=
"test2"
software_type2
=
"test2"
instance_xml2
=
"""<?xml version='1.0' encoding='utf-8'?>
<instance>
</instance>"""
sla_xml2
=
"""<?xml version='1.0' encoding='utf-8'?>
<instance>
</instance>"""
shared2
=
False
state2
=
"stopped"
person
.
requestSoftwareInstance
(
software_release
=
software_release2
,
software_title
=
software_title2
,
software_type
=
software_type2
,
instance_xml
=
instance_xml2
,
sla_xml
=
sla_xml2
,
shared
=
shared2
,
state
=
state2
,
)
hosting_subscription2
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertNotEquals
(
hosting_subscription
.
getRelativeUrl
(),
hosting_subscription2
.
getRelativeUrl
())
self
.
assertNotEquals
(
hosting_subscription
.
getReference
(),
hosting_subscription2
.
getReference
())
self
.
assertEquals
(
software_release2
,
hosting_subscription2
.
getUrlString
())
self
.
assertEquals
(
software_title2
,
hosting_subscription2
.
getTitle
())
self
.
assertEquals
(
software_type2
,
hosting_subscription2
.
getSourceReference
())
self
.
assertEquals
(
instance_xml2
,
hosting_subscription2
.
getTextContent
())
self
.
assertEquals
(
sla_xml2
,
hosting_subscription2
.
getSlaXml
())
self
.
assertEquals
(
shared2
,
hosting_subscription2
.
getRootSlave
())
self
.
assertEquals
(
"stop_requested"
,
hosting_subscription2
.
getSlapState
())
self
.
assertEquals
(
"validated"
,
hosting_subscription2
.
getValidationState
())
def
test_Person_requestSoftwareInstance_deletedHostingSubscription
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"stopped"
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
transaction
.
commit
()
self
.
tic
()
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"destroyed"
,
)
hosting_subscription2
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertEquals
(
None
,
hosting_subscription2
)
self
.
assertEquals
(
"destroy_requested"
,
hosting_subscription
.
getSlapState
())
def
test_Person_requestSoftwareInstance_noConflictWithDeletedHostingSubscription
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_title
=
"test"
software_type
=
"test"
instance_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
sla_xml
=
"test"
shared
=
True
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"stopped"
,
)
hosting_subscription
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
transaction
.
commit
()
self
.
tic
()
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"destroyed"
,
)
self
.
assertEquals
(
"destroy_requested"
,
hosting_subscription
.
getSlapState
())
transaction
.
commit
()
self
.
tic
()
person
.
requestSoftwareInstance
(
software_release
=
software_release
,
software_title
=
software_title
,
software_type
=
software_type
,
instance_xml
=
instance_xml
,
sla_xml
=
sla_xml
,
shared
=
shared
,
state
=
"started"
,
)
hosting_subscription2
=
person
.
REQUEST
.
get
(
'request_hosting_subscription'
)
self
.
assertEquals
(
"start_requested"
,
hosting_subscription2
.
getSlapState
())
self
.
assertNotEquals
(
hosting_subscription
.
getRelativeUrl
(),
hosting_subscription2
.
getRelativeUrl
())
class
TestSlapOSCorePersonRequestComputer
(
testSlapOSMixin
):
def
generateNewComputerTitle
(
self
):
return
'My Comp %s'
%
self
.
generateNewId
()
def
afterSetUp
(
self
):
super
(
TestSlapOSCorePersonRequestComputer
,
self
).
afterSetUp
()
portal
=
self
.
getPortalObject
()
new_id
=
self
.
generateNewId
()
# Clone person document
person_user
=
portal
.
person_module
.
template_member
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
person_user
.
edit
(
title
=
"live_test_%s"
%
new_id
,
reference
=
"live_test_%s"
%
new_id
,
default_email_text
=
"live_test_%s@example.org"
%
new_id
,
)
person_user
.
validate
()
for
assignment
in
person_user
.
contentValues
(
portal_type
=
"Assignment"
):
assignment
.
open
()
transaction
.
commit
()
# XXX Tic is needed to reindex the created open order
self
.
tic
()
# Login as new user
self
.
login
(
person_user
.
getReference
())
new_person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
self
.
assertEquals
(
person_user
.
getRelativeUrl
(),
new_person
.
getRelativeUrl
())
def
beforeTearDown
(
self
):
pass
def
test_request_requiredParameter
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
# computer_title is mandatory
self
.
assertRaises
(
TypeError
,
person
.
requestComputer
)
# if provided does not raise
computer_title
=
self
.
generateNewComputerTitle
()
person
.
requestComputer
(
computer_title
=
computer_title
)
def
test_request
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
computer_title
=
self
.
generateNewComputerTitle
()
person
.
requestComputer
(
computer_title
=
computer_title
)
# check what is returned via request
computer_url
=
person
.
REQUEST
.
get
(
'computer'
)
computer_absolute_url
=
person
.
REQUEST
.
get
(
'computer_url'
)
computer_reference
=
person
.
REQUEST
.
get
(
'computer_reference'
)
self
.
assertNotEqual
(
None
,
computer_url
)
self
.
assertNotEqual
(
None
,
computer_absolute_url
)
self
.
assertNotEqual
(
None
,
computer_reference
)
def
test_request_createdComputer
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
previous_id
=
self
.
getPortalObject
().
portal_ids
\
.
generateNewId
(
id_group
=
'slap_computer_reference'
,
id_generator
=
'uid'
)
computer_title
=
self
.
generateNewComputerTitle
()
person
.
requestComputer
(
computer_title
=
computer_title
)
# check what is returned via request
computer_url
=
person
.
REQUEST
.
get
(
'computer'
)
computer_absolute_url
=
person
.
REQUEST
.
get
(
'computer_url'
)
computer_reference
=
person
.
REQUEST
.
get
(
'computer_reference'
)
self
.
assertNotEqual
(
None
,
computer_url
)
self
.
assertNotEqual
(
None
,
computer_absolute_url
)
self
.
assertNotEqual
(
None
,
computer_reference
)
# check that title is ok
computer
=
person
.
restrictedTraverse
(
computer_url
)
self
.
assertEqual
(
computer_title
,
computer
.
getTitle
())
# check that data are sane
self
.
assertEqual
(
computer_absolute_url
,
computer
.
absolute_url
())
self
.
assertEqual
(
computer_reference
,
computer
.
getReference
())
self
.
assertEqual
(
'COMP-%s'
%
(
previous_id
+
1
),
computer
.
getReference
())
self
.
assertEqual
(
'validated'
,
computer
.
getValidationState
())
self
.
assertEqual
(
'open/personal'
,
computer
.
getAllocationScope
())
self
.
assertEqual
(
'open'
,
computer
.
getCapacityScope
())
def
test_request_notReindexedCompute
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
computer_title
=
self
.
generateNewComputerTitle
()
person
.
requestComputer
(
computer_title
=
computer_title
)
transaction
.
commit
()
self
.
assertRaises
(
NotImplementedError
,
person
.
requestComputer
,
computer_title
=
computer_title
)
def
test_multiple_request_createdComputer
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
previous_id
=
self
.
getPortalObject
().
portal_ids
\
.
generateNewId
(
id_group
=
'slap_computer_reference'
,
id_generator
=
'uid'
)
computer_title
=
self
.
generateNewComputerTitle
()
computer_title2
=
self
.
generateNewComputerTitle
()
person
.
requestComputer
(
computer_title
=
computer_title
)
# check what is returned via request
computer_url
=
person
.
REQUEST
.
get
(
'computer'
)
computer_absolute_url
=
person
.
REQUEST
.
get
(
'computer_url'
)
computer_reference
=
person
.
REQUEST
.
get
(
'computer_reference'
)
self
.
assertNotEqual
(
None
,
computer_url
)
self
.
assertNotEqual
(
None
,
computer_absolute_url
)
self
.
assertNotEqual
(
None
,
computer_reference
)
# check that title is ok
computer
=
person
.
restrictedTraverse
(
computer_url
)
self
.
assertEqual
(
computer_title
,
computer
.
getTitle
())
# check that data are sane
self
.
assertEqual
(
computer_absolute_url
,
computer
.
absolute_url
())
self
.
assertEqual
(
computer_reference
,
computer
.
getReference
())
self
.
assertEqual
(
'COMP-%s'
%
(
previous_id
+
1
),
computer
.
getReference
())
self
.
assertEqual
(
'validated'
,
computer
.
getValidationState
())
self
.
assertEqual
(
'open/personal'
,
computer
.
getAllocationScope
())
self
.
assertEqual
(
'open'
,
computer
.
getCapacityScope
())
self
.
tic
()
# request again the same computer
person
.
requestComputer
(
computer_title
=
computer_title
)
# check what is returned via request
computer_url
=
person
.
REQUEST
.
get
(
'computer'
)
computer_absolute_url
=
person
.
REQUEST
.
get
(
'computer_url'
)
computer_reference
=
person
.
REQUEST
.
get
(
'computer_reference'
)
self
.
assertNotEqual
(
None
,
computer_url
)
self
.
assertNotEqual
(
None
,
computer_absolute_url
)
self
.
assertNotEqual
(
None
,
computer_reference
)
# check that title is ok
computer
=
person
.
restrictedTraverse
(
computer_url
)
self
.
assertEqual
(
computer_title
,
computer
.
getTitle
())
# check that data are sane
self
.
assertEqual
(
computer_absolute_url
,
computer
.
absolute_url
())
self
.
assertEqual
(
computer_reference
,
computer
.
getReference
())
self
.
assertEqual
(
'COMP-%s'
%
(
previous_id
+
1
),
computer
.
getReference
())
self
.
assertEqual
(
'validated'
,
computer
.
getValidationState
())
self
.
assertEqual
(
'open/personal'
,
computer
.
getAllocationScope
())
self
.
assertEqual
(
'open'
,
computer
.
getCapacityScope
())
# and now another one
person
.
requestComputer
(
computer_title
=
computer_title2
)
# check what is returned via request
computer_url2
=
person
.
REQUEST
.
get
(
'computer'
)
computer_absolute_url2
=
person
.
REQUEST
.
get
(
'computer_url'
)
computer_reference2
=
person
.
REQUEST
.
get
(
'computer_reference'
)
self
.
assertNotEqual
(
None
,
computer_url2
)
self
.
assertNotEqual
(
None
,
computer_absolute_url2
)
self
.
assertNotEqual
(
None
,
computer_reference2
)
# check that computers are really different objects
self
.
assertNotEqual
(
computer_url2
,
computer_url
)
# check that title is ok
computer2
=
person
.
restrictedTraverse
(
computer_url2
)
self
.
assertEqual
(
computer_title2
,
computer2
.
getTitle
())
# check that data are sane
self
.
assertEqual
(
computer_absolute_url2
,
computer2
.
absolute_url
())
self
.
assertEqual
(
computer_reference2
,
computer2
.
getReference
())
self
.
assertEqual
(
'COMP-%s'
%
(
previous_id
+
2
),
computer2
.
getReference
())
self
.
assertEqual
(
'validated'
,
computer2
.
getValidationState
())
self
.
assertEqual
(
'open/personal'
,
computer2
.
getAllocationScope
())
self
.
assertEqual
(
'open'
,
computer2
.
getCapacityScope
())
def
test_request_duplicatedComputer
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
computer_title
=
self
.
generateNewComputerTitle
()
person
.
requestComputer
(
computer_title
=
computer_title
)
# check what is returned via request
computer_url
=
person
.
REQUEST
.
get
(
'computer'
)
computer_absolute_url
=
person
.
REQUEST
.
get
(
'computer_url'
)
computer_reference
=
person
.
REQUEST
.
get
(
'computer_reference'
)
self
.
assertNotEqual
(
None
,
computer_url
)
self
.
assertNotEqual
(
None
,
computer_absolute_url
)
self
.
assertNotEqual
(
None
,
computer_reference
)
# check that title is ok
computer
=
person
.
restrictedTraverse
(
computer_url
)
sm
=
getSecurityManager
()
try
:
self
.
login
()
computer2
=
computer
.
Base_createCloneDocument
(
batch_mode
=
1
)
computer2
.
validate
()
finally
:
setSecurityManager
(
sm
)
self
.
tic
()
self
.
assertRaises
(
NotImplementedError
,
person
.
requestComputer
,
computer_title
=
computer_title
)
class
TestSlapOSCoreSlapOSCloudInteractionWorkflow
(
testSlapOSMixin
):
def
_makePerson
(
self
):
new_id
=
self
.
generateNewId
()
self
.
person_user
=
self
.
portal
.
person_module
.
template_member
.
\
Base_createCloneDocument
(
batch_mode
=
1
)
self
.
person_user
.
edit
(
title
=
"live_test_%s"
%
new_id
,
reference
=
"live_test_%s"
%
new_id
,
default_email_text
=
"live_test_%s@example.org"
%
new_id
,
)
self
.
person_user
.
validate
()
for
assignment
in
self
.
person_user
.
contentValues
(
portal_type
=
"Assignment"
):
assignment
.
open
()
self
.
tic
()
def
test_Computer_setSubjectList
(
self
):
self
.
_makePerson
()
self
.
login
(
self
.
person_user
.
getReference
())
new_id
=
self
.
generateNewId
()
computer
=
self
.
portal
.
computer_module
.
newContent
(
portal_type
=
'Computer'
,
title
=
"Computer %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTCOMP-%s"
%
new_id
)
self
.
tic
()
assert
computer
.
getDestinationSectionValue
()
is
None
computer
.
edit
(
subject_list
=
[
self
.
person_user
.
getDefaultEmailText
()])
self
.
tic
()
assert
computer
.
getDestinationSection
()
==
\
self
.
person_user
.
getRelativeUrl
()
def
check_Instance_validate
(
self
,
portal_type
):
self
.
_makePerson
()
self
.
login
(
self
.
person_user
.
getReference
())
new_id
=
self
.
generateNewId
()
instance
=
self
.
portal
.
software_instance_module
.
newContent
(
portal_type
=
portal_type
,
title
=
"Instance %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTINST-%s"
%
new_id
)
def
verify_activeSense_call
(
self
):
if
self
.
getRelativeUrl
()
==
'portal_alarms/slapos_allocate_instance'
:
instance
.
portal_workflow
.
doActionFor
(
instance
,
action
=
'edit_action'
,
comment
=
'activeSense triggered'
)
else
:
return
self
.
activeSense_call
()
# Replace activeSense by a dummy method
from
Products.ERP5Type.Document.Alarm
import
Alarm
Alarm
.
activeSense_call
=
Alarm
.
activeSense
Alarm
.
activeSense
=
verify_activeSense_call
try
:
instance
.
validate
()
# instance.portal_alarms.slapos_allocate_instance.activeSense()
self
.
tic
()
finally
:
Alarm
.
activeSense
=
Alarm
.
activeSense_call
self
.
assertEqual
(
'activeSense triggered'
,
instance
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_SoftwareInstance_validate
(
self
):
return
self
.
check_Instance_validate
(
"Software Instance"
)
def
test_SlaveInstance_validate
(
self
):
return
self
.
check_Instance_validate
(
"Slave Instance"
)
def
test_SlaveInstance_requestDestroy
(
self
):
self
.
_makePerson
()
self
.
login
(
self
.
person_user
.
getReference
())
new_id
=
self
.
generateNewId
()
instance
=
self
.
portal
.
software_instance_module
.
newContent
(
portal_type
=
'Slave Instance'
,
title
=
"Instance %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTINST-%s"
%
new_id
,
destination_reference
=
"TESTINST-%s"
%
new_id
,
)
request_kw
=
dict
(
software_release
=
'http://example.org'
,
software_type
=
'http://example.org'
,
instance_xml
=
self
.
generateSafeXml
(),
sla_xml
=
self
.
generateSafeXml
(),
shared
=
True
,
)
instance
.
requestStop
(
**
request_kw
)
self
.
assertEqual
(
instance
.
getValidationState
(),
'draft'
)
instance
.
validate
()
self
.
assertEqual
(
instance
.
getValidationState
(),
'validated'
)
instance
.
requestDestroy
(
**
request_kw
)
self
.
assertEqual
(
instance
.
getValidationState
(),
'invalidated'
)
def
check_SoftwareInstallation_changeState
(
self
,
method_id
):
self
.
_makePerson
()
self
.
login
(
self
.
person_user
.
getReference
())
new_id
=
self
.
generateNewId
()
computer
=
self
.
portal
.
computer_module
.
newContent
(
portal_type
=
'Computer'
,
title
=
"Computer %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTCOMP-%s"
%
new_id
)
installation
=
self
.
portal
.
software_installation_module
.
newContent
(
portal_type
=
'Software Installation'
,
title
=
"Installation %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
aggregate_value
=
computer
,
)
self
.
tic
()
def
verify_reindexObject_call
(
self
,
*
args
,
**
kw
):
if
self
.
getRelativeUrl
()
==
computer
.
getRelativeUrl
():
computer
.
portal_workflow
.
doActionFor
(
computer
,
action
=
'edit_action'
,
comment
=
'reindexObject triggered on %s'
%
method_id
)
else
:
return
self
.
reindexObject_call
(
*
args
,
**
kw
)
# Replace activeSense by a dummy method
from
Products.ERP5Type.Base
import
Base
Base
.
reindexObject_call
=
Base
.
reindexObject
Base
.
reindexObject
=
verify_reindexObject_call
try
:
getattr
(
installation
,
method_id
)()
self
.
tic
()
finally
:
Base
.
reindexObject
=
Base
.
reindexObject_call
self
.
assertEqual
(
'reindexObject triggered on %s'
%
method_id
,
computer
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_SoftwareInstallation_changeState_onStart
(
self
):
return
self
.
check_SoftwareInstallation_changeState
(
'requestStart'
)
def
test_SoftwareInstallation_changeState_onDestroy
(
self
):
return
self
.
check_SoftwareInstallation_changeState
(
'requestDestroy'
)
def
check_SoftwareInstance_changeState
(
self
,
method_id
):
self
.
_makePerson
()
self
.
login
(
self
.
person_user
.
getReference
())
new_id
=
self
.
generateNewId
()
computer
=
self
.
portal
.
computer_module
.
newContent
(
portal_type
=
'Computer'
,
title
=
"Computer %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTCOMP-%s"
%
new_id
)
partition
=
computer
.
newContent
(
portal_type
=
'Computer Partition'
,
title
=
"Partition Computer %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTPART-%s"
%
new_id
)
instance
=
self
.
portal
.
software_instance_module
.
newContent
(
portal_type
=
"Software Instance"
,
title
=
"Instance %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTINST-%s"
%
new_id
,
aggregate_value
=
partition
,
destination_reference
=
"TESTINST-%s"
%
new_id
,
ssl_certificate
=
"foo"
,
ssl_key
=
"bar"
,
)
request_kw
=
dict
(
software_release
=
'http://example.org'
,
software_type
=
'http://example.org'
,
instance_xml
=
self
.
generateSafeXml
(),
sla_xml
=
self
.
generateSafeXml
(),
shared
=
False
,
)
if
method_id
==
'requestDestroy'
:
instance
.
requestStop
(
**
request_kw
)
self
.
tic
()
def
verify_reindexObject_call
(
self
,
*
args
,
**
kw
):
if
self
.
getRelativeUrl
()
==
partition
.
getRelativeUrl
():
partition
.
portal_workflow
.
doActionFor
(
partition
,
action
=
'edit_action'
,
comment
=
'reindexObject triggered on %s'
%
method_id
)
else
:
return
self
.
reindexObject_call
(
*
args
,
**
kw
)
# Replace activeSense by a dummy method
from
Products.ERP5Type.Base
import
Base
Base
.
reindexObject_call
=
Base
.
reindexObject
Base
.
reindexObject
=
verify_reindexObject_call
try
:
getattr
(
instance
,
method_id
)(
**
request_kw
)
self
.
tic
()
finally
:
Base
.
reindexObject
=
Base
.
reindexObject_call
self
.
assertEqual
(
'reindexObject triggered on %s'
%
method_id
,
partition
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
def
test_SoftwareInstance_changeState_onStart
(
self
):
return
self
.
check_SoftwareInstance_changeState
(
"requestStart"
)
def
test_SoftwareInstance_changeState_onStop
(
self
):
return
self
.
check_SoftwareInstance_changeState
(
"requestStop"
)
def
test_SoftwareInstance_changeState_onDestroy
(
self
):
return
self
.
check_SoftwareInstance_changeState
(
"requestDestroy"
)
def
check_change_instance_parameter
(
self
,
portal_type
,
method_id
):
self
.
_makePerson
()
self
.
login
(
self
.
person_user
.
getReference
())
new_id
=
self
.
generateNewId
()
instance
=
self
.
portal
.
software_instance_module
.
newContent
(
portal_type
=
portal_type
,
title
=
"Instance %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTINST-%s"
%
new_id
,
destination_reference
=
"TESTINST-%s"
%
new_id
,
ssl_certificate
=
"foo"
,
ssl_key
=
"bar"
,
)
self
.
tic
()
self
.
assertEqual
(
None
,
instance
.
workflow_history
[
'instance_slap_interface_workflow'
][
-
1
][
'action'
])
instance
.
edit
(
**
{
method_id
:
self
.
generateSafeXml
()})
self
.
tic
()
self
.
assertEqual
(
'bang'
,
instance
.
workflow_history
[
'instance_slap_interface_workflow'
][
-
1
][
'action'
])
def
test_change_instance_parameter_onInstanceUrlString
(
self
):
return
self
.
check_change_instance_parameter
(
"Software Instance"
,
'url_string'
)
def
test_change_instance_parameter_onInstanceTextContent
(
self
):
return
self
.
check_change_instance_parameter
(
"Software Instance"
,
'text_content'
)
def
test_change_instance_parameter_onInstanceSourceReference
(
self
):
return
self
.
check_change_instance_parameter
(
"Software Instance"
,
'source_reference'
)
def
test_change_instance_parameter_onInstanceSlaXML
(
self
):
return
self
.
check_change_instance_parameter
(
"Software Instance"
,
'sla_xml'
)
def
test_change_instance_parameter_onSlaveUrlString
(
self
):
return
self
.
check_change_instance_parameter
(
"Slave Instance"
,
'url_string'
)
def
test_change_instance_parameter_onSlaveTextContent
(
self
):
return
self
.
check_change_instance_parameter
(
"Slave Instance"
,
'text_content'
)
def
test_change_instance_parameter_onSlaveSourceReference
(
self
):
return
self
.
check_change_instance_parameter
(
"Slave Instance"
,
'source_reference'
)
def
test_change_instance_parameter_onSlaveSlaXML
(
self
):
return
self
.
check_change_instance_parameter
(
"Slave Instance"
,
'sla_xml'
)
def
test_SoftwareInstance_setPredecessorList
(
self
):
portal_type
=
"Software Instance"
self
.
_makePerson
()
self
.
login
(
self
.
person_user
.
getReference
())
new_id
=
self
.
generateNewId
()
instance3
=
self
.
portal
.
software_instance_module
.
newContent
(
portal_type
=
portal_type
,
title
=
"Instance %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTINST-%s"
%
new_id
,
destination_reference
=
"TESTINST-%s"
%
new_id
,
ssl_certificate
=
"foo"
,
ssl_key
=
"bar"
,
)
new_id
=
self
.
generateNewId
()
instance2
=
self
.
portal
.
software_instance_module
.
newContent
(
portal_type
=
portal_type
,
title
=
"Instance %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTINST-%s"
%
new_id
,
destination_reference
=
"TESTINST-%s"
%
new_id
,
ssl_certificate
=
"foo"
,
ssl_key
=
"bar"
,
predecessor_value
=
instance3
,
)
new_id
=
self
.
generateNewId
()
instance1
=
self
.
portal
.
software_instance_module
.
newContent
(
portal_type
=
portal_type
,
title
=
"Instance %s for %s"
%
(
new_id
,
self
.
person_user
.
getReference
()),
reference
=
"TESTINST-%s"
%
new_id
,
destination_reference
=
"TESTINST-%s"
%
new_id
,
ssl_certificate
=
"foo"
,
ssl_key
=
"bar"
,
predecessor_value
=
instance2
,
)
self
.
tic
()
def
verify_reindexObject_call
(
self
,
*
args
,
**
kw
):
if
self
.
getRelativeUrl
()
in
(
instance2
.
getRelativeUrl
(),
instance3
.
getRelativeUrl
()):
self
.
portal_workflow
.
doActionFor
(
instance1
,
action
=
'edit_action'
,
comment
=
'reindexObject triggered'
)
else
:
return
self
.
reindexObject_call
(
*
args
,
**
kw
)
# Replace activeSense by a dummy method
from
Products.ERP5Type.Base
import
Base
Base
.
reindexObject_call
=
Base
.
reindexObject
Base
.
reindexObject
=
verify_reindexObject_call
try
:
instance1
.
edit
(
predecessor_value
=
instance3
)
self
.
tic
()
finally
:
Base
.
reindexObject
=
Base
.
reindexObject_call
self
.
assertEqual
(
'reindexObject triggered'
,
instance1
.
workflow_history
[
'edit_workflow'
][
-
1
][
'comment'
])
self
.
assertEqual
(
'reindexObject triggered'
,
instance1
.
workflow_history
[
'edit_workflow'
][
-
2
][
'comment'
])
self
.
assertEqual
(
None
,
instance1
.
workflow_history
[
'edit_workflow'
][
-
3
][
'comment'
])
master/bt5/slapos_cloud/bt/revision
View file @
89a6f1c2
246
\ No newline at end of file
247
\ No newline at end of file
master/bt5/slapos_cloud/bt/template_test_id_list
View file @
89a6f1c2
testSlapOSCloudComputerPartitionSlapInterfaceWorkflow
testSlapOSCloudComputerSlapInterfaceWorkflow
testSlapOSCloudAlarm
testSlapOSCloudConstraint
testSlapOSCloudInstanceSlapInterfaceWorkflow
testSlapOSCloudPersonSlapInterfaceWorkflow
testSlapOSCloudPromiseSlapOSModuleIdGeneratorAlarm
testSlapOSCloudSlapOSAllocateInstanceAlarm
testSlapOSCloudSlapOSAssertHostingSubscriptionPredecessorAlarm
testSlapOSCloudSlapOSCloudInteractionWorkflow
testSlapOSCloudSlapOSFreeComputerPartitionAlarm
testSlapOSCloudSlapOSGarbageCollectDestroyedRootTreeAlarm
testSlapOSCloudSlapOSUpdateComputerCapacityScopeAlarm
testSlapOSCloudSecurityGroup
testSlapOSCloudShadow
\ No newline at end of file
testSlapOSCloudShadow
testSlapOSCloudWorkflow
\ No newline at end of file
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