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
14 from __future__ import absolute_import
19 from oslo_serialization import jsonutils
21 from yardstick.benchmark.scenarios.compute import cyclictest
24 @mock.patch('yardstick.benchmark.scenarios.compute.cyclictest.ssh')
25 class CyclictestTestCase(unittest.TestCase):
31 "rpm_dir": "/opt/rpm",
37 "script_dir": "/opt/scripts",
38 "image_dir": "/opt/image",
46 "max_min_latency": 50,
47 "max_avg_latency": 100,
48 "max_max_latency": 1000
61 "ip": "10.229.43.154",
62 "key_filename": "/yardstick/resources/files/yardstick_key",
69 def test_cyclictest_successful_setup(self, mock_ssh):
71 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
72 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
75 self.assertIsNotNone(c.guest)
76 self.assertIsNotNone(c.host)
77 self.assertEqual(c.setup_done, True)
79 def test_cyclictest_successful_no_sla(self, mock_ssh):
81 self.scenario_cfg.pop("sla", None)
82 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
83 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
86 c.guest = mock_ssh.SSH.from_node()
87 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
88 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
91 expected_result = jsonutils.loads(sample_output)
92 self.assertEqual(result, expected_result)
94 def test_cyclictest_successful_sla(self, mock_ssh):
96 self.scenario_cfg.update({"sla": {
98 "max_min_latency": 100,
99 "max_avg_latency": 500,
100 "max_max_latency": 1000
103 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
104 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
107 c.guest = mock_ssh.SSH.from_node()
108 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
109 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
112 expected_result = jsonutils.loads(sample_output)
113 self.assertEqual(result, expected_result)
115 def test_cyclictest_unsuccessful_sla_min_latency(self, mock_ssh):
118 self.scenario_cfg.update({"sla": {"max_min_latency": 10}})
119 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
120 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
123 c.guest = mock_ssh.SSH.from_node()
124 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
126 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
127 self.assertRaises(AssertionError, c.run, result)
129 def test_cyclictest_unsuccessful_sla_avg_latency(self, mock_ssh):
132 self.scenario_cfg.update({"sla": {"max_avg_latency": 10}})
133 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
134 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
137 c.guest = mock_ssh.SSH.from_node()
138 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
140 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
141 self.assertRaises(AssertionError, c.run, result)
143 def test_cyclictest_unsuccessful_sla_max_latency(self, mock_ssh):
146 self.scenario_cfg.update({"sla": {"max_max_latency": 10}})
147 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
148 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
151 c.guest = mock_ssh.SSH.from_node()
152 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
154 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
155 self.assertRaises(AssertionError, c.run, result)
157 def test_cyclictest_unsuccessful_script_error(self, mock_ssh):
160 self.scenario_cfg.update({"sla": {"max_max_latency": 10}})
161 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
162 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
165 c.guest = mock_ssh.SSH.from_node()
167 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
168 self.assertRaises(RuntimeError, c.run, result)
174 if __name__ == '__main__':