Commit 37935769 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Cédric Le Ninivin

slapos_jio_api_style: Improve Software Installation search and add tests

parent 18368070
......@@ -88,11 +88,6 @@
"const": "Software Installation",\n
"type": "string"\n
},\n
"processing_timestamp": {\n
"title": "Processing Timestamp",\n
"type": "number",\n
"description": "Timestamp set by the master node to mark when it was last processed in the master node. If it has been processed on master, it needs reprocessing on the compute node."\n
},\n
"api_revision": {\n
"title": "API Revision",\n
"type": "string",\n
......
import urllib
# Hardcoded
limit = 1000
web_section = context.getWebSectionValue()
......@@ -7,13 +9,12 @@ search_kw = {
"portal_type": "Software Installation",
"validation_state": "validated",
"jio_api_revision.web_section": web_section,
"select_list": ("aggregate_reference", "url_string", "slap_state", "portal_type", "slap_date", "jio_api_revision.revision"),
"select_list": ("aggregate_reference", "url_string", "slap_state", "portal_type", "jio_api_revision.revision"),
"sort_on": ("jio_api_revision.revision", "ASC"),
"limit": limit,
}
if "software_release_uri" in data_dict:
import urllib
search_kw["url_string"] = urllib.unquote(data_dict["software_release_uri"])
if "compute_node_id" in data_dict:
search_kw["strict_aggregate_reference"] = data_dict["compute_node_id"]
......@@ -22,7 +23,7 @@ if "from_api_revision" in data_dict:
result_list = [{
"get_parameters": {
"software_release_uri": x.url_string,
"software_release_uri": urllib.quote(x.url_string),
"compute_node_id": x.aggregate_reference,
"portal_type": x.portal_type,
},
......@@ -31,7 +32,6 @@ result_list = [{
"state": "available" if x.slap_state == "start_requested" else "destroyed",
"api_revision": x.revision,
"portal_type": x.portal_type,
"processing_timestamp": int(x.slap_date),
} for x in context.getPortalObject().portal_catalog(**search_kw)]
if result_list:
......
......@@ -188,7 +188,7 @@ class TestSlapOSJIOAPIMixin(SlapOSTestCaseMixin):
self._cleaupREQUEST()
class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJIOAPIMixin):
def test_01_getFullComputerInformation(self):
def test_01_getFullComputerInformationInstanceList(self):
self._makeComplexComputeNode(with_slave=True)
self.callUpdateRevisionAndTic()
......@@ -275,6 +275,72 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJIOAPIMixin):
"portal_type": instance.getPortalType(),
}, instance_dict)
def test_01_bis_getFullComputerInformationSoftwareList(self):
self._makeComplexComputeNode(with_slave=True)
self.callUpdateRevisionAndTic()
self.login(self.compute_node_user_id)
software_list_response = self.allDocsToApi({
"compute_node_id": self.compute_node_id,
"portal_type": "Software Installation",
})
response = self.portal.REQUEST.RESPONSE
if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % software_list_response)
self.assertEqual('application/json',
response.headers.get('content-type'))
self.assertTrue(software_list_response["$schema"].endswith("jIOWebSection_searchSoftwareInstallationFromJSON/getOutputJSONSchema"))
result_list = software_list_response["result_list"]
self.assertEqual(2, len(result_list))
software_list = [self.start_requested_software_installation, self.destroy_requested_software_installation]
# This is the expected instance list, it is sorted by api_revision
software_list.sort(key=lambda x: x.getJIOAPIRevision(self.web_site.api.getRelativeUrl()))
# Check result_list match instance_list=
expected_software_list = []
for software in software_list:
expected_software_list.append({
"api_revision": software.getJIOAPIRevision(self.web_site.api.getRelativeUrl()),
"get_parameters": {
"portal_type": "Software Installation",
"software_release_uri": urllib.quote(software.getUrlString()),
"compute_node_id": self.compute_node_id
},
"portal_type": "Software Installation",
"software_release_uri": software.getUrlString(),
"state": "available" if software.getSlapState() == "start_requested" else "destroyed",
"compute_node_id": self.compute_node_id,
})
self.assertEqual(expected_software_list, software_list_response["result_list"])
for i in range(len(expected_software_list)):
software_resut_dict = expected_software_list[i]
software = software_list[i]
# Get instance as "user"
self.login(self.compute_node_user_id)
software_dict = self.getToApi(software_resut_dict["get_parameters"])
response = self.portal.REQUEST.RESPONSE
if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % software_dict)
self.assertEqual('application/json',
response.headers.get('content-type'))
# Check Data is correct
self.maxDiff = None
status_dict = software.getAccessStatus()
self.assertEqual({
"$schema": software.getJSONSchemaUrl(),
"api_revision": software.getJIOAPIRevision(self.web_site.api.getRelativeUrl()),
"portal_type": "Software Installation",
"software_release_uri": software.getUrlString(),
"state": "available" if software.getSlapState() == "start_requested" else "destroyed",
"compute_node_id": self.compute_node_id,
"reported_state": status_dict.get("state"),
"status_message": status_dict.get("text"),
}, software_dict)
def test_02_computerBang(self):
self._makeComplexComputeNode()
......
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