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)
54 c.server = mock_ssh.SSH()
56 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
57 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
60 expected_result = json.loads(sample_output)
61 self.assertEqual(result, expected_result)
63 def test_cyclictest_successful_sla(self, mock_ssh):
65 c = cyclictest.Cyclictest(self.ctx)
75 "max_min_latency": 100,
76 "max_avg_latency": 500,
77 "max_max_latency": 1000,
83 c.server = mock_ssh.SSH()
85 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
86 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
89 expected_result = json.loads(sample_output)
90 self.assertEqual(result, expected_result)
92 def test_cyclictest_unsuccessful_sla_min_latency(self, mock_ssh):
94 c = cyclictest.Cyclictest(self.ctx)
97 "sla": {"max_min_latency": 10}
99 c.server = mock_ssh.SSH()
100 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
102 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
103 self.assertRaises(AssertionError, c.run, args)
105 def test_cyclictest_unsuccessful_sla_avg_latency(self, mock_ssh):
107 c = cyclictest.Cyclictest(self.ctx)
110 "sla": {"max_avg_latency": 10}
112 c.server = mock_ssh.SSH()
113 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
115 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
116 self.assertRaises(AssertionError, c.run, args)
118 def test_cyclictest_unsuccessful_sla_max_latency(self, mock_ssh):
120 c = cyclictest.Cyclictest(self.ctx)
123 "sla": {"max_max_latency": 10}
125 c.server = mock_ssh.SSH()
126 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
128 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
129 self.assertRaises(AssertionError, c.run, args)
131 def test_cyclictest_unsuccessful_script_error(self, mock_ssh):
133 c = cyclictest.Cyclictest(self.ctx)
143 "max_min_latency": 100,
144 "max_avg_latency": 500,
145 "max_max_latency": 1000,
151 c.server = mock_ssh.SSH()
153 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
154 self.assertRaises(RuntimeError, c.run, args)
160 if __name__ == '__main__':