1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 # Unittest for yardstick.benchmark.scenarios.compute.cyclictest.Cyclictest
12 from __future__ import absolute_import
17 from oslo_serialization import jsonutils
19 from yardstick.benchmark.scenarios.compute import cyclictest
22 @mock.patch('yardstick.benchmark.scenarios.compute.cyclictest.ssh')
23 class CyclictestTestCase(unittest.TestCase):
29 "rpm_dir": "/opt/rpm",
35 "script_dir": "/opt/scripts",
36 "image_dir": "/opt/image",
44 "max_min_latency": 50,
45 "max_avg_latency": 100,
46 "max_max_latency": 1000
59 "ip": "10.229.43.154",
60 "key_filename": "/yardstick/resources/files/yardstick_key",
67 def test_cyclictest_successful_setup(self, mock_ssh):
69 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
70 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
73 self.assertIsNotNone(c.guest)
74 self.assertIsNotNone(c.host)
75 self.assertTrue(c.setup_done)
77 def test_cyclictest_successful_no_sla(self, mock_ssh):
79 self.scenario_cfg.pop("sla", None)
80 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
81 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
84 c.guest = mock_ssh.SSH.from_node()
85 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
86 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
89 expected_result = jsonutils.loads(sample_output)
90 self.assertEqual(result, expected_result)
92 def test_cyclictest_successful_sla(self, mock_ssh):
94 self.scenario_cfg.update({"sla": {
96 "max_min_latency": 100,
97 "max_avg_latency": 500,
98 "max_max_latency": 1000
101 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
102 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
105 c.guest = mock_ssh.SSH.from_node()
106 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
107 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
110 expected_result = jsonutils.loads(sample_output)
111 self.assertEqual(result, expected_result)
113 def test_cyclictest_unsuccessful_sla_min_latency(self, mock_ssh):
116 self.scenario_cfg.update({"sla": {"max_min_latency": 10}})
117 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
118 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
121 c.guest = mock_ssh.SSH.from_node()
122 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
124 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
125 self.assertRaises(AssertionError, c.run, result)
127 def test_cyclictest_unsuccessful_sla_avg_latency(self, mock_ssh):
130 self.scenario_cfg.update({"sla": {"max_avg_latency": 10}})
131 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
132 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
135 c.guest = mock_ssh.SSH.from_node()
136 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
138 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
139 self.assertRaises(AssertionError, c.run, result)
141 def test_cyclictest_unsuccessful_sla_max_latency(self, mock_ssh):
144 self.scenario_cfg.update({"sla": {"max_max_latency": 10}})
145 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
146 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
149 c.guest = mock_ssh.SSH.from_node()
150 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
152 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
153 self.assertRaises(AssertionError, c.run, result)
155 def test_cyclictest_unsuccessful_script_error(self, mock_ssh):
158 self.scenario_cfg.update({"sla": {"max_max_latency": 10}})
159 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
160 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
163 c.guest = mock_ssh.SSH.from_node()
165 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
166 self.assertRaises(RuntimeError, c.run, result)