updates to check_cmd to just return output, as status is pointless

This commit is contained in:
Blake J. Harnden 2018-03-02 13:57:50 -08:00
parent 43554cbb62
commit a8ee7f35d6
12 changed files with 45 additions and 51 deletions

View file

@ -417,8 +417,8 @@ class PyCoreNode(PyCoreObj):
Runs shell command on node.
:param list[str]|str args: command to run
:return: exist status and combined stdout and stderr
:rtype: tuple[int, str]
:return: combined stdout and stderr
:rtype: str
:raises subprocess.CalledProcessError: when a non-zero exit status occurs
"""
raise NotImplementedError

View file

@ -26,20 +26,19 @@ def emane_version():
VERSION = EMANEUNK
try:
status, output = utils.check_cmd(args)
if status == 0:
if output.startswith("0.7.4"):
VERSION = EMANE074
elif output.startswith("0.8.1"):
VERSION = EMANE081
elif output.startswith("0.9.1"):
VERSION = EMANE091
elif output.startswith("0.9.2"):
VERSION = EMANE092
elif output.startswith("0.9.3"):
VERSION = EMANE093
elif output.startswith("1.0.1"):
VERSION = EMANE101
output = utils.check_cmd(args)
if output.startswith("0.7.4"):
VERSION = EMANE074
elif output.startswith("0.8.1"):
VERSION = EMANE081
elif output.startswith("0.9.1"):
VERSION = EMANE091
elif output.startswith("0.9.2"):
VERSION = EMANE092
elif output.startswith("0.9.3"):
VERSION = EMANE093
elif output.startswith("1.0.1"):
VERSION = EMANE101
except subprocess.CalledProcessError:
logger.exception("error checking emane version")
output = ""

View file

@ -927,10 +927,9 @@ class EmaneManager(ConfigurableManager):
try:
args = emanecmd + ["-f", os.path.join(path, "emane%d.log" % n),
os.path.join(path, "platform%d.xml" % n)]
logger.info("Emane.startdaemons2() running %s" % str(args))
status, output = node.check_cmd(args)
logger.info("Emane.startdaemons2() return code %d" % status)
logger.info("Emane.startdaemons2() output: %s" % output)
logger.info("Emane.startdaemons2() running %s", args)
output = node.check_cmd(args)
logger.info("Emane.startdaemons2() output: %s", output)
except subprocess.CalledProcessError:
logger.exception("error starting emane")

View file

@ -211,8 +211,8 @@ def check_cmd(args, **kwargs):
:param list[str]|str args: command arguments
:param dict kwargs: keyword arguments to pass to subprocess.Popen
:return: command status and stdout
:rtype: tuple[int, str]
:return: combined stdout and stderr
:rtype: str
:raises subprocess.CalledProcessError: when there is a non-zero exit status or the file to execute is not found
"""
kwargs["stdout"] = subprocess.PIPE
@ -224,7 +224,7 @@ def check_cmd(args, **kwargs):
status = p.wait()
if status != 0:
raise subprocess.CalledProcessError(status, args, stdout)
return status, stdout.strip()
return stdout.strip()
except OSError:
raise subprocess.CalledProcessError(-1, args)

View file

@ -650,7 +650,7 @@ class RJ45Node(PyCoreNode, PyCoreNetIf):
self.old_up = False
self.old_addrs = []
args = [constants.IP_BIN, "addr", "show", "dev", self.localname]
_, output = utils.check_cmd(args)
output = utils.check_cmd(args)
for line in output.split("\n"):
items = line.split()
if len(items) < 2:

View file

@ -389,7 +389,7 @@ class OvsCtrlNet(OvsNet):
Check if there are old control net bridges and delete them
"""
_, output = utils.check_cmd([constants.OVS_BIN, "list-br"])
output = utils.check_cmd([constants.OVS_BIN, "list-br"])
output = output.strip()
if output:
for line in output.split("\n"):

View file

@ -98,7 +98,7 @@ class SimpleLxcNode(PyCoreNode):
env["NODE_NUMBER"] = str(self.objid)
env["NODE_NAME"] = str(self.name)
_, output = utils.check_cmd(vnoded, env=env)
output = utils.check_cmd(vnoded, env=env)
self.pid = int(output)
# create vnode client
@ -187,8 +187,8 @@ class SimpleLxcNode(PyCoreNode):
Runs shell command on node.
:param list[str]|str args: command to run
:return: exist status and combined stdout and stderr
:rtype: tuple[int, str]
:return: combined stdout and stderr
:rtype: str
:raises subprocess.CalledProcessError: when a non-zero exit status occurs
"""
return self.client.check_cmd(args)
@ -284,7 +284,7 @@ class SimpleLxcNode(PyCoreNode):
if self.up:
# TODO: potentially find better way to query interface ID
# retrieve interface information
_, output = self.check_cmd(["ip", "link", "show", veth.name])
output = self.check_cmd(["ip", "link", "show", veth.name])
logger.info("interface command output: %s", output)
output = output.split("\n")
veth.flow_id = int(output[0].strip().split(":")[0]) + 1

View file

@ -104,14 +104,14 @@ class VnodeClient(object):
Run command and return exit status and combined stdout and stderr.
:param list[str]|str args: command to run
:return: exit status and combined stdout and stderr
:rtype: tuple[int, str]
:return: combined stdout and stderr
:rtype: str
:raises subprocess.CalledProcessError: when there is a non-zero exit status
"""
status, output = self.cmd_output(args)
if status != 0:
raise subprocess.CalledProcessError(status, args, output)
return status, output.strip()
return output.strip()
def popen(self, args):
"""

View file

@ -96,14 +96,14 @@ class PhysicalNode(PyCoreNode):
Runs shell command on node.
:param list[str]|str args: command to run
:return: exist status and combined stdout and stderr
:rtype: tuple[int, str]
:return: combined stdout and stderr
:rtype: str
:raises subprocess.CalledProcessError: when a non-zero exit status occurs
"""
status, output = self.cmd_output(args)
if status:
raise subprocess.CalledProcessError(status, args, output)
return status, output.strip()
return output.strip()
def shcmd(self, cmdstr, sh="/bin/sh"):
return self.cmd([sh, "-c", cmdstr])

View file

@ -408,11 +408,11 @@ class CoreServices(ConfigurableManager):
status = 0
# has validate commands
if len(validate_cmds) > 0:
if validate_cmds:
for args in validate_cmds:
logger.info("validating service %s using: %s", service._name, args)
try:
status, _ = node.check_cmd(args)
node.check_cmd(args)
except subprocess.CalledProcessError:
logger.exception("validate command failed")
status = -1
@ -439,15 +439,11 @@ class CoreServices(ConfigurableManager):
:return: status for stopping the services
:rtype: str
"""
status = ""
if len(service._shutdown) == 0:
# doesn't have a shutdown command
status += "0"
else:
status = "0"
if service._shutdown:
for args in service._shutdown:
try:
status, _ = node.check_cmd(args)
status = str(status)
node.check_cmd(args)
except subprocess.CalledProcessError:
logger.exception("error running stop command %s", args)
# TODO: determine if its ok to just return the bad exit status

View file

@ -25,8 +25,8 @@ class CoreDeploymentWriter(object):
def get_ipv4_addresses(hostname):
if hostname == 'localhost':
addr_list = []
args = (constants.IP_BIN, '-o', '-f', 'inet', 'addr', 'show')
_, output = utils.check_cmd(args)
args = [constants.IP_BIN, '-o', '-f', 'inet', 'addr', 'show']
output = utils.check_cmd(args)
for line in output.split(os.linesep):
split = line.split()
if not split:
@ -43,12 +43,12 @@ class CoreDeploymentWriter(object):
def get_interface_names(hostname):
"""
Uses same methodology of get_ipv4_addresses() to get
parallel list of interface names to go with ...
"""
parallel list of interface names to go with ...
"""
if hostname == 'localhost':
iface_list = []
args = (constants.IP_BIN, '-o', '-f', 'inet', 'addr', 'show')
_, output = utils.check_cmd(args)
args = [constants.IP_BIN, '-o', '-f', 'inet', 'addr', 'show']
output = utils.check_cmd(args)
for line in output.split(os.linesep):
split = line.split()
if not split:

View file

@ -188,7 +188,7 @@ class Core(object):
def ping_output(self, from_name, to_name):
from_node = self.nodes[from_name]
to_ip = str(self.get_ip(to_name))
_, output = from_node.check_cmd(["ping", "-i", "0.05", "-c", "3", to_ip])
output = from_node.check_cmd(["ping", "-i", "0.05", "-c", "3", to_ip])
return output
def iperf(self, from_name, to_name):