def validate_service(self, node: CoreNode, service: "CoreService") -> int: """ Run the validation command(s) for a service. :param node: node to validate service for :param service: service to validate :return: service validation status """ logging.debug("validating node(%s) service(%s)", node.name, service.name) cmds = service.validate if not service.custom: cmds = service.get_validate(node) status = 0 for cmd in cmds: logging.debug("validating service(%s) using: %s", service.name, cmd) try: node.cmd(cmd) except CoreCommandError as e: logging.debug( "node(%s) service(%s) validate failed", node.name, service.name ) logging.debug("cmd(%s): %s", e.cmd, e.output) status = -1 break return status
def ping(from_node: CoreNode, to_node: CoreNode, ip_prefixes: IpPrefixes): address = ip_prefixes.ip4_address(to_node.id) try: from_node.cmd(f"ping -c 1 {address}") status = 0 except CoreCommandError as e: status = e.returncode return status
def emanerunning(self, node: CoreNode) -> bool: """ Return True if an EMANE process associated with the given node is running, False otherwise. """ args = "pkill -0 -x emane" try: node.cmd(args) result = True except CoreCommandError: result = False return result
def stop_service(self, node: CoreNode, service: "CoreService") -> int: """ Stop a service on a node. :param node: node to stop a service on :param service: service to stop :return: status for stopping the services """ status = 0 for args in service.shutdown: try: node.cmd(args) except CoreCommandError as e: self.session.exception( ExceptionLevels.ERROR, "services", f"error stopping service {service.name}: {e.stderr}", node.id, ) logging.exception("error running stop command %s", args) status = -1 return status
def startup_service( self, node: CoreNode, service: "CoreService", wait: bool = False ) -> int: """ Startup a node service. :param node: node to reconfigure service for :param service: service to reconfigure :param wait: determines if we should wait to validate startup :return: status of startup """ cmds = service.startup if not service.custom: cmds = service.get_startup(node) status = 0 for cmd in cmds: try: node.cmd(cmd, wait) except CoreCommandError: logging.exception("error starting command") status = -1 return status