Ejemplo n.º 1
0
    def setUp(self):
        super(TestKvmRuntime, self).setUp()
        kvm_class = 'ganeti.hypervisor.hv_kvm.KVMHypervisor'
        self.MockOut('qmp',
                     mock.patch('ganeti.hypervisor.hv_kvm.QmpConnection'))
        self.MockOut('run_cmd', mock.patch('ganeti.utils.RunCmd'))
        self.MockOut('ensure_dirs', mock.patch('ganeti.utils.EnsureDirs'))
        self.MockOut('write_file', mock.patch('ganeti.utils.WriteFile'))
        self.MockOut(mock.patch(kvm_class + '.ValidateParameters'))
        self.MockOut(
            mock.patch('ganeti.hypervisor.hv_kvm.OpenTap',
                       return_value=('test_nic', [], [])))
        self.MockOut(mock.patch(kvm_class + '._ConfigureNIC'))
        self.MockOut(
            'pid_alive',
            mock.patch(kvm_class + '._InstancePidAlive',
                       return_value=('file', -1, False)))
        self.MockOut(mock.patch(kvm_class + '._ExecuteCpuAffinity'))
        self.MockOut(mock.patch(kvm_class + '._CallMonitorCommand'))

        self.cfg = ConfigMock()
        params = constants.HVC_DEFAULTS[constants.HT_KVM].copy()
        beparams = constants.BEC_DEFAULTS.copy()
        self.instance = self.cfg.AddNewInstance(name='name.example.com',
                                                hypervisor='kvm',
                                                hvparams=params,
                                                beparams=beparams)
Ejemplo n.º 2
0
    def ResetMocks(self):
        """Resets all mocks back to their initial state.

    This is useful if you want to execute more than one opcode in a single
    test.

    """
        self.cfg = ConfigMock()
        self.rpc = CreateRpcRunnerMock()
        self.ctx = GanetiContextMock(self)
        self.wconfd = WConfdMock()
        self.mcpu = ProcessorMock(self.ctx, self.wconfd)

        self._StopPatchers()
        try:
            self._iallocator_patcher = patchIAllocator(self._GetTestModule())
            self.iallocator_cls = self._iallocator_patcher.start()
        except (ImportError, AttributeError):
            # this test module does not use iallocator, no patching performed
            self._iallocator_patcher = None

        try:
            self._netutils_patcher = patchNetutils(self._GetTestModule())
            self.netutils_mod = self._netutils_patcher.start()
            SetupDefaultNetutilsMock(self.netutils_mod, self.cfg)
        except (ImportError, AttributeError):
            # this test module does not use netutils, no patching performed
            self._netutils_patcher = None

        try:
            self._ssh_patcher = patchSsh(self._GetTestModule())
            self.ssh_mod = self._ssh_patcher.start()
        except (ImportError, AttributeError):
            # this test module does not use ssh, no patching performed
            self._ssh_patcher = None

        try:
            self._rpc_patcher = patchRpc(self._GetTestModule())
            self.rpc_mod = self._rpc_patcher.start()
            SetupDefaultRpcModuleMock(self.rpc_mod)
        except (ImportError, AttributeError):
            # this test module does not use rpc, no patching performed
            self._rpc_patcher = None
Ejemplo n.º 3
0
 def _get_object_mock(self):
   """Returns a mocked instance of ConfigWriter"""
   cfg = ConfigMock(cfg_file=self.cfg_file)
   return cfg