3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
12 # Unittest for yardstick.benchmark.scenarios.compute.cyclictest.Cyclictest
18 from yardstick.benchmark.scenarios.compute import cyclictest
21 @mock.patch('yardstick.benchmark.scenarios.compute.cyclictest.ssh')
22 class CyclictestTestCase(unittest.TestCase):
27 "ip": "192.168.50.28",
29 "key_filename": "mykey.key"
33 def test_cyclictest_successful_setup(self, mock_ssh):
35 c = cyclictest.Cyclictest({}, self.ctx)
38 mock_ssh.SSH().execute.return_value = (0, '', '')
39 self.assertIsNotNone(c.client)
40 self.assertEqual(c.setup_done, True)
42 def test_cyclictest_successful_no_sla(self, mock_ssh):
55 c = cyclictest.Cyclictest(args, self.ctx)
58 c.server = mock_ssh.SSH()
60 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
61 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
64 expected_result = json.loads(sample_output)
65 self.assertEqual(result, expected_result)
67 def test_cyclictest_successful_sla(self, mock_ssh):
78 "max_min_latency": 100,
79 "max_avg_latency": 500,
80 "max_max_latency": 1000,
86 c = cyclictest.Cyclictest(args, self.ctx)
89 c.server = mock_ssh.SSH()
91 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
92 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
95 expected_result = json.loads(sample_output)
96 self.assertEqual(result, expected_result)
98 def test_cyclictest_unsuccessful_sla_min_latency(self, mock_ssh):
102 "sla": {"max_min_latency": 10}
104 c = cyclictest.Cyclictest(args, self.ctx)
107 c.server = mock_ssh.SSH()
108 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
110 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
111 self.assertRaises(AssertionError, c.run, result)
113 def test_cyclictest_unsuccessful_sla_avg_latency(self, mock_ssh):
117 "sla": {"max_avg_latency": 10}
119 c = cyclictest.Cyclictest(args, self.ctx)
122 c.server = mock_ssh.SSH()
123 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
125 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
126 self.assertRaises(AssertionError, c.run, result)
128 def test_cyclictest_unsuccessful_sla_max_latency(self, mock_ssh):
132 "sla": {"max_max_latency": 10}
134 c = cyclictest.Cyclictest(args, self.ctx)
137 c.server = mock_ssh.SSH()
138 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
140 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
141 self.assertRaises(AssertionError, c.run, result)
143 def test_cyclictest_unsuccessful_script_error(self, mock_ssh):
154 "max_min_latency": 100,
155 "max_avg_latency": 500,
156 "max_max_latency": 1000,
162 c = cyclictest.Cyclictest(args, self.ctx)
165 c.server = mock_ssh.SSH()
167 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
168 self.assertRaises(RuntimeError, c.run, result)
174 if __name__ == '__main__':