Example #1
0
    def install_update(self, install_data, update_dir=None):
        """
        Install OS X updates.

        Returns:

            Installation result

        """

        # Use to get the apps to be removed on the server side
        old_install_list = self.get_installed_applications()

        success = 'false'
        error = RvError.UpdatesNotFound
        restart = 'false'
        app_encoding = CreateApplication.null_application().to_dict()
        apps_to_delete = []
        apps_to_add = []

        if not update_dir:
            update_dir = settings.UpdatesDirectory

        #update_data = self._macsqlite.get_update_data(
        #    install_data.name
        #)

        if install_data.downloaded:
            success, error = self.pkg_installer.install(install_data)

            if success != 'true':
                logger.debug(
                    "Failed to install update {0}. success:{1}, error:{2}".
                    format(install_data.name, success, error))
                # Let the OS take care of downloading and installing.
                success, error = \
                    self.pkg_installer.complete_softwareupdate(install_data)

        else:
            logger.debug(
                ("Downloaded = False for: {0} calling "
                 "complete_softwareupdate.").format(install_data.name))

            success, error = \
                self.pkg_installer.complete_softwareupdate(install_data)

        if success == 'true':
            #restart = update_data.get(UpdateDataColumn.NeedsRestart, 'false')
            restart = self._get_reboot_required(install_data.name)

            new_install_list = self.get_installed_applications()

            app_encoding = self._get_app_encoding(install_data.name,
                                                  new_install_list)

            apps_to_add, apps_to_delete = self._get_apps_to_add_and_delete(
                old_install_list, new_install_list)

        return InstallResult(success, error, restart, app_encoding,
                             apps_to_delete, apps_to_add)
Example #2
0
    def install_update(self, install_data, update_dir=None):
        logger.debug('Received install_update call.')

        success = 'false'
        error = ''
        restart = 'false'
        app_encoding = CreateApplication.null_application().to_dict()
        apps_to_delete = []
        apps_to_add = []

        old_install_list = self.get_installed_applications()

        success, error, restart = self._yum_update(install_data.name)

        if success == 'true':

            new_install_list = self.get_installed_applications()

            app = self._get_installed_app(install_data.name, new_install_list)
            app_encoding = app.to_dict()

            apps_to_add, apps_to_delete = self._get_apps_to_add_and_delete(
                old_install_list, new_install_list
            )

        return InstallResult(
            success,
            error,
            restart,
            app_encoding,
            apps_to_delete,
            apps_to_add
        )
Example #3
0
    def install_supported_apps(self, install_data, update_dir=None):
        old_install_list = self.get_installed_applications()

        success = 'false'
        error = 'Failed to install application.'
        restart = 'false'
        app_encoding = "{}"
        apps_to_delete = []
        apps_to_add = []

        if not install_data.downloaded:
            error = 'Failed to download packages.'

            return InstallResult(success, error, restart, app_encoding,
                                 apps_to_delete, apps_to_add)

        if not update_dir:
            update_dir = settings.UpdatesDirectory

        try:
            update_dir = os.path.join(update_dir, install_data.id)
            success, error = self._rpm_install(update_dir,
                                               install_data.proc_niceness)

            if success == 'true':
                apps_to_add, apps_to_delete = \
                    self._get_apps_to_add_and_delete(old_install_list)

        except Exception as e:
            error = ("Failed to install updates from: {0}".format(
                install_data.name))

            logger.error(error)
            logger.exception(e)

        return InstallResult(success, error, restart, app_encoding,
                             apps_to_delete, apps_to_add)
Example #4
0
    def install_agent_update(self,
                             install_data,
                             operation_id,
                             update_dir=None):
        success = 'false'
        error = ''

        if update_dir is None:
            update_dir = settings.UpdatesDirectory

        if install_data.downloaded:
            update_dir = os.path.join(update_dir, install_data.id)

            dir_files = [
                file for file in os.listdir(update_dir)
                if re.search("vfagent*", file.lower())
            ]

            update_file = [file for file in dir_files if '.' not in file]

            if update_file:
                path_of_update = os.path.join(update_dir, update_file[0])

                agent_updater = updater.Updater()

                extra_cmds = [
                    '--operationid', operation_id, '--appid', install_data.id
                ]

                success, error = agent_updater.update(path_of_update,
                                                      extra_cmds)

            else:
                logger.error(
                    "Could not find update in: {0}".format(update_dir))
                error = 'Could not find update.'

        else:

            logger.debug("{0} was not downloaded. Returning false.".format(
                install_data.name))

            error = "Update not downloaded."

        return InstallResult(success, error, 'false', "{}", [], [])
Example #5
0
    def install_agent_update(self,
                             install_data,
                             operation_id,
                             update_dir=None):
        success = 'false'
        error = ''

        if update_dir is None:
            update_dir = settings.UpdatesDirectory

        if install_data.downloaded:
            update_dir = os.path.join(update_dir, install_data.id)
            dmgs = glob.glob(os.path.join(update_dir, "*.dmg"))

            path_of_update = [
                dmg for dmg in dmgs
                if re.search(r'vfagent.*\.dmg', dmg.lower())
            ]

            if path_of_update:
                path_of_update = path_of_update[0]

                agent_updater = updater.Updater()

                extra_cmds = [
                    '--operationid', operation_id, '--appid', install_data.id
                ]

                success, error = agent_updater.update(path_of_update,
                                                      extra_cmds)

            else:
                logger.error(
                    "Could not find update in: {0}".format(update_dir))
                error = 'Could not find update.'

        else:

            logger.debug("{0} was not downloaded. Returning false.".format(
                install_data.name))

            error = "Update not downloaded."

        return InstallResult(success, error, 'false', "{}", [], [])
Example #6
0
    def install_update(self, install_data, update_dir=None):
        logger.debug('Received install_update call.')

        old_install_list = self.get_installed_applications()

        success = 'false'
        error = ''
        restart = 'false'
        app_encoding = CreateApplication.null_application().to_dict()
        apps_to_delete = []
        apps_to_add = []

        if not update_dir:
            update_dir = settings.UpdatesDirectory

        if install_data.downloaded:

            packages_dir = os.path.join(update_dir, install_data.id)
            success, error, restart = self._yum_local_update(
                install_data.name, packages_dir, install_data.proc_niceness)

            if success == 'true':

                new_install_list = self.get_installed_applications()

                app = self._get_installed_app(install_data.name,
                                              new_install_list)
                app_encoding = app.to_dict()

                apps_to_add, apps_to_delete = self._get_apps_to_add_and_delete(
                    old_install_list, new_install_list)

        else:
            logger.debug("Downloaded = False for: {0}".format(
                install_data.name))
            error = "Failed to download packages."

        return InstallResult(success, error, restart, app_encoding,
                             apps_to_delete, apps_to_add)
Example #7
0
    def install_update(self, install_data, update_dir=None):
        logger.debug('Received install_update call.')

        old_install_list = self.get_installed_applications()

        success = 'false'
        error = RvError.UpdatesNotFound
        restart = 'false'
        app_encoding = CreateApplication.null_application().to_dict()
        apps_to_delete = []
        apps_to_add = []

        if not update_dir:
            update_dir = settings.UpdatesDirectory

        packages_dir = os.path.join(update_dir, install_data.id)
        moving_error = self._move_pkgs_to_apt_dir(packages_dir)

        if not moving_error:
            success, error, restart = self._apt_install(
                install_data.name, install_data.proc_niceness)

            if success == 'true':

                app = self._get_installed_app(install_data.name)
                app_encoding = app.to_dict()

                apps_to_add, apps_to_delete = \
                    self._get_apps_to_add_and_delete(old_install_list)

        else:
            error = moving_error

        # TODO(urgent): should I apt-get clean here or in rv_plugin?

        return InstallResult(success, error, restart, app_encoding,
                             apps_to_delete, apps_to_add)
Example #8
0
    def install_supported_apps(self, install_data, update_dir=None):

        old_install_list = self.get_installed_applications()

        success = 'false'
        error = 'Failed to install application.'
        restart = 'false'
        #app_encoding = []
        apps_to_delete = []
        apps_to_add = []

        if not install_data.downloaded:
            error = 'Failed to download packages.'

            return InstallResult(success, error, restart, "{}", apps_to_delete,
                                 apps_to_add)

        if not update_dir:
            update_dir = settings.UpdatesDirectory

        try:
            pkgs = glob.glob(
                os.path.join(update_dir, "%s/*.pkg" % install_data.id))
            dmgs = glob.glob(
                os.path.join(update_dir, "%s/*.dmg" % install_data.id))

            if pkgs:
                success, error = self._install_third_party_pkg(pkgs)

                if success == 'true':
                    #app_encoding = self._get_app_encoding(install_data.name)

                    apps_to_add, apps_to_delete = \
                        self._get_apps_to_add_and_delete(old_install_list)

            elif dmgs:
                success, error, app_names = self._install_third_party_dmgs(
                    dmgs, install_data.proc_niceness)

                if success == 'true':

                    apps_to_add, apps_to_delete = \
                        self._get_apps_to_add_and_delete(old_install_list)

                    # OSX may not index these newly installed applications
                    # in time, therefore the information gathering has to be
                    # done manually.
                    if app_names:
                        newly_installed = \
                            self._create_app_from_bundle_info(app_names)

                        apps_to_add.extend(
                            [app.to_dict() for app in newly_installed])

                    # TODO(urgent): figure out how to get apps_to_delete
                    # for dmgs with app bundles

        except Exception as e:
            logger.error("Failed to install: {0}".format(install_data.name))
            logger.exception(e)

        return InstallResult(success, error, restart, "{}", apps_to_delete,
                             apps_to_add)