self.event_callback_ids = set()
self._remote_host = None
self.callback_id = None
+ self.terminated = False
@property
def remote_host(self):
json_metric = json.loads(self.json_body)
self.json_body = ""
- for event_listener in self.event_listeners:
- try:
+ if not self.terminated:
+ for event_listener in self.event_listeners:
+ try:
+ self.logger.debug(
+ "Event listener callback")
+ event_listener(
+ self.callback_id, json_metric)
+ except Exception, e:
+ self.logger.exception(
+ "Notifying listener %s: %s",
+ self.callback_id, e)
self.logger.debug(
- "Event listener callback")
- event_listener(self.callback_id, json_metric)
- except Exception, e:
- self.logger.exception(
- "Notifying listener %s: %s",
- self.callback_id, e)
- self.logger.debug(
- "Event listener callback complete")
+ "Event listener callback complete")
except Exception, e:
self.logger.error("Error parsing JSON: %s", e)
except IOError:
def terminate(self):
self.logger.debug("Terminating fio on " + self.remote_host)
+ self.terminated = True
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+import copy
def slope(data_series):
[[x1,y1], [x2,y2], ..., [xm,ym]].
If this data pattern were to change, the data_treatement function
should be adjusted to ensure compatibility with the rest of the
- Steady State Dectection module.
+ Steady State Detection module.
"""
# In the particular case of an empty data series
beta2 = None
else: # The general case
+ data_series = copy.deepcopy(data_series)
m = len(data_series)
# To make sure at least one element is a float number so the result
# of the algorithm be a float number
--- /dev/null
+##############################################################################
+# Copyright (c) 2017 Dell EMC and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+from StringIO import StringIO
+import json
+import unittest
+
+from storperf.fio.fio_invoker import FIOInvoker
+
+
+class Test(unittest.TestCase):
+
+ simple_dictionary = {'Key': 'Value'}
+
+ def exceptional_event(self, callback_id, metric):
+ self.exception_called = True
+ raise Exception
+
+ def event(self, callback_id, metric):
+ self.metric = metric
+
+ def setUp(self):
+ self.exception_called = False
+ self.metric = None
+ self.fio_invoker = FIOInvoker()
+
+ def testStdoutValidJSON(self):
+ self.fio_invoker.register(self.event)
+ string = json.dumps(self.simple_dictionary, indent=4, sort_keys=True)
+
+ output = StringIO(string + "\n")
+ self.fio_invoker.stdout_handler(output)
+
+ self.assertEqual(self.simple_dictionary, self.metric)
+
+ def testStdoutValidJSONWithFIOOutput(self):
+ self.fio_invoker.register(self.event)
+ string = json.dumps(self.simple_dictionary, indent=4, sort_keys=True)
+ terminating = "fio: terminating on signal 2\n"
+ output = StringIO(terminating + string + "\n")
+ self.fio_invoker.stdout_handler(output)
+
+ self.assertEqual(self.simple_dictionary, self.metric)
+
+ def testStdoutNoJSON(self):
+ self.fio_invoker.register(self.event)
+ string = "{'key': 'value'}"
+
+ output = StringIO(string + "\n")
+ self.fio_invoker.stdout_handler(output)
+
+ self.assertEqual(None, self.metric)
+
+ def testStdoutInvalidJSON(self):
+ self.fio_invoker.register(self.event)
+ string = "{'key':\n}"
+
+ output = StringIO(string + "\n")
+ self.fio_invoker.stdout_handler(output)
+
+ self.assertEqual(None, self.metric)
+
+ def testStdoutAfterTerminated(self):
+ self.fio_invoker.register(self.event)
+ string = json.dumps(self.simple_dictionary, indent=4, sort_keys=True)
+
+ self.fio_invoker.terminated = True
+ output = StringIO(string + "\n")
+ self.fio_invoker.stdout_handler(output)
+
+ self.assertEqual(None, self.metric)
+
+ def testStdoutCallbackException(self):
+ self.fio_invoker.register(self.exceptional_event)
+ self.fio_invoker.register(self.event)
+ string = json.dumps(self.simple_dictionary, indent=4, sort_keys=True)
+
+ output = StringIO(string + "\n")
+ self.fio_invoker.stdout_handler(output)
+
+ self.assertEqual(self.simple_dictionary, self.metric)
+ self.assertEqual(self.exception_called, True)