Commit 56fa38cd authored by Romain Courteaud's avatar Romain Courteaud 🐙

slapos_json_rpc_api: 2 tests

parent 08d1e9e9
......@@ -1399,52 +1399,114 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJsonRpcMixin):
self.start_requested_software_instance.getSuccessorTitleList())
def test_InstanceAccess_26_stoppedComputePartition(self):
# XXX Should reported_state added to Instance returned json?
self._makeComplexComputeNode(self.project)
instance = self.start_requested_software_instance
self.login(instance.getUserId())
self.callInstancePutToApiAndCheck({
"reference": instance.getReference(),
"portal_type": "Software Instance",
"reported_state": "stopped",
})
response = self.callJsonRpcWebService("slapos.get.slapos_jio_api_get_software_instance", {
"portal_type": "Software Instance",
"reference": instance.getReference(),
})
instance_dict = json.loads(response.getBody())
self.assertEqual(
instance_dict["access_status_message"],
"#access Instance correctly stopped"
)
self.assertEqual(
instance_dict["state"],
"started"
with PinnedDateTime(self, DateTime('2020/05/19')):
# XXX Should reported_state added to Instance returned json?
self._makeComplexComputeNode(self.project)
instance = self.start_requested_software_instance
response = self.callJsonRpcWebService(
"slapos.put.slapos_jio_api_put_software_instance",
{
"reference": instance.getReference(),
"portal_type": "Software Instance",
"reported_state": "stopped"
},
instance.getUserId()
)
self.assertEqual('application/json', response.headers.get('content-type'))
self.assertEqual({
'reference': instance.getReference(),
'date': '2020-05-19T00:00:00+00:00',
'portal_type': 'Software Instance',
'success': 'Done'
}, byteify(json.loads(response.getBody())))
self.assertEqual(response.getStatus(), 200)
# Check get return the expected results after
response = self.callJsonRpcWebService(
"slapos.get.slapos_jio_api_get_software_instance",
{
"portal_type": "Software Instance",
"reference": instance.getReference(),
},
instance.getUserId()
)
self.assertEqual('application/json', response.headers.get('content-type'))
partition = instance.getAggregateValue(portal_type="Compute Partition")
self.assertEqual({
'access_status_message': "#access Instance correctly stopped",
"compute_node_id": partition.getParentValue().getReference(),
"compute_partition_id": partition.getReference(),
'full_ip_list': [],
'ip_list': [['', 'ip_address_1']],
'portal_type': 'Software Instance',
'processing_timestamp': 1589846400000000,
'reference': instance.getReference(),
'root_instance_title': instance.getSpecialiseTitle(),
'shared': False,
"sla_parameters": instance.getSlaXmlAsDict(),
"parameters": instance.getInstanceXmlAsDict(),
"connection_parameters": instance.getConnectionXmlAsDict(),
'software_release_uri': instance.getUrlString(),
'software_type': instance.getSourceReference(),
'state': 'started',
'title': instance.getTitle()
}, byteify(json.loads(response.getBody())))
self.assertEqual(response.getStatus(), 200)
def test_InstanceAccess_27_startedComputePartition(self):
# XXX Should reported_state added to Instance returned json?
self._makeComplexComputeNode(self.project)
instance = self.start_requested_software_instance
self.login(instance.getUserId())
self.callInstancePutToApiAndCheck({
"reference": instance.getReference(),
"portal_type": "Software Instance",
"reported_state": "started",
})
response = self.callJsonRpcWebService("slapos.get.slapos_jio_api_get_software_instance", {
"portal_type": "Software Instance",
"reference": instance.getReference(),
})
instance_dict = json.loads(response.getBody())
self.assertEqual(
instance_dict["access_status_message"],
"#access Instance correctly started"
)
self.assertEqual(
instance_dict["state"],
"started"
with PinnedDateTime(self, DateTime('2020/05/19')):
# XXX Should reported_state added to Instance returned json?
self._makeComplexComputeNode(self.project)
instance = self.start_requested_software_instance
response = self.callJsonRpcWebService(
"slapos.put.slapos_jio_api_put_software_instance",
{
"reference": instance.getReference(),
"portal_type": "Software Instance",
"reported_state": "started"
},
instance.getUserId()
)
self.assertEqual('application/json', response.headers.get('content-type'))
self.assertEqual({
'reference': instance.getReference(),
'date': '2020-05-19T00:00:00+00:00',
'portal_type': 'Software Instance',
'success': 'Done'
}, byteify(json.loads(response.getBody())))
self.assertEqual(response.getStatus(), 200)
# Check get return the expected results after
response = self.callJsonRpcWebService(
"slapos.get.slapos_jio_api_get_software_instance",
{
"portal_type": "Software Instance",
"reference": instance.getReference(),
},
instance.getUserId()
)
self.assertEqual('application/json', response.headers.get('content-type'))
partition = instance.getAggregateValue(portal_type="Compute Partition")
self.assertEqual({
'access_status_message': "#access Instance correctly started",
"compute_node_id": partition.getParentValue().getReference(),
"compute_partition_id": partition.getReference(),
'full_ip_list': [],
'ip_list': [['', 'ip_address_1']],
'portal_type': 'Software Instance',
'processing_timestamp': 1589846400000000,
'reference': instance.getReference(),
'root_instance_title': instance.getSpecialiseTitle(),
'shared': False,
"sla_parameters": instance.getSlaXmlAsDict(),
"parameters": instance.getInstanceXmlAsDict(),
"connection_parameters": instance.getConnectionXmlAsDict(),
'software_release_uri': instance.getUrlString(),
'software_type': instance.getSourceReference(),
'state': 'started',
'title': instance.getTitle()
}, byteify(json.loads(response.getBody())))
self.assertEqual(response.getStatus(), 200)
class TestSlapOSSlapToolPersonAccess(TestSlapOSJsonRpcMixin):
......
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