本文整理汇总了Python中testlib.namedTemporaryDir函数的典型用法代码示例。如果您正苦于以下问题:Python namedTemporaryDir函数的具体用法?Python namedTemporaryDir怎么用?Python namedTemporaryDir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了namedTemporaryDir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_upgrade_volatile_running_config
def test_upgrade_volatile_running_config(self):
with namedTemporaryDir() as pdir, namedTemporaryDir() as vdir:
with mock.patch.object(netconf, 'CONF_RUN_DIR', pdir),\
mock.patch.object(netconf, 'CONF_VOLATILE_RUN_DIR', vdir):
vol_rconfig = netconf.RunningConfig(volatile=True)
vol_rconfig.save()
netupgrade.upgrade()
pers_rconfig = netconf.RunningConfig()
self.assertFalse(vol_rconfig.config_exists())
self.assertTrue(pers_rconfig.config_exists())
示例2: _commonConvertExternalVM
def _commonConvertExternalVM(self, url):
with namedTemporaryDir() as v2v._V2V_DIR, \
namedTemporaryDir() as v2v._LOG_DIR:
v2v.convert_external_vm(url,
'root',
ProtectedPassword('mypassword'),
self.vminfo,
self.job_id,
FakeIRS())
job = v2v._jobs[self.job_id]
job.wait()
self.assertEqual(job.status, v2v.STATUS.DONE)
示例3: test_getblocksize
def test_getblocksize(self):
with namedTemporaryDir():
metadata = {blockSD.DMDK_LOGBLKSIZE: 2048,
blockSD.DMDK_PHYBLKSIZE: 1024}
manifest = self.make_manifest(metadata)
self.assertEquals(2048, manifest.logBlkSize)
self.assertEquals(1024, manifest.phyBlkSize)
示例4: test_getmetaparam
def test_getmetaparam(self):
with namedTemporaryDir():
metadata = {}
manifest = self.make_manifest(metadata)
metadata[sd.DMDK_SDUUID] = manifest.sdUUID
self.assertEquals(manifest.sdUUID,
manifest.getMetaParam(sd.DMDK_SDUUID))
示例5: VM
def VM(params=None, devices=None, runCpu=False,
arch=cpuarch.X86_64, status=None,
cif=None, create_device_objects=False,
post_copy=None, recover=False):
with namedTemporaryDir() as tmpDir:
with MonkeyPatchScope([(constants, 'P_VDSM_RUN', tmpDir),
(libvirtconnection, 'get', Connection),
(containersconnection, 'get', Connection),
(vm.Vm, '_updateDomainDescriptor',
_updateDomainDescriptor),
(vm.Vm, 'send_status_event',
lambda _, **kwargs: None)]):
vmParams = {'vmId': 'TESTING', 'vmName': 'nTESTING'}
vmParams.update({} if params is None else params)
cif = ClientIF() if cif is None else cif
fake = vm.Vm(cif, vmParams, recover=recover)
cif.vmContainer[fake.id] = fake
fake.arch = arch
fake.guestAgent = GuestAgent()
fake.conf['devices'] = [] if devices is None else devices
if create_device_objects:
fake._devices = common.dev_map_from_dev_spec_map(
fake._devSpecMapFromConf(), fake.log
)
fake._guestCpuRunning = runCpu
if status is not None:
fake._lastStatus = status
if post_copy is not None:
fake._post_copy = post_copy
sampling.stats_cache.add(fake.id)
yield fake
示例6: test_full
def test_full(self):
with namedTemporaryDir() as tmpdir:
filename = os.path.join(tmpdir, 'test')
with io.open(filename, "wb") as f:
f.write(b"x" * qcow2.CLUSTER_SIZE * 3)
runs = qemuimg.map(filename)
self.assertEqual(qcow2.count_clusters(runs), 3)
示例7: test_empty_sparse
def test_empty_sparse(self):
with namedTemporaryDir() as tmpdir:
filename = os.path.join(tmpdir, 'test')
with io.open(filename, "wb") as f:
f.truncate(MB)
runs = qemuimg.map(filename)
self.assertEqual(qcow2.count_clusters(runs), 0)
示例8: check_best_small
def check_best_small(self, compat, size):
with namedTemporaryDir() as tmpdir:
filename = os.path.join(tmpdir, 'test')
with io.open(filename, "wb") as f:
f.truncate(size)
f.write("x" * MB)
self.check_estimate(filename, compat)
示例9: test_check
def test_check(self):
with namedTemporaryDir() as tmpdir:
path = os.path.join(tmpdir, 'test.qcow2')
qemuimg.create(path, size=1048576, format=qemuimg.FORMAT.QCOW2)
info = qemuimg.check(path)
# The exact value depends on qcow2 internals
self.assertEqual(int, type(info['offset']))
示例10: testLoopMount
def testLoopMount(self):
with namedTemporaryDir() as mpath:
# two nested with blocks to be python 2.6 friendly
with createFloppyImage(FLOPPY_SIZE) as path:
m = mount.Mount(path, mpath)
with loop_mount(m):
self.assertTrue(m.isMounted())
示例11: test_getmetaparam
def test_getmetaparam(self):
with namedTemporaryDir() as tmpdir:
metadata = {sd.DMDK_VERSION: 3}
manifest = make_filesd_manifest(tmpdir, metadata)
metadata[sd.DMDK_SDUUID] = manifest.sdUUID
self.assertEquals(manifest.sdUUID,
manifest.getMetaParam(sd.DMDK_SDUUID))
示例12: test_getblocksize_defaults
def test_getblocksize_defaults(self):
with namedTemporaryDir() as tmpdir:
lvm = FakeLVM(tmpdir)
with MonkeyPatchScope([(blockSD, 'lvm', lvm)]):
manifest = make_blocksd(tmpdir, lvm)
self.assertEquals(512, manifest.logBlkSize)
self.assertEquals(512, manifest.phyBlkSize)
示例13: testFullDir
def testFullDir(self, persist=False):
"""
Test that rotator does it's basic functionality.
"""
# Prepare
prefix = "prefix"
stubContent = ('"Multiple exclamation marks", '
'he went on, shaking his head, '
'"are a sure sign of a diseased mind."')
# (C) Terry Pratchet - Small Gods
with namedTemporaryDir() as dir:
gen = 10
expectedDirContent = []
for i in range(gen):
fname = "%s.txt.%d" % (prefix, i + 1)
expectedDirContent.append("%s.txt.%d" % (prefix, i + 1))
f = open(os.path.join(dir, fname), "wb")
f.write(stubContent)
f.flush()
f.close()
# Rotate
misc.rotateFiles(dir, prefix, gen, persist=persist)
# Test result
currentDirContent = os.listdir(dir)
expectedDirContent.sort()
currentDirContent.sort()
self.assertEquals(currentDirContent, expectedDirContent)
示例14: test_lvpath
def test_lvpath(self):
with namedTemporaryDir() as tmpdir:
lvm = FakeLVM(tmpdir)
vg_name = 'foo'
lv_name = 'bar'
expected = os.path.join(tmpdir, 'dev', vg_name, lv_name)
self.assertEqual(expected, lvm.lvPath(vg_name, lv_name))
示例15: test_unsafe_create_volume
def test_unsafe_create_volume(self):
with namedTemporaryDir() as tmpdir:
path = os.path.join(tmpdir, 'test.qcow2')
# Using unsafe=True to verify that it is possible to create an
# image based on a non-existing backing file, like an inactive LV.
qemuimg.create(path, size=1048576, format=qemuimg.FORMAT.QCOW2,
backing='no-such-file', unsafe=True)