本文整理汇总了Python中virttest.compat_52lts.decode_to_text函数的典型用法代码示例。如果您正苦于以下问题:Python decode_to_text函数的具体用法?Python decode_to_text怎么用?Python decode_to_text使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了decode_to_text函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_chap_auth_target
def set_chap_auth_target(self):
"""
set up authentication information for every single initiator,
which provides the capability to define common login information
for all Endpoints in a TPG
"""
auth_cmd = "targetcli /iscsi/%s/tpg1/ " % self.target
attr_cmd = ("set attribute %s %s %s" %
("demo_mode_write_protect=0",
"generate_node_acls=1",
"cache_dynamic_acls=1"))
process.system(auth_cmd + attr_cmd)
# Set userid
userid_cmd = "%s set auth userid=%s" % (auth_cmd, self.chap_user)
output = decode_to_text(process.system_output(userid_cmd))
if self.chap_user not in output:
raise exceptions.TestFail("Failed to set user. (%s)" % output)
# Set password
passwd_cmd = "%s set auth password=%s" % (auth_cmd, self.chap_passwd)
output = decode_to_text(process.system_output(passwd_cmd))
if self.chap_passwd not in output:
raise exceptions.TestFail("Failed to set password. (%s)" % output)
# Save configuration
process.system("targetcli / saveconfig")
示例2: get_target_id
def get_target_id(self):
"""
Get target id from image name.
"""
cmd = "targetcli ls /iscsi 1"
target_info = decode_to_text(process.system_output(cmd))
target = None
for line in re.split("\n", target_info)[1:]:
if re.findall("o-\s\S+\s[\.]+\s\[TPGs:\s\d\]$", line):
# eg: iqn.2015-05.com.example:iscsi.disk
try:
target = re.findall("iqn[\.]\S+:\S+", line)[0]
except IndexError:
logging.info("No found target in %s", line)
continue
else:
continue
cmd = "targetcli ls /iscsi/%s/tpg1/luns" % target
luns_info = decode_to_text(process.system_output(cmd))
for lun_line in re.split("\n", luns_info):
if re.findall("o-\slun\d+", lun_line):
if self.emulated_image in lun_line:
break
else:
target = None
return target
示例3: glusterd_start
def glusterd_start():
"""
Check for glusterd status and start it
"""
cmd = "service glusterd status"
output = decode_to_text(process.system_output(cmd, ignore_status=True))
# The blank before 'active' makes a distinction with 'inactive'
if ' active' not in output or 'running' not in output:
cmd = "service glusterd start"
error_context.context("Starting gluster dameon failed")
output = decode_to_text(process.system_output(cmd))
示例4: info
def info(self, force_share=False, output="human"):
"""
Run qemu-img info command on image file and return its output.
:param output: string of output format(`human`, `json`)
"""
logging.debug("Run qemu-img info command on %s", self.image_filename)
backing_chain = self.params.get("backing_chain")
force_share &= self.cap_force_share
cmd = self.image_cmd
cmd += " info"
if force_share:
cmd += " -U"
if backing_chain == "yes":
if "--backing-chain" in self.help_text:
cmd += " --backing-chain"
else:
logging.warn("'--backing-chain' option is not supported")
if os.path.exists(self.image_filename) or self.is_remote_image():
cmd += " %s --output=%s" % (self.image_filename, output)
output = decode_to_text(process.system_output(cmd, verbose=True))
else:
logging.debug("Image file %s not found", self.image_filename)
output = None
return output
示例5: snapshot_apply
def snapshot_apply(self):
"""
Apply a snapshot image.
:note: params should contain:
snapshot_image_name -- the name of snapshot image file
"""
cmd = self.image_cmd
if self.snapshot_tag:
cmd += " snapshot -a %s %s" % (self.snapshot_image_filename,
self.image_filename)
else:
raise exceptions.TestError("Can not find the snapshot image"
" parameters")
decode_to_text(process.system_output(cmd))
示例6: gen_lvmap_mpath
def gen_lvmap_mpath(session=None):
"""
Return the name mapping between logical volume and device
mapper multipathed device.
:param session: When session is given, it means VM session
Otherwise default value means it work for host
:return: None or a dict like:
{"lv_name": dm_name}
"""
names_map = None
cmd = ("lvdisplay|awk '/LV Name/{n=$3} "
"/Block device/{d=$3; sub(\".*:\", \"dm-\", d); print n,d;}'")
if session:
output = session.cmd_output(cmd).strip()
else:
output = decode_to_text(process.system_output(cmd, shell=True))
lines = output.splitlines()
if len(lines) >= 1:
names_map = {}
for line in lines:
values = line.split()
lv_name, mpath_name = values[0], values[1]
names_map.update({lv_name: mpath_name})
return names_map
示例7: iscsi_logout
def iscsi_logout(target_name=None):
"""
Logout from a target. If the target name is not set then logout all
targets.
:params target_name: Name of the target.
"""
if target_name:
cmd = "iscsiadm --mode node --logout -T %s" % target_name
else:
cmd = "iscsiadm --mode node --logout all"
output = ''
try:
output = decode_to_text(process.system_output(cmd))
except process.CmdError as detail:
# iscsiadm will fail when no matching sessions found
# This failure makes no sense when target name is not specified
stderr = results_stderr_52lts(detail.result)
if not target_name and 'No matching sessions' in stderr:
logging.info("%s: %s", detail, stderr)
else:
raise
target_logout = ""
if "successful" in output:
target_logout = target_name
return target_logout
示例8: setup_pv
def setup_pv(self, vg):
"""
Setup physical volume device if exists return it directly;
"""
pvs = []
emulate_image_file = self.get_emulate_image_name()
cmd = "losetup -j %s" % emulate_image_file
output = decode_to_text(process.system_output(cmd))
try:
pv_name = re.findall("(/dev/loop\d+)", output, re.M | re.I)[-1]
pv = self.get_vol(pv_name, "pvs")
except IndexError:
pv = None
if pv is None:
img_file = self.make_emulate_image()
pv_name = self.make_volume(img_file)
pv_size = self.params["pv_size"]
pv = PhysicalVolume(pv_name, pv_size)
pv.create()
self.register(pv)
else:
logging.warn("PhysicalVolume(%s) really exists" % pv_name +
"skip to create it")
pv.set_vg(vg)
pvs.append(pv)
return pvs
示例9: snapshot_list
def snapshot_list(self):
"""
List all snapshots in the given image
"""
cmd = self.image_cmd
cmd += " snapshot -l %s" % self.image_filename
return decode_to_text(process.system_output(cmd))
示例10: get_chap_accounts
def get_chap_accounts(self):
"""
Get all CHAP authentication accounts
"""
cmd = "tgtadm --lld iscsi --op show --mode account"
all_accounts = decode_to_text(process.system_output(cmd))
if all_accounts:
all_accounts = list(map(str.strip, all_accounts.splitlines()[1:]))
return all_accounts
示例11: snapshot_create
def snapshot_create(self):
"""
Create a snapshot image.
:note: params should contain:
snapshot_image_name -- the name of snapshot image file
"""
cmd = self.image_cmd
if self.snapshot_tag:
cmd += " snapshot -c %s" % self.snapshot_image_filename
else:
raise exceptions.TestError("Can not find the snapshot image"
" parameters")
cmd += " %s" % self.image_filename
decode_to_text(process.system_output(cmd))
return self.snapshot_tag
示例12: is_gluster_vol_avail
def is_gluster_vol_avail(vol_name):
"""
Check if the volume already available
"""
cmd = "gluster volume info"
error_context.context("Gluster volume info failed")
output = decode_to_text(process.system_output(cmd))
volume_name = re.findall(r'Volume Name: (%s)\n' % vol_name, output)
if volume_name:
return gluster_vol_start(vol_name)
示例13: rbd_image_unmap
def rbd_image_unmap(rbd_pool_name, rbd_image_name):
"""
Unmaps the block device that was mapped via the rbd kernel module
:params rbd_pool_name: The name of rbd pool
:params rbd_image_name: The name of rbd image
"""
cmd = "rbd unmap /dev/rbd/%s/%s" % (rbd_pool_name, rbd_image_name)
output = decode_to_text(process.system_output(cmd, verbose=True))
if os.path.exist(os.path.join("/dev/rbd", rbd_pool_name, rbd_image_name)):
logging.debug("Failed to unmap image from local: %s" % output)
示例14: make_volume
def make_volume(self, img_file, extra_args=""):
"""
Map a file to loop back device;
:param img_file: image file path;
:return: loop back device name;
"""
cmd = "losetup %s --show --find %s" % (extra_args, img_file)
pv_name = decode_to_text(process.system_output(cmd))
self.params["pv_name"] = pv_name.strip()
return pv_name
示例15: check_memory_in_procfs
def check_memory_in_procfs(test, params, vm):
"""
Check memory info in procfs
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param vm: VM object
"""
qemu_pid = vm.get_pid()
policy = params['policy_mem']
if policy == 'preferred':
policy = 'prefer'
for mem_dev in params['mem_devs'].split():
memdev_params = params.object_params(mem_dev)
mem_size = memdev_params['size']
mem_size = int(float(utils_misc.normalize_data_size(mem_size, "K")))
smaps = process.system_output("grep -1 %d /proc/%d/smaps"
% (mem_size, qemu_pid))
smaps = decode_to_text(smaps).strip()
mem_path = memdev_params.get("mem-path")
if mem_path and (mem_path not in smaps):
test.fail("memdev = %s: mem-path '%s' is not in smaps '%s'!"
% (mem_dev, mem_path, smaps))
mem_start = smaps.split('-')[0]
numa_maps = process.system_output("grep %s /proc/%d/numa_maps"
% (mem_start, qemu_pid))
numa_maps = decode_to_text(numa_maps).strip()
if mem_path and (mem_path not in numa_maps):
test.fail("memdev = %s: mem-path '%s' is not in numa_maps '%s'!"
% (mem_dev, mem_path, numa_maps))
policy_numa = numa_maps.split()[1].split(':')
if policy != policy_numa[0]:
test.fail("memdev = %s:"
" 'policy' in numa_maps is '%s', but not '%s'!"
% (mem_dev, policy_numa[0], policy))
elif (policy != 'default'):
host_node = memdev_params['host-nodes']
if (policy_numa[1] != host_node):
test.fail("memdev = %s:"
" 'host-nodes' in numa_maps is '%s', but not '%s'!"
% (mem_dev, policy_numa[1], host_node))