Commit 5cb2dce0 authored by Rafael Monnerat's avatar Rafael Monnerat

[slapos_rest_api] Fix Filtering of instances

  This implementation is not optimal from performance point of view,
  however the fix is more urgent and the current implementation has
  nearly the same performance outcome.

  Optimisation should come later on query less objects per time.
parent e798948c
......@@ -608,16 +608,19 @@ class StatusPublisher(GenericPublisher):
"portal_categories/allocation_scope/open/public", None).getUid()
kw = dict(
portal_type=('Computer', 'Software Instance'),
validation_state="validated",
default_allocation_scope_uid=[open_friend,
open_personal,
open_public],
slap_state=['start_requested','stop_requested']
)
portal_type=['Computer', 'Software Instance']
)
d = {"list": []}
a = d['list'].append
for si in self.getPortalObject().portal_catalog(**kw):
if si.getPortalType() == "Software Instance" and \
si.getSlapState() not in ['start_requested','stop_requested']:
continue
if si.getPortalType() == "Computer" and \
si.getAllocationScopeUid() not in [open_friend, open_personal, open_public]:
continue
a('/'.join([self.getAPIRoot(), 'status', si.getRelativeUrl()]))
try:
d['list'][0]
......
......@@ -1916,8 +1916,18 @@ class TestStatusGET(SlapOSRestAPIV1InstanceMixin):
self.assertBasicResponse()
self.assertResponseCode(204)
def test_search_existing_instance(self):
def test_search_existing_start_instance(self):
self.software_instance = self.createSoftwareInstance(self.customer)
self.software_instance.workflow_history[\
'instance_slap_interface_workflow'].append({
'comment':'Directly in Started state',
'error_message': '',
'actor': 'ERP5TypeTestCase',
'slap_state': 'start_requested',
'time': DateTime(),
'action': 'foo_transition'})
transaction.commit()
self.software_instance.recursiveImmediateReindexObject()
transaction.commit()
self.connection.request(method='GET',
url='/'.join([self.api_path, 'status']),
......@@ -1932,9 +1942,21 @@ class TestStatusGET(SlapOSRestAPIV1InstanceMixin):
self.software_instance.getRelativeUrl()])]
}, self.json_response)
def test_check_no_destroyed_instance(self):
def test_search_existing_stop_instance(self):
self.software_instance = self.createSoftwareInstance(self.customer)
self.software_instance.edit(slap_state='destroy_requested')
self.software_instance.workflow_history[\
'instance_slap_interface_workflow'].append({
'comment':'Directly in stop state',
'error_message': '',
'actor': 'ERP5TypeTestCase',
'slap_state': 'stop_requested',
'time': DateTime(),
'action': 'foo_transition'})
transaction.commit()
self.software_instance.recursiveImmediateReindexObject()
transaction.commit()
self.connection.request(method='GET',
url='/'.join([self.api_path, 'status']),
......@@ -1945,7 +1967,27 @@ class TestStatusGET(SlapOSRestAPIV1InstanceMixin):
self.assertCacheControlHeader()
self.assertResponseJson()
self.assertEqual({
'list': []
'list': ['/'.join([self.api_url, 'status',
self.software_instance.getRelativeUrl()])]
}, self.json_response)
def test_check_no_destroyed_instance(self):
self.software_instance = self.createSoftwareInstance(self.customer)
self.software_instance.workflow_history[\
'instance_slap_interface_workflow'].append({
'comment':'Directly in destroyed state',
'error_message': '',
'actor': 'ERP5TypeTestCase',
'slap_state': 'destroy_requested',
'time': DateTime(),
'action': 'foo_transition'})
transaction.commit()
self.software_instance.recursiveImmediateReindexObject()
transaction.commit()
self.connection.request(method='GET',
url='/'.join([self.api_path, 'status']),
headers={'REMOTE_USER': self.customer_reference})
self.prepareResponse()
self.assertBasicResponse()
self.assertResponseCode(204)
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