changes to allow node container commands to leverage shell parameter when needed
This commit is contained in:
parent
e92441d728
commit
95c57bbad6
4 changed files with 14 additions and 11 deletions
|
@ -380,12 +380,13 @@ class CoreNodeBase(NodeBase):
|
||||||
|
|
||||||
return common
|
return common
|
||||||
|
|
||||||
def cmd(self, args, wait=True):
|
def cmd(self, args, wait=True, shell=False):
|
||||||
"""
|
"""
|
||||||
Runs a command within a node container.
|
Runs a command within a node container.
|
||||||
|
|
||||||
:param str args: command to run
|
:param str args: command to run
|
||||||
:param bool wait: True to wait for status, False otherwise
|
:param bool wait: True to wait for status, False otherwise
|
||||||
|
:param bool shell: True to use shell, False otherwise
|
||||||
:return: combined stdout and stderr
|
:return: combined stdout and stderr
|
||||||
:rtype: str
|
:rtype: str
|
||||||
:raises CoreCommandError: when a non-zero exit status occurs
|
:raises CoreCommandError: when a non-zero exit status occurs
|
||||||
|
@ -561,19 +562,20 @@ class CoreNode(CoreNodeBase):
|
||||||
finally:
|
finally:
|
||||||
self.rmnodedir()
|
self.rmnodedir()
|
||||||
|
|
||||||
def cmd(self, args, wait=True):
|
def cmd(self, args, wait=True, shell=False):
|
||||||
"""
|
"""
|
||||||
Runs a command that is used to configure and setup the network within a
|
Runs a command that is used to configure and setup the network within a
|
||||||
node.
|
node.
|
||||||
|
|
||||||
:param str args: command to run
|
:param str args: command to run
|
||||||
:param bool wait: True to wait for status, False otherwise
|
:param bool wait: True to wait for status, False otherwise
|
||||||
|
:param bool shell: True to use shell, False otherwise
|
||||||
:return: combined stdout and stderr
|
:return: combined stdout and stderr
|
||||||
:rtype: str
|
:rtype: str
|
||||||
:raises CoreCommandError: when a non-zero exit status occurs
|
:raises CoreCommandError: when a non-zero exit status occurs
|
||||||
"""
|
"""
|
||||||
if self.server is None:
|
if self.server is None:
|
||||||
return self.client.check_cmd(args, wait=wait)
|
return self.client.check_cmd(args, wait=wait, shell=shell)
|
||||||
else:
|
else:
|
||||||
args = self.client.create_cmd(args)
|
args = self.client.create_cmd(args)
|
||||||
return self.server.remote_cmd(args, wait=wait)
|
return self.server.remote_cmd(args, wait=wait)
|
||||||
|
|
|
@ -53,16 +53,17 @@ class VnodeClient:
|
||||||
def create_cmd(self, args):
|
def create_cmd(self, args):
|
||||||
return f"{VCMD_BIN} -c {self.ctrlchnlname} -- {args}"
|
return f"{VCMD_BIN} -c {self.ctrlchnlname} -- {args}"
|
||||||
|
|
||||||
def check_cmd(self, args, wait=True):
|
def check_cmd(self, args, wait=True, shell=False):
|
||||||
"""
|
"""
|
||||||
Run command and return exit status and combined stdout and stderr.
|
Run command and return exit status and combined stdout and stderr.
|
||||||
|
|
||||||
:param str args: command to run
|
:param str args: command to run
|
||||||
:param bool wait: True to wait for command status, False otherwise
|
:param bool wait: True to wait for command status, False otherwise
|
||||||
|
:param bool shell: True to use shell, False otherwise
|
||||||
:return: combined stdout and stderr
|
:return: combined stdout and stderr
|
||||||
:rtype: str
|
:rtype: str
|
||||||
:raises core.CoreCommandError: when there is a non-zero exit status
|
:raises core.CoreCommandError: when there is a non-zero exit status
|
||||||
"""
|
"""
|
||||||
self._verify_connection()
|
self._verify_connection()
|
||||||
args = self.create_cmd(args)
|
args = self.create_cmd(args)
|
||||||
return utils.cmd(args, wait=wait)
|
return utils.cmd(args, wait=wait, shell=shell)
|
||||||
|
|
|
@ -43,9 +43,9 @@ class DockerClient:
|
||||||
def stop_container(self):
|
def stop_container(self):
|
||||||
self.run(f"docker rm -f {self.name}")
|
self.run(f"docker rm -f {self.name}")
|
||||||
|
|
||||||
def check_cmd(self, cmd):
|
def check_cmd(self, cmd, wait=True, shell=False):
|
||||||
logging.info("docker cmd output: %s", cmd)
|
logging.info("docker cmd output: %s", cmd)
|
||||||
return utils.cmd(f"docker exec {self.name} {cmd}")
|
return utils.cmd(f"docker exec {self.name} {cmd}", wait=wait, shell=shell)
|
||||||
|
|
||||||
def create_ns_cmd(self, cmd):
|
def create_ns_cmd(self, cmd):
|
||||||
return f"nsenter -t {self.pid} -u -i -p -n {cmd}"
|
return f"nsenter -t {self.pid} -u -i -p -n {cmd}"
|
||||||
|
@ -148,10 +148,10 @@ class DockerNode(CoreNode):
|
||||||
self.client.stop_container()
|
self.client.stop_container()
|
||||||
self.up = False
|
self.up = False
|
||||||
|
|
||||||
def nsenter_cmd(self, args, wait=True):
|
def nsenter_cmd(self, args, wait=True, shell=False):
|
||||||
if self.server is None:
|
if self.server is None:
|
||||||
args = self.client.create_ns_cmd(args)
|
args = self.client.create_ns_cmd(args)
|
||||||
return utils.cmd(args, wait=wait)
|
return utils.cmd(args, wait=wait, shell=shell)
|
||||||
else:
|
else:
|
||||||
args = self.client.create_ns_cmd(args)
|
args = self.client.create_ns_cmd(args)
|
||||||
return self.server.remote_cmd(args, wait=wait)
|
return self.server.remote_cmd(args, wait=wait)
|
||||||
|
|
|
@ -47,9 +47,9 @@ class LxdClient:
|
||||||
def create_ns_cmd(self, cmd):
|
def create_ns_cmd(self, cmd):
|
||||||
return f"nsenter -t {self.pid} -m -u -i -p -n {cmd}"
|
return f"nsenter -t {self.pid} -m -u -i -p -n {cmd}"
|
||||||
|
|
||||||
def check_cmd(self, cmd, wait=True):
|
def check_cmd(self, cmd, wait=True, shell=False):
|
||||||
args = self.create_cmd(cmd)
|
args = self.create_cmd(cmd)
|
||||||
return utils.cmd(args, wait=wait)
|
return utils.cmd(args, wait=wait, shell=shell)
|
||||||
|
|
||||||
def copy_file(self, source, destination):
|
def copy_file(self, source, destination):
|
||||||
if destination[0] != "/":
|
if destination[0] != "/":
|
||||||
|
|
Loading…
Reference in a new issue