Commit 80551fca authored by Alain Takoudjou's avatar Alain Takoudjou Committed by Rafael Monnerat

Computer request software instance workflow

parent 00b13ea2
......@@ -333,6 +333,220 @@ class TestSlapOSCoreComputerSlapInterfaceWorkflow(testSlapOSMixin):
self.computer.requestSoftwareRelease, software_release_url=url,
state='available')
transaction.abort()
def test_Computer_requestSoftwareInstance_returnHostingSubscription(self):
self._makePerson()
self.computer.edit(source_administration=self.person_user.getRelativeUrl())
self.tic()
self.login(self.person_user.getReference())
software_release = self.generateNewSoftwareReleaseUrl()
software_title = "Test Software Instance from Computer"
software_type = "test"
instance_xml = """<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
shared = True
state = "started"
computer = self.computer
expected_sla_xml = """<?xml version='1.0' encoding='utf-8'?><instance>
<parameter id="computer_guid">%s</parameter>
</instance>
""" % computer.getReference()
computer.requestSoftwareInstance(
software_release=software_release,
software_title=software_title,
software_type=software_type,
instance_xml=instance_xml,
shared=shared,
state=state,
)
hosting_subscription = computer.REQUEST.get('request_hosting_subscription')
self.assertEquals("Hosting Subscription",
hosting_subscription.getPortalType())
self.assertEquals(computer.getRelativeUrl(),
hosting_subscription.getAggregateValue().getRelativeUrl())
self.assertEquals(hosting_subscription.getSlaXml(), expected_sla_xml)
self.assertEquals(hosting_subscription.getPredecessorValue().getSlaXml(),
expected_sla_xml)
def test_Computer_requestSoftwareInstance_requiredParameter(self):
self._makePerson()
self.computer.edit(source_administration=self.person_user.getRelativeUrl())
self.tic()
self.login(self.person_user.getReference())
software_release = self.generateNewSoftwareReleaseUrl()
software_title = "Test Software Instance from Computer"
software_type = "test"
instance_xml = """<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
shared = True
state = "started"
computer = self.computer
self.assertRaises(TypeError, computer.requestSoftwareInstance)
# software_release is mandatory
self.assertRaises(TypeError, computer.requestSoftwareInstance,
software_title=software_title,
software_type=software_type,
instance_xml=instance_xml,
shared=shared,
state=state,
)
# software_title is mandatory
self.assertRaises(TypeError, computer.requestSoftwareInstance,
software_release=software_release,
software_type=software_type,
instance_xml=instance_xml,
shared=shared,
state=state,
)
# software_type is mandatory
self.assertRaises(TypeError, computer.requestSoftwareInstance,
software_release=software_release,
software_title=software_title,
instance_xml=instance_xml,
shared=shared,
state=state,
)
# instance_xml is mandatory
self.assertRaises(TypeError, computer.requestSoftwareInstance,
software_release=software_release,
software_title=software_title,
software_type=software_type,
shared=shared,
state=state,
)
# shared is mandatory
self.assertRaises(TypeError, computer.requestSoftwareInstance,
software_release=software_release,
software_title=software_title,
software_type=software_type,
instance_xml=instance_xml,
state=state,
)
# state is mandatory
self.assertRaises(TypeError, computer.requestSoftwareInstance,
software_release=software_release,
software_title=software_title,
software_type=software_type,
instance_xml=instance_xml,
shared=shared,
)
def test_Computer_requestSoftwareInstance_acceptedState(self):
self._makePerson()
self.computer.edit(source_administration=self.person_user.getRelativeUrl())
self.tic()
self.login(self.person_user.getReference())
software_release = self.generateNewSoftwareReleaseUrl()
software_title = "Test Software Instance from Computer"
software_type = "test"
instance_xml = """<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
shared = True
state = "started"
computer = self.computer
# Only started, stopped, destroyed
self.assertRaises(ValueError, computer.requestSoftwareInstance,
software_release=software_release,
software_title=software_title,
software_type=software_type,
instance_xml=instance_xml,
shared=shared,
state="foo",
)
computer.requestSoftwareInstance(
software_release=software_release,
software_title="Computer started Software Instance",
software_type=software_type,
instance_xml=instance_xml,
shared=shared,
state="started",
)
hosting_subscription = computer.REQUEST.get('request_hosting_subscription')
self.assertEquals("start_requested", hosting_subscription.getSlapState())
computer.requestSoftwareInstance(
software_release=software_release,
software_title="Computer stopped Software Instance",
software_type=software_type,
instance_xml=instance_xml,
shared=shared,
state="stopped",
)
hosting_subscription = computer.REQUEST.get('request_hosting_subscription')
self.assertEquals("stop_requested", hosting_subscription.getSlapState())
computer.requestSoftwareInstance(
software_release=software_release,
software_title="Computer destroyed Software Instance",
software_type=software_type,
instance_xml=instance_xml,
shared=shared,
state="destroyed",
)
hosting_subscription = computer.REQUEST.get('request_hosting_subscription')
self.assertEquals(None, hosting_subscription)
def test_Computer_requestSoftwareInstance_duplicatedHostingSubscription(self):
self._makePerson()
self.computer.edit(source_administration=self.person_user.getRelativeUrl())
self.tic()
self.login(self.person_user.getReference())
software_release = self.generateNewSoftwareReleaseUrl()
software_title = "Test Software Instance from Computer"
software_type = "test"
instance_xml = """<?xml version="1.0" encoding="utf-8"?>
<instance>
</instance>
"""
shared = True
state = "started"
computer = self.computer
computer.requestSoftwareInstance(
software_release=software_release,
software_title=software_title,
software_type=software_type,
instance_xml=instance_xml,
shared=shared,
state=state,
)
hosting_subscription = computer.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, computer.requestSoftwareInstance,
software_release=software_release,
software_title=software_title,
software_type=software_type,
instance_xml=instance_xml,
shared=shared,
state=state,
)
def test_revokeCertificate(self):
self.login(self.computer.getReference())
......@@ -501,7 +715,7 @@ class TestSlapOSCorePersonComputerSupply(testSlapOSMixin):
def test_supply_available_createdSoftwareInstallation(self):
previous_id = self.getPortalObject().portal_ids\
.generateNewId(id_group='slap_software_installation_reference',
.generateNewId(id_group='slap_software_installation_reference',
id_generator='uid')
software_release = self.generateNewSoftwareReleaseUrl()
......@@ -525,7 +739,7 @@ class TestSlapOSCorePersonComputerSupply(testSlapOSMixin):
def test_multiple_supply_available_createdSoftwareInstallation(self):
previous_id = self.getPortalObject().portal_ids\
.generateNewId(id_group='slap_software_installation_reference',
.generateNewId(id_group='slap_software_installation_reference',
id_generator='uid')
software_release = self.generateNewSoftwareReleaseUrl()
......@@ -557,7 +771,7 @@ class TestSlapOSCorePersonComputerSupply(testSlapOSMixin):
def test_supply_available_destroyed(self):
previous_id = self.getPortalObject().portal_ids\
.generateNewId(id_group='slap_software_installation_reference',
.generateNewId(id_group='slap_software_installation_reference',
id_generator='uid')
software_release = self.generateNewSoftwareReleaseUrl()
......@@ -598,7 +812,7 @@ class TestSlapOSCorePersonComputerSupply(testSlapOSMixin):
def test_supply_available_destroyed_available(self):
previous_id = self.getPortalObject().portal_ids\
.generateNewId(id_group='slap_software_installation_reference',
.generateNewId(id_group='slap_software_installation_reference',
id_generator='uid')
software_release = self.generateNewSoftwareReleaseUrl()
......@@ -645,7 +859,7 @@ class TestSlapOSCorePersonComputerSupply(testSlapOSMixin):
def test_supply_available_destroyed_finalised_available(self):
previous_id = self.getPortalObject().portal_ids\
.generateNewId(id_group='slap_software_installation_reference',
.generateNewId(id_group='slap_software_installation_reference',
id_generator='uid')
software_release = self.generateNewSoftwareReleaseUrl()
......@@ -2145,7 +2359,7 @@ class TestSlapOSCorePersonRequest(testSlapOSMixin):
state=state,
)
hosting_subscription = person.REQUEST.get('request_hosting_subscription')
self.assertEquals("Hosting Subscription",
self.assertEquals("Hosting Subscription",
hosting_subscription.getPortalType())
def test_Person_requestSoftwareInstance_createHostingSubscription(self):
......@@ -2163,7 +2377,7 @@ class TestSlapOSCorePersonRequest(testSlapOSMixin):
state = "started"
previous_id = self.getPortalObject().portal_ids\
.generateNewId(id_group='slap_hosting_subscription_reference',
.generateNewId(id_group='slap_hosting_subscription_reference',
id_generator='uid')
person.requestSoftwareInstance(
......@@ -2753,7 +2967,7 @@ class TestSlapOSCoreSlapOSCloudInteractionWorkflow(testSlapOSMixin):
def verify_activeSense_call(self):
if self.getRelativeUrl() == 'portal_alarms/slapos_allocate_instance':
instance.portal_workflow.doActionFor(instance, action='edit_action',
instance.portal_workflow.doActionFor(instance, action='edit_action',
comment='activeSense triggered')
else:
return self.activeSense_call()
......@@ -2819,7 +3033,7 @@ class TestSlapOSCoreSlapOSCloudInteractionWorkflow(testSlapOSMixin):
def verify_reindexObject_call(self, *args, **kw):
if self.getRelativeUrl() == computer.getRelativeUrl():
computer.portal_workflow.doActionFor(computer, action='edit_action',
computer.portal_workflow.doActionFor(computer, action='edit_action',
comment='reindexObject triggered on %s' % method_id)
else:
return self.reindexObject_call(*args, **kw)
......@@ -2880,7 +3094,7 @@ class TestSlapOSCoreSlapOSCloudInteractionWorkflow(testSlapOSMixin):
def verify_reindexObject_call(self, *args, **kw):
if self.getRelativeUrl() == partition.getRelativeUrl():
partition.portal_workflow.doActionFor(partition, action='edit_action',
partition.portal_workflow.doActionFor(partition, action='edit_action',
comment='reindexObject triggered on %s' % method_id)
else:
return self.reindexObject_call(*args, **kw)
......@@ -3005,7 +3219,7 @@ class TestSlapOSCoreSlapOSCloudInteractionWorkflow(testSlapOSMixin):
def verify_reindexObject_call(self, *args, **kw):
if self.getRelativeUrl() in (instance2.getRelativeUrl(),
instance3.getRelativeUrl()):
self.portal_workflow.doActionFor(instance1, action='edit_action',
self.portal_workflow.doActionFor(instance1, action='edit_action',
comment='reindexObject triggered')
else:
return self.reindexObject_call(*args, **kw)
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
computer = state_change[\'object\']\n
person = computer.getSourceAdministrationValue()\n
\n
# Get required arguments\n
kwargs = state_change.kwargs\n
\n
# Required args\n
# Raise TypeError if all parameters are not provided\n
try:\n
software_release_url_string = kwargs[\'software_release\']\n
software_title = kwargs["software_title"]\n
software_type = kwargs["software_type"]\n
instance_xml = kwargs["instance_xml"]\n
is_slave = kwargs["shared"]\n
root_state = kwargs["state"]\n
except KeyError:\n
raise TypeError, "Computer_requestSoftwareInstance takes exactly 6 arguments"\n
\n
if person is None:\n
return\n
\n
sla_xml = """<?xml version=\'1.0\' encoding=\'utf-8\'?><instance>\n
<parameter id="computer_guid">%s</parameter>\n
</instance>\n
""" % computer.getReference()\n
\n
person.requestSoftwareInstance(\n
state=root_state,\n
software_release=software_release_url_string,\n
software_title=software_title,\n
software_type=software_type,\n
instance_xml=instance_xml,\n
sla_xml=sla_xml,\n
shared=is_slave\n
)\n
\n
hosting_subscription = context.REQUEST.get(\'request_hosting_subscription\', None)\n
if hosting_subscription is None:\n
return\n
\n
hosting_subscription.setAggregateValue(computer)\n
]]></string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Computer_requestSoftwareInstanceChange</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -26,6 +26,7 @@
<string>generate_certificate</string>
<string>report_computer_bang</string>
<string>request_computer_registration</string>
<string>request_software_instance</string>
<string>request_software_release</string>
<string>revoke_certificate</string>
</tuple>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="TransitionDefinition" module="Products.DCWorkflow.Transitions"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</string> </value>
</item>
<item>
<key> <string>actbox_icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value> <string>Computer_requestSoftwareInstanceChange</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>request_software_instance</string> </value>
</item>
<item>
<key> <string>new_state_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>script_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
323
\ No newline at end of file
324
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment