Ejemplo n.º 1
0
def schedule_sync(server_id, action_id, dry_run=0):
    log_debug(3, server_id, action_id)
    if dry_run:
        raise ShadowAction("dry run requested - skipping")

    kickstart_session_id = server_kickstart.get_kickstart_session_id(server_id,
                                                                     action_id)

    if kickstart_session_id is None:
        raise InvalidAction("Could not find kickstart session ID")

    row = server_kickstart.get_kickstart_session_info(kickstart_session_id, server_id)
    deploy_configs = (row['deploy_configs'] == 'Y')

    ks_package_profile = server_kickstart.get_kisckstart_session_package_profile(kickstart_session_id)
    # if the session doesn't have a pkg profile, try from the ks profile itself
    if not ks_package_profile:
        ks_package_profile = server_kickstart.get_kickstart_profile_package_profile(kickstart_session_id)

    if not ks_package_profile:
        log_debug(4, "No kickstart package profile")
        # No profile to bring this system to
        if deploy_configs:
            # We have to deploy configs, so pass in a server profile
            server_profile = server_kickstart.get_server_package_profile(server_id)
        else:
            # No configs to be deployed
            server_profile = None

        server_kickstart.schedule_config_deploy(server_id,
                                                action_id, kickstart_session_id, server_profile=server_profile)
        raise ShadowAction("Package sync not scheduled, missing kickstart "
                           "package profile; proceeding with configfiles.deploy")

    server_profile = server_kickstart.get_server_package_profile(server_id)

    installs, removes = server_packages.package_delta(server_profile,
                                                      ks_package_profile)

    if not (installs or removes):
        log_debug(4, "No packages to be installed/removed")
        if not deploy_configs:
            server_profile = None

        server_kickstart.schedule_config_deploy(server_id,
                                                action_id, kickstart_session_id, server_profile=None)
        raise ShadowAction("Package sync not scheduled, nothing to do")

    log_debug(4, "Scheduling kickstart delta")
    server_kickstart.schedule_kickstart_delta(server_id,
                                              kickstart_session_id, installs, removes)

    raise ShadowAction("Package sync scheduled")
list1 = [
    abiword2,
    abiword1,
    kernel2,
    kernel1,
    aalib2,
    quota,
    rpm,
    perl1,
]

list2 = [
    unzip1,
    unzip2,
    kernel3,
    aalib1,
    rpm,
    perl2,
]

i, r = server_packages.package_delta(list1, list2)
print("Install set:  ", i)
print("Remove set:   ", r)

assert i == [aalib1, kernel3, unzip1, unzip2], "Invalid install set %s" % i
assert r == [aalib2, abiword1, abiword2, kernel1, kernel2,
             quota], "Invalid remove set %s" % r

print("All assertions passed")
Ejemplo n.º 3
0
def schedule_sync(server_id, action_id, dry_run=0):
    log_debug(3, server_id, action_id)
    if dry_run:
        raise ShadowAction("dry run requested - skipping")

    kickstart_session_id = server_kickstart.get_kickstart_session_id(
        server_id, action_id)

    if kickstart_session_id is None:
        raise InvalidAction("Could not find kickstart session ID")

    row = server_kickstart.get_kickstart_session_info(kickstart_session_id,
                                                      server_id)
    deploy_configs = (row['deploy_configs'] == 'Y')

    ks_package_profile = server_kickstart.get_kisckstart_session_package_profile(
        kickstart_session_id)
    # if the session doesn't have a pkg profile, try from the ks profile itself
    if not ks_package_profile:
        ks_package_profile = server_kickstart.get_kickstart_profile_package_profile(
            kickstart_session_id)

    if not ks_package_profile:
        log_debug(4, "No kickstart package profile")
        # No profile to bring this system to
        if deploy_configs:
            # We have to deploy configs, so pass in a server profile
            server_profile = server_kickstart.get_server_package_profile(
                server_id)
        else:
            # No configs to be deployed
            server_profile = None

        server_kickstart.schedule_config_deploy(server_id,
                                                action_id,
                                                kickstart_session_id,
                                                server_profile=server_profile)
        raise ShadowAction(
            "Package sync not scheduled, missing kickstart "
            "package profile; proceeding with configfiles.deploy")

    server_profile = server_kickstart.get_server_package_profile(server_id)

    installs, removes = server_packages.package_delta(server_profile,
                                                      ks_package_profile)

    if not (installs or removes):
        log_debug(4, "No packages to be installed/removed")
        if not deploy_configs:
            server_profile = None

        server_kickstart.schedule_config_deploy(server_id,
                                                action_id,
                                                kickstart_session_id,
                                                server_profile=None)
        raise ShadowAction("Package sync not scheduled, nothing to do")

    log_debug(4, "Scheduling kickstart delta")
    server_kickstart.schedule_kickstart_delta(server_id, kickstart_session_id,
                                              installs, removes)

    raise ShadowAction("Package sync scheduled")
list1 = [
    abiword2,
    abiword1,
    kernel2,
    kernel1,
    aalib2,
    quota,
    rpm,
    perl1,
]

list2 = [
    unzip1,
    unzip2,
    kernel3,
    aalib1,
    rpm,
    perl2,
]

i, r = server_packages.package_delta(list1, list2)
print "Install set:  ", i
print "Remove set:   ", r

assert i == [ aalib1, kernel3, unzip1, unzip2 ], "Invalid install set %s" % i
assert r == [ aalib2, abiword1, abiword2, kernel1, kernel2, quota ], "Invalid remove set %s" % r

print "All assertions passed"