Ejemplo n.º 1
0
    def install_debug_package(self):
        """ installing debug package """
        cmd = 'dpkg -i ' + str(self.cfg.package_dir / self.debug_package)
        lh.log_cmd(cmd)
        os.environ['DEBIAN_FRONTEND'] = 'readline'
        debug_install = pexpect.spawnu(cmd)
        try:
            logging.info("waiting for the installation to finish")
            debug_install.expect(pexpect.EOF, timeout=60)
        except pexpect.exceptions.EOF:
            logging.info("TIMEOUT!")
            debug_install.close(force=True)
            ascii_print(debug_install.before)
        print()
        logging.info(str(self.debug_package) + ' Installation successfull')
        self.cfg.have_debug_package = True

        while debug_install.isalive():
            progress('.')
            if debug_install.exitstatus != 0:
                debug_install.close(force=True)
                ascii_print(debug_install.before)
                raise Exception(
                    str(self.debug_package) +
                    " debug installation didn't finish successfully!")
        return self.cfg.have_debug_package
Ejemplo n.º 2
0
 def install_rpm_package(self, package: str, upgrade: bool = False):
     """installing rpm package"""
     print("installing rpm package: %s" % package)
     if upgrade:
         option = "--upgrade"
     else:
         option = "--install"
     cmd = f"rpm {option} {package}"
     lh.log_cmd(cmd)
     install = pexpect.spawnu(cmd)
     install.logfile = sys.stdout
     try:
         logging.info("waiting for the installation to finish")
         install.expect(pexpect.EOF, timeout=90)
         output = install.before
         install.wait()
     except pexpect.exceptions.TIMEOUT as ex:
         logging.info("TIMEOUT!")
         install.close(force=True)
         output = install.before
         raise Exception(
             "Installation of the package {} didn't finish within 90 seconds! Output:\n{}"
             .format(str(package), output)) from ex
     if install.exitstatus != 0:
         install.close(force=True)
         raise Exception(
             "Installation of the package {} didn't finish successfully! Output:\n{}"
             .format(str(package), output))
     logging.info(str(self.debug_package) + " Installation successfull")
     return True
Ejemplo n.º 3
0
 def stop_service(self):
     logging.info("stopping service")
     cmd = ["service", "arangodb3", "stop"]
     lh.log_cmd(cmd)
     run_cmd_and_log_stdout(cmd)
     while self.check_service_up():
         time.sleep(1)
Ejemplo n.º 4
0
def create_dump_for_exe(exe_file: str, dump_file_dir: str):
    """run given executable with \"-?\" command line parameter and create a memory dump when it terminates"""
    exe_file = Path(exe_file)
    exe_name = exe_file.name
    with step(f"Create a memory dump of the program: {exe_name}"):
        dump_filename = None
        cmd = [
            "procdump", "-ma", "-t", "-x", dump_file_dir,
            str(exe_file), "-?"
        ]
        lh.log_cmd(cmd)
        with psutil.Popen(cmd,
                          bufsize=-1,
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE) as proc:
            (procdump_out, procdump_err) = proc.communicate()
            procdump_str = str(procdump_out, "UTF-8")
            attach(procdump_str, "procdump sdtout")
            attach(str(procdump_err), "procdump stderr")
            success_string = "Dump 1 complete"
            filename_regex = re.compile(
                r"^(\[\d{2}:\d{2}:\d{2}\] Dump 1 initiated: )(?P<filename>.*)$",
                re.MULTILINE)
            match = re.search(filename_regex, procdump_str)
            if procdump_str.find(success_string) < 0 or not match:
                raise Exception(
                    "procdump wasn't able to create a dump file: " +
                    procdump_str)
            dump_filename = match.group("filename")
        return dump_filename
Ejemplo n.º 5
0
def create_arangosh_dump(installer, dump_file_dir: str):
    """create arangosh memory dump file"""
    dump_filename = None
    with step("Start arangosh process"):
        exe_file = installer.cfg.bin_dir / "arangosh.exe"
        cmd = [str(exe_file)]
        arangosh_proc = psutil.Popen(cmd,
                                     bufsize=-1,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE)
        arangosh_pid = arangosh_proc.pid
    with step("Create a dump of arangosh process"):
        cmd = ["procdump", "-ma", str(arangosh_pid), dump_file_dir]
        lh.log_cmd(cmd)
        with psutil.Popen(cmd,
                          bufsize=-1,
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE) as proc:
            (procdump_out, procdump_err) = proc.communicate()
            procdump_str = str(procdump_out, "UTF-8")
            attach(procdump_str, "procdump sdtout")
            attach(str(procdump_err), "procdump stderr")
            success_string = "Dump 1 complete"
            filename_regex = re.compile(
                r"^(\[\d{2}:\d{2}:\d{2}\] Dump 1 initiated: )(?P<filename>.*)$",
                re.MULTILINE)
            match = re.search(filename_regex, procdump_str)
            if procdump_str.find(success_string) < 0 or not match:
                raise Exception(
                    "procdump wasn't able to create a dump file: " +
                    procdump_str)
            dump_filename = match.group("filename")
    with step("Kill arangosh process"):
        arangosh_proc.kill()
    return dump_filename
Ejemplo n.º 6
0
    def run_command(self, cmd, verbose=True):
        """ launch a command, print its name """
        run_cmd = [
            self.cfg.bin_dir / "arangosh",
            "--log.level", "v8=debug",
            "--server.endpoint", self.connect_instance.get_endpoint()
        ]

        run_cmd += [ "--server.username", str(self.cfg.username) ]
        run_cmd += [ "--server.password", str(self.connect_instance.get_passvoid()) ]

        # if self.cfg.username:
        #    run_cmd += [ "--server.username", str(self.cfg.username) ]

        # if self.cfg.passvoid:
        #    run_cmd += [ "--server.password", str(self.cfg.passvoid) ]

        run_cmd += [ "--javascript.execute-string", str(cmd[1]) ]

        if len(cmd) > 2:
            run_cmd += cmd[2:]

        arangosh_run = None
        if verbose:
            lh.log_cmd(run_cmd)
            arangosh_run = psutil.Popen(run_cmd)
        else:
            arangosh_run = psutil.Popen(run_cmd,
                                        stdout = DEVNULL,
                                        stderr = DEVNULL)

        exitcode = arangosh_run.wait(timeout=60)
        # logging.debug("exitcode {0}".format(exitcode))
        return exitcode == 0
Ejemplo n.º 7
0
 def run_backup(self, arguments, name, silent=False):
     """ launch the starter for this instance"""
     if not silent:
         logging.info("running hot backup " + name)
     args = [self.cfg.bin_dir / 'arangobackup'] + arguments + self.moreopts
     if not silent:
         lh.log_cmd(args)
     instance = psutil.Popen(args,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
     (output, err) = instance.communicate()
     if len(err) > 0:
         ascii_print(str(err))
     success = True
     if not silent:
         for line in output.splitlines():
             strline = str(line)
             ascii_print(strline)
             if strline.find('ERROR') >= 0:
                 success = False
     if instance.returncode != 0:
         raise Exception("arangobackup exited " + str(instance.returncode))
     if not success:
         raise Exception("arangobackup indicated 'ERROR' in its output!")
     return output.splitlines()
Ejemplo n.º 8
0
    def run_backup(self, arguments, name, silent=False, expect_to_fail=False, timeout=20):
        """run arangobackup"""
        if not silent:
            logging.info("running hot backup " + name)
        run_cmd = copy.deepcopy(self.cfg.default_backup_args)
        if self.cfg.verbose:
            run_cmd += ["--log.level=debug"]
        run_cmd += arguments
        lh.log_cmd(arguments, not silent)

        def inspect_line_result(line):
            strline = str(line)
            if strline.find("ERROR") >= 0:
                return True
            return False

        success, output, _, error_found = self.run_arango_tool_monitored(
            self.cfg.bin_dir / "arangobackup",
            run_cmd,
            timeout,
            inspect_line_result,
            self.cfg.verbose and not silent,
            expect_to_fail,
        )

        if not success:
            raise Exception("arangobackup exited " + str(output))

        if not success or error_found:
            raise Exception("arangobackup indicated 'ERROR' in its output: %s" % ascii_convert_str(output))
        return output
Ejemplo n.º 9
0
 def run_starter(self):
     """ launch the starter for this instance"""
     logging.info("running starter " + self.name)
     args = [self.cfg.bin_dir / 'arangodb'
             ] + self.hotbackup + self.arguments
     lh.log_cmd(args)
     self.instance = psutil.Popen(args)
     self.wait_for_logfile()
Ejemplo n.º 10
0
 def run_starter(self, expect_to_fail=False):
     """launch the starter for this instance"""
     logging.info("running starter " + self.name)
     args = [self.cfg.bin_dir / "arangodb"] + self.hotbackup_args + self.arguments
     lh.log_cmd(args)
     self.instance = psutil.Popen(args)
     logging.info("my starter has PID:" + str(self.instance.pid))
     if not expect_to_fail:
         self.wait_for_logfile()
Ejemplo n.º 11
0
    def start_service(self):
        assert self.instance

        logging.info("starting service")
        cmd = ["service", "arangodb3", "start"]
        lh.log_cmd(cmd)
        run_cmd_and_log_stdout(cmd)
        time.sleep(0.1)
        self.instance.detect_pid(1)  # should be owned by init
Ejemplo n.º 12
0
    def launch(self, testcase_no, moreopts=[]):
        """run arangobench"""
        testcase = BENCH_TODOS[testcase_no]
        arguments = [self.cfg.real_bin_dir / "arangobench"
                     ] + self.moreopts + moreopts
        for key in testcase.keys():
            arguments.append("--" + key)
            arguments.append(str(testcase[key]))

        lh.log_cmd(arguments, self.cfg.verbose)
        self.arguments = arguments
        self.instance = psutil.Popen(arguments)
        print("az" * 40)
Ejemplo n.º 13
0
 def un_install_package(self):
     cmd = ('dpkg --purge ' + 'arangodb3' +
            ('e' if self.cfg.enterprise else ''))
     lh.log_cmd(cmd)
     uninstall = pexpect.spawnu(cmd)
     try:
         uninstall.expect(['Purging', 'which isn\'t installed'])
         ascii_print(uninstall.before)
         uninstall.expect(pexpect.EOF)
         ascii_print(uninstall.before)
     except pexpect.exceptions.EOF:
         ascii_print(uninstall.before)
         sys.exit(1)
Ejemplo n.º 14
0
 def un_install_server_package_impl(self):
     """ uninstall server package """
     cmd = "dpkg --purge " + "arangodb3" + ("e" if self.cfg.enterprise else "")
     lh.log_cmd(cmd)
     uninstall = pexpect.spawnu(cmd)
     try:
         uninstall.expect(["Purging", "which isn't installed"])
         ascii_print(uninstall.before)
         uninstall.expect(pexpect.EOF)
         ascii_print(uninstall.before)
     except pexpect.exceptions.EOF as ex:
         ascii_print(uninstall.before)
         raise ex
     self.instance.search_for_warnings()
Ejemplo n.º 15
0
 def upgrade_server_package(self, old_installer):
     logging.info("upgrading Arangodb debian package")
     self.backup_dirs_number_before_upgrade = self.count_backup_dirs()
     os.environ["DEBIAN_FRONTEND"] = "readline"
     cmd = "dpkg -i " + str(self.cfg.package_dir / self.server_package)
     lh.log_cmd(cmd)
     server_upgrade = pexpect.spawnu(cmd)
     server_upgrade.logfile = sys.stdout
     while True:
         try:
             i = server_upgrade.expect(
                 [
                     "Upgrading database files",
                     "Database files are up-to-date",
                     "arangod.conf",
                 ],
                 timeout=120,
             )
             if i == 0:
                 logging.info("X" * 80)
                 ascii_print(server_upgrade.before)
                 logging.info("X" * 80)
                 logging.info("[X] Upgrading database files")
                 break
             if i == 1:
                 logging.info("X" * 80)
                 ascii_print(server_upgrade.before)
                 logging.info("X" * 80)
                 logging.info("[ ] Update not needed.")
                 break
             if i == 2:  # modified arangod.conf...
                 ascii_print(server_upgrade.before)
                 server_upgrade.sendline("Y")
                 # fallthrough - repeat.
         except pexpect.exceptions.EOF as ex:
             logging.info("X" * 80)
             ascii_print(server_upgrade.before)
             logging.info("X" * 80)
             logging.info("[E] Upgrade failed!")
             raise Exception("Upgrade failed!") from ex
     try:
         logging.info("waiting for the upgrade to finish")
         server_upgrade.expect(pexpect.EOF, timeout=30)
         ascii_print(server_upgrade.before)
     except pexpect.exceptions.EOF:
         logging.info("TIMEOUT!")
     self.set_system_instance()
     self.instance.detect_pid(1)  # should be owned by init
Ejemplo n.º 16
0
    def upgrade_server_package(self, old_installer):
        logging.info("upgrading Arangodb rpm package")

        self.cfg.passvoid = "RPM_passvoid_%d" % os.getpid()
        self.cfg.log_dir = Path("/var/log/arangodb3")
        self.cfg.dbdir = Path("/var/lib/arangodb3")
        self.cfg.appdir = Path("/var/lib/arangodb3-apps")
        self.cfg.cfgdir = Path("/etc/arangodb3")

        self.set_system_instance()

        # https://access.redhat.com/solutions/1189
        cmd = "rpm --upgrade " + str(
            self.cfg.package_dir / self.server_package)
        lh.log_cmd(cmd)
        server_upgrade = pexpect.spawnu(cmd)
        server_upgrade.logfile = sys.stdout

        try:
            server_upgrade.expect(
                "First Steps with ArangoDB:|server "
                "will now shut down due to upgrade,"
                "database initialization or admin restoration.")
            print(server_upgrade.before)
        except pexpect.exceptions.EOF as exc:
            lh.line("X")
            ascii_print(server_upgrade.before)
            lh.line("X")
            print("exception : " + str(exc))
            lh.line("X")
            logging.error("Upgrade failed!")
            raise exc

        logging.debug("found: upgrade message")

        logging.info("waiting for the upgrade to finish")
        try:
            server_upgrade.expect(pexpect.EOF, timeout=30)
            ascii_print(server_upgrade.before)
        except pexpect.exceptions.EOF as ex:
            logging.error("TIMEOUT! while upgrading package")
            raise ex

        logging.debug("upgrade successfully finished")
        self.start_service()
Ejemplo n.º 17
0
    def install_package(self):
        logging.info("installing Arangodb debian Tar package")
        logging.debug("package dir: {0.cfg.package_dir}- "
                      "server_package: {0.server_package}".format(self))

        if not self.cfg.installPrefix.exists():
            self.cfg.installPrefix.mkdir()
        cmd = [
            self.tar, '-xf',
            str(self.cfg.package_dir / self.server_package), '-C',
            str(self.cfg.installPrefix), '--strip-components', '1'
        ]
        lh.log_cmd(cmd)
        install = psutil.Popen(cmd)
        if install.wait() != 0:
            raise Exception("extracting the Archive failed!")
        print()
        logging.info('Installation successfull')
Ejemplo n.º 18
0
def create_arangod_dump(installer, starter_dir: str, dump_file_dir: str):
    """create arangod memory dump file"""
    starter = StarterManager(
        basecfg=installer.cfg,
        install_prefix=Path(starter_dir),
        instance_prefix="single",
        expect_instances=[InstanceType.SINGLE],
        mode="single",
        jwt_str="single",
    )
    dump_filename = None
    try:
        with step("Start a single server deployment"):
            starter.run_starter()
            starter.detect_instances()
            starter.detect_instance_pids()
            starter.set_passvoid("")
            pid = starter.all_instances[0].pid
        with step("Create a dump of arangod process"):
            cmd = ["procdump", "-ma", str(pid), dump_file_dir]
            lh.log_cmd(cmd)
            with psutil.Popen(cmd,
                              bufsize=-1,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE) as proc:
                (procdump_out, procdump_err) = proc.communicate()
                procdump_str = str(procdump_out, "UTF-8")
                attach(procdump_str, "procdump sdtout")
                attach(str(procdump_err), "procdump stderr")
                success_string = "Dump 1 complete"
                filename_regex = re.compile(
                    r"^(\[\d{2}:\d{2}:\d{2}\] Dump 1 initiated: )(?P<filename>.*)$",
                    re.MULTILINE)
                match = re.search(filename_regex, procdump_str)
                if procdump_str.find(success_string) < 0 or not match:
                    raise Exception(
                        "procdump wasn't able to create a dump file: " +
                        procdump_str)
                dump_filename = match.group("filename")
    finally:
        starter.terminate_instance()
        kill_all_processes()
    return dump_filename
Ejemplo n.º 19
0
    def uninstall_package(self, package_name, force=False):
        """uninstall package"""
        os.environ["DEBIAN_FRONTEND"] = "readline"
        force = "--force-depends" if force else ""
        cmd = f"dpkg --purge {force} {package_name}"
        lh.log_cmd(cmd)
        uninstall = pexpect.spawnu(cmd)
        try:
            uninstall.expect(["Removing", "which isn't installed"])
            ascii_print(uninstall.before)
            uninstall.expect(pexpect.EOF, timeout=30)
            ascii_print(uninstall.before)
        except pexpect.exceptions.EOF as ex:
            ascii_print(uninstall.before)
            raise ex

        while uninstall.isalive():
            progress(".")
            if uninstall.exitstatus != 0:
                uninstall.close(force=True)
                ascii_print(uninstall.before)
                raise Exception("Uninstallation of package %s didn't finish successfully!" % package_name)
Ejemplo n.º 20
0
    def install_client_package_impl(self):
        """install client package"""
        cmd = "dpkg -i " + str(self.cfg.package_dir / self.client_package)
        lh.log_cmd(cmd)
        os.environ["DEBIAN_FRONTEND"] = "readline"
        client_install = pexpect.spawnu(cmd)
        try:
            logging.info("waiting for the installation to finish")
            client_install.expect(pexpect.EOF, timeout=60)
        except pexpect.exceptions.EOF:
            logging.info("TIMEOUT!")
            client_install.close(force=True)
            ascii_print(client_install.before)
        print()
        logging.info(str(self.client_package) + " Installation successful")

        while client_install.isalive():
            progress(".")
        if client_install.exitstatus != 0:
            client_install.close(force=True)
            ascii_print(client_install.before)
            raise Exception(str(self.debug_package) + " client package installation didn't finish successfully!")
Ejemplo n.º 21
0
    def un_install_debug_package(self):
        os.environ['DEBIAN_FRONTEND'] = 'readline'
        cmd = ('dpkg --purge ' + 'arangodb3' +
               ('e-dbg' if self.cfg.enterprise else '-dbg'))
        lh.log_cmd(cmd)
        uninstall = pexpect.spawnu(cmd)
        try:
            uninstall.expect(['Removing', 'which isn\'t installed'])
            ascii_print(uninstall.before)
            uninstall.expect(pexpect.EOF, timeout=30)
            ascii_print(uninstall.before)
        except pexpect.exceptions.EOF:
            ascii_print(uninstall.before)
            sys.exit(1)

        while uninstall.isalive():
            progress('.')
            if uninstall.exitstatus != 0:
                uninstall.close(force=True)
                ascii_print(uninstall.before)
                raise Exception(
                    "Debug package uninstallation didn't finish successfully!")
Ejemplo n.º 22
0
    def install_server_package_impl(self):
        # pylint: disable=too-many-statements
        self.cfg.log_dir = Path("/var/log/arangodb3")
        self.cfg.dbdir = Path("/var/lib/arangodb3")
        self.cfg.appdir = Path("/var/lib/arangodb3-apps")
        self.cfg.cfgdir = Path("/etc/arangodb3")
        self.set_system_instance()
        logging.info("installing Arangodb RPM package")
        package = self.cfg.package_dir / self.server_package
        if not package.is_file():
            logging.info("package doesn't exist: %s", str(package))
            raise Exception("failed to find package")

        cmd = "rpm " + "-i " + str(package)
        lh.log_cmd(cmd)
        server_install = pexpect.spawnu(cmd)
        server_install.logfile = sys.stdout
        reply = None

        try:
            server_install.expect("the current password is")
            ascii_print(server_install.before)
            server_install.expect(pexpect.EOF, timeout=60)
            reply = server_install.before
            ascii_print(reply)
        except pexpect.exceptions.EOF as ex:
            ascii_print(server_install.before)
            logging.info("Installation failed!")
            raise ex

        while server_install.isalive():
            progress(".")
            if server_install.exitstatus != 0:
                raise Exception("server installation "
                                "didn't finish successfully!")

        start = reply.find("'")
        end = reply.find("'", start + 1)
        self.cfg.passvoid = reply[start + 1:end]

        self.start_service()
        self.instance.detect_pid(1)  # should be owned by init

        pwcheckarangosh = ArangoshExecutor(self.cfg, self.instance)
        if not pwcheckarangosh.js_version_check():
            logging.error(
                "Version Check failed -"
                "probably setting the default random password didn't work! %s",
                self.cfg.passvoid,
            )

        # should we wait for user here? or mark the error in a special way

        self.stop_service()

        self.cfg.passvoid = "RPM_passvoid_%d" % os.getpid()
        lh.log_cmd("/usr/sbin/arango-secure-installation")
        with pexpect.spawnu("/usr/sbin/arango-secure-installation") as etpw:
            etpw.logfile = sys.stdout
            result = None
            try:
                ask_for_pass = [
                    "Please enter a new password for the ArangoDB root user:"******"Please enter password for root user:"******"Not asked for password")

                etpw.sendline(self.cfg.passvoid)
                result = etpw.expect("Repeat password: "******"Not asked to repeat the password")
                ascii_print(etpw.before)
                logging.info("password should be set to: " + self.cfg.passvoid)
                etpw.sendline(self.cfg.passvoid)

                logging.info("expecting eof")
                logging.info("password should be set to: " + self.cfg.passvoid)
                result = etpw.expect(pexpect.EOF)

                logging.info("password should be set to: " + self.cfg.passvoid)
                ascii_print(etpw.before)

            # except pexpect.exceptions.EOF:
            except Exception as exc:
                logging.error("setting our password failed!")
                logging.error("X" * 80)
                logging.error("XO" * 80)
                logging.error(repr(self.cfg))
                logging.error("X" * 80)
                logging.error("result: " + str(result))
                logging.error("X" * 80)
                ascii_print(etpw.before)
                logging.error("X" * 80)
                raise exc

        self.start_service()
        self.instance.detect_pid(1)  # should be owned by init
Ejemplo n.º 23
0
    def run_monitored(self,
                      executeable,
                      args,
                      timeout=60,
                      result_line=dummy_line_result,
                      verbose=False,
                      expect_to_fail=False):
        """
        run a script in background tracing with a dynamic timeout that its got output (is still alive...)
        """

        run_cmd = [executeable] + args
        lh.log_cmd(run_cmd, verbose)
        with Popen(
                run_cmd,
                stdout=PIPE,
                stderr=PIPE,
                close_fds=ON_POSIX,
                cwd=self.cfg.test_data_dir.resolve(),
        ) as process:
            queue = Queue()
            thread1 = Thread(
                name="readIO",
                target=enqueue_stdout,
                args=(process.stdout, queue, self.connect_instance),
            )
            thread2 = Thread(
                name="readErrIO",
                target=enqueue_stderr,
                args=(process.stderr, queue, self.connect_instance),
            )
            thread1.start()
            thread2.start()

            try:
                print("me PID:%d launched PID:%d with LWPID:%d and LWPID:%d" %
                      (os.getpid(), process.pid, thread1.native_id,
                       thread2.native_id))
            except AttributeError:
                print(
                    "me PID:%d launched PID:%d with LWPID:N/A and LWPID:N/A" %
                    (os.getpid(), process.pid))

            # ... do other things here
            # out = logfile.open('wb')
            # read line without blocking
            have_timeout = False
            line_filter = False
            tcount = 0
            close_count = 0
            result = []
            while not have_timeout:
                if not verbose:
                    progress("sj" + str(tcount))
                line = ""
                try:
                    line = queue.get(timeout=1)
                    line_filter = line_filter or result_line(line)
                except Empty:
                    tcount += 1
                    if verbose:
                        progress("T " + str(tcount))
                    have_timeout = tcount >= timeout
                else:
                    tcount = 0
                    if isinstance(line, tuple):
                        if verbose:
                            print("e: " + str(line[0]))
                        if not str(line[0]).startswith("#"):
                            result.append(line)
                    else:
                        close_count += 1
                        if close_count == 2:
                            print(" done!")
                            break
            timeout_str = ""
            if have_timeout:
                timeout_str = "TIMEOUT OCCURED!"
                print(timeout_str)
                timeout_str += "\n"
                process.kill()
            rc_exit = process.wait()
            thread1.join()
            thread2.join()

        attach(str(rc_exit), f"Exit code: {str(rc_exit)}")

        if have_timeout or rc_exit != 0:
            res = (False, timeout_str + convert_result(result), rc_exit,
                   line_filter)
            if expect_to_fail:
                return res
            raise CliExecutionException("Execution failed.", res, have_timeout)

        if not expect_to_fail:
            if len(result) == 0:
                res = (True, "", 0, line_filter)
            else:
                res = (True, convert_result(result), 0, line_filter)
            return res

        if len(result) == 0:
            res = (True, "", 0, line_filter)
        else:
            res = (True, convert_result(result), 0, line_filter)
        raise CliExecutionException(
            "Execution was expected to fail, but exited successfully.", res,
            have_timeout)
Ejemplo n.º 24
0
    def run_script_monitored(self, cmd, args, timeout, result_line,
                             process_control=False, verbose=True):
       # pylint: disable=R0913 disable=R0902 disable=R0915 disable=R0912
        """
        runs a script in background tracing with
        a dynamic timeout that its got output
        (is still alive...)
        """
        run_cmd = [
            self.cfg.bin_dir / "arangosh",
            "--server.endpoint", self.connect_instance.get_endpoint(),
            "--log.level", "v8=debug",
            "--log.foreground-tty", "true"
        ]
        if process_control:
            run_cmd += ['--javascript.allow-external-process-control', 'true']
        run_cmd += [ "--server.username", str(self.cfg.username) ]
        run_cmd += [ "--server.password", str(self.connect_instance.get_passvoid()) ]

        run_cmd += [ "--javascript.execute", str(cmd[1]) ]

        if len(cmd) > 2:
            run_cmd += cmd[2:]

        if len(args) > 0:
            run_cmd += ['--'] + args

        if verbose:
            lh.log_cmd(run_cmd)
        process = Popen(run_cmd, stdout=PIPE, stderr=PIPE, close_fds=ON_POSIX)
        queue = Queue()
        thread1 = Thread(target=enqueue_stdout, args=(process.stdout,
                                                      queue,
                                                      self.connect_instance))
        thread2 = Thread(target=enqueue_stderr, args=(process.stderr,
                                                      queue,
                                                      self.connect_instance))
        thread1.start()
        thread2.start()

        # ... do other things here
        # out = logfile.open('wb')
        # read line without blocking
        have_timeout = False
        tcount = 0
        close_count = 0
        result = []
        while not have_timeout:
            if not verbose:
                progress("sj" + str(tcount))
            line = ''
            try:
                line = queue.get(timeout=1)
                result_line(line)
            except Empty:
                tcount += 1
                if verbose:
                    progress('T ' + str(tcount))
                have_timeout = tcount >= timeout
            else:
                tcount = 0
                if isinstance(line, tuple):
                    if verbose:
                        print("e: " + str(line[0]))
                    if not str(line[0]).startswith('#'):
                        result.append(line)
                else:
                    close_count += 1
                    if close_count == 2:
                        print(' done!')
                        break
        if have_timeout:
            print(" TIMEOUT OCCURED!")
            process.kill()
        rc_exit = process.wait()
        print(rc_exit)
        thread1.join()
        thread2.join()
        if have_timeout or rc_exit != 0:
            return (False, convert_result(result))
        if len(result) == 0:
            return (True, "")
        return (True, convert_result(result))
Ejemplo n.º 25
0
    def upgrade_package(self, old_installer):
        logging.info("upgrading Arangodb debian package")
        os.environ['DEBIAN_FRONTEND'] = 'readline'

        server_upgrade = pexpect.spawnu('dpkg -i ' + str(self.cfg.package_dir /
                                                         self.server_package))

        try:
            i == server_upgrade.expect(
                ['Upgrading database files', 'Database files are up-to-date'])
            ascii_print(server_upgrade.before)
            if i == 0:
                logging.info("Upgrading database files...")
            elif i == 1:
                logging.info("Database already up-to-date!")
        except pexpect.exceptions.EOF:
            logging.info("X" * 80)
            ascii_print(server_upgrade.before)
            logging.info("X" * 80)
            logging.info("[E] Upgrade failed!")
            sys.exit(1)

        cmd = 'dpkg -i ' + str(self.cfg.package_dir / self.server_package)
        lh.log_cmd(cmd)
        server_upgrade = pexpect.spawnu(cmd)

        while True:
            try:
                i = server_upgrade.expect([
                    'Upgrading database files',
                    'Database files are up-to-date', 'arangod.conf'
                ],
                                          timeout=60)
                if i == 0:
                    logging.info("X" * 80)
                    ascii_print(server_upgrade.before)
                    logging.info("X" * 80)
                    logging.info("[X] Upgrading database files")
                    break
                if i == 1:
                    logging.info("X" * 80)
                    ascii_print(server_upgrade.before)
                    logging.info("X" * 80)
                    logging.info("[ ] Update not needed.")
                    break
                if i == 2:  # modified arangod.conf...
                    ascii_print(server_upgrade.before)
                    server_upgrade.sendline('Y')
                    # fallthrough - repeat.
            except pexpect.exceptions.EOF:
                logging.info("X" * 80)
                ascii_print(server_upgrade.before)
                logging.info("X" * 80)
                logging.info("[E] Upgrade failed!")
                sys.exit(1)

        try:
            logging.info("waiting for the upgrade to finish")
            server_upgrade.expect(pexpect.EOF, timeout=30)
            ascii_print(server_upgrade.before)
        except pexpect.exceptions.EOF:
            logging.info("TIMEOUT!")
Ejemplo n.º 26
0
    def install_package(self):
        # pylint: disable=too-many-statements
        logging.info("installing Arangodb debian package")
        server_not_started = False
        os.environ['DEBIAN_FRONTEND'] = 'readline'
        self.cfg.passvoid = "sanoetuh"  # TODO
        logging.debug("package dir: {0.cfg.package_dir}- "
                      "server_package: {0.server_package}".format(self))
        cmd = 'dpkg -i ' + str(self.cfg.package_dir / self.server_package)
        lh.log_cmd(cmd)
        server_install = pexpect.spawnu(cmd)
        try:
            logging.debug("expect: user1")
            i = server_install.expect(['user:'******'arangod.conf'], timeout=120)
            # there are remaints of previous installations.
            # We overwrite existing config files.
            if i == 1:
                server_install.sendline('Y')
                ascii_print(server_install.before)
                server_install.expect('user:'******'user:'******'is-active arangodb3.service'") >= 0
        except pexpect.exceptions.EOF:
            logging.info("TIMEOUT!")
        while server_install.isalive():
            progress('.')
            if server_install.exitstatus != 0:
                raise Exception(
                    "server installation didn't finish successfully!")
        print()
        logging.info('Installation successfull')
        self.set_system_instance()
        if server_not_started:
            logging.info('Environment did not start arango service,'
                         'doing this now!')
            self.start_service()
        self.instance.detect_pid(1)  # should be owned by init
Ejemplo n.º 27
0
 def un_install_server_package_impl(self):
     """ uninstall the server package """
     self.stop_service()
     cmd = ["rpm", "-e", "arangodb3" + ("e" if self.cfg.enterprise else "")]
     lh.log_cmd(cmd)
     run_cmd_and_log_stdout(cmd)