Commit 3388debb authored by Thomas Thrainer's avatar Thomas Thrainer
Browse files

Add unit tests for LUBackupPrepare



This patch adds unit tests for LUBackupPrepare.
Signed-off-by: default avatarThomas Thrainer <thomasth@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent a80e802a
...@@ -1484,6 +1484,7 @@ python_test_support = \ ...@@ -1484,6 +1484,7 @@ python_test_support = \
test/py/cmdlib/testsupport/processor_mock.py \ test/py/cmdlib/testsupport/processor_mock.py \
test/py/cmdlib/testsupport/rpc_runner_mock.py \ test/py/cmdlib/testsupport/rpc_runner_mock.py \
test/py/cmdlib/testsupport/ssh_mock.py \ test/py/cmdlib/testsupport/ssh_mock.py \
test/py/cmdlib/testsupport/utils_mock.py \
test/py/cmdlib/testsupport/util.py test/py/cmdlib/testsupport/util.py
haskell_tests = test/hs/htest haskell_tests = test/hs/htest
......
...@@ -72,5 +72,28 @@ class TestLUBackupQuery(CmdlibTestCase): ...@@ -72,5 +72,28 @@ class TestLUBackupQuery(CmdlibTestCase):
}, ret) }, ret)
class TestLUBackupPrepare(CmdlibTestCase):
@patchUtils("instance_utils")
def testPrepareLocalExport(self, utils):
utils.ReadOneLineFile.return_value = "cluster_secret"
inst = self.cfg.AddNewInstance()
op = opcodes.OpBackupPrepare(instance_name=inst.name,
mode=constants.EXPORT_MODE_LOCAL)
self.ExecOpCode(op)
@patchUtils("instance_utils")
def testPrepareRemoteExport(self, utils):
utils.ReadOneLineFile.return_value = "cluster_secret"
inst = self.cfg.AddNewInstance()
self.rpc.call_x509_cert_create.return_value = \
self.RpcResultsBuilder() \
.CreateSuccessfulNodeResult(inst.primary_node,
("key_name",
testutils.ReadTestData("cert1.pem")))
op = opcodes.OpBackupPrepare(instance_name=inst.name,
mode=constants.EXPORT_MODE_REMOTE)
self.ExecOpCode(op)
if __name__ == "__main__": if __name__ == "__main__":
testutils.GanetiTestProgram() testutils.GanetiTestProgram()
...@@ -27,6 +27,7 @@ from cmdlib.testsupport.cmdlib_testcase import CmdlibTestCase, \ ...@@ -27,6 +27,7 @@ from cmdlib.testsupport.cmdlib_testcase import CmdlibTestCase, \
withLockedLU withLockedLU
from cmdlib.testsupport.config_mock import ConfigMock from cmdlib.testsupport.config_mock import ConfigMock
from cmdlib.testsupport.iallocator_mock import patchIAllocator from cmdlib.testsupport.iallocator_mock import patchIAllocator
from cmdlib.testsupport.utils_mock import patchUtils
from cmdlib.testsupport.lock_manager_mock import LockManagerMock from cmdlib.testsupport.lock_manager_mock import LockManagerMock
from cmdlib.testsupport.netutils_mock import patchNetutils, HostnameMock from cmdlib.testsupport.netutils_mock import patchNetutils, HostnameMock
from cmdlib.testsupport.processor_mock import ProcessorMock from cmdlib.testsupport.processor_mock import ProcessorMock
...@@ -40,6 +41,7 @@ __all__ = ["CmdlibTestCase", ...@@ -40,6 +41,7 @@ __all__ = ["CmdlibTestCase",
"CreateRpcRunnerMock", "CreateRpcRunnerMock",
"HostnameMock", "HostnameMock",
"patchIAllocator", "patchIAllocator",
"patchUtils",
"patchNetutils", "patchNetutils",
"patchSsh", "patchSsh",
"LockManagerMock", "LockManagerMock",
......
#
#
# Copyright (C) 2013 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""Support for mocking the utils module"""
from cmdlib.testsupport.util import patchModule
# pylint: disable=C0103
def patchUtils(module_under_test):
"""Patches the L{ganeti.utils} module for tests.
This function is meant to be used as a decorator for test methods.
@type module_under_test: string
@param module_under_test: the module within cmdlib which is tested. The
"ganeti.cmdlib" prefix is optional.
"""
return patchModule(module_under_test, "utils")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment