def setUp(self): self._test_dir = tempfile.mkdtemp() self.test_env['VDSM_CONF'] = self._test_dir + '/vdsm.conf' self.test_env['LCONF'] = self._test_dir + '/libvirtd.conf' self.test_env['QCONF'] = self._test_dir + '/qemu.conf' self.test_env['LDCONF'] = self._test_dir + '/qemu-sanlock.conf' self.test_env['QLCONF'] = self._test_dir + '/libvirtd' self.test_env['QNETWORK'] = 'NON_EXISTENT' for key, val in self.test_env.items(): if not key == 'VDSM_CONF': FakeLibvirtFiles[key]['path'] = val _setConfig( self, ('QLCONF', 'libvirtd'), ('LDCONF', 'qemu_sanlock'), ) self.vdsm_cfg = make_config(()) self.patch = monkeypatch.Patch([ (os, 'getuid', lambda: 0), (libvirt, 'config', self.vdsm_cfg), (libvirt, 'FILES', FakeLibvirtFiles), (cpuarch, 'real', lambda: cpuarch.X86_64), (cpuinfo, 'flags', lambda: ['pdpe1gb']), ]) self.patch.apply()
def __init__(self, *a, **kw): super(VdsmTestCase, self).__init__(*a, **kw) self.module = FakeModule() self.patch = monkeypatch.Patch([ (self.module, 'a', patched), (self.module, 'b', patched), ])
def setUp(self): self._test_dir = tempfile.mkdtemp() self.test_env['VDSM_CONF'] = self._test_dir + '/vdsm.conf' self.test_env['LCONF'] = self._test_dir + '/libvirtd.conf' self.test_env['QCONF'] = self._test_dir + '/qemu.conf' self.test_env['LDCONF'] = self._test_dir + '/qemu-sanlock.conf' self.test_env['QLCONF'] = self._test_dir + '/libvirtd' self.test_env['LRCONF'] = self._test_dir + '/logrotate-libvirtd' self.test_env['QNETWORK'] = 'NON_EXISTENT' self.test_env['LRCONF_EXAMPLE'] = os.path.join( LibvirtModuleConfigureTests.srcPath, 'lib/vdsm/tool/libvirtd.logrotate') for key, val in self.test_env.items(): configurator.LibvirtModuleConfigure.FILES[key]['path'] = val self._setConfig( ('QLCONF', 'libvirtd'), ('LDCONF', 'qemu_sanlock'), ) self.patch = monkeypatch.Patch([ (os, 'getuid', lambda: 0), (configurator.LibvirtModuleConfigure, '_getFile', lambda _, x: self.test_env[x]), (configurator.LibvirtModuleConfigure, '_sysvToUpstart', lambda _: True), (utils, 'isOvirtNode', lambda: False) ]) self.patch.apply()
def setUp(self): self._test_dir = tempfile.mkdtemp() self.test_env['VDSM_CONF'] = self._test_dir + '/vdsm.conf' self.test_env['LCONF'] = self._test_dir + '/libvirtd.conf' self.test_env['QCONF'] = self._test_dir + '/qemu.conf' self.test_env['LDCONF'] = self._test_dir + '/qemu-sanlock.conf' self.test_env['QLCONF'] = self._test_dir + '/libvirtd' self.test_env['QNETWORK'] = 'NON_EXISTENT' for key, val in self.test_env.items(): if not key == 'VDSM_CONF': FakeFiles[key]['path'] = val self._setConfig( ('QLCONF', 'libvirtd'), ('LDCONF', 'qemu_sanlock'), ) self.vdsm_cfg = make_config(()) self.patch = monkeypatch.Patch([(os, 'getuid', lambda: 0), (libvirt, 'config', self.vdsm_cfg), (libvirt, 'FILES', FakeFiles), (utils, 'isOvirtNode', lambda: False)]) self.patch.apply()
def setUp(self): configurators = { "a": MockModuleConfigurator("a", should_succeed=False), "b": MockModuleConfigurator("b", should_succeed=False), } self.patch = monkeypatch.Patch([ (configurator, "_CONFIGURATORS", configurators), ]) self.patch.apply()
def testInstanceMethodReplacement(self): patch = monkeypatch.Patch([(Class, 'instance_method', patched)]) self.assertEqual(Class().instance_method(), 'clean') old = Class.instance_method patch.apply() try: self.assertEqual(Class().instance_method(), 'patched') finally: patch.revert() self.assertEqual(Class().instance_method(), 'clean') self.assertEqual(old, Class.instance_method)
def testClassMethodReplacement(self): patch = monkeypatch.Patch([(Class, 'class_method', patched)]) self.assertEqual(Class.class_method(), 'clean') old = Class.class_method patch.apply() try: self.assertEqual(Class.class_method(), 'patched') self.assertEqual(getattr(Class.class_method, '__self__'), Class) finally: patch.revert() self.assertEqual(Class.class_method(), 'clean') self.assertEqual(old, Class.class_method) self.assertEqual(getattr(Class.class_method, '__self__'), Class)
def testStaticMethodReplacement(self): patch = monkeypatch.Patch([(Class, 'static_method', patched)]) self.assertEqual(Class.static_method(), 'clean') old = Class.static_method patch.apply() try: self.assertEqual(Class.static_method(), 'patched') self.assertFalse(hasattr(Class.static_method, '__self__')) finally: patch.revert() self.assertEqual(Class.static_method(), 'clean') self.assertEqual(old, Class.static_method) self.assertFalse(hasattr(Class.static_method, '__self__'))
def setUp(self): self._test_dir = tempfile.mkdtemp() self.test_env['ABRT_CONF'] = self._test_dir + '/abrt.conf' self.test_env['CCPP_CONF'] = self._test_dir + '/CCPP.conf' self.test_env['VMCORE_CONF'] = self._test_dir + '/vmcore.conf' self.test_env['PKG_CONF'] = self._test_dir + \ '/abrt-action-save-package-data.conf' for key, val in self.test_env.items(): FakeAbrtFiles[key]['path'] = val self.patch = monkeypatch.Patch([(abrt, 'FILES', FakeAbrtFiles)]) self.patch.apply()
def setUp(self): self._temp_dir = mkdtemp() mounts, mtab = self._createFiles(self._temp_dir, 1000) old_stat = os.stat def mock_stat(path): if path.startswith('/dev/loop'): return old_stat('/') return old_stat(path) self._patch = monkeypatch.Patch([(mount, '_PROC_MOUNTS_PATH', mounts), (mount, '_ETC_MTAB_PATH', mtab), (mount, '_SYS_DEV_BLOCK_PATH', self._temp_dir), (mount, '_loopFsSpecs', {}), (os, 'stat', mock_stat), (stat, 'S_ISBLK', lambda x: True)]) self._patch.apply()
def setUp(self): self._test_dir = tempfile.mkdtemp() test_env['LCONF'] = self._test_dir + '/libvirtd.conf' test_env['QCONF'] = self._test_dir + '/qemu.conf' test_env['LDCONF'] = self._test_dir + '/qemu-sanlock.conf' test_env['QLCONF'] = self._test_dir + '/libvirtd' test_env['LIBVIRT_LOGROTATE'] = \ self._test_dir + '/logrotate-libvirtd' test_env['VDSM_CONF_FILE'] = self._test_dir + '/vdsm.conf' test_env['FORCE_RECONFIGURE'] = self._test_dir + '/reconfigure' utils.touchFile(test_env['LIBVIRT_LOGROTATE']) self._setConfig('QLCONF', 'libvirtd') self._setConfig('QCONF', 'qemu') self._setConfig('LDCONF', 'qemu-sanlock') self.patch = monkeypatch.Patch([(os, 'getuid', lambda: 0), (configurator.LibvirtModuleConfigure, '_get_libvirt_exec', get_libvirt_exec) ]) self.patch.apply()
def setUp(self): self._test_dir = tempfile.mkdtemp() self.test_env['VDSM_CONF'] = self._test_dir + '/vdsm.conf' self.test_env['LCONF'] = self._test_dir + '/libvirtd.conf' self.test_env['QCONF'] = self._test_dir + '/qemu.conf' self.test_env['LDCONF'] = self._test_dir + '/qemu-sanlock.conf' self.test_env['QLCONF'] = self._test_dir + '/libvirtd' self.test_env['QNETWORK'] = 'NON_EXISTENT' for key, val in self.test_env.items(): libvirt.FILES[key]['path'] = val self._setConfig( ('QLCONF', 'libvirtd'), ('LDCONF', 'qemu_sanlock'), ) self.patch = monkeypatch.Patch([(os, 'getuid', lambda: 0), (libvirt, '_getFile', lambda x: self.test_env[x]), (utils, 'isOvirtNode', lambda: False)]) self.patch.apply()
def setUp(self): self.temp_dir = tempfile.mkdtemp() self.patch = monkeypatch.Patch([(upgrade, 'P_VDSM_LIB', self.temp_dir) ]) os.mkdir(os.path.join(self.temp_dir, 'upgrade')) self.patch.apply()
def testAlreadyReverted(self): patch = monkeypatch.Patch([(FakeModule(), 'a', patched)]) patch.apply() patch.revert() self.assertRaises(AssertionError, patch.revert)
def testNotApplied(self): patch = monkeypatch.Patch([(FakeModule(), 'a', patched)]) self.assertRaises(AssertionError, patch.revert)