updated other node system commands to be ran in such a way that should work if local or remote using shell commands

This commit is contained in:
bharnden 2019-10-05 16:10:01 -07:00
parent 95296988c5
commit cca57bba47

View file

@ -2,12 +2,9 @@
Defines the base logic for nodes used within core. Defines the base logic for nodes used within core.
""" """
import errno
import logging import logging
import os import os
import random import random
import shutil
import signal
import socket import socket
import string import string
import threading import threading
@ -309,7 +306,7 @@ class CoreNodeBase(NodeBase):
return return
if self.tmpnodedir: if self.tmpnodedir:
shutil.rmtree(self.nodedir, ignore_errors=True) self.net_cmd(["rm", "-rf", self.nodedir])
def addnetif(self, netif, ifindex): def addnetif(self, netif, ifindex):
""" """
@ -522,8 +519,8 @@ class CoreNode(CoreNodeBase):
:rtype: bool :rtype: bool
""" """
try: try:
os.kill(self.pid, 0) self.net_cmd(["kill", "-9", str(self.pid)])
except OSError: except CoreCommandError:
return False return False
return True return True
@ -560,6 +557,7 @@ class CoreNode(CoreNodeBase):
output = self.net_cmd(vnoded, env=env) output = self.net_cmd(vnoded, env=env)
self.pid = int(output) self.pid = int(output)
logging.debug("node(%s) pid: %s", self.name, self.pid)
# create vnode client # create vnode client
self.client = client.VnodeClient(self.name, self.ctrlchnlname) self.client = client.VnodeClient(self.name, self.ctrlchnlname)
@ -599,21 +597,17 @@ class CoreNode(CoreNodeBase):
for netif in self.netifs(): for netif in self.netifs():
netif.shutdown() netif.shutdown()
# attempt to kill node process and wait for termination of children # kill node process if present
try: try:
os.kill(self.pid, signal.SIGTERM) self.net_cmd(["kill", "-9", str(self.pid)])
os.waitpid(self.pid, 0) except CoreCommandError:
except OSError as e: logging.exception("error killing process")
if e.errno != 10:
logging.exception("error killing process")
# remove node directory if present # remove node directory if present
try: try:
os.unlink(self.ctrlchnlname) self.net_cmd(["rm", "-rf", self.ctrlchnlname])
except OSError as e: except CoreCommandError:
# no such file or directory logging.exception("error removing node directory")
if e.errno != errno.ENOENT:
logging.exception("error removing node directory")
# clear interface data, close client, and mark self and not up # clear interface data, close client, and mark self and not up
self._netif.clear() self._netif.clear()
@ -1029,9 +1023,9 @@ class CoreNode(CoreNodeBase):
:return: nothing :return: nothing
""" """
hostfilename = self.hostfilename(filename) hostfilename = self.hostfilename(filename)
shutil.copy2(srcfilename, hostfilename) self.net_cmd(["cp", "-a", srcfilename, hostfilename])
if mode is not None: if mode is not None:
os.chmod(hostfilename, mode) self.net_cmd(["chmod", oct(mode), hostfilename])
logging.info( logging.info(
"node(%s) copied file: %s; mode: %s", self.name, hostfilename, mode "node(%s) copied file: %s; mode: %s", self.name, hostfilename, mode
) )