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):
26 "host": "192.168.50.28",
28 "key_filename": "mykey.key"
31 def test_cyclictest_successful_setup(self, mock_ssh):
33 c = cyclictest.Cyclictest(self.ctx)
36 mock_ssh.SSH().execute.return_value = (0, '', '')
37 self.assertIsNotNone(c.client)
38 self.assertEqual(c.setup_done, True)
40 def test_cyclictest_successful_no_sla(self, mock_ssh):
42 c = cyclictest.Cyclictest(self.ctx)
56 c.server = mock_ssh.SSH()
58 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
59 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
62 expected_result = json.loads(sample_output)
63 self.assertEqual(result, expected_result)
65 def test_cyclictest_successful_sla(self, mock_ssh):
67 c = cyclictest.Cyclictest(self.ctx)
77 "max_min_latency": 100,
78 "max_avg_latency": 500,
79 "max_max_latency": 1000,
87 c.server = mock_ssh.SSH()
89 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
90 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
93 expected_result = json.loads(sample_output)
94 self.assertEqual(result, expected_result)
96 def test_cyclictest_unsuccessful_sla_min_latency(self, mock_ssh):
98 c = cyclictest.Cyclictest(self.ctx)
101 "sla": {"max_min_latency": 10}
105 c.server = mock_ssh.SSH()
106 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
108 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
109 self.assertRaises(AssertionError, c.run, args, result)
111 def test_cyclictest_unsuccessful_sla_avg_latency(self, mock_ssh):
113 c = cyclictest.Cyclictest(self.ctx)
116 "sla": {"max_avg_latency": 10}
120 c.server = mock_ssh.SSH()
121 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
123 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
124 self.assertRaises(AssertionError, c.run, args, result)
126 def test_cyclictest_unsuccessful_sla_max_latency(self, mock_ssh):
128 c = cyclictest.Cyclictest(self.ctx)
131 "sla": {"max_max_latency": 10}
135 c.server = mock_ssh.SSH()
136 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
138 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
139 self.assertRaises(AssertionError, c.run, args, result)
141 def test_cyclictest_unsuccessful_script_error(self, mock_ssh):
143 c = cyclictest.Cyclictest(self.ctx)
153 "max_min_latency": 100,
154 "max_avg_latency": 500,
155 "max_max_latency": 1000,
163 c.server = mock_ssh.SSH()
165 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
166 self.assertRaises(RuntimeError, c.run, args, result)
172 if __name__ == '__main__':