本文整理汇总了Python中vdsm.common.commands.execCmd函数的典型用法代码示例。如果您正苦于以下问题:Python execCmd函数的具体用法?Python execCmd怎么用?Python execCmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了execCmd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __enter__
def __enter__(self):
rc, out, err = execCmd([_SSH_AGENT.cmd], raw=True)
if rc != 0:
raise V2VError('Error init ssh-agent, exit code: %r'
', out: %r, err: %r' %
(rc, out, err))
m = self._ssh_auth_re.match(out)
# looking for: SSH_AUTH_SOCK=/tmp/ssh-VEE74ObhTWBT/agent.29917
self._auth = {m.group(1): m.group(2)}
self._agent_pid = m.group(3)
try:
rc, out, err = execCmd([_SSH_ADD.cmd], env=self._auth)
except:
self._kill_agent()
raise
if rc != 0:
# 1 = general fail
# 2 = no agnet
if rc != 2:
self._kill_agent()
raise V2VError('Error init ssh-add, exit code: %r'
', out: %r, err: %r' %
(rc, out, err))
示例2: testWriteLargeData
def testWriteLargeData(self):
data = """The Doctor: Davros, if you had created a virus in your
laboratory, something contagious and infectious
that killed on contact, a virus that would
destroy all other forms of life; would you allow
its use?
Davros: It is an interesting conjecture.
The Doctor: Would you do it?
Davros: The only living thing... The microscopic organism...
reigning supreme... A fascinating idea.
The Doctor: But would you do it?
Davros: Yes; yes. To hold in my hand, a capsule that
contained such power. To know that life and death on
such a scale was my choice. To know that the tiny
pressure on my thumb, enough to break the glass,
would end everything. Yes! I would do it! That power
would set me up above the gods! And through the
Daleks, I shall have that power! """
# (C) BBC - Doctor Who
data = data * 100
p = commands.execCmd([EXT_CAT], sync=False)
self.log.info("Writing data to std out")
p.stdin.write(data)
p.stdin.flush()
self.log.info("Written data reading")
self.assertEqual(p.stdout.read(len(data)), data)
示例3: testExec
def testExec(self):
"""
Tests that execCmd execs and returns the correct ret code
"""
ret, out, err = commands.execCmd([EXT_ECHO])
self.assertEqual(ret, 0)
示例4: cleanup_transient_repository
def cleanup_transient_repository(*args):
"""
cleanup-transient-repository
Cleanup the unused transient disks present in the repository.
(NOTE: it is recommended to NOT execute this command when the vdsm
daemon is running)
"""
if len(args) > 1:
raise ExtraArgsError()
transient_images = set(glob.glob(os.path.join(TRANSIENT_DISKS_REPO, "*")))
if len(transient_images) == 0:
return # Nothing to do
cmd_ret, cmd_out, cmd_err = execCmd([_fuser.cmd] + list(transient_images))
# According to: "fuser returns a non-zero return code if none of the
# specified files is accessed or in case of a fatal error. If at least
# one access has been found, fuser returns zero." we can discard the
# return code.
# NOTE: the list of open files is printed to cmd_err with an extra ":"
# character appended (removed by [:-1]).
open_transient_images = set(x[:-1] for x in cmd_err)
for image_path in transient_images - open_transient_images:
# NOTE: This could cause a race with the creation of a virtual
# machine with a transient disk (if vdsm is running).
try:
os.unlink(image_path)
except OSError as e:
if e.errno != os.errno.ENOENT:
raise
示例5: testV2VOutput
def testV2VOutput(self):
cmd = [FAKE_VIRT_V2V.cmd,
'-v',
'-x',
'-ic', self.vpx_url,
'-o', 'vdsm',
'-of', 'raw',
'-oa', 'sparse',
'--vdsm-image-uuid', self.image_id_a,
'--vdsm-vol-uuid', self.volume_id_a,
'--vdsm-image-uuid', self.image_id_b,
'--vdsm-vol-uuid', self.volume_id_b,
'--password-file', '/tmp/mypass',
'--vdsm-vm-uuid', self.job_id,
'--vdsm-ovf-output', '/usr/local/var/run/vdsm/v2v',
'--machine-readable',
'-os', '/rhev/data-center/%s/%s' % (self.pool_id,
self.domain_id),
self.vm_name]
rc, output, error = execCmd(cmd, raw=True)
self.assertEqual(rc, 0)
with io.open('fake-virt-v2v.out', 'rb') as f:
self.assertEqual(output, f.read())
with io.open('fake-virt-v2v.err', 'rb') as f:
self.assertEqual(error, f.read())
示例6: run_dd
def run_dd(self, args):
cmd = [constants.EXT_DD]
cmd.extend(args)
rc, out, err = commands.execCmd(cmd, raw=True, data=self.data)
assert rc == 0, "Process failed: rc={} err={}".format(rc, err)
assert err != '', "No data from stderr"
return out
示例7: snapshotScheduleDisable
def snapshotScheduleDisable():
command = [_snapSchedulerPath.cmd, "disable_force"]
rc, out, err = commands.execCmd(command)
if rc not in [0, SNAP_SCHEDULER_ALREADY_DISABLED_RC]:
raise ge.GlusterDisableSnapshotScheduleFailedException(
rc)
return True
示例8: _kill_agent
def _kill_agent(self):
rc, out, err = execCmd([_SSH_AGENT.cmd, '-k'],
env={'SSH_AGENT_PID': self._agent_pid})
if rc != 0:
logging.error('Error killing ssh-agent (PID=%r), exit code: %r'
', out: %r, err: %r' %
(self._agent_pid, rc, out, err))
示例9: volumeStatvfs
def volumeStatvfs(volumeName, host=GLUSTER_VOL_HOST,
port=GLUSTER_VOL_PORT,
protocol=GLUSTER_VOL_PROTOCOL):
module = "vdsm.gluster.gfapi"
command = [sys.executable, '-m', module, '-v', volumeName,
'-p', str(port), '-H', host, '-t', protocol, '-c', 'statvfs']
# to include /usr/share/vdsm in python path
env = os.environ.copy()
env['PYTHONPATH'] = "%s:%s" % (
env.get("PYTHONPATH", ""), constants.P_VDSM)
env['PYTHONPATH'] = ":".join(map(os.path.abspath,
env['PYTHONPATH'].split(":")))
rc, out, err = commands.execCmd(command, raw=True, env=env)
if rc != 0:
raise ge.GlfsStatvfsException(rc, [out], [err])
res = json.loads(out)
return os.statvfs_result((res['f_bsize'],
res['f_frsize'],
res['f_blocks'],
res['f_bfree'],
res['f_bavail'],
res['f_files'],
res['f_ffree'],
res['f_favail'],
res['f_flag'],
res['f_namemax']))
示例10: removeEphemeralBridge
def removeEphemeralBridge(bridgeName):
rc, out, err = commands.execCmd([
EXT_IP, 'link', 'del', bridgeName, 'type', 'bridge'])
if rc != 0:
raise EnvironmentError(
'Failed to remove ephemeral dummy bridge. Err: %s' % err
)
示例11: upload
def upload(url, path, headers={}):
cmd = [constants.EXT_CURL_IMG_WRAP, "--upload"]
cmd.extend(_headersToOptions(headers) + [path, url])
rc, out, err = commands.execCmd(cmd)
if rc != 0:
raise CurlError(rc, out, err)
示例12: __exit__
def __exit__(self, *args):
rc, out, err = execCmd([_SSH_ADD.cmd, '-d'], env=self._auth)
if rc != 0:
logging.error('Error deleting ssh-add, exit code: %r'
', out: %r, err: %r' %
(rc, out, err))
self._kill_agent()
示例13: test_limit_rss
def test_limit_rss():
# This should fail to allocate about 100 MiB.
script = "s = 100 * 1024**2 * 'x'"
cmd = ["python", "-c", script]
cmd = cmdutils.prlimit(cmd, address_space=100 * 1024**2)
rc, out, err = commands.execCmd(cmd, raw=True)
assert rc == 1
assert b"MemoryError" in err
示例14: _validate_module
def _validate_module(name):
if not os.path.exists('/sys/module/' + name):
cmd_modprobe = [modprobe.cmd, name]
rc, out, err = commands.execCmd(cmd_modprobe, sudo=True)
if rc != 0:
raise SkipTest("This test requires %s module "
"(failed to load module: rc=%s, out=%s, err=%s)" %
(name, rc, out, err))
示例15: testStdErr
def testStdErr(self):
"""
Tests that execCmd correctly returns the standard error of the prog it
executes.
"""
cmd = ["sh", "-c", "echo it works! >&2"]
ret, stdout, stderr = commands.execCmd(cmd)
self.assertEqual(stderr[0].decode("ascii"), "it works!")