aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/benchmark
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/benchmark')
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_attacker_general.py1
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_monitor_general.py2
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_operation_general.py2
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_result_checker_general.py1
-rw-r--r--tests/unit/benchmark/scenarios/networking/netutilization_sample_output1.txt9
-rw-r--r--tests/unit/benchmark/scenarios/networking/netutilization_sample_output2.txt13
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_netutilization.py225
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_networkcapacity.py56
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_ping.py14
-rw-r--r--tests/unit/benchmark/scenarios/storage/test_storagecapacity.py98
-rw-r--r--tests/unit/benchmark/scenarios/storage/test_storperf.py214
11 files changed, 630 insertions, 5 deletions
diff --git a/tests/unit/benchmark/scenarios/availability/test_attacker_general.py b/tests/unit/benchmark/scenarios/availability/test_attacker_general.py
index 643c1e7ac..aa2e0cc4d 100644
--- a/tests/unit/benchmark/scenarios/availability/test_attacker_general.py
+++ b/tests/unit/benchmark/scenarios/availability/test_attacker_general.py
@@ -33,6 +33,7 @@ class GeneralAttackerServiceTestCase(unittest.TestCase):
'action_parameter':{'process_name':'nova_api'},
'rollback_parameter':{'process_name':'nova_api'},
'key':'stop-service',
+ 'attack_key':'stop-service',
'host': 'node1',
}
diff --git a/tests/unit/benchmark/scenarios/availability/test_monitor_general.py b/tests/unit/benchmark/scenarios/availability/test_monitor_general.py
index b48434c99..de7d26cbf 100644
--- a/tests/unit/benchmark/scenarios/availability/test_monitor_general.py
+++ b/tests/unit/benchmark/scenarios/availability/test_monitor_general.py
@@ -32,6 +32,7 @@ class GeneralMonitorServiceTestCase(unittest.TestCase):
self.monitor_cfg = {
'monitor_type': 'general-monitor',
'key': 'service-status',
+ 'monitor_key': 'service-status',
'host': 'node1',
'monitor_time': 3,
'parameter': {'serviceName': 'haproxy'},
@@ -40,6 +41,7 @@ class GeneralMonitorServiceTestCase(unittest.TestCase):
self.monitor_cfg_noparam = {
'monitor_type': 'general-monitor',
'key': 'service-status',
+ 'monitor_key': 'service-status',
'host': 'node1',
'monitor_time': 3,
'sla': {'max_outage_time': 1}
diff --git a/tests/unit/benchmark/scenarios/availability/test_operation_general.py b/tests/unit/benchmark/scenarios/availability/test_operation_general.py
index 6713733a8..26cd3f7c4 100644
--- a/tests/unit/benchmark/scenarios/availability/test_operation_general.py
+++ b/tests/unit/benchmark/scenarios/availability/test_operation_general.py
@@ -34,11 +34,13 @@ class GeneralOperaionTestCase(unittest.TestCase):
'action_parameter': {'ins_cup': 2},
'rollback_parameter': {'ins_id': 'id123456'},
'key': 'nova-create-instance',
+ 'operation_key': 'nova-create-instance',
'host': 'node1',
}
self.operation_cfg_noparam = {
'operation_type': 'general-operation',
'key': 'nova-create-instance',
+ 'operation_key': 'nova-create-instance',
'host': 'node1',
}
diff --git a/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py b/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py
index 88a9b9d20..bbadf0ac3 100644
--- a/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py
+++ b/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py
@@ -38,6 +38,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase):
'condition' : 'eq',
'expectedValue' : 1,
'key' : 'process-checker',
+ 'checker_key' : 'process-checker',
'host': 'node1'
}
diff --git a/tests/unit/benchmark/scenarios/networking/netutilization_sample_output1.txt b/tests/unit/benchmark/scenarios/networking/netutilization_sample_output1.txt
new file mode 100644
index 000000000..f90457cb3
--- /dev/null
+++ b/tests/unit/benchmark/scenarios/networking/netutilization_sample_output1.txt
@@ -0,0 +1,9 @@
+Linux 3.19.0-25-generic (huawei-pod4) 07/19/2016 _x86_64_ (1 CPU)
+
+02:01:50 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil
+02:01:51 PM eth0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
+02:01:51 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
+
+Average: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil
+Average: eth0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
+Average: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
diff --git a/tests/unit/benchmark/scenarios/networking/netutilization_sample_output2.txt b/tests/unit/benchmark/scenarios/networking/netutilization_sample_output2.txt
new file mode 100644
index 000000000..417613ec1
--- /dev/null
+++ b/tests/unit/benchmark/scenarios/networking/netutilization_sample_output2.txt
@@ -0,0 +1,13 @@
+Linux 3.19.0-25-generic (huawei-pod4) 07/19/2016 _x86_64_ (1 CPU)
+
+02:01:50 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil
+02:01:51 PM eth0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
+02:01:51 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
+
+02:01:52 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil
+02:01:53 PM eth0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
+02:01:53 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
+
+Average: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil
+Average: eth0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
+Average: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
diff --git a/tests/unit/benchmark/scenarios/networking/test_netutilization.py b/tests/unit/benchmark/scenarios/networking/test_netutilization.py
new file mode 100644
index 000000000..eb6626fea
--- /dev/null
+++ b/tests/unit/benchmark/scenarios/networking/test_netutilization.py
@@ -0,0 +1,225 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and other.
+#
+# 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
+##############################################################################
+
+# Unittest for yardstick.benchmark.scenarios.networking.netutilization.NetUtilization
+
+import mock
+import unittest
+import os
+
+from yardstick.benchmark.scenarios.networking import netutilization
+
+
+@mock.patch('yardstick.benchmark.scenarios.networking.netutilization.ssh')
+class NetUtilizationTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.ctx = {
+ 'host': {
+ 'ip': '172.16.0.137',
+ 'user': 'cirros',
+ 'key_filename': "mykey.key"
+ }
+ }
+
+ self.result = {}
+
+ def test_setup_success(self, mock_ssh):
+ options = {
+ "interval": 1,
+ "count": 1
+ }
+ args = {'options': options}
+
+ n = netutilization.NetUtilization(args, self.ctx)
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+
+ n.setup()
+ self.assertIsNotNone(n.client)
+ self.assertTrue(n.setup_done)
+
+ def test_execute_command_success(self, mock_ssh):
+ options = {
+ "interval": 1,
+ "count": 1
+ }
+ args = {'options': options}
+
+ n = netutilization.NetUtilization(args, self.ctx)
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+ n.setup()
+
+ expected_result = 'abcdefg'
+ mock_ssh.SSH().execute.return_value = (0, expected_result, '')
+ result = n._execute_command("foo")
+ self.assertEqual(result, expected_result)
+
+ def test_execute_command_failed(self, mock_ssh):
+ options = {
+ "interval": 1,
+ "count": 1
+ }
+ args = {'options': options}
+
+ n = netutilization.NetUtilization(args, self.ctx)
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+ n.setup()
+
+ mock_ssh.SSH().execute.return_value = (127, '', 'abcdefg')
+ self.assertRaises(RuntimeError, n._execute_command,
+ "failed")
+
+ def test_get_network_utilization_success(self, mock_ssh):
+ options = {
+ "interval": 1,
+ "count": 1
+ }
+ args = {'options': options}
+
+ n = netutilization.NetUtilization(args, self.ctx)
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+ n.setup()
+
+ mpstat_output = self._read_file("netutilization_sample_output1.txt")
+ mock_ssh.SSH().execute.return_value = (0, mpstat_output, '')
+ result = n._get_network_utilization()
+
+ expected_result = \
+ {"network_utilization_maximun": {
+ "lo": {"rxcmp/s": "0.00",
+ "%ifutil": "0.00",
+ "txcmp/s": "0.00",
+ "txkB/s": "0.00",
+ "rxkB/s": "0.00",
+ "rxpck/s": "0.00",
+ "txpck/s": "0.00",
+ "rxmcst/s": "0.00"},
+ "eth0": {"rxcmp/s": "0.00",
+ "%ifutil": "0.00",
+ "txcmp/s": "0.00",
+ "txkB/s": "0.00",
+ "rxkB/s": "0.00",
+ "rxpck/s": "0.00",
+ "txpck/s": "0.00",
+ "rxmcst/s": "0.00"}},
+ "network_utilization_average": {
+ "lo": {"rxcmp/s": "0.00",
+ "%ifutil": "0.00",
+ "txcmp/s": "0.00",
+ "txkB/s": "0.00",
+ "rxkB/s": "0.00",
+ "rxpck/s": "0.00",
+ "txpck/s": "0.00",
+ "rxmcst/s": "0.00"},
+ "eth0": {"rxcmp/s": "0.00",
+ "%ifutil": "0.00",
+ "txcmp/s": "0.00",
+ "txkB/s": "0.00",
+ "rxkB/s": "0.00",
+ "rxpck/s": "0.00",
+ "txpck/s": "0.00",
+ "rxmcst/s": "0.00"}},
+ "network_utilization_minimum": {
+ "lo": {"rxcmp/s": "0.00",
+ "%ifutil": "0.00",
+ "txcmp/s": "0.00",
+ "txkB/s": "0.00",
+ "rxkB/s": "0.00",
+ "rxpck/s": "0.00",
+ "txpck/s": "0.00",
+ "rxmcst/s": "0.00"},
+ "eth0": {"rxcmp/s": "0.00",
+ "%ifutil": "0.00",
+ "txcmp/s": "0.00",
+ "txkB/s": "0.00",
+ "rxkB/s": "0.00",
+ "rxpck/s": "0.00",
+ "txpck/s": "0.00",
+ "rxmcst/s": "0.00"}}}
+
+ self.assertDictEqual(result, expected_result)
+
+ def test_get_network_utilization_2_success(self, mock_ssh):
+ options = {
+ "interval": 1,
+ "count": 2
+ }
+ args = {'options': options}
+
+ n = netutilization.NetUtilization(args, self.ctx)
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+ n.setup()
+
+ mpstat_output = self._read_file("netutilization_sample_output2.txt")
+ mock_ssh.SSH().execute.return_value = (0, mpstat_output, '')
+ result = n._get_network_utilization()
+
+ expected_result = \
+ {"network_utilization_maximun": {
+ "lo": {"rxcmp/s": "0.00",
+ "%ifutil": "0.00",
+ "txcmp/s": "0.00",
+ "txkB/s": "0.00",
+ "rxkB/s": "0.00",
+ "rxpck/s": "0.00",
+ "txpck/s": "0.00",
+ "rxmcst/s": "0.00"},
+ "eth0": {"rxcmp/s": "0.00",
+ "%ifutil": "0.00",
+ "txcmp/s": "0.00",
+ "txkB/s": "0.00",
+ "rxkB/s": "0.00",
+ "rxpck/s": "0.00",
+ "txpck/s": "0.00",
+ "rxmcst/s": "0.00"}},
+ "network_utilization_average": {
+ "lo": {"rxcmp/s": "0.00",
+ "%ifutil": "0.00",
+ "txcmp/s": "0.00",
+ "txkB/s": "0.00",
+ "rxkB/s": "0.00",
+ "rxpck/s": "0.00",
+ "txpck/s": "0.00",
+ "rxmcst/s": "0.00"},
+ "eth0": {"rxcmp/s": "0.00",
+ "%ifutil": "0.00",
+ "txcmp/s": "0.00",
+ "txkB/s": "0.00",
+ "rxkB/s": "0.00",
+ "rxpck/s": "0.00",
+ "txpck/s": "0.00",
+ "rxmcst/s": "0.00"}},
+ "network_utilization_minimum": {
+ "lo": {"rxcmp/s": "0.00",
+ "%ifutil": "0.00",
+ "txcmp/s": "0.00",
+ "txkB/s": "0.00",
+ "rxkB/s": "0.00",
+ "rxpck/s": "0.00",
+ "txpck/s": "0.00",
+ "rxmcst/s": "0.00"},
+ "eth0": {"rxcmp/s": "0.00",
+ "%ifutil": "0.00",
+ "txcmp/s": "0.00",
+ "txkB/s": "0.00",
+ "rxkB/s": "0.00",
+ "rxpck/s": "0.00",
+ "txpck/s": "0.00",
+ "rxmcst/s": "0.00"}}}
+
+ self.assertDictEqual(result, expected_result)
+
+ def _read_file(self, filename):
+ curr_path = os.path.dirname(os.path.abspath(__file__))
+ output = os.path.join(curr_path, filename)
+ with open(output) as f:
+ sample_output = f.read()
+ return sample_output
diff --git a/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py b/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py
new file mode 100644
index 000000000..e3a096446
--- /dev/null
+++ b/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd 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
+##############################################################################
+
+# Unittest for yardstick.benchmark.scenarios.networking.networkcapacity.NetworkCapacity
+
+import mock
+import unittest
+import os
+import json
+
+from yardstick.benchmark.scenarios.networking import networkcapacity
+
+SAMPLE_OUTPUT = '{"Number of connections":"308","Number of frames received": "166503"}'
+
+@mock.patch('yardstick.benchmark.scenarios.networking.networkcapacity.ssh')
+class NetworkCapacityTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.ctx = {
+ 'host': {
+ 'ip': '172.16.0.137',
+ 'user': 'cirros',
+ 'password': "root"
+ },
+ }
+
+ self.result = {}
+
+ def test_capacity_successful_setup(self, mock_ssh):
+ c = networkcapacity.NetworkCapacity({}, self.ctx)
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+ c.setup()
+ self.assertIsNotNone(c.client)
+ self.assertTrue(c.setup_done)
+
+ def test_capacity_successful(self, mock_ssh):
+ c = networkcapacity.NetworkCapacity({}, self.ctx)
+
+ mock_ssh.SSH().execute.return_value = (0, SAMPLE_OUTPUT, '')
+ c.run(self.result)
+ expected_result = json.loads(SAMPLE_OUTPUT)
+ self.assertEqual(self.result, expected_result)
+
+ def test_capacity_unsuccessful_script_error(self, mock_ssh):
+ c = networkcapacity.NetworkCapacity({}, self.ctx)
+
+ mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
+ self.assertRaises(RuntimeError, c.run, self.result)
diff --git a/tests/unit/benchmark/scenarios/networking/test_ping.py b/tests/unit/benchmark/scenarios/networking/test_ping.py
index 600974510..8d35b8490 100644
--- a/tests/unit/benchmark/scenarios/networking/test_ping.py
+++ b/tests/unit/benchmark/scenarios/networking/test_ping.py
@@ -36,6 +36,7 @@ class PingTestCase(unittest.TestCase):
args = {
'options': {'packetsize': 200},
+ 'target': 'ares.demo'
}
result = {}
@@ -43,14 +44,15 @@ class PingTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, '100', '')
p.run(result)
- self.assertEqual(result, {'rtt': {'10.229.17.105': 100.0}})
+ self.assertEqual(result, {'rtt': {'ares': 100.0}})
@mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
def test_ping_successful_sla(self, mock_ssh):
args = {
'options': {'packetsize': 200},
- 'sla': {'max_rtt': 150}
+ 'sla': {'max_rtt': 150},
+ 'target': 'ares.demo'
}
result = {}
@@ -58,14 +60,15 @@ class PingTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, '100', '')
p.run(result)
- self.assertEqual(result, {'rtt': {'10.229.17.105': 100.0}})
+ self.assertEqual(result, {'rtt': {'ares': 100.0}})
@mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
def test_ping_unsuccessful_sla(self, mock_ssh):
args = {
'options': {'packetsize': 200},
- 'sla': {'max_rtt': 50}
+ 'sla': {'max_rtt': 50},
+ 'target': 'ares.demo'
}
result = {}
@@ -79,7 +82,8 @@ class PingTestCase(unittest.TestCase):
args = {
'options': {'packetsize': 200},
- 'sla': {'max_rtt': 50}
+ 'sla': {'max_rtt': 50},
+ 'target': 'ares.demo'
}
result = {}
diff --git a/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py b/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py
new file mode 100644
index 000000000..ace0ca374
--- /dev/null
+++ b/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py
@@ -0,0 +1,98 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd 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
+##############################################################################
+
+# Unittest for yardstick.benchmark.scenarios.storage.storagecapacity.StorageCapacity
+
+import mock
+import unittest
+import os
+import json
+
+from yardstick.benchmark.scenarios.storage import storagecapacity
+
+DISK_SIZE_SAMPLE_OUTPUT = '{"Numberf of devides": "2", "Total disk size in bytes": "1024000000"}'
+BLOCK_SIZE_SAMPLE_OUTPUT = '{"/dev/sda": 1024, "/dev/sdb": 4096}'
+DISK_UTIL_RAW_OUTPUT = "vda 10.00\nvda 0.00"
+DISK_UTIL_SAMPLE_OUTPUT = '{"vda": {"avg_util": 5.0, "max_util": 10.0, "min_util": 0.0}}'
+
+@mock.patch('yardstick.benchmark.scenarios.storage.storagecapacity.ssh')
+class StorageCapacityTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.scn = {
+ "options": {
+ 'test_type': 'disk_size'
+ }
+ }
+ self.ctx = {
+ "host": {
+ 'ip': '172.16.0.137',
+ 'user': 'cirros',
+ 'password': "root"
+ }
+ }
+ self.result = {}
+
+ def test_capacity_successful_setup(self, mock_ssh):
+ c = storagecapacity.StorageCapacity(self.scn, self.ctx)
+
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+ c.setup()
+ self.assertIsNotNone(c.client)
+ self.assertTrue(c.setup_done)
+
+ def test_capacity_disk_size_successful(self, mock_ssh):
+ c = storagecapacity.StorageCapacity(self.scn, self.ctx)
+
+ mock_ssh.SSH().execute.return_value = (0, DISK_SIZE_SAMPLE_OUTPUT, '')
+ c.run(self.result)
+ expected_result = json.loads(DISK_SIZE_SAMPLE_OUTPUT)
+ self.assertEqual(self.result, expected_result)
+
+ def test_capacity_block_size_successful(self, mock_ssh):
+ args = {
+ "options": {
+ 'test_type': 'block_size'
+ }
+ }
+ c = storagecapacity.StorageCapacity(args, self.ctx)
+
+ mock_ssh.SSH().execute.return_value = (0, BLOCK_SIZE_SAMPLE_OUTPUT, '')
+ c.run(self.result)
+ expected_result = json.loads(BLOCK_SIZE_SAMPLE_OUTPUT)
+ self.assertEqual(self.result, expected_result)
+
+ def test_capacity_disk_utilization_successful(self, mock_ssh):
+ args = {
+ "options": {
+ 'test_type': 'disk_utilization',
+ 'interval': 1,
+ 'count': 2
+ }
+ }
+ c = storagecapacity.StorageCapacity(args, self.ctx)
+
+ mock_ssh.SSH().execute.return_value = (0, DISK_UTIL_RAW_OUTPUT, '')
+ c.run(self.result)
+ expected_result = json.loads(DISK_UTIL_SAMPLE_OUTPUT)
+ self.assertEqual(self.result, expected_result)
+
+ def test_capacity_unsuccessful_script_error(self, mock_ssh):
+ c = storagecapacity.StorageCapacity(self.scn, self.ctx)
+
+ mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
+ self.assertRaises(RuntimeError, c.run, self.result)
+
+def main():
+ unittest.main()
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/unit/benchmark/scenarios/storage/test_storperf.py b/tests/unit/benchmark/scenarios/storage/test_storperf.py
new file mode 100644
index 000000000..d87ed733c
--- /dev/null
+++ b/tests/unit/benchmark/scenarios/storage/test_storperf.py
@@ -0,0 +1,214 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd.
+#
+# 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
+##############################################################################
+
+# Unittest for yardstick.benchmark.scenarios.storage.storperf.StorPerf
+
+import mock
+import unittest
+import requests
+import json
+
+from yardstick.benchmark.scenarios.storage import storperf
+
+
+def mocked_requests_config_post(*args, **kwargs):
+ class MockResponseConfigPost:
+ def __init__(self, json_data, status_code):
+ self.content = json_data
+ self.status_code = status_code
+
+ return MockResponseConfigPost('{"stack_id": "dac27db1-3502-4300-b301-91c64e6a1622","stack_created": "false"}', 200)
+
+
+def mocked_requests_config_get(*args, **kwargs):
+ class MockResponseConfigGet:
+ def __init__(self, json_data, status_code):
+ self.content = json_data
+ self.status_code = status_code
+
+ return MockResponseConfigGet('{"stack_id": "dac27db1-3502-4300-b301-91c64e6a1622","stack_created": "true"}', 200)
+
+
+def mocked_requests_job_get(*args, **kwargs):
+ class MockResponseJobGet:
+ def __init__(self, json_data, status_code):
+ self.content = json_data
+ self.status_code = status_code
+
+ return MockResponseJobGet('{"_ssd_preconditioning.queue-depth.8.block-size.16384.duration": 6}', 200)
+
+
+def mocked_requests_job_post(*args, **kwargs):
+ class MockResponseJobPost:
+ def __init__(self, json_data, status_code):
+ self.content = json_data
+ self.status_code = status_code
+
+ return MockResponseJobPost('{"job_id": \
+ "d46bfb8c-36f4-4a40-813b-c4b4a437f728"}', 200)
+
+
+def mocked_requests_job_delete(*args, **kwargs):
+ class MockResponseJobDelete:
+ def __init__(self, json_data, status_code):
+ self.content = json_data
+ self.status_code = status_code
+
+ return MockResponseJobDelete('{}', 200)
+
+
+def mocked_requests_delete(*args, **kwargs):
+ class MockResponseDelete:
+ def __init__(self, json_data, status_code):
+ self.json_data = json_data
+ self.status_code = status_code
+
+ return MockResponseDelete('{}', 200)
+
+
+def mocked_requests_delete_failed(*args, **kwargs):
+ class MockResponseDeleteFailed:
+ def __init__(self, json_data, status_code):
+ self.json_data = json_data
+ self.status_code = status_code
+
+ if args[0] == "http://172.16.0.137:5000/api/v1.0/configurations":
+ return MockResponseDeleteFailed('{"message": "Teardown failed"}', 400)
+
+ return MockResponseDeleteFailed('{}', 404)
+
+
+class StorPerfTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.ctx = {
+ 'host': {
+ 'ip': '172.16.0.137',
+ 'user': 'cirros',
+ 'key_filename': "mykey.key"
+ }
+ }
+
+ self.result = {}
+
+ @mock.patch('yardstick.benchmark.scenarios.storage.storperf.requests.post',
+ side_effect=mocked_requests_config_post)
+ @mock.patch('yardstick.benchmark.scenarios.storage.storperf.requests.get',
+ side_effect=mocked_requests_config_get)
+ def test_successful_setup(self, mock_post, mock_get):
+ options = {
+ "agent_count": 8,
+ "public_network": 'ext-net',
+ "volume_size": 10,
+ "block_sizes": 4096,
+ "queue_depths": 4,
+ "workload": "rs",
+ "StorPerf_ip": "192.168.23.2",
+ "query_interval": 10,
+ "timeout": 60
+ }
+
+ args = {
+ "options": options
+ }
+
+ s = storperf.StorPerf(args, self.ctx)
+
+ s.setup()
+
+ self.assertTrue(s.setup_done)
+
+ @mock.patch('yardstick.benchmark.scenarios.storage.storperf.requests.post',
+ side_effect=mocked_requests_job_post)
+ @mock.patch('yardstick.benchmark.scenarios.storage.storperf.requests.get',
+ side_effect=mocked_requests_job_get)
+ @mock.patch('yardstick.benchmark.scenarios.storage.storperf.requests.delete',
+ side_effect=mocked_requests_job_delete)
+ def test_successful_run(self, mock_post, mock_get, mock_delete):
+ options = {
+ "agent_count": 8,
+ "public_network": 'ext-net',
+ "volume_size": 10,
+ "block_sizes": 4096,
+ "queue_depths": 4,
+ "workload": "rs",
+ "StorPerf_ip": "192.168.23.2",
+ "query_interval": 10,
+ "timeout": 60
+ }
+
+ args = {
+ "options": options
+ }
+
+ s = storperf.StorPerf(args, self.ctx)
+ s.setup_done = True
+
+ sample_output = '{"_ssd_preconditioning.queue-depth.8.block-size.16384.duration": 6}'
+
+ expected_result = json.loads(sample_output)
+
+ s.run(self.result)
+
+ self.assertEqual(self.result, expected_result)
+
+ @mock.patch('yardstick.benchmark.scenarios.storage.storperf.requests.delete', side_effect=mocked_requests_delete)
+ def test_successful_teardown(self, mock_delete):
+ options = {
+ "agent_count": 8,
+ "public_network": 'ext-net',
+ "volume_size": 10,
+ "block_sizes": 4096,
+ "queue_depths": 4,
+ "workload": "rs",
+ "StorPerf_ip": "192.168.23.2",
+ "query_interval": 10,
+ "timeout": 60
+ }
+
+ args = {
+ "options": options
+ }
+
+ s = storperf.StorPerf(args, self.ctx)
+
+ s.teardown()
+
+ self.assertFalse(s.setup_done)
+
+ @mock.patch('yardstick.benchmark.scenarios.storage.storperf.requests.delete', side_effect=mocked_requests_delete_failed)
+ def test_failed_teardown(self, mock_delete):
+ options = {
+ "agent_count": 8,
+ "public_network": 'ext-net',
+ "volume_size": 10,
+ "block_sizes": 4096,
+ "queue_depths": 4,
+ "workload": "rs",
+ "StorPerf_ip": "192.168.23.2",
+ "query_interval": 10,
+ "timeout": 60
+ }
+
+ args = {
+ "options": options
+ }
+
+ s = storperf.StorPerf(args, self.ctx)
+
+ self.assertRaises(AssertionError, s.teardown(), self.result)
+
+
+def main():
+ unittest.main()
+
+if __name__ == '__main__':
+ main()