Merge branch '5.1_shell_cleanup' of git-ssh.web.boeing.com:Boeing-CORE/CORE into 5.1_shell_cleanup
This commit is contained in:
commit
01060c50ff
3 changed files with 30 additions and 5 deletions
|
@ -173,8 +173,10 @@ class SimpleLxcNode(PyCoreNode):
|
|||
source = os.path.abspath(source)
|
||||
logger.info("mounting %s at %s" % (source, target))
|
||||
try:
|
||||
shcmd = 'mkdir -p "%s" && %s -n --bind "%s" "%s"' % (target, constants.MOUNT_BIN, source, target)
|
||||
self.client.shcmd(shcmd)
|
||||
cmd = 'mkdir -p "%s" && %s -n --bind "%s" "%s"' % (target, constants.MOUNT_BIN, source, target)
|
||||
status, output = self.client.shcmd_result(cmd)
|
||||
if status:
|
||||
raise IOError("error during mount: %s" % output)
|
||||
self._mounts.append((source, target))
|
||||
except IOError:
|
||||
logger.exception("mounting failed for %s at %s", source, target)
|
||||
|
@ -447,8 +449,16 @@ class SimpleLxcNode(PyCoreNode):
|
|||
:param str filename: file name to add
|
||||
:return: nothing
|
||||
"""
|
||||
shcmd = 'mkdir -p $(dirname "%s") && mv "%s" "%s" && sync' % (filename, srcname, filename)
|
||||
self.client.shcmd(shcmd)
|
||||
logger.info("adding file from %s to %s", srcname, filename)
|
||||
directory = os.path.dirname(filename)
|
||||
|
||||
try:
|
||||
cmd = 'mkdir -p "%s" && mv "%s" "%s" && sync' % (directory, srcname, filename)
|
||||
status, output = self.client.shcmd_result(cmd)
|
||||
if status:
|
||||
logger.error("error adding file: %s", output)
|
||||
except IOError:
|
||||
logger.exception("error during addfile")
|
||||
|
||||
def getaddr(self, ifname, rescan=False):
|
||||
"""
|
||||
|
|
|
@ -6,6 +6,7 @@ by invoking the vcmd shell command.
|
|||
"""
|
||||
|
||||
import os
|
||||
import shlex
|
||||
|
||||
import vcmd
|
||||
|
||||
|
@ -93,6 +94,10 @@ class VnodeClient(object):
|
|||
"""
|
||||
self._verify_connection()
|
||||
|
||||
# split shell string to shell array for convenience
|
||||
if type(args) == str:
|
||||
args = shlex.split(args)
|
||||
|
||||
p, stdin, stdout, stderr = self.popen(args)
|
||||
output = stdout.read() + stderr.read()
|
||||
stdin.close()
|
||||
|
@ -184,6 +189,17 @@ class VnodeClient(object):
|
|||
"""
|
||||
return self.cmd([sh, "-c", cmdstr])
|
||||
|
||||
def shcmd_result(self, cmd, sh="/bin/sh"):
|
||||
"""
|
||||
Execute a shell command and return the exist status and combined output.
|
||||
|
||||
:param str cmd: shell command to run
|
||||
:param str sh: shell to run command in
|
||||
:return: exist status and combined output
|
||||
:rtype: tuple[int, str]
|
||||
"""
|
||||
return self.cmdresult([sh, "-c", cmd])
|
||||
|
||||
def getaddr(self, ifname, rescan=False):
|
||||
"""
|
||||
Get address for interface on node.
|
||||
|
|
|
@ -186,7 +186,6 @@ class TestCore:
|
|||
assert not client.shcmd(command[0])
|
||||
|
||||
# check various command using command line
|
||||
vnodeclient.USE_VCMD_MODULE = False
|
||||
assert not client.cmd(command)
|
||||
status, output = client.cmdresult(command)
|
||||
assert not status
|
||||
|
|
Loading…
Reference in a new issue