Exemplo n.º 1
0
def install_bundle(args):
    """
    "Installs" a bundle (validates it and stores a copy).

    "Bundles" are just JSON problem unlock weightmaps which are exposed to
    and used by the web server.

    All problems specified in a bundle must already be installed.
    """
    if not args.bundle_path:
        logger.error("No problem source path specified")
        raise FatalException
    bundle_path = args.bundle_path
    bundle_obj = get_bundle(bundle_path)

    if os.path.isdir(join(BUNDLE_ROOT, sanitize_name(bundle_obj["name"]))):
        logger.error(
            f"A bundle with name {bundle_obj['name']} is " + "already installed"
        )
        raise FatalException

    for problem_name, info in bundle_obj["dependencies"].items():
        if not os.path.isdir(join(PROBLEM_ROOT, problem_name)):
            logger.error(
                f"Problem {problem_name} must be installed "
                + "before installing bundle"
            )
            raise FatalException
        for dependency_name in info["weightmap"]:
            if not os.path.isdir(join(PROBLEM_ROOT, dependency_name)):
                logger.error(
                    f"Problem {dependency_name} must be installed "
                    + "before installing bundle"
                )
                raise FatalException

    bundle_destination = join(
        BUNDLE_ROOT, sanitize_name(bundle_obj["name"]), "bundle.json"
    )
    os.makedirs(os.path.dirname(bundle_destination), exist_ok=True)
    shutil.copy(bundle_path, bundle_destination)
    logger.info(f"Installed bundle {bundle_obj['name']}")
Exemplo n.º 2
0
def uninstall_problem(problem_name):
    """
    Uninstalls a given problem, which means that the generated debian package
    and source files within the SHARED_ROOT directory are removed.

    An uninstalled problem will no longer appear when listing problems, even
    if deployed instances remain (undeploying all instances of a problem
    before uninstallation is recommended.)

    Additionally, any assigned instance ports for the problem will be
    removed from the port map.
    """
    acquire_lock()

    try:
        # Remove .deb package used to install dependencies on deployment
        os.remove(join(DEB_ROOT, problem_name + '.deb'))

        # Remove problem source used for templating instances
        shutil.rmtree(join(PROBLEM_ROOT, problem_name))

        # Remove any ports assigned to this problem from the port map
        port_map_path = join(SHARED_ROOT, 'port_map.json')
        with open(port_map_path, 'r') as f:
            port_map = json.load(f)
            port_map = {literal_eval(k): v for k, v in port_map.items()}

        port_map = {k: v for k, v in port_map.items() if k[0] != problem_name}

        with open(port_map_path, 'w') as f:
            stringified_port_map = {repr(k): v for k, v in port_map.items()}
            json.dump(stringified_port_map, f)

    except Exception as e:
        logger.error(f"An error occurred while uninstalling {problem_name}:")
        logger.error(f'{str(e)}')
        raise FatalException

    logger.info(f"{problem_name} removed successfully")
    release_lock()
Exemplo n.º 3
0
def uninstall_bundle(args):
    """
    Uninstall a bundle by deleting it from the shell servers.

    Problems referenced within the bundle are not affected.
    """
    if not args.bundle_name:
        logger.error("No bundle name specified")
        raise FatalException
    bundle_name = args.bundle_name

    bundle_dir = join(BUNDLE_ROOT, sanitize_name(bundle_name))
    if not os.path.isdir(bundle_dir):
        logger.error(f"Bundle '{bundle_name}' is not installed")
    else:
        shutil.rmtree(bundle_dir)
        logger.info(f"Bundle '{bundle_name}' successfully removed")