예제 #1
0
def test_inventory_property_handles_missing_groups(temp_dir, _instance):
    platforms = [{'name': 'instance-1'}, {'name': 'instance-2'}]
    _instance._config.config['platforms'] = platforms

    x = {
        'ungrouped': {
            'hosts': {
                'instance-1': {'foo': 'bar', 'ansible_connection': 'docker'},
                'instance-2': {'foo': 'bar', 'ansible_connection': 'docker'},
            },
            'vars': {},
        },
        'all': {
            'hosts': {
                'instance-1': {'foo': 'bar', 'ansible_connection': 'docker'},
                'instance-2': {'foo': 'bar', 'ansible_connection': 'docker'},
            },
            'vars': {
                'molecule_file': "{{ lookup('env', 'MOLECULE_FILE') }}",
                'molecule_ephemeral_directory': "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}",
                'molecule_scenario_directory': "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}",
                'molecule_yml': "{{ lookup('file', molecule_file) | molecule_from_yaml }}",
                'molecule_instance_config': "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}",
                'molecule_no_log': "{{ lookup('env', 'MOLECULE_NO_LOG') or not "
                "molecule_yml.provisioner.log|default(False) | bool }}",
            },
        },
    }

    assert is_subset(x, _instance.inventory)
예제 #2
0
def test_inventory_property_handles_missing_groups(temp_dir, _instance):
    platforms = [{"name": "instance-1"}, {"name": "instance-2"}]
    _instance._config.config["platforms"] = platforms

    x = {
        "ungrouped": {
            "hosts": {
                "instance-1": {
                    "foo": "bar",
                    "ansible_connection": "docker"
                },
                "instance-2": {
                    "foo": "bar",
                    "ansible_connection": "docker"
                },
            },
            "vars": {},
        },
        "all": {
            "hosts": {
                "instance-1": {
                    "foo": "bar",
                    "ansible_connection": "docker"
                },
                "instance-2": {
                    "foo": "bar",
                    "ansible_connection": "docker"
                },
            },
            "vars": {
                "molecule_file":
                "{{ lookup('env', 'MOLECULE_FILE') }}",
                "molecule_ephemeral_directory":
                "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}",
                "molecule_scenario_directory":
                "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}",
                "molecule_yml":
                "{{ lookup('file', molecule_file) | molecule_from_yaml }}",
                "molecule_instance_config":
                "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}",
                "molecule_no_log":
                "{{ lookup('env', 'MOLECULE_NO_LOG') or not "
                "molecule_yml.provisioner.log|default(False) | bool }}",
            },
        },
    }

    assert is_subset(x, _instance.inventory)
예제 #3
0
def test_write_inventory(temp_dir, _instance):
    _instance._write_inventory()

    assert os.path.isfile(_instance.inventory_file)

    data = util.safe_load_file(_instance.inventory_file)

    x = {
        "ungrouped": {
            "vars": {}
        },
        "bar": {
            "hosts": {
                "instance-1": {
                    "foo": "bar",
                    "ansible_connection": "docker"
                }
            },
            "children": {
                "child1": {
                    "hosts": {
                        "instance-1": {
                            "foo": "bar",
                            "ansible_connection": "docker"
                        }
                    }
                }
            },
            "vars": {
                "molecule_file":
                "{{ lookup('env', 'MOLECULE_FILE') }}",
                "molecule_ephemeral_directory":
                "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}",
                "molecule_scenario_directory":
                "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}",
                "molecule_yml":
                "{{ lookup('file', molecule_file) | molecule_from_yaml }}",
                "molecule_instance_config":
                "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}",
                "molecule_no_log":
                "{{ lookup('env', 'MOLECULE_NO_LOG') or not "
                "molecule_yml.provisioner.log|default(False) | bool }}",
            },
        },
        "all": {
            "hosts": {
                "instance-1": {
                    "foo": "bar",
                    "ansible_connection": "docker"
                },
                "instance-2": {
                    "foo": "bar",
                    "ansible_connection": "docker"
                },
            },
            "vars": {
                "molecule_file":
                "{{ lookup('env', 'MOLECULE_FILE') }}",
                "molecule_ephemeral_directory":
                "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}",
                "molecule_scenario_directory":
                "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}",
                "molecule_yml":
                "{{ lookup('file', molecule_file) | molecule_from_yaml }}",
                "molecule_instance_config":
                "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}",
                "molecule_no_log":
                "{{ lookup('env', 'MOLECULE_NO_LOG') or not "
                "molecule_yml.provisioner.log|default(False) | bool }}",
            },
        },
        "foo": {
            "hosts": {
                "instance-1": {
                    "foo": "bar",
                    "ansible_connection": "docker"
                },
                "instance-2": {
                    "foo": "bar",
                    "ansible_connection": "docker"
                },
            },
            "children": {
                "child1": {
                    "hosts": {
                        "instance-1": {
                            "foo": "bar",
                            "ansible_connection": "docker"
                        }
                    }
                },
                "child2": {
                    "hosts": {
                        "instance-2": {
                            "foo": "bar",
                            "ansible_connection": "docker"
                        }
                    }
                },
            },
            "vars": {
                "molecule_file":
                "{{ lookup('env', 'MOLECULE_FILE') }}",
                "molecule_ephemeral_directory":
                "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}",
                "molecule_scenario_directory":
                "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}",
                "molecule_yml":
                "{{ lookup('file', molecule_file) | molecule_from_yaml }}",
                "molecule_instance_config":
                "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}",
                "molecule_no_log":
                "{{ lookup('env', 'MOLECULE_NO_LOG') or not "
                "molecule_yml.provisioner.log|default(False) | bool }}",
            },
        },
        "baz": {
            "hosts": {
                "instance-2": {
                    "foo": "bar",
                    "ansible_connection": "docker"
                }
            },
            "children": {
                "child2": {
                    "hosts": {
                        "instance-2": {
                            "foo": "bar",
                            "ansible_connection": "docker"
                        }
                    }
                }
            },
            "vars": {
                "molecule_file":
                "{{ lookup('env', 'MOLECULE_FILE') }}",
                "molecule_ephemeral_directory":
                "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}",
                "molecule_scenario_directory":
                "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}",
                "molecule_yml":
                "{{ lookup('file', molecule_file) | molecule_from_yaml }}",
                "molecule_instance_config":
                "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}",
                "molecule_no_log":
                "{{ lookup('env', 'MOLECULE_NO_LOG') or not "
                "molecule_yml.provisioner.log|default(False) | bool }}",
            },
        },
    }

    assert is_subset(x, data)
예제 #4
0
def test_connection_options(_instance):
    x = {"ansible_connection": "docker", "foo": "bar"}

    assert is_subset(x, _instance.connection_options("foo"))
예제 #5
0
def test_write_inventory(temp_dir, _instance):
    _instance._write_inventory()

    assert os.path.isfile(_instance.inventory_file)

    data = util.safe_load_file(_instance.inventory_file)

    x = {
        'ungrouped': {
            'vars': {}
        },
        'bar': {
            'hosts': {
                'instance-1': {
                    'foo': 'bar',
                    'ansible_connection': 'docker'
                }
            },
            'children': {
                'child1': {
                    'hosts': {
                        'instance-1': {
                            'foo': 'bar',
                            'ansible_connection': 'docker'
                        }
                    }
                }
            },
            'vars': {
                'molecule_file':
                "{{ lookup('env', 'MOLECULE_FILE') }}",
                'molecule_ephemeral_directory':
                "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}",
                'molecule_scenario_directory':
                "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}",
                'molecule_yml':
                "{{ lookup('file', molecule_file) | molecule_from_yaml }}",
                'molecule_instance_config':
                "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}",
                'molecule_no_log':
                "{{ lookup('env', 'MOLECULE_NO_LOG') or not "
                "molecule_yml.provisioner.log|default(False) | bool }}",
            },
        },
        'all': {
            'hosts': {
                'instance-1': {
                    'foo': 'bar',
                    'ansible_connection': 'docker'
                },
                'instance-2': {
                    'foo': 'bar',
                    'ansible_connection': 'docker'
                },
            },
            'vars': {
                'molecule_file':
                "{{ lookup('env', 'MOLECULE_FILE') }}",
                'molecule_ephemeral_directory':
                "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}",
                'molecule_scenario_directory':
                "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}",
                'molecule_yml':
                "{{ lookup('file', molecule_file) | molecule_from_yaml }}",
                'molecule_instance_config':
                "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}",
                'molecule_no_log':
                "{{ lookup('env', 'MOLECULE_NO_LOG') or not "
                "molecule_yml.provisioner.log|default(False) | bool }}",
            },
        },
        'foo': {
            'hosts': {
                'instance-1': {
                    'foo': 'bar',
                    'ansible_connection': 'docker'
                },
                'instance-2': {
                    'foo': 'bar',
                    'ansible_connection': 'docker'
                },
            },
            'children': {
                'child1': {
                    'hosts': {
                        'instance-1': {
                            'foo': 'bar',
                            'ansible_connection': 'docker'
                        }
                    }
                },
                'child2': {
                    'hosts': {
                        'instance-2': {
                            'foo': 'bar',
                            'ansible_connection': 'docker'
                        }
                    }
                },
            },
            'vars': {
                'molecule_file':
                "{{ lookup('env', 'MOLECULE_FILE') }}",
                'molecule_ephemeral_directory':
                "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}",
                'molecule_scenario_directory':
                "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}",
                'molecule_yml':
                "{{ lookup('file', molecule_file) | molecule_from_yaml }}",
                'molecule_instance_config':
                "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}",
                'molecule_no_log':
                "{{ lookup('env', 'MOLECULE_NO_LOG') or not "
                "molecule_yml.provisioner.log|default(False) | bool }}",
            },
        },
        'baz': {
            'hosts': {
                'instance-2': {
                    'foo': 'bar',
                    'ansible_connection': 'docker'
                }
            },
            'children': {
                'child2': {
                    'hosts': {
                        'instance-2': {
                            'foo': 'bar',
                            'ansible_connection': 'docker'
                        }
                    }
                }
            },
            'vars': {
                'molecule_file':
                "{{ lookup('env', 'MOLECULE_FILE') }}",
                'molecule_ephemeral_directory':
                "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}",
                'molecule_scenario_directory':
                "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}",
                'molecule_yml':
                "{{ lookup('file', molecule_file) | molecule_from_yaml }}",
                'molecule_instance_config':
                "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}",
                'molecule_no_log':
                "{{ lookup('env', 'MOLECULE_NO_LOG') or not "
                "molecule_yml.provisioner.log|default(False) | bool }}",
            },
        },
    }

    assert is_subset(x, data)
예제 #6
0
def test_connection_options(_instance):
    x = {'ansible_connection': 'docker', 'foo': 'bar'}

    assert is_subset(x, _instance.connection_options('foo'))
예제 #7
0
def test_ansible_connection_options(_instance):
    x = {}

    assert is_subset(x, _instance.ansible_connection_options("foo"))