Commit 957caa17 authored by Titouan Soulard's avatar Titouan Soulard Committed by Romain Courteaud

slapos_jio_api_style: update references to project_reference

parent 68a93a87
import json
import urllib
compute_node_id = data_dict.get("compute_node_id", None) compute_node_id = data_dict.get("compute_node_id", None)
compute_partition_id = data_dict.get("compute_partition_id", None) compute_partition_id = data_dict.get("compute_partition_id", None)
...@@ -19,7 +22,6 @@ portal = context.getPortalObject() ...@@ -19,7 +22,6 @@ portal = context.getPortalObject()
# Loads partition parameter # Loads partition parameter
partition_parameter = data_dict.get("parameters", None) partition_parameter = data_dict.get("parameters", None)
if partition_parameter: if partition_parameter:
import json
try: try:
partition_parameter = json.loads(partition_parameter) partition_parameter = json.loads(partition_parameter)
except ValueError, e: except ValueError, e:
...@@ -41,7 +43,6 @@ try: ...@@ -41,7 +43,6 @@ try:
filter_kw = data_dict.get("sla_parameters", {}) filter_kw = data_dict.get("sla_parameters", {})
partition_reference = data_dict.get("title") partition_reference = data_dict.get("title")
import urllib
kw = dict(software_release=urllib.unquote(data_dict.get("software_release_uri")), kw = dict(software_release=urllib.unquote(data_dict.get("software_release_uri")),
software_type=data_dict.get("software_type", "RootSoftwareInstance"), software_type=data_dict.get("software_type", "RootSoftwareInstance"),
software_title=partition_reference, software_title=partition_reference,
...@@ -49,7 +50,7 @@ try: ...@@ -49,7 +50,7 @@ try:
shared=data_dict.get("shared", False), shared=data_dict.get("shared", False),
sla_xml=castToStr(filter_kw), sla_xml=castToStr(filter_kw),
state=data_dict.get("state", "started"), state=data_dict.get("state", "started"),
project_reference=data_dict.get("project_reference")) project_reference=data_dict.get("project_reference", None))
if compute_node_id and compute_partition_id: if compute_node_id and compute_partition_id:
compute_partition = portal.portal_catalog.getComputePartitionObject( compute_partition = portal.portal_catalog.getComputePartitionObject(
...@@ -58,8 +59,13 @@ try: ...@@ -58,8 +59,13 @@ try:
) )
requester = compute_partition.getSoftwareInstance() requester = compute_partition.getSoftwareInstance()
instance_tree = requester.getSpecialiseValue() instance_tree = requester.getSpecialiseValue()
if instance_tree is not None and instance_tree.getSlapState() == "stop_requested":
kw['state'] = 'stopped' if instance_tree is not None:
kw["project_reference"] = instance_tree.getFollowUpReference()
if instance_tree.getSlapState() == "stop_requested":
kw['state'] = 'stopped'
key = '_'.join([instance_tree.getRelativeUrl(), partition_reference]) key = '_'.join([instance_tree.getRelativeUrl(), partition_reference])
else: else:
# requested as root, so done by human # requested as root, so done by human
......
...@@ -975,13 +975,11 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -975,13 +975,11 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
try: try:
requestInstance = instance.__class__.requestInstance requestInstance = instance.__class__.requestInstance
project_reference = self.project.getReference()
instance.__class__.requestInstance = calledRequestInstance instance.__class__.requestInstance = calledRequestInstance
partition_id = instance.getAggregateValue(portal_type='Compute Partition').getReference() partition_id = instance.getAggregateValue(portal_type='Compute Partition').getReference()
self.login(instance.getUserId()) self.login(instance.getUserId())
response_dict = self.postToApi({ response_dict = self.postToApi({
"portal_type": "Software Instance", "portal_type": "Software Instance",
"project_reference": project_reference,
"software_release_uri": "req_release", "software_release_uri": "req_release",
"software_type": "req_type", "software_type": "req_type",
"title": "req_reference", "title": "req_reference",
...@@ -996,7 +994,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -996,7 +994,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertEqual(self.called_instance_request, { self.assertEqual(self.called_instance_request, {
'instance_xml': "<?xml version='1.0' encoding='utf-8'?>\n<instance/>\n", 'instance_xml': "<?xml version='1.0' encoding='utf-8'?>\n<instance/>\n",
"project_reference": project_reference, 'project_reference': self.project.getReference(),
'software_title': 'req_reference', 'software_title': 'req_reference',
'software_release': 'req_release', 'software_release': 'req_release',
'state': 'started', 'state': 'started',
...@@ -1024,13 +1022,11 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -1024,13 +1022,11 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
try: try:
requestInstance = instance.__class__.requestInstance requestInstance = instance.__class__.requestInstance
project_reference = self.project.getReference()
instance.__class__.requestInstance = calledRequestInstance instance.__class__.requestInstance = calledRequestInstance
partition_id = instance.getAggregateValue(portal_type='Compute Partition').getReference() partition_id = instance.getAggregateValue(portal_type='Compute Partition').getReference()
self.login(instance.getUserId()) self.login(instance.getUserId())
response_dict = self.postToApi({ response_dict = self.postToApi({
"portal_type": "Software Instance", "portal_type": "Software Instance",
"project_reference": project_reference,
"software_release_uri": "req_release", "software_release_uri": "req_release",
"software_type": "req_type", "software_type": "req_type",
"title": "req_reference", "title": "req_reference",
...@@ -1044,7 +1040,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -1044,7 +1040,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertEqual(self.called_instance_request, { self.assertEqual(self.called_instance_request, {
'instance_xml': "<?xml version='1.0' encoding='utf-8'?>\n<instance/>\n", 'instance_xml': "<?xml version='1.0' encoding='utf-8'?>\n<instance/>\n",
"project_reference": project_reference, 'project_reference': self.project.getReference(),
'software_title': 'req_reference', 'software_title': 'req_reference',
'software_release': 'req_release', 'software_release': 'req_release',
'shared': False, 'shared': False,
...@@ -1072,13 +1068,11 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -1072,13 +1068,11 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
try: try:
requestInstance = instance.__class__.requestInstance requestInstance = instance.__class__.requestInstance
project_reference = self.project.getReference()
instance.__class__.requestInstance = calledRequestInstance instance.__class__.requestInstance = calledRequestInstance
partition_id = instance.getAggregateValue(portal_type='Compute Partition').getReference() partition_id = instance.getAggregateValue(portal_type='Compute Partition').getReference()
self.login(instance.getUserId()) self.login(instance.getUserId())
response_dict = self.postToApi({ response_dict = self.postToApi({
"portal_type": "Software Instance", "portal_type": "Software Instance",
"project_reference": project_reference,
"software_release_uri": "req_release", "software_release_uri": "req_release",
"software_type": "req_type", "software_type": "req_type",
"title": "req_reference", "title": "req_reference",
...@@ -1093,7 +1087,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -1093,7 +1087,7 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertEqual(self.called_instance_request, { self.assertEqual(self.called_instance_request, {
'instance_xml': "<?xml version='1.0' encoding='utf-8'?>\n<instance/>\n", 'instance_xml': "<?xml version='1.0' encoding='utf-8'?>\n<instance/>\n",
"project_reference": project_reference, 'project_reference': self.project.getReference(),
'software_title': 'req_reference', 'software_title': 'req_reference',
'software_release': 'req_release', 'software_release': 'req_release',
'shared': False, 'shared': False,
......
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