def test_provisioner_has_errors(_config):
    x = {
        "provisioner": [{
            "config_options": ["must be of dict type"],
            "connection_options": ["must be of dict type"],
            "playbooks": [{
                "destroy": ["must be of string type"],
                "create": ["must be of string type"],
                "side_effect": ["must be of string type"],
                "prepare": ["must be of string type"],
                "converge": ["must be of string type"],
            }],
            "children": ["must be of dict type"],
            "inventory": [{
                "hosts": ["must be of dict type"],
                "group_vars": ["must be of dict type"],
                "host_vars": ["must be of dict type"],
                "links": ["must be of dict type"],
            }],
            "env": [{
                "foo": ["value does not match regex '^[A-Z0-9_-]+$'"],
                "foo-bar": ["value does not match regex '^[A-Z0-9_-]+$'"],
                "foo-bar-baz": [
                    "value does not match regex '^[A-Z0-9_-]+$'",
                    "null value not allowed",
                ],
            }],
            "options": ["must be of dict type"],
            "name": ["must be of string type"],
            "log": ["must be of boolean type"],
        }]
    }

    assert x == schema_v3.validate(_config)
Ejemplo n.º 2
0
def test_provisioner_has_errors(_config):
    x = {
        'provisioner': [{
            'config_options': ['must be of dict type'],
            'connection_options': ['must be of dict type'],
            'playbooks': [{
                'destroy': ['must be of string type'],
                'create': ['must be of string type'],
                'side_effect': ['must be of string type'],
                'prepare': ['must be of string type'],
                'converge': ['must be of string type'],
            }],
            'children': ['must be of dict type'],
            'inventory': [{
                'hosts': ['must be of dict type'],
                'group_vars': ['must be of dict type'],
                'host_vars': ['must be of dict type'],
                'links': ['must be of dict type'],
            }],
            'env': [{
                'foo': ["value does not match regex '^[A-Z0-9_-]+$'"],
                'foo-bar': ["value does not match regex '^[A-Z0-9_-]+$'"],
                'foo-bar-baz': [
                    "value does not match regex '^[A-Z0-9_-]+$'",
                    'null value not allowed',
                ],
            }],
            'options': ['must be of dict type'],
            'name': ['must be of string type'],
            'log': ['must be of boolean type'],
        }]
    }

    assert x == schema_v3.validate(_config)
Ejemplo n.º 3
0
def test_platforms_driver_name_required(_config):
    if "platforms" in _config:
        del _config["platforms"][0]["name"]
    else:
        _config["platforms"] = [{"foo": "bar"}]
    x = {"platforms": [{0: [{"name": ["required field"]}]}]}

    assert x == schema_v3.validate(_config)
Ejemplo n.º 4
0
    def _validate(self):
        msg = "Validating schema {}.".format(self.molecule_file)
        LOG.debug(msg)

        errors = schema_v3.validate(self.config)
        if errors:
            msg = f"Failed to validate {self.molecule_file}\n\n{errors}"
            util.sysexit_with_message(msg)
Ejemplo n.º 5
0
def test_platforms_docker_has_errors(_config):
    x = {
        'platforms': [
            {
                0: [
                    {
                        'name': ['must be of string type'],
                        'hostname': ['must be of string type'],
                        'image': ['must be of string type'],
                        'pull': ['must be of boolean type'],
                        'dockerfile': ['must be of string type'],
                        'pre_build_image': ['must be of boolean type'],
                        'registry': [
                            {
                                'url': ['must be of string type'],
                                'credentials': [
                                    {
                                        'username': ['must be of string type'],
                                        'password': ['must be of string type'],
                                        'email': ['must be of string type'],
                                    }
                                ],
                            }
                        ],
                        'override_command': ['must be of boolean type'],
                        'command': ['must be of string type'],
                        'tty': ['must be of boolean type'],
                        'pid_mode': ['must be of string type'],
                        'privileged': ['must be of boolean type'],
                        'security_opts': [{0: ['must be of string type']}],
                        'volumes': [{0: ['must be of string type']}],
                        'keep_volumes': ['must be of boolean type'],
                        'tmpfs': [{0: ['must be of string type']}],
                        'capabilities': [{0: ['must be of string type']}],
                        'sysctls': ['must be of dict type'],
                        'exposed_ports': [{0: ['must be of string type']}],
                        'published_ports': [{0: ['must be of string type']}],
                        'ulimits': [{0: ['must be of string type']}],
                        'dns_servers': [{0: ['must be of string type']}],
                        'etc_hosts': ['must be of [\'string\', \'dict\'] type'],
                        'env': ['must be of dict type'],
                        'restart_policy': ['must be of string type'],
                        'restart_retries': ['must be of integer type'],
                        'networks': [{0: [{'name': ['must be of string type']}]}],
                        'network_mode': ['must be of string type'],
                        'purge_networks': ['must be of boolean type'],
                        'docker_host': ['must be of string type'],
                        'cacert_path': ['must be of string type'],
                        'cert_path': ['must be of string type'],
                        'key_path': ['must be of string type'],
                        'tls_verify': ['must be of boolean type'],
                    }
                ]
            }
        ]
    }

    assert x == schema_v3.validate(_config)
Ejemplo n.º 6
0
def test_valid(temp_dir, _molecule_file, _role_directory, _command_args, _instance):
    _instance._process_templates("molecule", _command_args, _role_directory)

    data = util.safe_load_file(_molecule_file)

    assert {} == schema_v3.validate(data)

    cmd = ["yamllint", "-s", _molecule_file]
    pytest.helpers.run_command(cmd)
Ejemplo n.º 7
0
def test_valid(temp_dir, _molecule_file, _role_directory, _command_args, _instance):
    _instance._process_templates('molecule', _command_args, _role_directory)

    data = util.safe_load_file(_molecule_file)

    assert {} == schema_v3.validate(data)

    cmd = sh.yamllint.bake('-s', _molecule_file)
    pytest.helpers.run_command(cmd)
Ejemplo n.º 8
0
def test_platforms_hetznercloud_fields_required(_config, _required_field):
    del _config["platforms"][0][_required_field]
    expected_config = {
        "platforms": [{
            0: [{
                _required_field: ["required field"]
            }]
        }]
    }
    assert expected_config == schema_v3.validate(_config)
Ejemplo n.º 9
0
    def _validate(self):
        msg = 'Validating schema {}.'.format(self.molecule_file)
        LOG.info(msg)

        errors = schema_v3.validate(self.config)
        if errors:
            msg = "Failed to validate.\n\n{}".format(errors)
            util.sysexit_with_message(msg)

        msg = 'Validation completed successfully.'
        LOG.success(msg)
Ejemplo n.º 10
0
def test_drivers(driver, temp_dir, _molecule_file, _role_directory,
                 _command_args, _instance):
    _command_args["driver_name"] = driver
    _instance._process_templates("molecule", _command_args, _role_directory)

    data = util.safe_load_file(_molecule_file)

    assert {} == schema_v3.validate(data)

    cmd = sh.yamllint.bake("-s", _molecule_file)
    pytest.helpers.run_command(cmd)
Ejemplo n.º 11
0
def test_scenario_has_errors(_config):
    x = {
        "scenario": [
            {
                "converge_sequence": [{0: ["must be of string type"]}],
                "check_sequence": [{0: ["must be of string type"]}],
                "create_sequence": [{0: ["must be of string type"]}],
                "destroy_sequence": [{0: ["must be of string type"]}],
                "test_sequence": [{0: ["must be of string type"]}],
            }
        ]
    }

    assert x == schema_v3.validate(_config)
Ejemplo n.º 12
0
def test_platforms_unique_names(_config):
    instance_name = _config["platforms"][0]["name"]
    _config["platforms"] += [{"name": instance_name}]  # duplicate platform name

    expected_validation_errors = {
        "platforms": [
            {
                0: [{"name": ["'{}' is not unique".format(instance_name)]}],
                1: [{"name": ["'{}' is not unique".format(instance_name)]}],
            }
        ]
    }

    assert expected_validation_errors == schema_v3.validate(_config)
Ejemplo n.º 13
0
def test_provisioner_config_env_disallowed_field(_config):
    x = {
        'provisioner': [{
            'env': [{
                'ANSIBLE_BECOME_METHOD':
                ['disallowed user provided config option'],
                'ANSIBLE_BECOME': ['disallowed user provided config option'],
                'ANSIBLE_BECOME_USER':
                ['disallowed user provided config option'],
            }]
        }]
    }

    assert x == schema_v3.validate(_config)
Ejemplo n.º 14
0
def test_platforms_unique_names(_config):
    instance_name = _config['platforms'][0]['name']
    _config['platforms'] += [{'name': instance_name}]  # duplicate platform name

    expected_validation_errors = {
        'platforms': [
            {
                0: [{'name': ["'{}' is not unique".format(instance_name)]}],
                1: [{'name': ["'{}' is not unique".format(instance_name)]}],
            }
        ]
    }

    assert expected_validation_errors == schema_v3.validate(_config)
Ejemplo n.º 15
0
def test_dependency_has_errors(_config):
    x = {
        'dependency': [{
            'name': ['must be of string type'],
            'enabled': ['must be of boolean type'],
            'options': ['must be of dict type'],
            'env': [{
                'foo': ["value does not match regex '^[A-Z0-9_-]+$'"],
                'foo-bar': ["value does not match regex '^[A-Z0-9_-]+$'"],
            }],
        }]
    }

    assert x == schema_v3.validate(_config)
Ejemplo n.º 16
0
def test_driver_has_errors(_config):
    x = {
        "driver": [
            {
                "safe_files": [{0: ["must be of string type"]}],
                "options": [{"managed": ["must be of boolean type"]}],
                "ssh_connection_options": [{0: ["must be of string type"]}],
                "name": ["must be of string type"],
                "provider": [{"name": ["must be of string type"]}],
            }
        ]
    }

    assert x == schema_v3.validate(_config)
def test_dependency_has_errors(_config):
    x = {
        "dependency": [{
            "name": ["must be of string type"],
            "enabled": ["must be of boolean type"],
            "options": ["must be of dict type"],
            "env": [{
                "foo": ["value does not match regex '^[A-Z0-9_-]+$'"],
                "foo-bar": ["value does not match regex '^[A-Z0-9_-]+$'"],
            }],
        }]
    }

    assert x == schema_v3.validate(_config)
def test_provisioner_config_env_disallowed_field(_config):
    x = {
        "provisioner": [{
            "env": [{
                "ANSIBLE_BECOME_METHOD":
                ["disallowed user provided config option"],
                "ANSIBLE_BECOME": ["disallowed user provided config option"],
                "ANSIBLE_BECOME_USER":
                ["disallowed user provided config option"],
            }]
        }]
    }

    assert x == schema_v3.validate(_config)
Ejemplo n.º 19
0
def test_platforms_hetznercloud_has_errors(_config):
    expected_config = {
        "platforms": [{
            0: [{
                "name": ["must be of string type"],
                "server_type": ["must be of string type"],
                "volumes": ["must be of list type"],
                "image": ["must be of string type"],
                "location": ["must be of string type"],
                "datacenter": ["must be of string type"],
                "user_data": ["must be of string type"],
            }]
        }]
    }

    assert expected_config == schema_v3.validate(_config)
def test_provisioner_config_options_disallowed_field(_config):
    x = {
        "provisioner": [{
            "config_options": [{
                "defaults": [{
                    "filter_plugins":
                    ["disallowed user provided config option"],
                    "library": ["disallowed user provided config option"],
                    "roles_path": ["disallowed user provided config option"],
                }],
                "privilege_escalation":
                ["disallowed user provided config option"],
            }]
        }]
    }

    assert x == schema_v3.validate(_config)
Ejemplo n.º 21
0
def test_provisioner_config_options_disallowed_field(_config):
    x = {
        'provisioner': [{
            'config_options': [{
                'defaults': [{
                    'filter_plugins':
                    ['disallowed user provided config option'],
                    'library': ['disallowed user provided config option'],
                    'roles_path': ['disallowed user provided config option'],
                }],
                'privilege_escalation':
                ['disallowed user provided config option'],
            }]
        }]
    }

    assert x == schema_v3.validate(_config)
Ejemplo n.º 22
0
def test_verifier_has_errors(_config):
    x = {
        'verifier': [{
            'name': ['must be of string type'],
            'enabled': ['must be of boolean type'],
            'env': [{
                'foo': ["value does not match regex '^[A-Z0-9_-]+$'"],
                'foo-bar': ["value does not match regex '^[A-Z0-9_-]+$'"],
            }],
            'directory': ['must be of string type'],
            'additional_files_or_dirs': [{
                0: ['must be of string type']
            }],
            'options': ['must be of dict type'],
        }]
    }

    assert x == schema_v3.validate(_config)
Ejemplo n.º 23
0
def test_verifier_has_errors(_config):
    x = {
        "verifier": [{
            "name": ["must be of string type"],
            "enabled": ["must be of boolean type"],
            "env": [{
                "foo": ["value does not match regex '^[A-Z0-9_-]+$'"],
                "foo-bar": ["value does not match regex '^[A-Z0-9_-]+$'"],
            }],
            "directory": ["must be of string type"],
            "additional_files_or_dirs": [{
                0: ["must be of string type"]
            }],
            "options": ["must be of dict type"],
        }]
    }

    assert x == schema_v3.validate(_config)
Ejemplo n.º 24
0
def test_platforms_env_should_refuse_keys_with_special_char(_config):
    _config["platforms"][0]["env"] = {"FOO#BAR": "bar", "foo/baz": "bar"}
    x = {
        "platforms": [{
            0: [{
                "env": [{
                    "FOO#BAR":
                    ["value does not match regex "
                     "'^[a-zA-Z0-9._-]+$'"],
                    "foo/baz":
                    ["value does not match regex "
                     "'^[a-zA-Z0-9._-]+$'"],
                }]
            }]
        }]
    }

    assert x == schema_v3.validate(_config)
Ejemplo n.º 25
0
def test_driver_has_errors(_config):
    x = {
        'driver': [{
            'safe_files': [{
                0: ['must be of string type']
            }],
            'options': [{
                'managed': ['must be of boolean type']
            }],
            'ssh_connection_options': [{
                0: ['must be of string type']
            }],
            'name': ['must be of string type'],
            'provider': [{
                'name': ['must be of string type']
            }],
        }]
    }

    assert x == schema_v3.validate(_config)
Ejemplo n.º 26
0
def test_scenario_has_errors(_config):
    x = {
        'scenario': [{
            'converge_sequence': [{
                0: ['must be of string type']
            }],
            'check_sequence': [{
                0: ['must be of string type']
            }],
            'create_sequence': [{
                0: ['must be of string type']
            }],
            'destroy_sequence': [{
                0: ['must be of string type']
            }],
            'test_sequence': [{
                0: ['must be of string type']
            }],
        }]
    }

    assert x == schema_v3.validate(_config)
Ejemplo n.º 27
0
def test_platforms_env_should_refuse_keys_with_special_char(_config):
    _config['platforms'][0]['env'] = {'FOO#BAR': 'bar', 'foo/baz': 'bar'}
    x = {
        'platforms': [
            {
                0: [
                    {
                        'env': [
                            {
                                'FOO#BAR': [
                                    'value does not match regex ' "'^[a-zA-Z0-9._-]+$'"
                                ],
                                'foo/baz': [
                                    'value does not match regex ' "'^[a-zA-Z0-9._-]+$'"
                                ],
                            }
                        ]
                    }
                ]
            }
        ]
    }

    assert x == schema_v3.validate(_config)
Ejemplo n.º 28
0
def test_platforms_delegated(_config):
    assert {} == schema_v3.validate(_config)
def test_driver_provider_name_nullable(_config):
    assert {} == schema_v3.validate(_config)
def test_driver(_config):
    assert {} == schema_v3.validate(_config)