Пример #1
0
    def test_config(self):
        config = ssh_schemas.RosterEntryConfig()

        expected = {
            '$schema': 'http://json-schema.org/draft-04/schema#',
            'title': 'Roster Entry',
            'description': 'Salt SSH roster entry definition',
            'type': 'object',
            'properties': {
                'host': {
                    'title': 'Host',
                    'description': 'The IP address or DNS name of the remote host',
                    'type': 'string',
                    'pattern': r'^((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|([A-Za-z0-9][A-Za-z0-9\.\-]{1,255}))$',
                    'minLength': 1
                },
                'port': {
                    'description': 'The target system\'s ssh port number',
                    'title': 'Port',
                    'default': 22,
                    'maximum': 65535,
                    'minimum': 0,
                    'type': 'integer'
                },
                'user': {
                    'default': 'root',
                    'type': 'string',
                    'description': 'The user to log in as. Defaults to root',
                    'title': 'User',
                    'minLength': 1
                },
                'passwd': {
                    'title': 'Password',
                    'type': 'string',
                    'description': 'The password to log in with',
                    'format': 'secret',
                    'minLength': 1
                },
                'priv': {
                    'type': 'string',
                    'description': 'File path to ssh private key, defaults to salt-ssh.rsa',
                    'title': 'Private Key',
                    'minLength': 1
                },
                'priv_passwd': {
                    'type': 'string',
                    'description': 'Passphrase for private key file',
                    'title': 'Private Key passphrase',
                    'format': 'secret',
                    'minLength': 1,
                },
                'sudo': {
                    'default': False,
                    'type': 'boolean',
                    'description': 'run command via sudo. Defaults to False',
                    'title': 'Sudo'
                },
                'timeout': {
                    'type': 'integer',
                    'description': 'Number of seconds to wait for response when establishing an SSH connection',
                    'title': 'Timeout'
                },
                'thin_dir': {
                    'type': 'string',
                    'description': 'The target system\'s storage directory for Salt components. Defaults to /tmp/salt-<hash>.',
                    'title': 'Thin Directory'
                },
                # The actuall representation of the minion options would make this HUGE!
                'minion_opts': ssh_schemas.DictItem(title='Minion Options',
                                                    description='Dictionary of minion options',
                                                    properties=MinionConfiguration()).serialize(),
            },
            'anyOf': [
                {
                    'required': [
                        'passwd'
                    ]
                },
                {
                    'required': [
                        'priv'
                    ]
                }
            ],
            'required': [
                'host',
                'user',
            ],
            'x-ordering': [
                'host',
                'port',
                'user',
                'passwd',
                'priv',
                'priv_passwd',
                'sudo',
                'timeout',
                'thin_dir',
                'minion_opts'
            ],
            'additionalProperties': False
        }
        try:
            self.assertDictContainsSubset(expected['properties'], config.serialize()['properties'])
            self.assertDictContainsSubset(expected, config.serialize())
        except AssertionError:
            import salt.utils.json
            print(salt.utils.json.dumps(config.serialize(), indent=4))
            raise
Пример #2
0
    def test_config(self):
        config = ssh_schemas.RosterEntryConfig()

        expected = {
            "$schema": "http://json-schema.org/draft-04/schema#",
            "title": "Roster Entry",
            "description": "Salt SSH roster entry definition",
            "type": "object",
            "properties": {
                "host": {
                    "title": "Host",
                    "description": "The IP address or DNS name of the remote host",
                    "type": "string",
                    "pattern": r"^((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|([A-Za-z0-9][A-Za-z0-9\.\-]{1,255}))$",
                    "minLength": 1,
                },
                "port": {
                    "description": "The target system's ssh port number",
                    "title": "Port",
                    "default": 22,
                    "maximum": 65535,
                    "minimum": 0,
                    "type": "integer",
                },
                "user": {
                    "default": "root",
                    "type": "string",
                    "description": "The user to log in as. Defaults to root",
                    "title": "User",
                    "minLength": 1,
                },
                "passwd": {
                    "title": "Password",
                    "type": "string",
                    "description": "The password to log in with",
                    "format": "secret",
                    "minLength": 1,
                },
                "priv": {
                    "type": "string",
                    "description": "File path to ssh private key, defaults to salt-ssh.rsa",
                    "title": "Private Key",
                    "minLength": 1,
                },
                "priv_passwd": {
                    "type": "string",
                    "description": "Passphrase for private key file",
                    "title": "Private Key passphrase",
                    "format": "secret",
                    "minLength": 1,
                },
                "sudo": {
                    "default": False,
                    "type": "boolean",
                    "description": "run command via sudo. Defaults to False",
                    "title": "Sudo",
                },
                "timeout": {
                    "type": "integer",
                    "description": "Number of seconds to wait for response when establishing an SSH connection",
                    "title": "Timeout",
                },
                "thin_dir": {
                    "type": "string",
                    "description": "The target system's storage directory for Salt components. Defaults to /tmp/salt-<hash>.",
                    "title": "Thin Directory",
                },
                # The actuall representation of the minion options would make this HUGE!
                "minion_opts": ssh_schemas.DictItem(
                    title="Minion Options",
                    description="Dictionary of minion options",
                    properties=MinionConfiguration(),
                ).serialize(),
            },
            "anyOf": [{"required": ["passwd"]}, {"required": ["priv"]}],
            "required": ["host", "user"],
            "x-ordering": [
                "host",
                "port",
                "user",
                "passwd",
                "priv",
                "priv_passwd",
                "sudo",
                "timeout",
                "thin_dir",
                "minion_opts",
            ],
            "additionalProperties": False,
        }
        try:
            self.assertDictContainsSubset(
                expected["properties"], config.serialize()["properties"]
            )
            self.assertDictContainsSubset(expected, config.serialize())
        except AssertionError:
            import salt.utils.json

            print(salt.utils.json.dumps(config.serialize(), indent=4))
            raise