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
20 from yardstick.common import exceptions as y_exc
23 @mock.patch('yardstick.benchmark.scenarios.compute.cyclictest.ssh')
24 class CyclictestTestCase(unittest.TestCase):
30 "rpm_dir": "/opt/rpm",
36 "script_dir": "/opt/scripts",
37 "image_dir": "/opt/image",
45 "max_min_latency": 50,
46 "max_avg_latency": 100,
47 "max_max_latency": 1000
60 "ip": "10.229.43.154",
61 "key_filename": "/yardstick/resources/files/yardstick_key",
68 def test_cyclictest_successful_setup(self, mock_ssh):
70 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
71 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
74 self.assertIsNotNone(c.guest)
75 self.assertIsNotNone(c.host)
76 self.assertTrue(c.setup_done)
78 def test_cyclictest_successful_no_sla(self, mock_ssh):
80 self.scenario_cfg.pop("sla", None)
81 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
82 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
85 c.guest = mock_ssh.SSH.from_node()
86 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
87 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
90 expected_result = jsonutils.loads(sample_output)
91 self.assertEqual(result, expected_result)
93 def test_cyclictest_successful_sla(self, mock_ssh):
95 self.scenario_cfg.update({"sla": {
97 "max_min_latency": 100,
98 "max_avg_latency": 500,
99 "max_max_latency": 1000
102 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
103 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
106 c.guest = mock_ssh.SSH.from_node()
107 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
108 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
111 expected_result = jsonutils.loads(sample_output)
112 self.assertEqual(result, expected_result)
114 def test_cyclictest_unsuccessful_sla_min_latency(self, mock_ssh):
117 self.scenario_cfg.update({"sla": {"max_min_latency": 10}})
118 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
119 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
122 c.guest = mock_ssh.SSH.from_node()
123 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
125 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
126 self.assertRaises(y_exc.SLAValidationError, c.run, result)
128 def test_cyclictest_unsuccessful_sla_avg_latency(self, mock_ssh):
131 self.scenario_cfg.update({"sla": {"max_avg_latency": 10}})
132 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
133 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
136 c.guest = mock_ssh.SSH.from_node()
137 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
139 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
140 self.assertRaises(y_exc.SLAValidationError, c.run, result)
142 def test_cyclictest_unsuccessful_sla_max_latency(self, mock_ssh):
145 self.scenario_cfg.update({"sla": {"max_max_latency": 10}})
146 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
147 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
150 c.guest = mock_ssh.SSH.from_node()
151 sample_output = '{"min": 100, "avg": 500, "max": 1000}'
153 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
154 self.assertRaises(y_exc.SLAValidationError, c.run, result)
156 def test_cyclictest_unsuccessful_script_error(self, mock_ssh):
159 self.scenario_cfg.update({"sla": {"max_max_latency": 10}})
160 c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
161 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
164 c.guest = mock_ssh.SSH.from_node()
166 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
167 self.assertRaises(RuntimeError, c.run, result)