How to use the nornir.core.deserializer.inventory.Inventory.deserialize function in nornir

To help you get started, we’ve selected a few nornir examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nornir-automation / nornir / tests / core / test_inventory.py View on Github external
def test_to_dict(self):
        inv = deserializer.Inventory.deserialize(**inv_dict)
        inv_serialized = deserializer.Inventory.serialize(inv).dict()
        for k, v in inv_dict.items():
            assert v == inv_serialized[k]
github nornir-automation / nornir / tests / core / test_inventory.py View on Github external
def test_attributes_resolution(self):
        inv = deserializer.Inventory.deserialize(**inv_dict)
        assert inv.hosts["dev1.group_1"].password == "a_password"
        assert inv.hosts["dev2.group_1"].password == "from_group1"
        assert inv.hosts["dev3.group_2"].password == "docker"
        assert inv.hosts["dev4.group_2"].password == "from_parent_group"
        assert inv.hosts["dev5.no_group"].password == "docker"
github nornir-automation / nornir / tests / core / test_inventory.py View on Github external
def test_filtering(self):
        inv = deserializer.Inventory.deserialize(**inv_dict)
        unfiltered = sorted(list(inv.hosts.keys()))
        assert unfiltered == [
            "dev1.group_1",
            "dev2.group_1",
            "dev3.group_2",
            "dev4.group_2",
            "dev5.no_group",
        ]

        www = sorted(list(inv.filter(role="www").hosts.keys()))
        assert www == ["dev1.group_1", "dev3.group_2"]

        www_site1 = sorted(list(inv.filter(role="www", site="site1").hosts.keys()))
        assert www_site1 == ["dev1.group_1"]

        www_site1 = sorted(
github nornir-automation / nornir / tests / core / test_inventory.py View on Github external
def test_has_parents(self):
        inv = deserializer.Inventory.deserialize(**inv_dict)
        assert inv.hosts["dev1.group_1"].has_parent_group(inv.groups["group_1"])
        assert not inv.hosts["dev1.group_1"].has_parent_group(inv.groups["group_2"])
        assert inv.hosts["dev1.group_1"].has_parent_group("group_1")
        assert not inv.hosts["dev1.group_1"].has_parent_group("group_2")
github nornir-automation / nornir / tests / core / test_inventory.py View on Github external
def test_get_groups_dict(self):
        inv = deserializer.Inventory.deserialize(**inv_dict)
        groups_dict = inv.get_groups_dict()
        assert type(groups_dict) == dict
        assert groups_dict["group_1"]["password"] == "from_group1"
        assert groups_dict["group_2"]["data"]["site"] == "site2"
github nornir-automation / nornir / tests / core / test_inventory.py View on Github external
def test_get_defaults_dict(self):
        inv = deserializer.Inventory.deserialize(**inv_dict)
        defaults_dict = inv.get_defaults_dict()
        con_options = defaults_dict["connection_options"]["dummy"]
        assert type(defaults_dict) == dict
        assert defaults_dict["username"] == "root"
        assert con_options["hostname"] == "dummy_from_defaults"
        assert "blah" in con_options["extras"]
github nornir-automation / nornir / tests / core / test_inventory.py View on Github external
def test_filter_unique_keys(self):
        inv = deserializer.Inventory.deserialize(**inv_dict)
        filtered = sorted(list(inv.filter(www_server="nginx").hosts.keys()))
        assert filtered == ["dev1.group_1"]
github nornir-automation / nornir / tests / core / test_inventory.py View on Github external
def test_children_of_str(self):
        inv = deserializer.Inventory.deserialize(**inv_dict)
        assert inv.children_of_group("parent_group") == {
            inv.hosts["dev1.group_1"],
            inv.hosts["dev2.group_1"],
            inv.hosts["dev4.group_2"],
        }

        assert inv.children_of_group("group_1") == {
            inv.hosts["dev1.group_1"],
            inv.hosts["dev2.group_1"],
        }

        assert inv.children_of_group("group_2") == {
            inv.hosts["dev4.group_2"],
            inv.hosts["dev3.group_2"],
        }
github nornir-automation / nornir / tests / core / test_inventory.py View on Github external
def test_inventory_deserializer(self):
        inv = deserializer.Inventory.deserialize(**inv_dict)
        assert inv.groups["group_1"] in inv.hosts["dev1.group_1"].groups