1 ##############################################################################
2 # Copyright (c) 2016 Huan Li and others
3 # lihuansse@tongji.edu.cn
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.availability.operation
13 from __future__ import absolute_import
16 from yardstick.benchmark.scenarios.availability.operation import \
20 # pylint: disable=unused-argument
21 # disable this for now because I keep forgetting mock patch arg ordering
24 @mock.patch('yardstick.benchmark.scenarios.availability.operation.'
25 'operation_general.ssh')
26 @mock.patch('yardstick.benchmark.scenarios.availability.operation.'
27 'operation_general.open')
28 class GeneralOperaionTestCase(unittest.TestCase):
34 "key_filename": "/root/.ssh/id_rsa"
36 self.context = {"node1": host}
37 self.operation_cfg = {
38 'operation_type': 'general-operation',
39 'action_parameter': {'ins_cup': 2},
40 'rollback_parameter': {'ins_id': 'id123456'},
41 'key': 'nova-create-instance',
42 'operation_key': 'nova-create-instance',
45 self.operation_cfg_noparam = {
46 'operation_type': 'general-operation',
47 'key': 'nova-create-instance',
48 'operation_key': 'nova-create-instance',
52 def test__operation_successful(self, mock_open, mock_ssh):
53 ins = operation_general.GeneralOperaion(self.operation_cfg,
55 mock_ssh.SSH.from_node().execute.return_value = (0, "success", '')
60 def test__operation_successful_noparam(self, mock_open, mock_ssh):
61 ins = operation_general.GeneralOperaion(self.operation_cfg_noparam,
63 mock_ssh.SSH.from_node().execute.return_value = (0, "success", '')
68 def test__operation_fail(self, mock_open, mock_ssh):
69 ins = operation_general.GeneralOperaion(self.operation_cfg,
71 mock_ssh.SSH.from_node().execute.return_value = (1, "failed", '')