summaryrefslogtreecommitdiffstats
path: root/storperf/tests
diff options
context:
space:
mode:
authormbeierl <mark.beierl@emc.com>2015-11-23 08:23:47 -0800
committermbeierl <mark.beierl@emc.com>2015-11-23 20:15:59 -0800
commit002920e29d7fa4a28abec96773b470c90bafe55d (patch)
tree893f45209a84f197ef6ec3848ed83fc9df3eab8f /storperf/tests
parentd480e8746512caf8821c42582e7ab75d25b3127b (diff)
Adding workload modules
Adding the ablity to define workloads in modules which can be referenced from the API. Breaking out the test execution into its own class so it will be easier to support ReST or other interfaces. Added flake8 and code coverage reports where possible to merge and verify jobs Change-Id: Ieb51e4e7e1e989288a6f81f4757709669914a196 JIRA: STORPERF-21 Signed-off-by: mbeierl <mark.beierl@emc.com>
Diffstat (limited to 'storperf/tests')
-rw-r--r--storperf/tests/carbon_tests/__init__.py0
-rw-r--r--storperf/tests/carbon_tests/emitter_test.py68
-rw-r--r--storperf/tests/carbon_tests/json_to_carbon_test.py118
3 files changed, 186 insertions, 0 deletions
diff --git a/storperf/tests/carbon_tests/__init__.py b/storperf/tests/carbon_tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/storperf/tests/carbon_tests/__init__.py
diff --git a/storperf/tests/carbon_tests/emitter_test.py b/storperf/tests/carbon_tests/emitter_test.py
new file mode 100644
index 0000000..c26e837
--- /dev/null
+++ b/storperf/tests/carbon_tests/emitter_test.py
@@ -0,0 +1,68 @@
+##############################################################################
+# Copyright (c) 2015 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
+##############################################################################
+
+import unittest
+
+import json
+import SocketServer
+import threading
+from time import sleep
+
+from carbon import converter
+from carbon.emitter import CarbonMetricTransmitter
+
+
+class MetricsHandler(SocketServer.BaseRequestHandler):
+
+ def handle(self):
+ # Echo the back to the client
+ CarbonMetricTransmitterTest.response = self.request.recv(1024)
+ return
+
+
+class MetricsServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
+ pass
+
+
+class CarbonMetricTransmitterTest(unittest.TestCase):
+ listen_port = 0
+ response = None
+
+ def setUp(self):
+
+ address = ('localhost', 0)
+ server = MetricsServer(address, MetricsHandler)
+ ip, self.listen_port = server.server_address
+
+ t = threading.Thread(target=server.serve_forever)
+ t.setDaemon(True)
+ t.start()
+
+ def test_transmit_metrics(self):
+
+ testconv = converter.JSONToCarbon()
+ json_object = json.loads("""{"timestamp" : "12345", "key":"value" }""")
+ result = testconv.convert_to_dictionary(json_object, "host.run-name")
+
+ emitter = CarbonMetricTransmitter()
+ emitter.carbon_port = self.listen_port
+ emitter.transmit_metrics(result)
+
+ count = 0
+
+ while (CarbonMetricTransmitterTest.response is None and count < 10):
+ count += 1
+ sleep(0.1)
+
+ self.assertEqual("host.run-name.key value 12345\n",
+ CarbonMetricTransmitterTest.response,
+ CarbonMetricTransmitterTest.response)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/storperf/tests/carbon_tests/json_to_carbon_test.py b/storperf/tests/carbon_tests/json_to_carbon_test.py
new file mode 100644
index 0000000..6d62418
--- /dev/null
+++ b/storperf/tests/carbon_tests/json_to_carbon_test.py
@@ -0,0 +1,118 @@
+##############################################################################
+# Copyright (c) 2015 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
+##############################################################################
+
+import unittest
+import json
+
+from carbon.converter import JSONToCarbon
+
+
+class JSONToCarbonTest(unittest.TestCase):
+
+ single_json_text_element = """{ "key" : "value" }"""
+ single_json_numeric_element = """{ "key" : 123 }"""
+ single_json_key_with_spaces = """{ "key with spaces" : "value" }"""
+ single_json_value_with_spaces = """{ "key" : "value with spaces" }"""
+ json_map_name_with_spaces = \
+ """{ "map with spaces" : { "key" : "value" } }"""
+ json_list_name_with_spaces = \
+ """{ "list with spaces" : [{ "key" : "value" }] }"""
+
+ simple_fio_json = """
+{
+ "fio version" : "fio-2.2.10",
+ "timestamp" : 1444144664,
+ "time" : "Tue Oct 6 11:17:44 2015",
+ "jobs" : [
+ {
+ "jobname" : "random-read",
+ "groupid" : 0,
+ "error" : 0,
+ "eta" : 0,
+ "elapsed" : 26,
+ "read" : {
+ "io_bytes" : 7116,
+ "bw" : 275,
+ "iops" : 68.99,
+ "runtime" : 25788,
+ "total_ios" : 1779,
+ "short_ios" : 0,
+ "drop_ios" : 0,
+ "slat" : {
+ "min" : 0,
+ "max" : 0,
+ "mean" : 0.00,
+ "stddev" : 0.00
+ }
+ }
+ }]
+}
+"""
+
+ def setUp(self):
+ pass
+
+ def test_to_string(self):
+ testconv = JSONToCarbon()
+ json_object = json.loads(self.simple_fio_json)
+ result = testconv.convert_to_dictionary(json_object, "host.run-name")
+ self.assertEqual("7116", result[
+ "host.run-name.jobs.1.read.io_bytes"],
+ result["host.run-name.jobs.1.read.io_bytes"])
+
+ def test_single_text_element_no_prefix(self):
+ testconv = JSONToCarbon()
+ result = testconv.convert_to_dictionary(
+ json.loads(self.single_json_text_element))
+
+ self.assertEqual("value", result["key"], result["key"])
+
+ def test_single_numeric_element_no_prefix(self):
+ testconv = JSONToCarbon()
+ result = testconv.convert_to_dictionary(
+ json.loads(self.single_json_numeric_element))
+
+ self.assertEqual("123", result["key"], result["key"])
+
+ def test_single_text_key_space_element_no_prefix(self):
+ testconv = JSONToCarbon()
+ result = testconv.convert_to_dictionary(
+ json.loads(self.single_json_key_with_spaces))
+
+ self.assertEqual(
+ "value", result["key_with_spaces"], result["key_with_spaces"])
+
+ def test_single_text_value_space_element_no_prefix(self):
+ testconv = JSONToCarbon()
+ result = testconv.convert_to_dictionary(
+ json.loads(self.single_json_value_with_spaces))
+
+ self.assertEqual("value_with_spaces", result["key"], result["key"])
+
+ def test_map_name_with_space_no_prefix(self):
+ testconv = JSONToCarbon()
+ result = testconv.convert_to_dictionary(
+ json.loads(self.json_map_name_with_spaces))
+
+ self.assertEqual(
+ "value", result["map_with_spaces.key"],
+ result["map_with_spaces.key"])
+
+ def test_list_name_with_space_no_prefix(self):
+ testconv = JSONToCarbon()
+ result = testconv.convert_to_dictionary(
+ json.loads(self.json_list_name_with_spaces))
+
+ self.assertEqual(
+ "value", result["list_with_spaces.1.key"],
+ result["list_with_spaces.1.key"])
+
+
+if __name__ == '__main__':
+ unittest.main()