Exemplo n.º 1
0
def InitNornsible(nr: Nornir) -> Nornir:
    """
    Patch nornir object based on cli arguments

    Arguments:
        nr: Nornir object

    Returns:
        nr: Nornir object; modified if cli args dictate the need to do so; otherwise passed as is

    Raises:
        N/A  # noqa

    """
    cli_args = parse_cli_args(sys.argv[1:])

    nr.run_tags = cli_args.pop("run_tags")
    nr.skip_tags = cli_args.pop("skip_tags")

    if any(a for a in cli_args.values()):
        nr.config = patch_config(cli_args, nr.config)
        nr.inventory = patch_inventory(cli_args, nr.inventory)

    if not cli_args["disable_delegate"]:
        nr.inventory = patch_inventory_delegate(nr.inventory)

    return nr
Exemplo n.º 2
0
def test_parse_cli_args_basic_none():
    args = ["somethingelse", "notrelevant"]
    args = parse_cli_args(args)
    assert args["limit"] is False
    assert args["groups"] is False
    assert args["skip_tags"] == []
    assert args["run_tags"] == []
    assert args["workers"] is False
Exemplo n.º 3
0
def test_patch_inventory_limit_host_ignore_case():
    args = ["-l", "UPPER-HOST"]
    args = parse_cli_args(args)
    nr = InitNornir(
        inventory={
            "plugin": "nornir.plugins.inventory.simple.SimpleInventory",
            "options": {
                "host_file":
                f"{TEST_DIR}_test_nornir_inventory/basic/hosts.yaml",
                "group_file":
                f"{TEST_DIR}_test_nornir_inventory/basic/groups.yaml",
            },
        },
        logging={"enabled": False},
    )
    nr.inventory = patch_inventory(args, nr.inventory)
    assert set(nr.inventory.hosts.keys()) == {"UPPER-HOST"}
Exemplo n.º 4
0
def test_patch_config_basic_limit_workers():
    args = ["-w", "10"]
    args = parse_cli_args(args)
    nr = InitNornir(
        inventory={
            "plugin": "nornir.plugins.inventory.simple.SimpleInventory",
            "options": {
                "host_file":
                f"{TEST_DIR}_test_nornir_inventory/basic/hosts.yaml",
                "group_file":
                f"{TEST_DIR}_test_nornir_inventory/basic/groups.yaml",
            },
        },
        logging={"enabled": False},
    )
    nr.config = patch_config(args, nr.config)
    assert nr.config.core.num_workers == 10
Exemplo n.º 5
0
def test_parse_cli_args_basic_short():
    args = [
        "-l",
        "sea-eos-1",
        "-g",
        "sea",
        "-s",
        "deploy_configs",
        "-t",
        "render_configs",
        "-w",
        "10",
    ]
    args = parse_cli_args(args)
    assert args["limit"] == {"sea-eos-1"}
    assert args["groups"] == {"sea"}
    assert args["skip_tags"] == {"deploy_configs"}
    assert args["run_tags"] == {"render_configs"}
    assert args["workers"] == 10
Exemplo n.º 6
0
def test_parse_cli_args_basic_long():
    args = [
        "--limit",
        "sea-eos-1",
        "--groups",
        "sea",
        "--skip",
        "deploy_configs",
        "--tags",
        "render_configs",
        "--workers",
        "10",
        "--disable-delegate",
    ]
    args = parse_cli_args(args)
    assert args["limit"] == {"sea-eos-1"}
    assert args["groups"] == {"sea"}
    assert args["skip_tags"] == {"deploy_configs"}
    assert args["run_tags"] == {"render_configs"}
    assert args["workers"] == 10