Commit 7f6a241c authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Dont calculate things that user has no access into

parent 3242ed28
...@@ -3,14 +3,9 @@ if REQUEST is not None: ...@@ -3,14 +3,9 @@ if REQUEST is not None:
raise Unauthorized raise Unauthorized
node_dict = {} node_dict = {}
partition_dict = {}
for compute_node in compute_node_list: for compute_node in compute_node_list:
reference = compute_node.getReference() node_dict[compute_node.getReference()] = compute_node.getAccessStatus()
node_dict[reference] = compute_node.getAccessStatus()
partition_dict[reference] = compute_node.getComputePartitionNewsDict()
return {"compute_node": node_dict, return {"compute_node": node_dict,
"partition": partition_dict,
"reference": context.getReference(), "reference": context.getReference(),
"portal_type": context.getPortalType(), "portal_type": context.getPortalType()}
"monitor_url": context.Base_getStatusMonitorUrl(compute_node_list=compute_node_list)}
base_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type:"Software Instance" AND ' base_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type:"Software Instance" AND '
if context.getPortalType() in ["Organisation", "Computer Network"]:
if compute_node_list is None:
return ""
compute_node_reference = ",".join([ '"' + i.getReference() + '"' for i in compute_node_list])
return base_url + "aggregate_reference:(%s)" % compute_node_reference
if context.getPortalType() == "Instance Tree": if context.getPortalType() == "Instance Tree":
for connection_parameter in context.InstanceTree_getConnectionParameterList(raw=True): for connection_parameter in context.InstanceTree_getConnectionParameterList(raw=True):
if connection_parameter['connection_key'] == "monitor-setup-url": if connection_parameter['connection_key'] == "monitor-setup-url":
...@@ -15,6 +9,3 @@ if context.getPortalType() == "Instance Tree": ...@@ -15,6 +9,3 @@ if context.getPortalType() == "Instance Tree":
if context.getPortalType() in ["Software Instance", "Slave Instance"]: if context.getPortalType() in ["Software Instance", "Slave Instance"]:
return base_url + "reference:%s" % context.getReference() return base_url + "reference:%s" % context.getReference()
if context.getPortalType() == "Compute Node":
return base_url + "aggregate_reference:%s" % context.getReference()
...@@ -2,14 +2,4 @@ from zExceptions import Unauthorized ...@@ -2,14 +2,4 @@ from zExceptions import Unauthorized
if REQUEST is not None: if REQUEST is not None:
raise Unauthorized raise Unauthorized
def get_compute_partition_dict(): return context.getAccessStatus()
compute_node_dict = context.getAccessStatus()
compute_partition_dict = context.getComputePartitionNewsDict()
return {"compute_node": compute_node_dict,
"partition": compute_partition_dict,
"portal_type": compute_node_dict['portal_type'],
"reference": compute_node_dict['reference'],
"monitor_url": context.Base_getStatusMonitorUrl()}
return get_compute_partition_dict()
...@@ -470,9 +470,7 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -470,9 +470,7 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin):
compute_node = self._makeComputeNode() compute_node = self._makeComputeNode()
self._logFakeAccess(compute_node) self._logFakeAccess(compute_node)
news_dict = compute_node.ComputeNode_getNewsDict() news_dict = compute_node.ComputeNode_getNewsDict()
monitor_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type:"Software Instance" AND aggregate_reference:%s' % (compute_node.getReference()) expected_news_dict = {'created_at': self.created_at,
expected_news_dict = {'compute_node':
{'created_at': self.created_at,
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0, 'no_data_since_5_minutes': 0,
'portal_type': compute_node.getPortalType(), 'portal_type': compute_node.getPortalType(),
...@@ -480,12 +478,7 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -480,12 +478,7 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin):
'since': self.created_at, 'since': self.created_at,
'state': 'start_requested', 'state': 'start_requested',
'text': '#access OK', 'text': '#access OK',
'user': 'SlapOS Master'}, 'user': 'SlapOS Master'}
'partition': {},
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference(),
'monitor_url': monitor_url
}
self.assertEqual(_decode_with_json(news_dict), self.assertEqual(_decode_with_json(news_dict),
_decode_with_json(expected_news_dict)) _decode_with_json(expected_news_dict))
self.tic() self.tic()
...@@ -500,10 +493,8 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -500,10 +493,8 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin):
state='stop_requested') state='stop_requested')
news_dict = compute_node.ComputeNode_getNewsDict() news_dict = compute_node.ComputeNode_getNewsDict()
compute_node.getSlapState = fakeStopRequestedSlapState compute_node.getSlapState = fakeStopRequestedSlapState
monitor_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type:"Software Instance" AND aggregate_reference:%s' % (compute_node.getReference())
expected_news_dict = {'compute_node': expected_news_dict = {'created_at': self.created_at,
{'created_at': self.created_at,
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0, 'no_data_since_5_minutes': 0,
'portal_type': compute_node.getPortalType(), 'portal_type': compute_node.getPortalType(),
...@@ -511,11 +502,7 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -511,11 +502,7 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin):
'since': self.created_at, 'since': self.created_at,
'state': 'stop_requested', 'state': 'stop_requested',
'text': '#access OK', 'text': '#access OK',
'user': 'SlapOS Master'}, 'user': 'SlapOS Master'
'partition': {},
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference(),
'monitor_url': monitor_url
} }
self.assertEqual(_decode_with_json(news_dict), self.assertEqual(_decode_with_json(news_dict),
_decode_with_json(expected_news_dict)) _decode_with_json(expected_news_dict))
...@@ -531,10 +518,8 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -531,10 +518,8 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin):
state='destroy_requested') state='destroy_requested')
news_dict = compute_node.ComputeNode_getNewsDict() news_dict = compute_node.ComputeNode_getNewsDict()
compute_node.getSlapState = fakeDestroyRequestedSlapState compute_node.getSlapState = fakeDestroyRequestedSlapState
monitor_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type:"Software Instance" AND aggregate_reference:%s' % (compute_node.getReference())
expected_news_dict = {'compute_node': expected_news_dict = {'created_at': self.created_at,
{'created_at': self.created_at,
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
'no_data_since_5_minutes': 0, 'no_data_since_5_minutes': 0,
'portal_type': compute_node.getPortalType(), 'portal_type': compute_node.getPortalType(),
...@@ -542,11 +527,7 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -542,11 +527,7 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin):
'since': self.created_at, 'since': self.created_at,
'state': 'destroy_requested', 'state': 'destroy_requested',
'text': '#access OK', 'text': '#access OK',
'user': 'SlapOS Master'}, 'user': 'SlapOS Master'
'partition': {},
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference(),
'monitor_url': monitor_url
} }
self.assertEqual(_decode_with_json(news_dict), self.assertEqual(_decode_with_json(news_dict),
_decode_with_json(expected_news_dict)) _decode_with_json(expected_news_dict))
...@@ -559,20 +540,14 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -559,20 +540,14 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin):
def test_no_data(self): def test_no_data(self):
compute_node = self._makeComputeNode() compute_node = self._makeComputeNode()
news_dict = compute_node.ComputeNode_getNewsDict() news_dict = compute_node.ComputeNode_getNewsDict()
monitor_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type:"Software Instance" AND aggregate_reference:%s' % (compute_node.getReference()) expected_news_dict = {'created_at': self.created_at,
expected_news_dict = {'compute_node': 'no_data': 1,
{'created_at': self.created_at,
'no_data': 1,
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference(),
'since': self.created_at,
'state': '',
'text': '#error no data found for %s' % compute_node.getReference(),
'user': 'SlapOS Master'},
'partition': {},
'portal_type': compute_node.getPortalType(), 'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference(), 'reference': compute_node.getReference(),
'monitor_url': monitor_url 'since': self.created_at,
'state': '',
'text': '#error no data found for %s' % compute_node.getReference(),
'user': 'SlapOS Master'
} }
self.assertEqual(_decode_with_json(news_dict), self.assertEqual(_decode_with_json(news_dict),
_decode_with_json(expected_news_dict)) _decode_with_json(expected_news_dict))
...@@ -586,32 +561,19 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -586,32 +561,19 @@ class TestComputeNode_getNewsDict(TestSlapOSHalJsonStyleMixin):
compute_node = self._makeComputeNode() compute_node = self._makeComputeNode()
instance = self._makeInstance() instance = self._makeInstance()
instance.setAggregateValue(self.partition0) instance.setAggregateValue(self.partition0)
monitor_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type:"Software Instance" AND aggregate_reference:%s' % (compute_node.getReference())
self.tic() self.tic()
self._logFakeAccess(compute_node) self._logFakeAccess(compute_node)
news_dict = compute_node.ComputeNode_getNewsDict() news_dict = compute_node.ComputeNode_getNewsDict()
expected_news_dict = {'compute_node': expected_news_dict = {u'created_at': u'%s' % self.created_at,
{u'created_at': u'%s' % self.created_at, 'no_data_since_15_minutes': 0,
'no_data_since_15_minutes': 0, 'no_data_since_5_minutes': 0,
'no_data_since_5_minutes': 0,
'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference(),
u'since': u'%s' % self.created_at,
u'state': u'start_requested',
u'text': u'#access OK',
u'user': u'SlapOS Master'},
'partition': {self.partition0.getReference(): {'created_at': self.created_at,
'no_data': 1,
'portal_type': instance.getPortalType(),
'reference': instance.getReference(),
'since': self.created_at,
'state': '',
'text': '#error no data found for %s' % (instance.getReference()),
'user': 'SlapOS Master'}},
'portal_type': compute_node.getPortalType(), 'portal_type': compute_node.getPortalType(),
'reference': compute_node.getReference(), 'reference': compute_node.getReference(),
'monitor_url': monitor_url u'since': u'%s' % self.created_at,
u'state': u'start_requested',
u'text': u'#access OK',
u'user': u'SlapOS Master'
} }
self.assertEqual(_decode_with_json(news_dict), self.assertEqual(_decode_with_json(news_dict),
_decode_with_json(expected_news_dict)) _decode_with_json(expected_news_dict))
...@@ -634,7 +596,7 @@ class TestComputerNetwork_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -634,7 +596,7 @@ class TestComputerNetwork_getNewsDict(TestSlapOSHalJsonStyleMixin):
self.tic() self.tic()
self._logFakeAccess(compute_node) self._logFakeAccess(compute_node)
news_dict = network.ComputerNetwork_getNewsDict() news_dict = network.ComputerNetwork_getNewsDict()
expected_news_dict = {'compute_node': expected_news_dict = {'compute_node': (
{ compute_node.getReference(): { compute_node.getReference():
{u'created_at': u'%s' % self.created_at, {u'created_at': u'%s' % self.created_at,
'no_data_since_15_minutes': 0, 'no_data_since_15_minutes': 0,
...@@ -644,24 +606,10 @@ class TestComputerNetwork_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -644,24 +606,10 @@ class TestComputerNetwork_getNewsDict(TestSlapOSHalJsonStyleMixin):
u'since': u'%s' % self.created_at, u'since': u'%s' % self.created_at,
u'state': u'start_requested', u'state': u'start_requested',
u'text': u'#access OK', u'text': u'#access OK',
u'user': u'SlapOS Master'}}, u'user': u'SlapOS Master'}}
'monitor_url': 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type:"Software Instance" AND aggregate_reference:("%s")' % (
compute_node.getReference()
), ),
'portal_type': network.getPortalType(), 'portal_type': network.getPortalType(),
'reference': network.getReference(), 'reference': network.getReference()
'partition':
{ compute_node.getReference():
{self.partition0.getReference(): {'created_at': self.created_at,
'no_data': 1,
'portal_type': instance.getPortalType(),
'reference': instance.getReference(),
'since': self.created_at,
'state': '',
'text': '#error no data found for %s' % (instance.getReference()),
'user': 'SlapOS Master'}
}
}
} }
...@@ -673,8 +621,6 @@ class TestComputerNetwork_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -673,8 +621,6 @@ class TestComputerNetwork_getNewsDict(TestSlapOSHalJsonStyleMixin):
news_dict = network.ComputerNetwork_getNewsDict() news_dict = network.ComputerNetwork_getNewsDict()
expected_news_dict = { expected_news_dict = {
'compute_node': {}, 'compute_node': {},
'partition': {},
'monitor_url': 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type:"Software Instance" AND aggregate_reference:()',
'portal_type': network.getPortalType(), 'portal_type': network.getPortalType(),
'reference': network.getReference()} 'reference': network.getReference()}
self.assertEqual(_decode_with_json(news_dict), self.assertEqual(_decode_with_json(news_dict),
...@@ -695,9 +641,6 @@ class TestOrganisation_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -695,9 +641,6 @@ class TestOrganisation_getNewsDict(TestSlapOSHalJsonStyleMixin):
self._logFakeAccess(compute_node) self._logFakeAccess(compute_node)
news_dict = organisation.Organisation_getNewsDict() news_dict = organisation.Organisation_getNewsDict()
expected_news_dict = { expected_news_dict = {
'monitor_url': 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type:"Software Instance" AND aggregate_reference:("%s")' % (
compute_node.getReference()
),
'portal_type': 'Organisation', 'portal_type': 'Organisation',
'reference': organisation.getReference(), 'reference': organisation.getReference(),
'compute_node': 'compute_node':
...@@ -710,19 +653,7 @@ class TestOrganisation_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -710,19 +653,7 @@ class TestOrganisation_getNewsDict(TestSlapOSHalJsonStyleMixin):
u'since': u'%s' % self.created_at, u'since': u'%s' % self.created_at,
u'state': u'start_requested', u'state': u'start_requested',
u'text': u'#access OK', u'text': u'#access OK',
u'user': u'SlapOS Master'}}, u'user': u'SlapOS Master'}}
'partition':
{ compute_node.getReference():
{self.partition0.getReference(): {'created_at': self.created_at,
'no_data': 1,
'portal_type': instance.getPortalType(),
'reference': instance.getReference(),
'since': self.created_at,
'state': '',
'text': '#error no data found for %s' % (instance.getReference()),
'user': 'SlapOS Master'}
}
}
} }
...@@ -734,8 +665,6 @@ class TestOrganisation_getNewsDict(TestSlapOSHalJsonStyleMixin): ...@@ -734,8 +665,6 @@ class TestOrganisation_getNewsDict(TestSlapOSHalJsonStyleMixin):
news_dict = organisation.Organisation_getNewsDict() news_dict = organisation.Organisation_getNewsDict()
expected_news_dict = { expected_news_dict = {
'compute_node': {}, 'compute_node': {},
'partition': {},
'monitor_url': 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type:"Software Instance" AND aggregate_reference:()',
'portal_type': 'Organisation', 'portal_type': 'Organisation',
'reference': organisation.getReference()} 'reference': organisation.getReference()}
self.assertEqual(_decode_with_json(news_dict), self.assertEqual(_decode_with_json(news_dict),
......
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