Ejemplo n.º 1
0
    def _run_linux(self, cmd, expect_fail, detach=False):

        ret_value = None

        _cmd = cmd
        if detach:
            _cmd = "nohup {} &> /dev/null &".format(cmd)

        logger.info("[LDROPLET {}]: running: {}".format(self.id, _cmd))

        out = self.conn.run(_cmd, warn=True)
        if not detach:
            ret_value = (out.exited, out.stdout.strip())
        if (not detach and ret_value[0] != 0):
            if not expect_fail:
                logger.error("[LDROPLET {}]: {}".format(self.id, ret_value[1]))
            else:
                logger.info("[LDROPLET {}]: {}".format(self.id, ret_value[1]))

        if not detach:
            logger.debug(
                "[LDROPLET {}]: running\n    command:\n {}, \n    exit_code: {},\n    output:\n {}"
                .format(self.id, _cmd, ret_value[0], ret_value[1]))

        return ret_value
Ejemplo n.º 2
0
def do_run_get_rpc_test(test, droplet, call):
    """
    Helper function for verifying delete RPC was successful
    """
    if call[0] == "ep " + droplet.phy_itf or call[
            0] == "ep_substrate " + droplet.phy_itf:
        log_string = "[DROPLET {}]: Expecting failure for RPC call.".format(
            droplet.id)
        cmd = f'''{droplet.trn_cli_get_ep} \'{call[1]}\''''
        return droplet.exec_cli_rpc(log_string, cmd, True)[0]
    elif call[0] == "net " + droplet.phy_itf:
        log_string = "[DROPLET {}]: Expecting failure for RPC call.".format(
            droplet.id)
        cmd = f'''{droplet.trn_cli_get_net} \'{call[1]}\''''
        return droplet.exec_cli_rpc(log_string, cmd, True)[0]
    elif call[0] == "vpc " + droplet.phy_itf:
        log_string = "[DROPLET {}]: Expecting failure for RPC call.".format(
            droplet.id)
        cmd = f'''{droplet.trn_cli_get_vpc} \'{call[1]}\''''
        return droplet.exec_cli_rpc(log_string, cmd, True)[0]
    elif call[
            0] == "load":  # We assume agent was loaded and unloaded correctly
        return 1
    else:
        logger.error("[{}]: Unidentified rpc call: {}@{}".format(
            droplet.id, call[0], call[1]))
        return 0
Ejemplo n.º 3
0
 def _get_linux_file(self, path):
     logger.error("[LDROPLET {}]: Fetching file {}".format(self.id, path))
     fd = BytesIO()
     self.conn.get(path, '/tmp/resultdata')
     with open('/tmp/resultdata', 'r') as datfile:
         data = datfile.read()
     return data
Ejemplo n.º 4
0
    def bootstrap(self):
        if self.droplet_type == 'docker':
            self._create_docker_container()
            self.load_transit_xdp()
            self.start_pcap()
            return

        logger.error("Unsupported droplet type!")
Ejemplo n.º 5
0
    def get_file(self, path):
        if self.droplet_type == 'docker':
            return self._get_docker_file(path)

        if self.droplet_type == 'linux':
            return self._get_linux_file(path)

        logger.error("Unsupported droplet type!")
Ejemplo n.º 6
0
    def bootstrap(self):
        if self.droplet_type == 'docker':
            self._create_docker_container()
            return

        if self.droplet_type == 'linux':
            self.prepare_remote_host()
            return

        logger.error("Unsupported droplet type!")
Ejemplo n.º 7
0
    def run(self, cmd, detach=False, expect_fail=False):
        """
        Runs a command directly on the droplet
        """
        if self.droplet_type == 'docker':
            return self._run_docker(cmd, expect_fail, detach)

        if self.droplet_type == 'linux':
            return self._run_linux(cmd, expect_fail, detach)

        logger.error("Unsupported droplet type!")
Ejemplo n.º 8
0
def do_check_failed_rpcs(test, droplets):
    exit_code = 0
    logger.info("{} Checking for unexpected failed RPC calls {}".format(
        '=' * 20, '=' * 20))
    for d in droplets:
        if len(d.rpc_failures.keys()) > 0:
            exit_code = 1
            for cmd in d.rpc_failures.keys():
                logger.error(
                    "[DROPLET {}]: Unexpected failed command ran: {} at {}".
                    format(d.id, d.rpc_failures[cmd], cmd))
            print()
    test.assertEqual(exit_code, 0)
Ejemplo n.º 9
0
    def local(self, cmd):
        ret_value = None
        logger.info("[LOCAL {}]: running: {}".format(self.id, cmd))
        try:
            out = run_cmd(cmd)
            ret_value = (out[0], out[1])
            if (ret_value[0] != 0):
                logger.error("[LOCAL {}]: {}".format(self.id, ret_value[1]))

            logger.debug(
                "[LOCAL {}]: running\n    command:\n {}, \n    exit_code: {},\n    output:\n {}"
                .format(self.id, cmd, ret_value[0], ret_value[1]))

            return ret_value
        except Exception as e:
            logger.error("[LOCAL {}]: {}".format(self.id, str(e)))
            return None
Ejemplo n.º 10
0
    def run(self, cmd, detach=False):
        """
        Runs a command directly on the droplet
        """

        ret_value = None
        if (self.droplet_type == 'docker'):
            out = self.container.exec_run(cmd, detach=detach)
            if not detach:
                ret_value = (out.exit_code, out.output.decode("utf-8"))

        logger.info("[DROPLET {}]: running: {}".format(self.id, cmd))
        if (not detach and ret_value[0] == 1):
            logger.error("[DROPLET {}]: {}".format(self.id, ret_value[1]))

        if not detach:
            logger.debug(
                "[DROPLET {}]: running\n    command:\n {}, \n    exit_code: {},\n    output:\n {}".format(self.id, cmd, ret_value[0], ret_value[1]))

        return ret_value
Ejemplo n.º 11
0
    def _run_docker(self, cmd, expect_fail, detach=False):

        ret_value = None

        out = self.container.exec_run(cmd, detach=detach)
        if not detach:
            ret_value = (out.exit_code, out.output.decode("utf-8"))

        logger.info("[DROPLET {}]: running: {}".format(self.id, cmd))
        if (not detach and ret_value[0] != 0):
            if not expect_fail:
                logger.error("[LDROPLET {}]: {}".format(self.id, ret_value[1]))
            else:
                logger.info("[LDROPLET {}]: {}".format(self.id, ret_value[1]))

        if not detach:
            logger.debug(
                "[DROPLET {}]: running\n    command:\n {}, \n    exit_code: {},\n    output:\n {}"
                .format(self.id, cmd, ret_value[0], ret_value[1]))

        return ret_value
Ejemplo n.º 12
0
def do_validate_delete_test(test, droplets):
    """
    Validates deletes RPC calls are correctly made after an update.
    * Condition #1: All update calls have a corresponding delete.
    # 2: All delete calls happen AFTER their corresponding update call is made.
    * Condition
    * Condition #3: All corresponding get RPC calls return an error after delete
    """
    exit_code = 0
    for d in droplets:
        for update in d.rpc_updates:
            if update not in d.rpc_deletes.keys():
                exit_code = 1
                logger.error(
                    "[{}]: No corresponding delete call was made for the update. {}"
                    .format(d.id, update))
                test.assertEqual(exit_code, 0)
            if d.rpc_updates[update] > d.rpc_deletes[update]:
                exit_code = 1
                logger.error(
                    "[{}]: The following update was made after delete was called. {}"
                    .format(d.id, update))
                test.assertEqual(exit_code, 0)
            if do_run_get_rpc_test(test, d, update) == 0:
                exit_code = 1
                logger.error(
                    "[{}]: Get RPC returned a valid object after delete. {}".
                    format(d.id, update))
                test.assertEqual(exit_code, 0)
    test.assertEqual(exit_code, 0)
Ejemplo n.º 13
0
def do_check_failed_rpcs(test, droplets):
    """
    Checks to see if any RPCs ran on the given list of droplets returned an error.
    """
    exit_code = 0
    logger.info("{} Checking for unexpected failed RPC calls {}".format(
        '=' * 20, '=' * 20))
    for d in droplets:
        if len(d.rpc_failures.keys()) > 0:
            exit_code = 1
            for cmd in d.rpc_failures.keys():
                logger.error(
                    "[DROPLET {}]: Unexpected failed command ran: {} at {}".
                    format(d.id, d.rpc_failures[cmd], cmd))
            print()
    if exit_code == 0:
        logger.info("{} No failed RPC calls found! {}".format(
            '=' * 20, '=' * 20))
    else:
        logger.error("{} Found failed RPC calls! {}".format(
            '=' * 20, '=' * 20))
    test.assertEqual(exit_code, 0)
Ejemplo n.º 14
0
 def update_agent_ep(self, itf):
     logger.error(
         "[DROPLET {}]: not implemented, no use case for now!".format(
             self.id))