|
34 | 34 | from six.moves import socketserver
|
35 | 35 |
|
36 | 36 | from .test import Cleanup
|
| 37 | +from docker.errors import APIError |
37 | 38 |
|
38 | 39 | # FIXME: missing tests for
|
39 | 40 | # export; history; insert; port; push; tag; get; load; stats
|
@@ -245,30 +246,80 @@ def runTest(self):
|
245 | 246 | self.assertFalse(inspect_data['VolumesRW'][mount_dest])
|
246 | 247 |
|
247 | 248 |
|
248 |
| -@unittest.skipIf(NOT_ON_HOST, 'Tests running inside a container; no syslog') |
249 |
| -class TestCreateContainerWithLogConfig(BaseTestCase): |
250 |
| - def runTest(self): |
251 |
| - config = docker.utils.LogConfig( |
252 |
| - type=docker.utils.LogConfig.types.SYSLOG, |
253 |
| - config={'key1': 'val1'} |
| 249 | +class CreateContainerWithLogConfigTest(BaseTestCase): |
| 250 | + def test_valid_log_driver_and_log_opt(self): |
| 251 | + log_config = docker.utils.LogConfig( |
| 252 | + type='json-file', |
| 253 | + config={'max-file': '100'} |
254 | 254 | )
|
255 |
| - ctnr = self.client.create_container( |
| 255 | + |
| 256 | + container = self.client.create_container( |
256 | 257 | 'busybox', ['true'],
|
257 |
| - host_config=self.client.create_host_config(log_config=config) |
| 258 | + host_config=self.client.create_host_config(log_config=log_config) |
258 | 259 | )
|
259 |
| - self.assertIn('Id', ctnr) |
260 |
| - self.tmp_containers.append(ctnr['Id']) |
261 |
| - self.client.start(ctnr) |
262 |
| - info = self.client.inspect_container(ctnr) |
263 |
| - self.assertIn('HostConfig', info) |
264 |
| - host_config = info['HostConfig'] |
265 |
| - self.assertIn('LogConfig', host_config) |
266 |
| - log_config = host_config['LogConfig'] |
267 |
| - self.assertIn('Type', log_config) |
268 |
| - self.assertEqual(log_config['Type'], config.type) |
269 |
| - self.assertIn('Config', log_config) |
270 |
| - self.assertEqual(type(log_config['Config']), dict) |
271 |
| - self.assertEqual(log_config['Config'], config.config) |
| 260 | + self.tmp_containers.append(container['Id']) |
| 261 | + self.client.start(container) |
| 262 | + |
| 263 | + info = self.client.inspect_container(container) |
| 264 | + container_log_config = info['HostConfig']['LogConfig'] |
| 265 | + |
| 266 | + self.assertEqual(container_log_config['Type'], log_config.type) |
| 267 | + self.assertEqual(container_log_config['Config'], log_config.config) |
| 268 | + |
| 269 | + def test_invalid_log_driver_raises_exception(self): |
| 270 | + log_config = docker.utils.LogConfig( |
| 271 | + type='asdf-nope', |
| 272 | + config={} |
| 273 | + ) |
| 274 | + |
| 275 | + container = self.client.create_container( |
| 276 | + 'busybox', ['true'], |
| 277 | + host_config=self.client.create_host_config(log_config=log_config) |
| 278 | + ) |
| 279 | + |
| 280 | + expected_msg = "logger: no log driver named 'asdf-nope' is registered" |
| 281 | + with self.assertRaisesRegexp(APIError, expected_msg): |
| 282 | + # raises an internal server error 500 |
| 283 | + self.client.start(container) |
| 284 | + |
| 285 | + @unittest.skip("Reason: https://github.com/docker/docker/issues/15633") |
| 286 | + def test_valid_no_log_driver_specified(self): |
| 287 | + log_config = docker.utils.LogConfig( |
| 288 | + type="", |
| 289 | + config={'max-file': '100'} |
| 290 | + ) |
| 291 | + |
| 292 | + container = self.client.create_container( |
| 293 | + 'busybox', ['true'], |
| 294 | + host_config=self.client.create_host_config(log_config=log_config) |
| 295 | + ) |
| 296 | + self.tmp_containers.append(container['Id']) |
| 297 | + self.client.start(container) |
| 298 | + |
| 299 | + info = self.client.inspect_container(container) |
| 300 | + container_log_config = info['HostConfig']['LogConfig'] |
| 301 | + |
| 302 | + self.assertEqual(container_log_config['Type'], "json-file") |
| 303 | + self.assertEqual(container_log_config['Config'], log_config.config) |
| 304 | + |
| 305 | + def test_valid_no_config_specified(self): |
| 306 | + log_config = docker.utils.LogConfig( |
| 307 | + type="json-file", |
| 308 | + config=None |
| 309 | + ) |
| 310 | + |
| 311 | + container = self.client.create_container( |
| 312 | + 'busybox', ['true'], |
| 313 | + host_config=self.client.create_host_config(log_config=log_config) |
| 314 | + ) |
| 315 | + self.tmp_containers.append(container['Id']) |
| 316 | + self.client.start(container) |
| 317 | + |
| 318 | + info = self.client.inspect_container(container) |
| 319 | + container_log_config = info['HostConfig']['LogConfig'] |
| 320 | + |
| 321 | + self.assertEqual(container_log_config['Type'], "json-file") |
| 322 | + self.assertEqual(container_log_config['Config'], {}) |
272 | 323 |
|
273 | 324 |
|
274 | 325 | @unittest.skipIf(not EXEC_DRIVER_IS_NATIVE, 'Exec driver not native')
|
|
0 commit comments