コード例 #1
0
ファイル: common_utils.py プロジェクト: jbeecham/ovirt-engine
def getRpmVersion(rpmName=basedefs.ENGINE_RPM_NAME):
    """
    extracts rpm version
    from a given rpm package name
    default rpm is 'rhevm'

    returns version (string)
    """
    # Update build number on welcome page
    logging.debug("retrieving version for %s rpm" % rpmName)

    # TODO
    # Do not create miniyum here, pass it via argument
    miniyum = MiniYum(sink=MiniYumSink())

    res = [
        p for p in miniyum.queryPackages(patterns=[rpmName])
        if p['operation'] == 'installed'
    ]

    if len(res) != 1:
        raise Exception(output_messages.ERR_READ_RPM_VER % rpmName)

    return "%s-%s" % (res[0]['version'], res[0]['release'])
コード例 #2
0
ファイル: vds_bootstrap.py プロジェクト: doronunu/vdsm
def main():
    """
Usage: vds_bootstrap.py [options] <url> <subject> <random_num>

options:
    -v <bootstrap inteface version> - default 1
    -O <organizationName>
    -t <systemTime>
    -f <firewall_rules_file> -- override firewall rules.
    -V - don't install virtualization service
    -g - install gluster service
obsolete options:
    -r <rev_num>
    """
    try:
        rev_num = None
        orgName = 'Red Hat Inc.'
        systime = None
        firewallRulesFile = None
        engine_ssh_key = None
        installVirtualizationService = True
        installGlusterService = False
        bridgeName = None
        opts, args = getopt.getopt(sys.argv[1:], "v:r:O:t:f:S:n:u:B:Vg")
        for o, v in opts:
            if o == "-v":
                deployUtil.setBootstrapInterfaceVersion(int(v))
            if o == "-r":
                rev_num = v
            if o == "-O":
                orgName = v
            if o == "-t":
                systime = v
            if o == "-V":
                installVirtualizationService = False
            if o == "-g":
                installGlusterService = True
            elif o == '-f':
                firewallRulesFile = v
                NEEDED_SERVICES.append('iptables')
            elif o == '-S':
                engine_ssh_key = v
            elif o == '-B':
                bridgeName = v

        url = args[0]
        subject = args[1]
        random_num = args[2]
        # Where is REVISION defined ????
        #if not rev_num:
        #    rev_num = REVISION
    except:
        print main.__doc__
        return False

    #
    # miniyum setup must be done first as process
    # is probably going to be reexecute with
    # proper selinux role
    #
    miniyum = None
    if deployUtil.getBootstrapInterfaceVersion() >= 2:
        try:
            from miniyum import MiniYum

            miniyumsink = myminiyumsink()
            MiniYum.setup_log_hook(sink=miniyumsink)
            extraLog = open(LOGFILE, "a")
            miniyum = MiniYum(sink=miniyumsink, extraLog=extraLog)
            miniyum.selinux_role()
        except:
            logging.error("MiniYum selinux setup failed", exc_info=True)
            print "<BSTRAP component='RHEV_INSTALL' status='FAIL'/>"
            return False

    logging.debug('**** Start VDS Validation ****')
    try:
        ret = VdsValidation(
            url, subject, random_num, rev_num, orgName, systime,
            firewallRulesFile, engine_ssh_key,
            installVirtualizationService, installGlusterService,
            bridgeName, miniyum
        )
    except:
        logging.error("VDS validation failed", exc_info=True)
        logging.error(main.__doc__)
        logging.debug("<BSTRAP component='RHEV_INSTALL' status='FAIL'/>")
        print "<BSTRAP component='RHEV_INSTALL' status='FAIL'/>"
        return False
    else:
        message = ("<BSTRAP component='RHEV_INSTALL' status=")
        if ret:
            message += ("'OK'/>")
        else:
            message += ("'FAIL'/>")

        print(message)
        logging.debug(message)

    logging.debug('**** End VDS Validation ****')
    sys.stdout.flush()
    return ret
コード例 #3
0
def main(options):
    # BEGIN: PROCESS-INITIALIZATION
    miniyumsink = utils.MiniYumSink()
    MiniYum.setup_log_hook(sink=miniyumsink)
    extraLog = open(logFile, "a")
    miniyum = MiniYum(sink=miniyumsink, extraLog=extraLog)
    miniyum.selinux_role()
    # END: PROCESS-INITIALIZATION

    # we do not wish to be interrupted
    signal.signal(signal.SIGINT, signal.SIG_IGN)

    rhyum = MYum(miniyum)
    db = DB()
    ca = CA()
    DB_NAME_TEMP = "%s_%s" % (basedefs.DB_NAME, utils.getCurrentDateTime())

    # Handle pgpass
    if not os.path.exists(basedefs.DB_PASS_FILE):
        if not os.path.exists(basedefs.ORIG_PASS_FILE):
            logging.error(MSG_ERROR_PGPASS)
            print MSG_ERROR_PGPASS
            sys.exit(1)
        else:
            logging.info("Info: Found .pgpass file at old location. Moving it to a new location.")

            # Create directory if needed
            dbPassFileDirectory = os.path.dirname(basedefs.DB_PASS_FILE)
            if not os.path.exists(dbPassFileDirectory):
                os.makedirs(dbPassFileDirectory)
            shutil.copy(basedefs.ORIG_PASS_FILE, basedefs.DB_PASS_FILE)

            # File is copied/created by root, so no need to verify the owner.
            os.chmod(basedefs.DB_PASS_FILE, 0600)
    else:
        logging.info("Info: %s file found. Continue.", basedefs.DB_PASS_FILE)

    # Functions/parameters definitions
    stopEngineService = [stopEngine]
    preupgradeFunc = [preupgradeUUIDCheck]
    upgradeFunc = [rhyum.update]
    postFunc = [modifyUUIDs, ca.commit, runPost]
    engineService = basedefs.ENGINE_SERVICE_NAME
    # define db connections services
    etlService = utils.Service(basedefs.ETL_SERVICE_NAME)
    notificationService = utils.Service(basedefs.NOTIFIER_SERVICE_NAME)

    if unsupportedVersionsPresent():
        print MSG_ERROR_INCOMPATIBLE_UPGRADE
        raise Exception(MSG_ERROR_INCOMPATIBLE_UPGRADE)

    rhyum.clean()

    with rhyum.transaction():
        # Check for upgrade, else exit
        runFunc([rhyum.begin], MSG_INFO_CHECK_UPDATE)
        if rhyum.emptyTransaction:
            logging.debug(MSG_INFO_NO_UPGRADE_AVAIL)
            print MSG_INFO_NO_UPGRADE_AVAIL
            sys.exit(0)

        packages = rhyum.getPackages()
        name_packages = [p['name'] for p in packages]

        print MSG_INFO_UPGRADE_AVAIL % (len(packages))
        for p in packages:
            print " * %s" % p['display_name']
        if options.check_update:
            sys.exit(100)

        if RPM_SETUP in name_packages and not options.force_current_setup_rpm:
            logging.debug(MSG_ERROR_NEW_SETUP_AVAIL)
            print MSG_ERROR_NEW_SETUP_AVAIL
            sys.exit(3)

        # Make sure we will be able to rollback
        if not rhyum.rollbackAvailable(packages) and options.yum_rollback:
            logging.debug(MSG_ERROR_NO_ROLLBACK_AVAIL)
            print MSG_ERROR_NO_ROLLBACK_AVAIL
            print MSG_ERROR_CHECK_LOG % logFile
            sys.exit(2)

        # Update is related to database if:
        # 1. database related package is updated
        # 2. CA upgrade is going to alter parameters within database
        # 3. UUID update will take place
        updateRelatedToDB = False
        for package in RPM_BACKEND, RPM_DBSCRIPTS:
            if package in name_packages:
                updateRelatedToDB = True
                logging.debug("related to database package %s" % package)
        updateRelatedToDB = updateRelatedToDB or ca.mayUpdateDB()
        updateRelatedToDB = updateRelatedToDB or hostids

        # No rollback in this case
        try:
            # We ask the user before stoping ovirt-engine or take command line option
            if options.unattended_upgrade or checkEngine(engineService):
                # Stopping engine
                runFunc(stopEngineService, MSG_INFO_STOP_ENGINE)
                if updateRelatedToDB:
                    runFunc([[stopDbRelatedServices, etlService, notificationService]], MSG_INFO_STOP_DB)
            else:
                # This means that user chose not to stop ovirt-engine
                logging.debug("exiting gracefully")
                print MSG_INFO_STOP_INSTALL_EXIT
                sys.exit(0)

            # Preupgrade checks
            runFunc(preupgradeFunc, MSG_INFO_PREUPGRADE)

            # Backup DB
            if updateRelatedToDB:
                runFunc([db.backup], MSG_INFO_BACKUP_DB)
                runFunc([[db.rename, DB_NAME_TEMP]], MSG_INFO_RENAME_DB)

        except Exception as e:
            print e
            raise

        # In case of failure, do rollback
        try:
            # yum update
            runFunc(upgradeFunc, MSG_INFO_YUM_UPDATE)

            # check if update is relevant to db update
            if updateRelatedToDB:

                # Update the db and restore its name back
                runFunc([db.update], MSG_INFO_DB_UPDATE)
                runFunc([[db.rename, basedefs.DB_NAME]], MSG_INFO_RESTORE_DB)

                # Bring up any services we shut down before db upgrade
                startDbRelatedServices(etlService, notificationService)

            # CA restore
            runFunc([ca.prepare], MSG_INFO_PKI_PREPARE)

            # post install conf
            runFunc(postFunc, MSG_INFO_RUN_POST)

        except:
            logging.error(traceback.format_exc())
            logging.error("Rolling back update")

            print MSG_ERROR_UPGRADE
            print MSG_INFO_REASON%(sys.exc_info()[1])

            # CA restore
            runFunc([ca.rollback], MSG_INFO_PKI_ROLLBACK)

            # allow db restore
            if updateRelatedToDB:
                try:
                    runFunc([db.restore], MSG_INFO_DB_RESTORE)
                except:
                    # This Exception have already been logged, so just pass along
                    pass

            raise

        finally:
            # start engine
            runFunc([startEngine], MSG_INFO_START_ENGINE)

        # Print log location on success
        addAdditionalMessages(etlService.isServiceAvailable())
        print "\n%s\n" % MSG_INFO_UPGRADE_OK
        printMessages()
コード例 #4
0
ファイル: vds_bootstrap.py プロジェクト: oVirtorg/vdsm
def main():
    """
Usage: vds_bootstrap.py [options] <url> <subject> <random_num>

options:
    -v <bootstrap inteface version> - default 1
    -O <organizationName>
    -t <systemTime>
    -f <firewall_rules_file> -- override firewall rules.
    -V - don't install virtualization service
    -g - install gluster service
obsolete options:
    -r <rev_num>
    """
    try:
        rev_num = None
        orgName = 'Red Hat Inc.'
        systime = None
        firewallRulesFile = None
        engine_ssh_key = None
        installVirtualizationService = True
        installGlusterService = False
        bridgeName = None
        opts, args = getopt.getopt(sys.argv[1:], "v:r:O:t:f:S:n:u:B:Vg")
        for o, v in opts:
            if o == "-v":
                deployUtil.setBootstrapInterfaceVersion(int(v))
            if o == "-r":
                rev_num = v
            if o == "-O":
                orgName = v
            if o == "-t":
                systime = v
            if o == "-V":
                installVirtualizationService = False
            if o == "-g":
                installGlusterService = True
            elif o == '-f':
                firewallRulesFile = v
                NEEDED_SERVICES.append('iptables')
            elif o == '-S':
                engine_ssh_key = v
            elif o == '-B':
                bridgeName = v

        url = args[0]
        subject = args[1]
        random_num = args[2]
        # Where is REVISION defined ????
        # if not rev_num:
        #    rev_num = REVISION
    except:
        print main.__doc__
        return False

    #
    # miniyum setup must be done first as process
    # is probably going to be reexecute with
    # proper selinux role
    #
    miniyum = None
    if deployUtil.getBootstrapInterfaceVersion() >= 2:
        try:
            from miniyum import MiniYum

            miniyumsink = myminiyumsink()
            MiniYum.setup_log_hook(sink=miniyumsink)
            extraLog = open(LOGFILE, "a")
            miniyum = MiniYum(sink=miniyumsink, extraLog=extraLog)
            miniyum.selinux_role()
        except:
            logging.error("MiniYum selinux setup failed", exc_info=True)
            print "<BSTRAP component='RHEV_INSTALL' status='FAIL'/>"
            return False

    logging.debug('**** Start VDS Validation ****')
    try:
        ret = VdsValidation(url, subject, random_num, rev_num, orgName,
                            systime, firewallRulesFile, engine_ssh_key,
                            installVirtualizationService,
                            installGlusterService, bridgeName, miniyum)
    except:
        logging.error("VDS validation failed", exc_info=True)
        logging.error(main.__doc__)
        logging.debug("<BSTRAP component='RHEV_INSTALL' status='FAIL'/>")
        print "<BSTRAP component='RHEV_INSTALL' status='FAIL'/>"
        return False
    else:
        message = ("<BSTRAP component='RHEV_INSTALL' status=")
        if ret:
            message += ("'OK'/>")
        else:
            message += ("'FAIL'/>")

        print(message)
        logging.debug(message)

    logging.debug('**** End VDS Validation ****')
    sys.stdout.flush()
    return ret
コード例 #5
0
def main(options):
    # BEGIN: PROCESS-INITIALIZATION
    miniyumsink = utils.MiniYumSink()
    MiniYum.setup_log_hook(sink=miniyumsink)
    extraLog = open(logFile, "a")

    # Place getEngineVersion here or new version can't be detected
    startVersion = utils.getEngineVersion()
    logging.debug("Start version is %s ", startVersion)

    miniyum = MiniYum(sink=miniyumsink, extraLog=extraLog)
    miniyum.selinux_role()
    # END: PROCESS-INITIALIZATION

    # we do not wish to be interrupted
    signal.signal(signal.SIGINT, signal.SIG_IGN)

    rhyum = MYum(miniyum)
    db = DB()
    ca = CA()
    DB_NAME_TEMP = "%s_%s" % (basedefs.DB_NAME, utils.getCurrentDateTime())

    # Handle pgpass
    if not os.path.exists(basedefs.DB_PASS_FILE):
        if not os.path.exists(basedefs.ORIG_PASS_FILE):
            logging.error(MSG_ERROR_PGPASS)
            print MSG_ERROR_PGPASS
            sys.exit(1)
        else:
            logging.info(
                "Info: Found .pgpass file at old location. Moving it to a new location."
            )

            # Create directory if needed
            dbPassFileDirectory = os.path.dirname(basedefs.DB_PASS_FILE)
            if not os.path.exists(dbPassFileDirectory):
                os.makedirs(dbPassFileDirectory)
            shutil.copy(basedefs.ORIG_PASS_FILE, basedefs.DB_PASS_FILE)
            # Edit .pgpass
            editPgpass(basedefs.DB_PASS_FILE)

            # File is copied/created by root, so no need to verify the owner.
            os.chmod(basedefs.DB_PASS_FILE, 0600)
    else:
        logging.info("Info: %s file found. Continue.", basedefs.DB_PASS_FILE)

    # Functions/parameters definitions
    currentDbName = basedefs.DB_NAME
    stopEngineService = [stopEngine]
    startEngineService = [startEngine]
    preupgradeFunc = [preupgradeUUIDCheck]
    upgradeFunc = [rhyum.update]
    postFunc = [modifyUUIDs, ca.commit, runPost]
    engineService = basedefs.ENGINE_SERVICE_NAME
    # define db connections services
    etlService = utils.Service(basedefs.ETL_SERVICE_NAME)
    notificationService = utils.Service(basedefs.NOTIFIER_SERVICE_NAME)

    # Check for the available free space in required locations:
    # 1. DB backups location
    # 2. Yum cache location (for downloading packages)
    # 3. /usr/share location (for installing jboss and engine)
    if not options.no_space_check:
        # The second part of the map is the space required in each location for
        # the successfull upgrade.
        required_folders_map = {
            basedefs.DIR_DB_BACKUPS: basedefs.CONST_DB_SIZE,
            basedefs.DIR_YUM_CACHE: basedefs.CONST_DOWNLOAD_SIZE_MB,
            basedefs.DIR_PKGS_INSTALL: basedefs.CONST_INSTALL_SIZE_MB,
        }
        utils.checkAvailableSpace(
            required=required_folders_map,
            dbName=currentDbName,
            dbFolder=basedefs.DIR_DB_BACKUPS,
            msg=output_messages.MSG_STOP_UPGRADE_SPACE,
        )

    # Check minimal supported versions of installed components
    if unsupportedVersionsPresent(dbName=currentDbName):
        print MSG_ERROR_INCOMPATIBLE_UPGRADE
        raise Exception(MSG_ERROR_INCOMPATIBLE_UPGRADE)

    rhyum.clean()

    with rhyum.transaction():
        # Check for upgrade, else exit
        runFunc([rhyum.begin], MSG_INFO_CHECK_UPDATE)
        if rhyum.emptyTransaction:
            logging.debug(MSG_INFO_NO_UPGRADE_AVAIL)
            print MSG_INFO_NO_UPGRADE_AVAIL
            sys.exit(0)

        packages = rhyum.getPackages()
        name_packages = [p['name'] for p in packages]

        print MSG_INFO_UPGRADE_AVAIL % (len(packages))
        for p in packages:
            print " * %s" % p['display_name']
        if options.check_update:
            sys.exit(100)

        if RPM_SETUP in name_packages and not options.force_current_setup_rpm:
            logging.debug(MSG_ERROR_NEW_SETUP_AVAIL)
            print MSG_ERROR_NEW_SETUP_AVAIL
            sys.exit(3)

        # Make sure we will be able to rollback
        if not rhyum.rollbackAvailable(packages) and options.yum_rollback:
            logging.debug(MSG_ERROR_NO_ROLLBACK_AVAIL)
            print MSG_ERROR_NO_ROLLBACK_AVAIL
            print MSG_ERROR_CHECK_LOG % logFile
            sys.exit(2)

        # Update is related to database if:
        # 1. database related package is updated
        # 2. CA upgrade is going to alter parameters within database
        # 3. UUID update will take place
        updateRelatedToDB = False
        for package in RPM_BACKEND, RPM_DBSCRIPTS:
            if package in name_packages:
                updateRelatedToDB = True
                logging.debug("related to database package %s" % package)
        updateRelatedToDB = updateRelatedToDB or ca.mayUpdateDB()
        updateRelatedToDB = updateRelatedToDB or hostids

        # No rollback in this case
        try:
            # We ask the user before stoping ovirt-engine or take command line option
            if options.unattended_upgrade or checkEngine(engineService):
                # Stopping engine
                runFunc(stopEngineService,
                        MSG_INFO_STOP_ENGINE % engineService)
                if updateRelatedToDB:
                    runFunc([[
                        stopDbRelatedServices, etlService, notificationService
                    ]], MSG_INFO_STOP_DB)

                if not options.ignore_tasks:
                    # Check that there are no running tasks/compensations
                    try:
                        checkRunningTasks()
                    # If something went wrong, restart DB services and the engine
                    except:
                        runFunc([[
                            startDbRelatedServices, etlService,
                            notificationService
                        ]], MSG_INFO_START_DB)
                        runFunc(startEngineService,
                                MSG_INFO_START_ENGINE % engineService)
                        raise
            else:
                # This means that user chose not to stop ovirt-engine
                logging.debug("exiting gracefully")
                print MSG_INFO_STOP_INSTALL_EXIT
                sys.exit(0)

            # Preupgrade checks
            runFunc(preupgradeFunc, MSG_INFO_PREUPGRADE)

            # Backup DB
            if updateRelatedToDB:
                runFunc([db.backup], MSG_INFO_BACKUP_DB)
                runFunc([[db.rename, DB_NAME_TEMP]], MSG_INFO_RENAME_DB)

        except Exception as e:
            print e
            raise

        # In case of failure, do rollback
        try:
            # yum update
            runFunc(upgradeFunc, MSG_INFO_YUM_UPDATE)

            # check if update is relevant to db update
            if updateRelatedToDB:

                # Update the db and restore its name back
                runFunc([db.update], MSG_INFO_DB_UPDATE)
                runFunc([[db.rename, basedefs.DB_NAME]], MSG_INFO_RESTORE_DB)

                # Bring up any services we shut down before db upgrade
                startDbRelatedServices(etlService, notificationService)

            if startVersion.startswith("3.1"):
                runFunc([utils.updateEngineSysconfig],
                        MSG_INFO_UPDATE_ENGINE_SYSCONFIG)
                messages.append(MSG_OVIRT_ENGINE_RECREATED)

            # CA restore
            runFunc([ca.prepare], MSG_INFO_PKI_PREPARE)

            # post install conf
            runFunc(postFunc, MSG_INFO_RUN_POST)

        except:
            logging.error(traceback.format_exc())
            logging.error("Rolling back update")

            print MSG_ERROR_UPGRADE
            print MSG_INFO_REASON % (sys.exc_info()[1])

            # CA restore
            runFunc([ca.rollback], MSG_INFO_PKI_ROLLBACK)

            # allow db restore
            if updateRelatedToDB:
                try:
                    runFunc([db.restore], MSG_INFO_DB_RESTORE)
                except:
                    # This Exception have already been logged, so just pass along
                    pass

            raise

        finally:
            # start engine
            runFunc([startEngine], MSG_INFO_START_ENGINE % engineService)
            # restart httpd
            runFunc([restartHttpd], "Restarting web server")

        # Print log location on success
        addAdditionalMessages(etlService.isServiceAvailable())
        print "\n%s\n" % MSG_INFO_UPGRADE_OK
        printMessages()