本文整理汇总了Python中testlib.namedTemporaryDir函数的典型用法代码示例。如果您正苦于以下问题:Python namedTemporaryDir函数的具体用法?Python namedTemporaryDir怎么用?Python namedTemporaryDir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了namedTemporaryDir函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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())
开发者ID:EdDev,项目名称:vdsm,代码行数:13,代码来源:netupgrade_test.py
示例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)
开发者ID:nirs,项目名称:vdsm,代码行数:13,代码来源:v2v_test.py
示例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)
开发者ID:kvaps,项目名称:vdsm,代码行数:7,代码来源:manifest_tests.py
示例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))
开发者ID:kvaps,项目名称:vdsm,代码行数:7,代码来源:manifest_tests.py
示例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
开发者ID:EdDev,项目名称:vdsm,代码行数:31,代码来源:vmfakelib.py
示例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)
开发者ID:EdDev,项目名称:vdsm,代码行数:7,代码来源:storage_qcow2_test.py
示例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)
开发者ID:EdDev,项目名称:vdsm,代码行数:7,代码来源:storage_qcow2_test.py
示例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)
开发者ID:EdDev,项目名称:vdsm,代码行数:7,代码来源:storage_qcow2_test.py
示例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']))
开发者ID:yingyun001,项目名称:vdsm,代码行数:7,代码来源:qemuimgTests.py
示例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())
开发者ID:nirs,项目名称:vdsm,代码行数:7,代码来源:mount_test.py
示例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))
开发者ID:borisroman,项目名称:vdsm,代码行数:7,代码来源:manifest_tests.py
示例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)
开发者ID:borisroman,项目名称:vdsm,代码行数:7,代码来源:manifest_tests.py
示例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)
开发者ID:Caez83,项目名称:vdsm,代码行数:30,代码来源:miscTests.py
示例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))
开发者ID:yingyun001,项目名称:vdsm,代码行数:7,代码来源:storagefakelibTests.py
示例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)
开发者ID:nirs,项目名称:vdsm,代码行数:7,代码来源:qemuimg_test.py
示例16: testEmptyDir
def testEmptyDir(self, persist=False):
"""
Test that when given an empty dir the rotator works correctly.
"""
prefix = "prefix"
with namedTemporaryDir() as dir:
misc.rotateFiles(dir, prefix, 0, persist=persist)
开发者ID:Caez83,项目名称:vdsm,代码行数:7,代码来源:miscTests.py
示例17: test_create_new
def test_create_new(self):
with namedTemporaryDir() as tmpdir:
target = os.path.join(tmpdir, "target")
link = os.path.join(tmpdir, "link")
fileUtils.atomic_symlink(target, link)
self.assertEqual(os.readlink(link), target)
self.assertFalse(os.path.exists(link + ".tmp"))
开发者ID:yingyun001,项目名称:vdsm,代码行数:7,代码来源:fileUtilTests.py
示例18: test_error_isfile
def test_error_isfile(self):
with namedTemporaryDir() as tmpdir:
target = os.path.join(tmpdir, "target")
link = os.path.join(tmpdir, "link")
with open(link, 'w') as f:
f.write('data')
self.assertRaises(OSError, fileUtils.atomic_symlink, target, link)
开发者ID:yingyun001,项目名称:vdsm,代码行数:7,代码来源:fileUtilTests.py
示例19: test_getallimages
def test_getallimages(self):
with namedTemporaryDir() as tmpdir:
manifest = make_filesd_manifest(tmpdir)
self.assertEqual(set(), manifest.getAllImages())
img_uuid = str(uuid.uuid4())
make_file_volume(manifest.domaindir, VOLSIZE, img_uuid)
self.assertIn(img_uuid, manifest.getAllImages())
开发者ID:fancyKai,项目名称:vdsm,代码行数:7,代码来源:manifest_tests.py
示例20: test_teardown_failure
def test_teardown_failure(self):
job_id = make_uuid()
sp_id = make_uuid()
sd_id = make_uuid()
img0_id = make_uuid()
img1_id = TEARDOWN_ERROR_IMAGE_ID
vol0_id = make_uuid()
vol1_id = make_uuid()
images = [
{'sd_id': sd_id, 'img_id': img0_id, 'vol_id': vol0_id},
{'sd_id': sd_id, 'img_id': img1_id, 'vol_id': vol1_id},
]
expected = [
('prepareImage', (sd_id, sp_id, img0_id, vol0_id),
{'allowIllegal': True}),
('prepareImage', (sd_id, sp_id, img1_id, vol1_id),
{'allowIllegal': True}),
('teardownImage', (sd_id, sp_id, img1_id), {}),
('teardownImage', (sd_id, sp_id, img0_id), {}),
]
with namedTemporaryDir() as base:
irs = FakeIRS(base)
job = seal.Job(job_id, sp_id, images, irs)
job.autodelete = False
job.run()
wait_for_job(job)
self.assertEqual(jobs.STATUS.FAILED, job.status)
self.assertEqual(expected, irs.__calls__)
开发者ID:EdDev,项目名称:vdsm,代码行数:32,代码来源:seal_job_test.py
注:本文中的testlib.namedTemporaryDir函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论