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
19 from yardstick.benchmark.scenarios.compute import plugintest
22 @mock.patch('yardstick.benchmark.scenarios.compute.plugintest.ssh')
23 class PluginTestTestCase(unittest.TestCase):
31 'key_filename': "mykey.key",
39 def test_sample_successful_setup(self, mock_ssh):
40 s = plugintest.PluginTest({}, self.ctx)
41 mock_ssh.SSH().execute.return_value = (0, '', '')
44 self.assertIsNotNone(s.client)
45 self.assertTrue(s.setup_done)
47 def test_sample_successful(self, mock_ssh):
48 s = plugintest.PluginTest({}, self.ctx)
50 sample_output = '{"Test Output": "Hello world!"}'
51 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
53 expected_result = json.loads(sample_output)
54 self.assertEqual(self.result, expected_result)
56 def test_sample_unsuccessful_script_error(self, mock_ssh):
57 s = plugintest.PluginTest({}, self.ctx)
59 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
60 self.assertRaises(RuntimeError, s.run, self.result)