コード例 #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
コード例 #2
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()
コード例 #3
0
 def wait_for_upgrade(self):
     """ wait for the upgrade commanding starter to finish """
     for line in self.upgradeprocess.stderr:
         ascii_print(line)
     ret = self.upgradeprocess.wait()
     logging.info("StarterManager: Upgrade command exited: %s", str(ret))
     if ret != 0:
         raise Exception("Upgrade process exited with non-zero reply")
コード例 #4
0
def _mountdmg(dmgpath):
    """
    Attempts to mount the dmg at dmgpath and returns first mountpoint
    """
    mountpoints = []
    cmd = [
        "/usr/bin/hdiutil",
        "attach",
        str(dmgpath),
        "-mountRandom",
        "/tmp",
        "-nobrowse",
        "-plist",
        "-owners",
        "on",
    ]
    print(cmd)
    pliststr = ""
    with subprocess.Popen(
            cmd,
            bufsize=-1,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            stdin=subprocess.PIPE,
    ) as proc:
        proc.stdin.write(b"y\n")  # answer 'Agree Y/N?' the dumb way...
        # pylint: disable=unused-variable
        (pliststr, _) = proc.communicate()

    offset = pliststr.find(b'<?xml version="1.0" encoding="UTF-8"?>')
    if offset > 0:
        print("got string")
        print(offset)
        ascii_print(str(pliststr[0:offset]))
        pliststr = pliststr[offset:]

    if proc.returncode:
        logging.error("while mounting")
        return None
    if pliststr:
        # pliststr = bytearray(pliststr, 'ascii')
        # print(pliststr)
        plist = plistlib.loads(pliststr)
        print(plist)
        for entity in plist["system-entities"]:
            if "mount-point" in entity:
                mountpoints.append(entity["mount-point"])
    else:
        raise Exception("plist empty")
    return mountpoints[0]
コード例 #5
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
コード例 #6
0
 def run_installer_script(self):
     """this will run the installer script from the dmg"""
     enterprise = "e" if self.cfg.enterprise else ""
     script = (Path(self.mountpoint) /
               "ArangoDB3{}-CLI.app".format(enterprise) / "Contents" /
               "MacOS" / "ArangoDB3-CLI")
     print(script)
     os.environ["STORAGE_ENGINE"] = "auto"
     installscript = pexpect.spawnu(str(script))
     try:
         installscript.expect("is ready for business. Have fun!",
                              timeout=60)
         ascii_print(installscript.before)
     except pexpect.exceptions.EOF:
         ascii_print(installscript.before)
     installscript.kill(0)
コード例 #7
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()
コード例 #8
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!")
コード例 #9
0
    def mountdmg(self, dmgpath):
        """
        Attempts to mount the dmg at dmgpath and returns first mountpoint
        """
        mountpoints = []
        # dmgname = os.path.basename(dmgpath)
        cmd = ['/usr/bin/hdiutil', 'attach', str(dmgpath),
               '-mountRandom', '/tmp', '-nobrowse', '-plist',
               '-owners', 'on']
        print(cmd)
        proc = subprocess.Popen(cmd, bufsize=-1,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE,
                                stdin=subprocess.PIPE)
        proc.stdin.write(b"y\n") # answer 'Agree Y/N?' the dumb way...
        (pliststr,) = proc.communicate()
        # print(str(pliststr))

        offset = pliststr.find(b'<?xml version="1.0" encoding="UTF-8"?>')
        if offset > 0:
            print('got string')
            print(offset)
            ascii_print(str(pliststr[0:offset]))
            pliststr = pliststr[offset:]

        if proc.returncode:
            logging.error('while mounting')
            return None
        if pliststr:
            # pliststr = bytearray(pliststr, 'ascii')
            # print(pliststr)
            plist = plistlib.loads(pliststr)
            print(plist)
            for entity in plist['system-entities']:
                if 'mount-point' in entity:
                    mountpoints.append(entity['mount-point'])
        else:
            raise Exception("plist empty")
        return mountpoints[0]
コード例 #10
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)
コード例 #11
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()
コード例 #12
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!")
コード例 #13
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)
コード例 #14
0
    def un_install_package(self, package_name: str):
        """Uninstall package"""
        print('uninstalling rpm package "%s"' % package_name)
        uninstall = pexpect.spawnu("rpm -e " + package_name)
        uninstall.logfile = sys.stdout
        try:
            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 packages %s failed. " %
                                package_name)
コード例 #15
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
コード例 #16
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!")
コード例 #17
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