Kaydet (Commit) 35b30e69 authored tarafından Mazz Mosley's avatar Mazz Mosley

Remove validation of supported log drivers

By having this hardcoded list of log drivers, it is a bottleneck
to us supporting more log drivers.

The daemon already validates if a log driver is valid or not, so rather
than duplicating that validation, let's pass the log_driver along.

This allows support for new/more log drivers as they become supported
in docker without having to wait for both docker-py and docker-compose
to support them.

Keeping the current list of log driver types for backwards compatibility.
Signed-off-by: 's avatarMazz Mosley <mazz@houseofmnowster.com>
üst 90538cf0
......@@ -20,21 +20,17 @@ class DictType(dict):
class LogConfig(DictType):
types = LogConfigTypesEnum
def __init__(self, **kwargs):
type_ = kwargs.get('type', kwargs.get('Type'))
config = kwargs.get('config', kwargs.get('Config'))
if type_ not in self.types._values:
raise ValueError("LogConfig.type must be one of ({0})".format(
', '.join(self.types._values)
))
log_driver_type = kwargs.get('type', kwargs.get('Type'))
config = kwargs.get('config', kwargs.get('Config')) or {}
if config and not isinstance(config, dict):
raise ValueError("LogConfig.config must be a dictionary")
super(LogConfig, self).__init__({
'Type': type_,
'Config': config or {}
'Type': log_driver_type,
'Config': config
})
@property
......@@ -43,10 +39,6 @@ class LogConfig(DictType):
@type.setter
def type(self, value):
if value not in self.types._values:
raise ValueError("LogConfig.type must be one of {0}".format(
', '.join(self.types._values)
))
self['Type'] = value
@property
......
......@@ -34,6 +34,7 @@ from six.moves import BaseHTTPServer
from six.moves import socketserver
from .test import Cleanup
from docker.errors import APIError
# FIXME: missing tests for
# export; history; insert; port; push; tag; get; load; stats
......@@ -265,6 +266,22 @@ class CreateContainerWithLogConfigTest(BaseTestCase):
self.assertEqual(container_log_config['Type'], log_config.type)
self.assertEqual(container_log_config['Config'], log_config.config)
def test_invalid_log_driver_raises_exception(self):
log_config = docker.utils.LogConfig(
type='asdf-nope',
config={}
)
container = self.client.create_container(
'busybox', ['true'],
host_config=create_host_config(log_config=log_config)
)
expected_msg = "logger: no log driver named 'asdf-nope' is registered"
with self.assertRaisesRegexp(APIError, expected_msg):
# raises an internal server error 500
self.client.start(container)
@unittest.skipIf(not EXEC_DRIVER_IS_NATIVE, 'Exec driver not native')
class TestCreateContainerReadOnlyFs(BaseTestCase):
......
......@@ -192,29 +192,19 @@ class UtilsTest(base.BaseTestCase):
self.assertRaises(ValueError, lambda: Ulimit(name='hello', hard='456'))
def test_create_host_config_dict_logconfig(self):
dct = {'type': LogConfig.types.SYSLOG, 'config': {'key1': 'val1'}}
config = create_host_config(
log_config=dct, version=DEFAULT_DOCKER_API_VERSION
)
dct = {'type': 'syslog', 'config': {'key1': 'val1'}}
config = create_host_config(log_config=dct)
self.assertIn('LogConfig', config)
self.assertTrue(isinstance(config['LogConfig'], LogConfig))
self.assertEqual(dct['type'], config['LogConfig'].type)
def test_create_host_config_obj_logconfig(self):
obj = LogConfig(type=LogConfig.types.SYSLOG, config={'key1': 'val1'})
config = create_host_config(
log_config=obj, version=DEFAULT_DOCKER_API_VERSION
)
obj = LogConfig(type='syslog', config={'key1': 'val1'})
config = create_host_config(log_config=obj)
self.assertIn('LogConfig', config)
self.assertTrue(isinstance(config['LogConfig'], LogConfig))
self.assertEqual(obj, config['LogConfig'])
def test_logconfig_invalid_type(self):
self.assertRaises(ValueError, lambda: LogConfig(type='xxx', config={}))
self.assertRaises(ValueError, lambda: LogConfig(
type=LogConfig.types.JSON, config='helloworld'
))
def test_resolve_repository_name(self):
# docker hub library image
self.assertEqual(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment