Esempio n. 1
0
def validate_config(guest_config):
    errors = []

    def _validate(config, schema):
        validation_errors = []
        for key, data in config.items():
            result = validate_schema(data, schema)
            if result.errors:
                validation_errors.append(result.errors)
        return validation_errors

    guest_config_result = _validate(guest_config['guest_config'],
                                    load_data(GUEST_CONFIG_SCHEMA))
    guest_pairs_result = _validate(guest_config['guest_pairs'],
                                   load_data(GUEST_PAIRS_SCHEMA))

    if guest_config_result:
        errors += guest_config_result

    if guest_pairs_result:
        errors += guest_pairs_result

    return errors
Esempio n. 2
0
def validate_data(guest_data, guest_default_data=False):
    """
    Validate data conforms to required schema
    :param guest_data: Guest data dict
    :param guest_default_data: True if validating guest defaults
    :return: errors list
    """
    errors = []
    schema = load_data(GUEST_SCHEMA_FILE)
    # Guest default schema should be the same as a guest
    # schema apart from the vagrant box name attribute.
    if guest_default_data:
        schema['vagrant_box']['schema'].pop('name')

    for guest, data in guest_data.items():
        result = validate_schema(data, schema)
        if result.errors:
            errors.append(result.errors)

    return errors
Esempio n. 3
0
def test_guest_data_matches_dict():
    assert load_data('examples/guests.yml') == mock_guest_data
Esempio n. 4
0
def mock_data(filename):
    return load_data(f'{filename}')
Esempio n. 5
0
    update_guest_interfaces,
    add_blackhole_interfaces,
    update_guest_data,
    update_guest_additional_storage,
    int_to_port_map,
    generate_int_to_port_mappings,
    create_reserved_interfaces,
    generate_connection_strings,
)
from .mock_data import (
    mock_guest_data,
    mock_guest_interfaces,
    mock_connection_data,
)

config = load_data(DEFAULT_CONFIG_FILE)


def mock_data(filename):
    return load_data(f'{filename}')


def test_guest_data_matches_dict():
    assert load_data('examples/guests.yml') == mock_guest_data


def test_generate_loopbacks_guest_dict_not_dict_type_raises_exception():
    with pytest.raises(AttributeError):
        generate_loopbacks(guest_dict="")

Esempio n. 6
0
def test_load_json_data():
    data = load_data(f'{BASE_DIR}/../tests/mock_json_data.json', data_type='json')
    assert {'some': 'data'} == data
Esempio n. 7
0
def test_load_data_with_invalid_data_type_raises_attribute_error():
    with pytest.raises(AttributeError):
        load_data('blah', data_type='invalid')
Esempio n. 8
0
def test_validate_guest_schema():
    data = {'vagrant_box': {'name': 'box-name'}}
    schema = load_data(GUEST_SCHEMA_FILE)
    result = validate_schema(data, schema)
    assert not result.errors