mirror of https://github.com/docker/docker-py.git
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: Mazz Mosley <mazz@houseofmnowster.com>
This commit is contained in:
parent
90538cf0a3
commit
35b30e69df
|
|
@ -20,21 +20,17 @@ class DictType(dict):
|
||||||
|
|
||||||
|
|
||||||
class LogConfig(DictType):
|
class LogConfig(DictType):
|
||||||
types = LogConfigTypesEnum
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
type_ = kwargs.get('type', kwargs.get('Type'))
|
log_driver_type = kwargs.get('type', kwargs.get('Type'))
|
||||||
config = kwargs.get('config', kwargs.get('Config'))
|
config = kwargs.get('config', kwargs.get('Config')) or {}
|
||||||
if type_ not in self.types._values:
|
|
||||||
raise ValueError("LogConfig.type must be one of ({0})".format(
|
|
||||||
', '.join(self.types._values)
|
|
||||||
))
|
|
||||||
if config and not isinstance(config, dict):
|
if config and not isinstance(config, dict):
|
||||||
raise ValueError("LogConfig.config must be a dictionary")
|
raise ValueError("LogConfig.config must be a dictionary")
|
||||||
|
|
||||||
super(LogConfig, self).__init__({
|
super(LogConfig, self).__init__({
|
||||||
'Type': type_,
|
'Type': log_driver_type,
|
||||||
'Config': config or {}
|
'Config': config
|
||||||
})
|
})
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
@ -43,10 +39,6 @@ class LogConfig(DictType):
|
||||||
|
|
||||||
@type.setter
|
@type.setter
|
||||||
def type(self, value):
|
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
|
self['Type'] = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ from six.moves import BaseHTTPServer
|
||||||
from six.moves import socketserver
|
from six.moves import socketserver
|
||||||
|
|
||||||
from .test import Cleanup
|
from .test import Cleanup
|
||||||
|
from docker.errors import APIError
|
||||||
|
|
||||||
# FIXME: missing tests for
|
# FIXME: missing tests for
|
||||||
# export; history; insert; port; push; tag; get; load; stats
|
# 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['Type'], log_config.type)
|
||||||
self.assertEqual(container_log_config['Config'], log_config.config)
|
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')
|
@unittest.skipIf(not EXEC_DRIVER_IS_NATIVE, 'Exec driver not native')
|
||||||
class TestCreateContainerReadOnlyFs(BaseTestCase):
|
class TestCreateContainerReadOnlyFs(BaseTestCase):
|
||||||
|
|
|
||||||
|
|
@ -192,29 +192,19 @@ class UtilsTest(base.BaseTestCase):
|
||||||
self.assertRaises(ValueError, lambda: Ulimit(name='hello', hard='456'))
|
self.assertRaises(ValueError, lambda: Ulimit(name='hello', hard='456'))
|
||||||
|
|
||||||
def test_create_host_config_dict_logconfig(self):
|
def test_create_host_config_dict_logconfig(self):
|
||||||
dct = {'type': LogConfig.types.SYSLOG, 'config': {'key1': 'val1'}}
|
dct = {'type': 'syslog', 'config': {'key1': 'val1'}}
|
||||||
config = create_host_config(
|
config = create_host_config(log_config=dct)
|
||||||
log_config=dct, version=DEFAULT_DOCKER_API_VERSION
|
|
||||||
)
|
|
||||||
self.assertIn('LogConfig', config)
|
self.assertIn('LogConfig', config)
|
||||||
self.assertTrue(isinstance(config['LogConfig'], LogConfig))
|
self.assertTrue(isinstance(config['LogConfig'], LogConfig))
|
||||||
self.assertEqual(dct['type'], config['LogConfig'].type)
|
self.assertEqual(dct['type'], config['LogConfig'].type)
|
||||||
|
|
||||||
def test_create_host_config_obj_logconfig(self):
|
def test_create_host_config_obj_logconfig(self):
|
||||||
obj = LogConfig(type=LogConfig.types.SYSLOG, config={'key1': 'val1'})
|
obj = LogConfig(type='syslog', config={'key1': 'val1'})
|
||||||
config = create_host_config(
|
config = create_host_config(log_config=obj)
|
||||||
log_config=obj, version=DEFAULT_DOCKER_API_VERSION
|
|
||||||
)
|
|
||||||
self.assertIn('LogConfig', config)
|
self.assertIn('LogConfig', config)
|
||||||
self.assertTrue(isinstance(config['LogConfig'], LogConfig))
|
self.assertTrue(isinstance(config['LogConfig'], LogConfig))
|
||||||
self.assertEqual(obj, config['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):
|
def test_resolve_repository_name(self):
|
||||||
# docker hub library image
|
# docker hub library image
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue