3 ##############################################################################
4 # Copyright (c) 2015 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.cmd.commands.task
17 from yardstick.cmd.commands import task
20 class TaskCommandsTestCase(unittest.TestCase):
22 @mock.patch('yardstick.cmd.commands.task.Context')
23 def test_parse_nodes_host_target_same_context(self, mock_context):
28 scenario_cfg = {"nodes": nodes}
32 "key_filename": "/root/.ssh/id_rsa"
34 mock_context.get_server.return_value = server_info
35 context_cfg = task.parse_nodes_with_context(scenario_cfg)
37 self.assertEqual(context_cfg["host"], server_info)
38 self.assertEqual(context_cfg["target"], server_info)
40 @mock.patch('yardstick.cmd.commands.task.Context')
41 @mock.patch('yardstick.cmd.commands.task.base_runner')
42 def test_run(self, mock_base_runner, mock_ctx):
44 {'host': 'athena.demo',
45 'target': 'ares.demo',
53 t = task.TaskCommands()
55 runner.join.return_value = 0
56 mock_base_runner.Runner.get.return_value = runner
57 t._run([scenario], False, "yardstick.out")
58 self.assertTrue(runner.run.called)
60 @mock.patch('yardstick.cmd.commands.task.os')
61 def test_check_precondition(self, mock_os):
64 {'installer_type': 'compass',
65 'deploy_scenarios': 'os-nosdn',
66 'pod_name': 'huawei-pod1'
70 t = task.TaskParser('/opt')
71 mock_os.environ.get.side_effect = ['compass', 'os-nosdn', 'huawei-pod1']
72 result = t._check_precondition(cfg)
73 self.assertTrue(result)