Ejemplo n.º 1
0
def test_compile_values():
    inv = InventoryModule()
    found_value = instances['Instances'][0]
    chain_of_keys = instance_data_filter_to_boto_attr['instance.group-id']
    for attr in chain_of_keys:
        found_value = inv._compile_values(found_value, attr)
    assert found_value == "sg-12345678"
Ejemplo n.º 2
0
def test_set_credentials(monkeypatch):
    inv = InventoryModule()
    inv._options = {'aws_access_key_id': 'test_access_key',
                    'aws_secret_access_key': 'test_secret_key',
                    'aws_security_token': 'test_security_token',
                    'boto_profile': 'test_profile'}
    inv._set_credentials()

    assert inv.boto_profile == "test_profile"
    assert inv.aws_access_key_id == "test_access_key"
    assert inv.aws_secret_access_key == "test_secret_key"
    assert inv.aws_security_token == "test_security_token"
Ejemplo n.º 3
0
def test_boto3_conn():
    inv = InventoryModule()
    inv._options = {"boto_profile": "first_precedence",
                    "aws_access_key_id": "test_access_key",
                    "aws_secret_access_key": "test_secret_key",
                    "aws_security_token": "test_security_token"}
    inv._set_credentials()
    with pytest.raises(AnsibleError) as error_message:
        for connection, region in inv._boto3_conn(regions=['us-east-1']):
            assert error_message == "Insufficient credentials found."
Ejemplo n.º 4
0
def test_insufficient_credentials(monkeypatch):
    inv = InventoryModule()
    with pytest.raises(AnsibleError) as error_message:
        inv._set_credentials()
        assert "Insufficient boto credentials found" in error_message
Ejemplo n.º 5
0
def test_get_hostname():
    hostnames = ['ip-address', 'dns-name']
    inv = InventoryModule()
    instance = instances['Instances'][0]
    assert inv._get_hostname(instance, hostnames) == "12.345.67.890"
Ejemplo n.º 6
0
def test_get_hostname_default():
    inv = InventoryModule()
    instance = instances['Instances'][0]
    assert inv._get_hostname(instance, hostnames=None) == "ec2-12-345-67-890.compute-1.amazonaws.com"
Ejemplo n.º 7
0
def test_get_boto_attr_chain():
    inv = InventoryModule()
    instance = instances['Instances'][0]
    assert inv._get_boto_attr_chain('network-interface.addresses.private-ip-address', instance) == "098.76.54.321"
Ejemplo n.º 8
0
def inventory():
    return InventoryModule()