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
|
||||
|
||||
def cmd(self, args, wait=True):
|
||||
def cmd(self, args, wait=True, shell=False):
|
||||
"""
|
||||
Runs a command within a node container.
|
||||
|
||||
:param str args: command to run
|
||||
:param bool wait: True to wait for status, False otherwise
|
||||
:param bool shell: True to use shell, False otherwise
|
||||
:return: combined stdout and stderr
|
||||
:rtype: str
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
|
@ -561,19 +562,20 @@ class CoreNode(CoreNodeBase):
|
|||
finally:
|
||||
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
|
||||
node.
|
||||
|
||||
:param str args: command to run
|
||||
:param bool wait: True to wait for status, False otherwise
|
||||
:param bool shell: True to use shell, False otherwise
|
||||
:return: combined stdout and stderr
|
||||
:rtype: str
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
if self.server is None:
|
||||
return self.client.check_cmd(args, wait=wait)
|
||||
return self.client.check_cmd(args, wait=wait, shell=shell)
|
||||
else:
|
||||
args = self.client.create_cmd(args)
|
||||
return self.server.remote_cmd(args, wait=wait)
|
||||
|
|
|
@ -53,16 +53,17 @@ class VnodeClient:
|
|||
def create_cmd(self, 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.
|
||||
|
||||
:param str args: command to run
|
||||
: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
|
||||
:rtype: str
|
||||
:raises core.CoreCommandError: when there is a non-zero exit status
|
||||
"""
|
||||
self._verify_connection()
|
||||
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):
|
||||
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)
|
||||
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):
|
||||
return f"nsenter -t {self.pid} -u -i -p -n {cmd}"
|
||||
|
@ -148,10 +148,10 @@ class DockerNode(CoreNode):
|
|||
self.client.stop_container()
|
||||
self.up = False
|
||||
|
||||
def nsenter_cmd(self, args, wait=True):
|
||||
def nsenter_cmd(self, args, wait=True, shell=False):
|
||||
if self.server is None:
|
||||
args = self.client.create_ns_cmd(args)
|
||||
return utils.cmd(args, wait=wait)
|
||||
return utils.cmd(args, wait=wait, shell=shell)
|
||||
else:
|
||||
args = self.client.create_ns_cmd(args)
|
||||
return self.server.remote_cmd(args, wait=wait)
|
||||
|
|
|
@ -47,9 +47,9 @@ class LxdClient:
|
|||
def create_ns_cmd(self, 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)
|
||||
return utils.cmd(args, wait=wait)
|
||||
return utils.cmd(args, wait=wait, shell=shell)
|
||||
|
||||
def copy_file(self, source, destination):
|
||||
if destination[0] != "/":
|
||||
|
|
Loading…
Reference in a new issue