From 7602a54309adbe5c5346ee6befecc2e596976504 Mon Sep 17 00:00:00 2001 From: mbeierl Date: Tue, 11 Jul 2017 15:12:35 -0400 Subject: Change all paths Changes the paths of all source code so that it exists under the dockerfile location for each container. This way we can use COPY instead of git clone, as well as use the existing JJB. Change-Id: I883b2957d89659c164fff0a1ebc4d677c534796d JIRA: STORPERF-188 Signed-off-by: mbeierl --- docker/storperf-master/tests/db_tests/__init__.py | 8 + .../tests/db_tests/configuration_db_test.py | 71 ++++++++ .../tests/db_tests/graphite_db_test.py | 112 ++++++++++++ .../storperf-master/tests/db_tests/job_db_test.py | 198 +++++++++++++++++++++ 4 files changed, 389 insertions(+) create mode 100644 docker/storperf-master/tests/db_tests/__init__.py create mode 100644 docker/storperf-master/tests/db_tests/configuration_db_test.py create mode 100644 docker/storperf-master/tests/db_tests/graphite_db_test.py create mode 100644 docker/storperf-master/tests/db_tests/job_db_test.py (limited to 'docker/storperf-master/tests/db_tests') diff --git a/docker/storperf-master/tests/db_tests/__init__.py b/docker/storperf-master/tests/db_tests/__init__.py new file mode 100644 index 0000000..73334c7 --- /dev/null +++ b/docker/storperf-master/tests/db_tests/__init__.py @@ -0,0 +1,8 @@ +############################################################################## +# 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 +############################################################################## diff --git a/docker/storperf-master/tests/db_tests/configuration_db_test.py b/docker/storperf-master/tests/db_tests/configuration_db_test.py new file mode 100644 index 0000000..d8b021a --- /dev/null +++ b/docker/storperf-master/tests/db_tests/configuration_db_test.py @@ -0,0 +1,71 @@ +############################################################################## +# 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 +############################################################################## + +from storperf.db.configuration_db import ConfigurationDB +import os +import unittest + + +class ConfigurationDBTest(unittest.TestCase): + + def setUp(self): + ConfigurationDB.db_name = __name__ + '.db' + try: + os.remove(ConfigurationDB.db_name) + except OSError: + pass + self.config_db = ConfigurationDB() + + def tearDown(self): + try: + os.remove(ConfigurationDB.db_name) + except OSError: + pass + + def test_create_key(self): + expected = "ABCDE-12345" + + self.config_db.set_configuration_value( + "test", "key", expected) + + actual = self.config_db.get_configuration_value( + "test", "key") + + self.assertEqual( + expected, actual, "Did not expect: " + str(actual)) + + def test_update_key(self): + expected = "ABCDE-12345" + + self.config_db.set_configuration_value( + "test", "key", "initial_value") + + self.config_db.set_configuration_value( + "test", "key", expected) + + actual = self.config_db.get_configuration_value( + "test", "key") + + self.assertEqual( + expected, actual, "Did not expect: " + str(actual)) + + def test_deleted_key(self): + expected = None + + self.config_db.set_configuration_value( + "test", "key", "initial_value") + + self.config_db.delete_configuration_value( + "test", "key") + + actual = self.config_db.get_configuration_value( + "test", "key") + + self.assertEqual( + expected, actual, "Did not expect: " + str(actual)) diff --git a/docker/storperf-master/tests/db_tests/graphite_db_test.py b/docker/storperf-master/tests/db_tests/graphite_db_test.py new file mode 100644 index 0000000..d4c6fb6 --- /dev/null +++ b/docker/storperf-master/tests/db_tests/graphite_db_test.py @@ -0,0 +1,112 @@ +############################################################################## +# Copyright (c) 2016 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 mock + +from storperf.db.graphite_db import GraphiteDB + + +class MockResponse(): + + def __init__(self): + self.content = "" + self.status_code = 200 + + +class GraphiteDBTest(unittest.TestCase): + + def setUp(self): + self.graphdb = GraphiteDB() + self.graphdb._job_db = self + + def test_wildcard_pattern(self): + workload = "job_id" + expected = "job_id.*.*.*.*.*.*" + actual = self.graphdb.make_fullname_pattern(workload) + self.assertEqual(expected, actual, actual) + + def test_no_wildcard_pattern(self): + workload = "job_id.workload.host.queue-depth.1.block-size.16" + actual = self.graphdb.make_fullname_pattern(workload) + self.assertEqual(workload, actual, actual) + + def test_fetch_averages(self): + # self.graphdb.fetch_averages(u'32d31724-fac1-44f3-9033-ca8e00066a36') + pass + + @mock.patch("requests.get") + def test_fetch_series(self, mock_requests): + + response = MockResponse() + response.content = """ +[ + { + "datapoints": [ + [null,1480455880], + [null,1480455890], + [null,1480455900], + [205.345,1480455910], + [201.59,1480455920], + [205.76,1480455930], + [null,1480455940], + [null,1480455950], + [null,1480455960], + [215.655,1480455970], + [214.16,1480455980], + [213.57,1480455990], + [null,1480456000], + [null,1480456010], + [null,1480456020], + [219.37,1480456030], + [219.28,1480456040], + [217.75,1480456050], + [null,1480456060] + ], + "target":"averageSeries(.8192.*.jobs.1.write.iops)" + } +]""" + expected = [[1480455910, 205.345], + [1480455920, 201.59], + [1480455930, 205.76], + [1480455970, 215.655], + [1480455980, 214.16], + [1480455990, 213.57], + [1480456030, 219.37], + [1480456040, 219.28], + [1480456050, 217.75]] + + mock_requests.side_effect = (response, ) + + actual = self.graphdb.fetch_series("workload", "iops", + "write", 0, 600) + self.assertEqual(expected, actual) + + def fetch_workloads(self, workload): + workloads = [[u'32d31724-fac1-44f3-9033-ca8e00066a36.' + u'_warm_up.queue-depth.32.block-size.8192.10-9-15-151', + u'1462379653', u'1462379893'], + [u'32d31724-fac1-44f3-9033-ca8e00066a36.' + u'_warm_up.queue-depth.32.block-size.8192.10-9-15-150', + u'1462379653', u'1462379898'], + [u'32d31724-fac1-44f3-9033-ca8e00066a36' + u'.rw.queue-depth.128.block-size.8192.10-9-15-151', + u'1462379898', u'1462380028'], + [u'32d31724-fac1-44f3-9033-ca8e00066a36' + u'.rw.queue-depth.128.block-size.8192.10-9-15-150', + u'1462379898', u'1462380032'], + [u'32d31724-fac1-44f3-9033-ca8e00066a36' + u'.rw.queue-depth.16.block-size.8192.10-9-15-151', + u'1462380032', u'1462380312'], + [u'32d31724-fac1-44f3-9033-ca8e00066a36' + u'.rw.queue-depth.16.block-size.8192.10-9-15-150', + u'1462380032', u'1462380329'], + ] + return workloads diff --git a/docker/storperf-master/tests/db_tests/job_db_test.py b/docker/storperf-master/tests/db_tests/job_db_test.py new file mode 100644 index 0000000..25fda1f --- /dev/null +++ b/docker/storperf-master/tests/db_tests/job_db_test.py @@ -0,0 +1,198 @@ +############################################################################## +# Copyright (c) 2016 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 os +import sqlite3 +import unittest + +import mock + +from storperf.db.job_db import JobDB +from storperf.workloads.rr import rr + + +class JobDBTest(unittest.TestCase): + + def setUp(self): + JobDB.db_name = __name__ + '.db' + try: + os.remove(JobDB.db_name) + except OSError: + pass + self.job = JobDB() + + def tearDown(self): + try: + os.remove(JobDB.db_name) + except OSError: + pass + + @mock.patch("uuid.uuid4") + def test_create_job(self, mock_uuid): + expected = "ABCDE-12345" + mock_uuid.side_effect = (expected,) + + self.job.create_job_id() + + actual = self.job.job_id + + self.assertEqual( + expected, actual, "Did not expect: " + str(actual)) + + @mock.patch("uuid.uuid4") + def test_duplicate_job_generated(self, mock_uuid): + duplicate = "EDCBA-12345" + expected = "EDCBA-54321" + + mock_uuid.side_effect = (duplicate, duplicate, expected,) + + self.job.create_job_id() + self.job.create_job_id() + + actual = self.job.job_id + + self.assertEqual( + expected, actual, "Did not expect: " + str(actual)) + + @mock.patch("uuid.uuid4") + @mock.patch("calendar.timegm") + def test_start_job(self, mock_calendar, mock_uuid): + job_id = "ABCDE-12345" + start_time = "12345" + mock_calendar.side_effect = (start_time,) + mock_uuid.side_effect = (job_id,) + workload = rr() + + db = sqlite3.connect(JobDB.db_name) + cursor = db.cursor() + + row = cursor.execute( + """select * from jobs + where job_id = ? + and workload = ?""", + (job_id, workload.fullname,)) + + self.assertEqual(None, + row.fetchone(), + "Should not have been a row in the db") + + self.job.start_workload(workload) + + cursor.execute( + """select job_id, workload, start from jobs + where job_id = ? + and workload = ?""", + (job_id, workload.fullname,)) + + row = cursor.fetchone() + + self.assertNotEqual(None, row, "Should be a row in the db") + self.assertEqual(job_id, row[0], "Did not expect " + str(row[0])) + self.assertEqual( + workload.fullname, row[1], "Did not expect " + str(row[1])) + self.assertEqual(start_time, row[2], "Did not expect " + str(row[2])) + + @mock.patch("uuid.uuid4") + @mock.patch("calendar.timegm") + def test_end_job(self, mock_calendar, mock_uuid): + job_id = "ABCDE-12345" + start_time = "12345" + end_time = "54321" + mock_calendar.side_effect = (start_time, end_time,) + mock_uuid.side_effect = (job_id,) + workload = rr() + + self.job.start_workload(workload) + self.job.end_workload(workload) + + db = sqlite3.connect(JobDB.db_name) + cursor = db.cursor() + cursor.execute( + """select job_id, workload, start, end from jobs + where job_id = ? + and workload = ?""", + (job_id, workload.fullname,)) + + row = cursor.fetchone() + + self.assertNotEqual(None, row, "Should be a row in the db") + self.assertEqual(job_id, row[0], "Did not expect " + str(row[0])) + self.assertEqual( + workload.fullname, row[1], "Did not expect " + str(row[1])) + self.assertEqual(start_time, row[2], "Did not expect " + str(row[2])) + self.assertEqual(end_time, row[3], "Did not expect " + str(row[3])) + + @mock.patch("uuid.uuid4") + @mock.patch("calendar.timegm") + def test_duplicate_start_job(self, mock_calendar, mock_uuid): + job_id = "ABCDE-12345" + start_time_1 = "12345" + start_time_2 = "12346" + + mock_calendar.side_effect = (start_time_1, start_time_2) + mock_uuid.side_effect = (job_id,) + workload = rr() + + db = sqlite3.connect(JobDB.db_name) + cursor = db.cursor() + + self.job.start_workload(workload) + self.job.start_workload(workload) + + cursor.execute( + """select job_id, workload, start from jobs + where job_id = ? + and workload = ?""", + (job_id, workload.fullname,)) + + row = cursor.fetchone() + + self.assertNotEqual(None, row, "Should be a row in the db") + self.assertEqual(job_id, row[0], "Did not expect " + str(row[0])) + self.assertEqual( + workload.fullname, row[1], "Did not expect " + str(row[1])) + self.assertEqual(start_time_2, row[2], "Did not expect " + str(row[2])) + + @mock.patch("uuid.uuid4") + @mock.patch("calendar.timegm") + def test_end_job_without_start(self, mock_calendar, mock_uuid): + job_id = "ABCDE-12345" + start_time = "12345" + end_time = "54321" + mock_calendar.side_effect = (start_time, end_time,) + mock_uuid.side_effect = (job_id,) + workload = rr() + + self.job.end_workload(workload) + + db = sqlite3.connect(JobDB.db_name) + cursor = db.cursor() + cursor.execute( + """select job_id, workload, start, end from jobs + where job_id = ? + and workload = ?""", + (job_id, workload.fullname,)) + + row = cursor.fetchone() + + self.assertNotEqual(None, row, "Should be a row in the db") + self.assertEqual(job_id, row[0], "Did not expect " + str(row[0])) + self.assertEqual( + workload.fullname, row[1], "Did not expect " + str(row[1])) + # The start time is set to the same time as end if it was never set + # before + self.assertEqual(start_time, row[2], "Did not expect " + str(row[2])) + self.assertEqual(start_time, row[3], "Did not expect " + str(row[3])) + + def test_job_params(self): + expected = {u"a": 1, u"b": 2} + self.job.job_id = "ABCD" + self.job.record_workload_params(expected) + actual = self.job.fetch_workload_params(self.job.job_id) + self.assertEqual(expected, actual) -- cgit 1.2.3-korg