def test_groups(mock_driver):
    inventory = NodeInventory(driver=mock_driver,
                              restrict_to_groups={
                                  "TEST1": ["198.168.1.1"],
                                  "TEST2": ["198.168.1.1", "198.168.2.1"],
                              })
    inventory.sync()
    assert inventory.get_groups() == ["TEST1", "TEST2"]
def test_find(nodes, mock_driver, query, expected_indices):
    inventory = NodeInventory(driver=mock_driver,
                              restrict_to_groups={
                                  "TEST1": ["198.168.1.1"],
                                  "TEST2": ["198.168.1.1", "198.168.2.1"],
                              })
    inventory.sync()
    assert list(
        inventory.find_nodes(query)) == [nodes[x] for x in expected_indices]
def test_sync(nodes, mock_driver):
    inventory = NodeInventory(driver=mock_driver,
                              restrict_to_groups={
                                  "TEST1": ["198.168.1.1"],
                                  "TEST2": ["198.168.1.1", "198.168.2.1"],
                              })
    inventory.sync()
    assert inventory.groups == {"TEST1": nodes[0:1], "TEST2": nodes[0:2]}
    assert inventory.get_azs() == ["AZ1", "AZ2"]
def test_get_by_ip(nodes, mock_driver, ip, should_find, index):
    inventory = NodeInventory(driver=mock_driver,
                              restrict_to_groups={
                                  "TEST1": ["198.168.1.1"],
                                  "TEST2": ["198.168.1.1", "198.168.2.1"],
                              })
    inventory.sync()
    if should_find:
        assert inventory.get_node_by_ip(ip) is nodes[index]
    else:
        assert inventory.get_node_by_ip(ip) == None