Exemplo n.º 1
0
    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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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