本文整理汇总了Python中utils.fail函数的典型用法代码示例。如果您正苦于以下问题:Python fail函数的具体用法?Python fail怎么用?Python fail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fail函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: mode_pre
def mode_pre(session_dir, args):
global gtmpfilename
"""
Read from Session file and write to session.pre file
"""
endtime_to_update = int(time.time()) - get_changelog_rollover_time(
args.volume)
status_file = os.path.join(session_dir, args.volume, "status")
status_file_pre = status_file + ".pre"
mkdirp(os.path.dirname(args.outfile), exit_on_err=True, logger=logger)
# If Pre status file exists and running pre command again
if os.path.exists(status_file_pre) and not args.regenerate_outfile:
fail("Post command is not run after last pre, "
"use --regenerate-outfile")
start = 0
try:
with open(status_file) as f:
start = int(f.read().strip())
except ValueError:
pass
except (OSError, IOError) as e:
fail("Error Opening Session file %s: %s"
% (status_file, e), logger=logger)
logger.debug("Pre is called - Session: %s, Volume: %s, "
"Start time: %s, End time: %s"
% (args.session, args.volume, start, endtime_to_update))
prefix = datetime.now().strftime("%Y%m%d-%H%M%S-%f-")
gtmpfilename = prefix + next(tempfile._get_candidate_names())
run_cmd_nodes("pre", args, start=start, end=-1, tmpfilename=gtmpfilename)
# Merger
if args.full:
cmd = ["sort", "-u"] + node_outfiles + ["-o", args.outfile]
execute(cmd,
exit_msg="Failed to merge output files "
"collected from nodes", logger=logger)
else:
# Read each Changelogs db and generate finaldb
create_file(args.outfile, exit_on_err=True, logger=logger)
outfilemerger = OutputMerger(args.outfile + ".db", node_outfiles)
write_output(args.outfile, outfilemerger, args.field_separator)
try:
os.remove(args.outfile + ".db")
except (IOError, OSError):
pass
run_cmd_nodes("cleanup", args, tmpfilename=gtmpfilename)
with open(status_file_pre, "w", buffering=0) as f:
f.write(str(endtime_to_update))
sys.stdout.write("Generated output file %s\n" % args.outfile)
开发者ID:raghavendrabhat,项目名称:glusterfs,代码行数:60,代码来源:main.py
示例2: post_servers_1234_action
def post_servers_1234_action(self, body, **kw):
assert_equal(len(body.keys()), 1)
action = body.keys()[0]
if action == 'reboot':
assert_equal(body[action].keys(), ['type'])
assert_in(body[action]['type'], ['HARD', 'SOFT'])
elif action == 'rebuild':
assert_equal(body[action].keys(), ['imageId'])
elif action == 'resize':
assert_equal(body[action].keys(), ['flavorId'])
elif action == 'createBackup':
assert_equal(set(body[action].keys()),
set(['name', 'rotation', 'backup_type']))
elif action == 'confirmResize':
assert_equal(body[action], None)
# This one method returns a different response code
return (204, None)
elif action == 'revertResize':
assert_equal(body[action], None)
elif action == 'migrate':
assert_equal(body[action], None)
elif action == 'addFixedIp':
assert_equal(body[action].keys(), ['networkId'])
elif action == 'removeFixedIp':
assert_equal(body[action].keys(), ['address'])
else:
fail("Unexpected server action: %s" % action)
return (202, None)
开发者ID:EdLeafe,项目名称:python-novaclient,代码行数:28,代码来源:fakeserver.py
示例3: post_servers_1234_action
def post_servers_1234_action(self, body, **kw):
assert_equal(len(body.keys()), 1)
action = body.keys()[0]
if action == "reboot":
assert_equal(body[action].keys(), ["type"])
assert_in(body[action]["type"], ["HARD", "SOFT"])
elif action == "rebuild":
assert_equal(body[action].keys(), ["imageId"])
elif action == "resize":
assert_equal(body[action].keys(), ["flavorId"])
elif action == "confirmResize":
assert_equal(body[action], None)
# This one method returns a different response code
return (204, None)
elif action == "revertResize":
assert_equal(body[action], None)
elif action == "migrate":
assert_equal(body[action], None)
elif action == "addFixedIp":
assert_equal(body[action].keys(), ["networkId"])
elif action == "removeFixedIp":
assert_equal(body[action].keys(), ["address"])
else:
fail("Unexpected server action: %s" % action)
return (202, None)
开发者ID:blamarvt,项目名称:python-novaclient,代码行数:25,代码来源:fakeserver.py
示例4: main
def main():
# Bind to service port
server_port = mach.BootstrapServer.lookup("org.freenas.test.mach.ipc-server")
local_port = mach.Port()
print 'Service port: {0}'.format(server_port)
print 'Local port: {0}'.format(local_port)
# Send a few messages
for i in range(0, 100):
msg = mach.Message()
msg.bits = mach.make_msg_bits(
mach.MessageType.MACH_MSG_TYPE_COPY_SEND,
mach.MessageType.MACH_MSG_TYPE_MAKE_SEND
)
msg.body = bytearray(random_str())
local_port.send(server_port, msg)
reply = local_port.receive()
print 'Received reply: {0}'.format(reply.body)
if reply.body != msg.body:
fail('Reply mismatch: {0} != {1}'.format(msg.body, reply.body))
# Exit
msg = mach.Message()
msg.bits = mach.make_msg_bits(
mach.MessageType.MACH_MSG_TYPE_COPY_SEND,
mach.MessageType.MACH_MSG_TYPE_MAKE_SEND
)
msg.body = bytearray('EXIT')
mach.null_port.send(server_port, msg)
开发者ID:650elx,项目名称:middleware,代码行数:32,代码来源:echoclient.py
示例5: main
def main():
args = _get_args()
mkdirp(conf.get_opt("session_dir"), exit_on_err=True)
if args.mode == "list":
session_dir = conf.get_opt("session_dir")
else:
session_dir = os.path.join(conf.get_opt("session_dir"),
args.session)
if not os.path.exists(session_dir) and args.mode not in ["create", "list"]:
fail("Invalid session %s" % args.session)
vol_dir = os.path.join(session_dir, args.volume)
if not os.path.exists(vol_dir) and args.mode not in ["create", "list"]:
fail("Session %s not created with volume %s" %
(args.session, args.volume))
mkdirp(os.path.join(conf.get_opt("log_dir"), args.session, args.volume),
exit_on_err=True)
log_file = os.path.join(conf.get_opt("log_dir"),
args.session,
args.volume,
"cli.log")
setup_logger(logger, log_file, args.debug)
# globals() will have all the functions already defined.
# mode_<args.mode> will be the function name to be called
globals()["mode_" + args.mode](session_dir, args)
开发者ID:bcicen,项目名称:glusterfs,代码行数:29,代码来源:main.py
示例6: gfid_to_path_using_batchfind
def gfid_to_path_using_batchfind(brick, gfids_file, output_file):
"""
find -samefile gets the inode number and crawls entire namespace
to get the list of files/dirs having same inode number.
Do find without any option, except the ignore directory option,
print the output in <INODE_NUM> <PATH> format, use this output
to look into in-memory dictionary of inode numbers got from the
list of GFIDs
"""
with open(output_file, "a+") as fout:
inode_dict = {}
with open(gfids_file) as f:
for gfid in f:
gfid = gfid.strip()
backend_path = os.path.join(brick, ".glusterfs",
gfid[0:2], gfid[2:4], gfid)
try:
inode_dict[str(os.stat(backend_path).st_ino)] = 1
except (IOError, OSError) as e:
if e.errno == ENOENT:
continue
else:
fail("%s Failed to convert to path from "
"GFID %s: %s" % (brick, gfid, e), logger=logger)
if not inode_dict:
return
def inode_filter(path):
try:
st = os.lstat(path)
except (OSError, IOError) as e:
if e.errno == ENOENT:
st = None
else:
raise
if st and inode_dict.get(str(st.st_ino), None):
return True
return False
brick_path_len = len(brick)
def output_callback(path):
path = path.strip()
path = path[brick_path_len+1:]
output_write(fout, path, args.output_prefix)
ignore_dirs = [os.path.join(brick, dirname)
for dirname in
conf.get_opt("brick_ignore_dirs").split(",")]
# Length of brick path, to remove from output path
find(brick, callback_func=output_callback,
filter_func=inode_filter,
ignore_dirs=ignore_dirs)
fout.flush()
os.fsync(fout.fileno())
开发者ID:SourabhShenoy,项目名称:glusterfs,代码行数:60,代码来源:changelog.py
示例7: mode_pre
def mode_pre(session_dir, args):
"""
Read from Session file and write to session.pre file
"""
endtime_to_update = int(time.time()) - int(
conf.get_opt("changelog_rollover_time"))
status_file = os.path.join(session_dir, args.volume, "status")
status_file_pre = status_file + ".pre"
mkdirp(os.path.dirname(args.outfile), exit_on_err=True, logger=logger)
start = 0
try:
with open(status_file) as f:
start = int(f.read().strip())
except ValueError:
pass
except (OSError, IOError) as e:
fail("Error Opening Session file %s: %s"
% (status_file, e), logger=logger)
logger.debug("Pre is called - Session: %s, Volume: %s, "
"Start time: %s, End time: %s"
% (args.session, args.volume, start, endtime_to_update))
run_in_nodes(args.volume, start, args)
with open(status_file_pre, "w", buffering=0) as f:
f.write(str(endtime_to_update))
sys.stdout.write("Generated output file %s\n" % args.outfile)
开发者ID:SourabhShenoy,项目名称:glusterfs,代码行数:31,代码来源:main.py
示例8: _run_match
def _run_match(self):
"""Match log files"""
cwd_listdir = [path.join(self.cwd, f) for f in listdir(self.cwd)]
suffix = '{}.log.match'.format(self.testnum)
def is_matchfile(f):
"""Match file ends with specific suffix and a char before suffix
is not a digit"""
before_suffix = -len(suffix) - 1
return path.isfile(f) and f.endswith(suffix) and \
not f[before_suffix].isdigit()
match_files = filter(is_matchfile, cwd_listdir)
prefix = 'perl ' if sys.platform == 'win32' else ''
match_cmd = prefix + path.join(hlp.ROOTDIR, 'match')
for mf in match_files:
cmd = '{} {}'.format(match_cmd, mf)
proc = sp.run(cmd.split(), stdout=sp.PIPE, cwd=self.cwd,
stderr=sp.STDOUT, universal_newlines=True)
if proc.returncode != 0:
fail(proc.stdout, exit_code=proc.returncode)
else:
self.msg.print_verbose(proc.stdout)
开发者ID:wlemkows,项目名称:nvml,代码行数:25,代码来源:basetest.py
示例9: get_nodes
def get_nodes(volume):
"""
Get the gluster volume info xml output and parse to get
the brick details.
"""
global vol_statusStr;
cmd = ["gluster", 'volume', 'info', volume, "--xml"]
_, data, _ = execute(cmd,
exit_msg="Failed to Run Gluster Volume Info",
logger=logger)
tree = etree.fromstring(data)
# Test to check if volume has been deleted after session creation
count_el = tree.find('volInfo/volumes/count')
if int(count_el.text) == 0:
fail("Unable to get volume details", logger=logger)
# this status is used in caller: run_cmd_nodes
vol_statusStr = tree.find('volInfo/volumes/volume/statusStr').text
nodes = []
volume_el = tree.find('volInfo/volumes/volume')
try:
for b in volume_el.findall('bricks/brick'):
nodes.append((b.find('hostUuid').text,
b.find('name').text))
except (ParseError, AttributeError, ValueError) as e:
fail("Failed to parse Volume Info: %s" % e, logger=logger)
return nodes
开发者ID:bcicen,项目名称:glusterfs,代码行数:31,代码来源:main.py
示例10: read
def read(self, arg):
newresult = {}
f = open(self.arg_id(arg), "r")
for line in f.readlines():
line = line.strip().split()
if len(line) % 2 == 1 or len(line) < 2:
# Fail
utils.fail(self.arg_id(arg))
f.close()
return
new_key = {k: v for k, v in arg}
# parse line
for i in xrange(0, len(line) - 2, 2):
i_name = line[i]
i_value = float(line[i + 1])
new_key[i_name] = i_value
new_key["name"] = line[-2]
newresult[utils.dict2tuple(new_key)] = float(line[-1])
# Merge result with newresult
for k in newresult.keys():
self.result[k] = newresult[k]
f.close()
开发者ID:cjf00000,项目名称:experiments,代码行数:28,代码来源:dir.py
示例11: export
def export(self, targz: str, **kwargs: dict):
if not os.path.isdir(self.path):
utils.fail("%s: VM does not exist" % self.name)
exit(1)
if not targz:
targz = '%s.tar.gz' % self.name
targz = os.path.abspath(targz)
utils.info("exporting to %s" % targz)
tar = '%s/%s' % (self.path, os.path.basename(os.path.splitext(targz)[0]))
if os.path.exists(targz):
utils.fail("%s: package already exists" % targz)
exit(1)
os.chdir(self.path) # create intermediate files in VM's path
utils.pend("package disk image")
utils.execute(['tar', '-cSf', tar, os.path.basename(self.path_raw)])
utils.ok()
for s in self.snapshots:
utils.pend("package snapshot: %s" % s)
local_snapshot = '%s.%s' % (os.path.basename(self.path_raw), s)
utils.execute(['tar', '-rf', tar, local_snapshot])
utils.ok()
utils.pend("compress package", msg="may take some time")
utils.execute(['gzip', '-c', tar], outfile=targz)
utils.ok()
utils.pend("clean up")
os.unlink(tar)
utils.ok()
self.scan_snapshots()
开发者ID:AmesianX,项目名称:chef,代码行数:34,代码来源:vm.py
示例12: exec
def exec(self, cmd, args='', expected_exit=0):
"""Execute binary in current test context"""
env = {**self.env, **os.environ.copy(), **self.test.utenv}
if sys.platform == 'win32':
env['PATH'] = self.build.libdir + os.pathsep +\
envconfig['GLOBAL_LIB_PATH'] + os.pathsep +\
env.get('PATH', '')
cmd = os.path.join(self.build.exedir, cmd) + '.exe'
else:
if self.test.ld_preload:
env['LD_PRELOAD'] = env.get('LD_PRELOAD', '') + os.pathsep +\
self.test.ld_preload
self.valgrind.handle_ld_preload(self.test.ld_preload)
env['LD_LIBRARY_PATH'] = self.build.libdir + os.pathsep +\
envconfig['GLOBAL_LIB_PATH'] + os.pathsep +\
env.get('LD_LIBRARY_PATH', '')
cmd = os.path.join(self.test.cwd, cmd) + self.build.exesuffix
cmd = '{} {}'.format(self.valgrind.cmd, cmd)
proc = sp.run('{} {}'.format(cmd, args), env=env, cwd=self.test.cwd,
shell=True, timeout=self.conf.timeout, stdout=sp.PIPE,
stderr=sp.STDOUT, universal_newlines=True)
if sys.platform != 'win32' and expected_exit == 0 \
and not self.valgrind.validate_log():
self.test.fail(proc.stdout)
if proc.returncode != expected_exit:
fail(proc.stdout, exit_code=proc.returncode)
else:
self.msg.print_verbose(proc.stdout)
开发者ID:wlemkows,项目名称:nvml,代码行数:34,代码来源:context.py
示例13: mode_create
def mode_create(session_dir, args):
validate_session_name(args.session)
logger.debug("Init is called - Session: %s, Volume: %s"
% (args.session, args.volume))
mkdirp(session_dir, exit_on_err=True, logger=logger)
mkdirp(os.path.join(session_dir, args.volume), exit_on_err=True,
logger=logger)
status_file = os.path.join(session_dir, args.volume, "status")
if os.path.exists(status_file) and not args.force:
fail("Session %s already created" % args.session, logger=logger)
if not os.path.exists(status_file) or args.force:
ssh_setup(args)
enable_volume_options(args)
# Add Rollover time to current time to make sure changelogs
# will be available if we use this time as start time
time_to_update = int(time.time()) + get_changelog_rollover_time(
args.volume)
run_cmd_nodes("create", args, time_to_update=str(time_to_update))
if not os.path.exists(status_file) or args.reset_session_time:
with open(status_file, "w") as f:
f.write(str(time_to_update))
sys.stdout.write("Session %s created with volume %s\n" %
(args.session, args.volume))
sys.exit(0)
开发者ID:gluster,项目名称:glusterfs,代码行数:32,代码来源:main.py
示例14: main
def main():
# Start service
try:
l = launchd.Launchd()
l.load(PLIST)
except OSError, e:
fail('Cannot load launchd job: {0}', e)
开发者ID:650elx,项目名称:middleware,代码行数:7,代码来源:echo.py
示例15: main
def main():
# Create send port
try:
send = mach.Port()
send.insert_right(mach.MessageType.MACH_MSG_TYPE_MAKE_SEND)
print 'Send port: {0}'.format(send)
except mach.MachException, e:
fail('Cannot create send port: {0}'.format(e))
开发者ID:NextBSD,项目名称:py-mach,代码行数:8,代码来源:ool-multiple.py
示例16: vm_init
def vm_init(path: str):
utils.pend("initialise VM directory: %s" % path)
try:
os.mkdir(path)
except OSError as e:
utils.fail(e.strip())
exit(1)
utils.ok()
开发者ID:AmesianX,项目名称:chef,代码行数:8,代码来源:vm.py
示例17: mode_list
def mode_list(session_dir, args):
"""
List available sessions to stdout, if session name is set
only list that session.
"""
if args.session:
if not os.path.exists(os.path.join(session_dir, args.session)):
fail("Invalid Session", logger=logger)
sessions = [args.session]
else:
sessions = []
for d in os.listdir(session_dir):
if d != ".keys":
sessions.append(d)
output = []
for session in sessions:
# Session Volume Last Processed
volnames = os.listdir(os.path.join(session_dir, session))
for volname in volnames:
if args.volume and args.volume != volname:
continue
status_file = os.path.join(session_dir, session, volname, "status")
last_processed = None
try:
with open(status_file) as f:
last_processed = f.read().strip()
except (OSError, IOError) as e:
if e.errno == ENOENT:
pass
else:
raise
output.append((session, volname, last_processed))
if output:
sys.stdout.write("%s %s %s\n" % ("SESSION".ljust(25),
"VOLUME".ljust(25),
"SESSION TIME".ljust(25)))
sys.stdout.write("-"*75)
sys.stdout.write("\n")
for session, volname, last_processed in output:
sess_time = 'Session Corrupted'
if last_processed:
try:
sess_time = human_time(last_processed)
except TypeError:
sess_time = 'Session Corrupted'
sys.stdout.write("%s %s %s\n" % (session.ljust(25),
volname.ljust(25),
sess_time.ljust(25)))
if not output:
if args.session or args.volume:
fail("Invalid Session", logger=logger)
else:
sys.stdout.write("No sessions found.\n")
开发者ID:newpant,项目名称:glusterfs,代码行数:58,代码来源:main.py
示例18: __init__
def __init__(self, path_yaml: str):
if not os.path.isfile(path_yaml):
utils.fail("%s: file not found" % path_yaml)
exit(1)
yaml = Batch.YAML(path_yaml)
self.variables = yaml.tree['variables']
self.commands = []
for ctoken, i in zip(yaml.tree['commands'], range(len(yaml.tree['commands']))):
c = Batch.Command(ctoken, self.variables)
self.commands.append(c)
开发者ID:AmesianX,项目名称:chef,代码行数:10,代码来源:batch.py
示例19: import_raw
def import_raw(self, raw: str, force: bool):
if not os.path.exists(raw):
utils.fail("%s: file not found" % raw)
exit(1)
self.initialise(force)
utils.pend("copy disk image")
utils.execute(['cp', raw, self.path_raw])
utils.ok()
开发者ID:AmesianX,项目名称:chef,代码行数:10,代码来源:vm.py
示例20: set_parts
def set_parts(self, *parts):
"""
Adds a main pool to the poolset file.
The function accepts a list of Parts of any length.
Should not be called more than once.
"""
if not self.parts:
self.parts = list(parts)
else:
fail('This function should not be called more than once.')
开发者ID:krzycz,项目名称:nvml,代码行数:10,代码来源:poolset.py
注:本文中的utils.fail函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论