1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
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.memload.MEMLoad
12 from __future__ import absolute_import
17 from yardstick.benchmark.scenarios.compute import memload
20 @mock.patch('yardstick.benchmark.scenarios.compute.memload.ssh')
21 class MEMLoadTestCase(unittest.TestCase):
28 'key_filename': "mykey.key"
34 def test_memload_successful_setup(self, mock_ssh):
35 m = memload.MEMLoad({}, self.ctx)
36 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
39 self.assertIsNotNone(m.client)
40 self.assertTrue(m.setup_done)
42 def test_execute_command_success(self, mock_ssh):
43 m = memload.MEMLoad({}, self.ctx)
44 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
47 expected_result = 'abcdefg'
48 mock_ssh.SSH.from_node().execute.return_value = (0, expected_result, '')
49 result = m._execute_command("foo")
50 self.assertEqual(result, expected_result)
52 def test_execute_command_failed(self, mock_ssh):
53 m = memload.MEMLoad({}, self.ctx)
54 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
57 mock_ssh.SSH.from_node().execute.return_value = (127, '', 'Failed executing \
59 self.assertRaises(RuntimeError, m._execute_command,
62 def test_get_mem_usage_successful(self, mock_ssh):
67 args = {"options": options}
68 m = memload.MEMLoad(args, self.ctx)
69 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
72 output = self._read_file("memload_sample_output.txt")
73 mock_ssh.SSH.from_node().execute.return_value = (0, output, '')
74 result = m._get_mem_usage()
93 "buff/cache": "853528",
97 "available": "67252400"
102 self.assertEqual(result, expected_result)
104 def _read_file(self, filename):
105 curr_path = os.path.dirname(os.path.abspath(__file__))
106 output = os.path.join(curr_path, filename)
107 with open(output) as f:
108 sample_output = f.read()