コード例 #1
0
ファイル: dc_checkpoint.py プロジェクト: tsoome/slim_source
def add_finalizer_scripts(cp, manifest_server_obj, finalizer_obj):
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    """Check to see if the finalizer script should be executed. It should only
    be executed if 1) checkpointing is available/on and 2) the steps to
    pause or resume at don't exclude it.

    Input:
            manifest_server_obj - Manifest server object
            finalizer_obj - finalizer object
    Returns:
            SUCCESS - no error
            GENERAL_ERR - unable to register one or more finalizer script

    """

    dc_log = logging.getLogger(DC_LOGGER_NAME)

    # assume no error, if there's an error, this will be set to 1
    ret = SUCCESS

    finalizer_script_list = get_manifest_list(manifest_server_obj,
                                              FINALIZER_SCRIPT_NAME)

    resumestep = cp.get_resume_step()
    pausestep = cp.get_pause_step()
    stop_on_err = get_manifest_boolean(manifest_server_obj,
                                       STOP_ON_ERR)
    if stop_on_err is None:
        # this should never happen, since default module should have
        # taken care of filling in the default value of true
        stop_on_err = 1

    for script in finalizer_script_list:
        if not script:
            continue

        if not cp.get_checkpointing_avail():
            # Queue up the finalizer script and return
            if (queue_up_finalizer_script(cp, finalizer_obj,
                                          manifest_server_obj,
                                          script)):
                dc_log.error("Failed to register finalizer " \
                             "script: " + script)
                if (stop_on_err):
                    return GENERAL_ERR
                else:
                    ret = GENERAL_ERR
            continue

        currentstep = cp.get_current_step()
        if currentstep == pausestep:
            # Pause after checkpointing. This means we queue up the
            # checkpoint script but not the finalizer script.
            if (queue_up_checkpoint_script(cp, finalizer_obj)):
                dc_log.error("Failed to register checkpoint " \
                             "script with finalizer module")
                if (stop_on_err):
                    return GENERAL_ERR
                else:
                    ret = GENERAL_ERR
            return (ret)
        if currentstep > resumestep:
            # We're past the resume step and we have checkpointing,
            # so register the checkpointing script and the finalizer
            # script.
            if (queue_up_checkpoint_script(cp, finalizer_obj)):
                dc_log.error("Failed to register checkpoint " \
                             "script with finalizer module")
                if (stop_on_err):
                    return GENERAL_ERR
                else:
                    ret = GENERAL_ERR
            if (queue_up_finalizer_script(cp, finalizer_obj,
                                          manifest_server_obj,
                                          script)):
                dc_log.error("Failed to register finalizer " \
                             "script: " + script)
                if (stop_on_err):
                    return GENERAL_ERR
                else:
                    ret = GENERAL_ERR
            continue
        elif currentstep == resumestep:
            # At the specified step to resume from.
            # Register the rollback script and the finalizer script.
            if (queue_up_rollback_script(cp, finalizer_obj)):
                dc_log.error("Failed to register rollback " \
                             "script with finalizer module")
                if (stop_on_err):
                    return GENERAL_ERR
                else:
                    ret = GENERAL_ERR
            if (queue_up_finalizer_script(cp, finalizer_obj,
                                          manifest_server_obj,
                                          script)):
                dc_log.error("Failed to register finalizer " \
                             "script: " + script)
                if (stop_on_err):
                    return GENERAL_ERR
                else:
                    ret = GENERAL_ERR
            continue
        else:
            # We're not yet to the specified resume step so
            # increment our step counter and continue on.
            cp.incr_current_step()
            continue

    return (ret)
コード例 #2
0
    if (len(sys.argv) != 6):  # Don't forget sys.argv[0] is the script itself.
        raise Exception, (sys.argv[0] + ": Requires 5 args:\n" +
                          "    Reader socket, pkg_image area, temp dir,\n" +
                          "    boot archive build area, media area.")

    # collect input arguments from what this script sees as a commandline.
    mfest_socket = sys.argv[1]  # Manifest reader socket
    pkg_img_path = sys.argv[2]  # package image area mountpoint

    # get the manifest reader object from the socket
    manifest_reader_obj = ManifestRead(mfest_socket)

    # Get the password for the root user from the manifest
    root_passwd_text = get_manifest_value(manifest_reader_obj, ROOT_PASSWD)
    is_plaintext = get_manifest_boolean(manifest_reader_obj,
                                        ROOT_PASSWD_PLAINTEXT)

    print "root_passwd_text = " + root_passwd_text
    print "is_plaintext = " + str(is_plaintext)

    if is_plaintext:
        encrypted_root_passwd = encrypt_password(root_passwd_text,
                                                 alt_root=pkg_img_path)
    else:
        encrypted_root_passwd = root_passwd_text

    print "Encrypted root password: "******"root")
コード例 #3
0
def main_func():
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    """Main processing function for the Distribution Constructor. Will set
    up the checkpoints, create the build area, start the socket server to
    read the manifest file, create the finalizer script queue and then
    start the execution of the finalizer scripts. 

    """

    dc_log = logging.getLogger(DC_LOGGER_NAME)

    # Must be root to run DC. Check for that.
    if os.getuid() != 0:
        dc_log.error("You must be root to run distro_const")
        return 1

    # Sets the umask for the DC app
    os.umask(022)

    cp = dc_ckp.Checkpoints()

    try:
        # Create the object used to extract the data
        manifest_server_obj = get_manifest_server_obj(cp)
    except UsageError:
        raise
    except:
        return 1

    try:
        # Start the socket server
        start_manifest_server(manifest_server_obj)

        # Set up to shut down socket server cleanly on exit
        atexit.register(manifest_server_obj.stop_socket_server)
    except ManifestServError:
        return 1

    # create the build area and determine if
    # checkpointing is available. When creating the
    # build area we also create the areas for the
    # package image (pkg_image), output media (media),
    # logfiles (logs) and boot archive (boot_archive).
    if ti.create_build_area(cp, manifest_server_obj):
        return 1

    # Set up the structures for all checkpoints
    if cp.get_checkpointing_avail() == True:
        if dc_ckp.checkpoint_setup(cp, manifest_server_obj):
            return 1

    # Parse the command line so we know to resume (and where) or not
    ret = parse_command_line(cp, manifest_server_obj)
    if ret == 1:
             # Don't continue processing. Return but nothing is wrong.
        return 0
    if ret == -1:
             # Error parsing the command line. Return indicating such.
        return 1

    # The build is going to start, will start logging
    (simple_log_name, detail_log_name) = \
        dcu.setup_dc_logfile_names(cp.get_build_area_mntpt() + LOGS)
    dc_log.info("Simple Log: " + simple_log_name)
    dc_log.info("Detail Log: " + detail_log_name)
    dcu.add_file_logging(simple_log_name, detail_log_name)

    dc_log.info("Build started " + time.asctime(time.localtime()))
    dc_log.info("Distribution name: " +
        (dcu.get_manifest_value(manifest_server_obj, DISTRO_NAME)))
    dataset = cp.get_build_area_dataset()
    if dataset is not None:
        dc_log.info("Build Area dataset: " + dataset)
    dc_log.info("Build Area mount point: " + cp.get_build_area_mntpt())

    # If we're doing a build that is a -r or -R build, then
    # we don't need to cleanup.
    if cp.get_resume_step() == -1:
        # Cleanup the pkg_image area via either a remove of the files
        # if there is not checkpointing or rolling back to the @empty
        # snapshot if there is checkpointing.
        if cleanup_build_data_area(cp) != 0:
            dc_log.info("Build completed " + time.asctime(time.localtime()))
            dc_log.info("Build failed.")
            return 1

    stop_on_err_bool = dcu.get_manifest_boolean(manifest_server_obj,
                                                STOP_ON_ERR)

    # register the scripts with the finalizer
    build_area = cp.get_build_area_mntpt()
    pkg_img_area = build_area + PKG_IMAGE
    tmp_area = build_area + TMP
    ba_build_area = build_area + BOOT_ARCHIVE
    media_dir = build_area + MEDIA

    finalizer_obj = DCFinalizer([manifest_server_obj.get_sockname(),
                                 pkg_img_area, tmp_area, ba_build_area,
                                 media_dir])
    if (finalizer_obj.change_exec_params(stop_on_err=stop_on_err_bool,
                                         logger_name = DC_LOGGER_NAME) != 0):
        dc_log.error("Unable to set stop on error or logger name "
                     "for finalizer")

    status = dc_ckp.add_finalizer_scripts(cp, manifest_server_obj,
                                          finalizer_obj)
    if (status != SUCCESS):
        dc_log.info("Build completed " + time.asctime(time.localtime()))
        dc_log.info("Build failed.")
        return (status)

    # Execute the finalizer scripts
    status = finalizer_obj.execute()
    dc_log.info("Build completed " + time.asctime(time.localtime()))
    if (status != 0):
        dc_log.info("Build failed.")
    else:
        dc_log.info("Build is successful.")

    return (status)