3 ##############################################################################
4 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
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.plugintest.PluginTest
14 from __future__ import absolute_import
19 from oslo_serialization import jsonutils
21 from yardstick.benchmark.scenarios.compute import plugintest
24 @mock.patch('yardstick.benchmark.scenarios.compute.plugintest.ssh')
25 class PluginTestTestCase(unittest.TestCase):
33 'key_filename': "mykey.key",
41 def test_sample_successful_setup(self, mock_ssh):
42 s = plugintest.PluginTest({}, self.ctx)
43 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
46 self.assertIsNotNone(s.client)
47 self.assertTrue(s.setup_done)
49 def test_sample_successful(self, mock_ssh):
50 s = plugintest.PluginTest({}, self.ctx)
52 sample_output = '{"Test Output": "Hello world!"}'
53 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
55 expected_result = jsonutils.loads(sample_output)
56 self.assertEqual(self.result, expected_result)
58 def test_sample_unsuccessful_script_error(self, mock_ssh):
59 s = plugintest.PluginTest({}, self.ctx)
61 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
62 self.assertRaises(RuntimeError, s.run, self.result)