Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add awslogs to LogConfigTypesEnum #2849

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions docker/api/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ def create_container(self, image, command=None, hostname=None, user=None,

.. code-block:: python

client.api.create_host_config(port_bindings={1111: ('127.0.0.1', 4567)})
client.api.create_host_config(
port_bindings={1111: ('127.0.0.1', 4567)}
)

Or without host port assignment:

Expand Down Expand Up @@ -581,8 +583,11 @@ def create_host_config(self, *args, **kwargs):

Example:

>>> client.api.create_host_config(privileged=True, cap_drop=['MKNOD'],
volumes_from=['nostalgic_newton'])
>>> client.api.create_host_config(
privileged=True,
cap_drop=['MKNOD'],
volumes_from=['nostalgic_newton']
)
{'CapDrop': ['MKNOD'], 'LxcConf': None, 'Privileged': True,
'VolumesFrom': ['nostalgic_newton'], 'PublishAllPorts': False}

Expand Down
8 changes: 6 additions & 2 deletions docker/api/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,9 @@ def pull(self, repository, tag=None, stream=False, auth_config=None,

Example:

>>> for line in client.api.pull('busybox', stream=True, decode=True):
>>> for line in client.api.pull(
'busybox', stream=True, decode=True
):
... print(json.dumps(line, indent=4))
{
"status": "Pulling image (latest) from busybox",
Expand Down Expand Up @@ -458,7 +460,9 @@ def push(self, repository, tag=None, stream=False, auth_config=None,
If the server returns an error.

Example:
>>> for line in client.api.push('yourname/app', stream=True, decode=True):
>>> for line in client.api.push(
'yourname/app', stream=True, decode=True
):
... print(line)
{'status': 'Pushing repository yourname/app (1 tags)'}
{'status': 'Pushing','progressDetail': {}, 'id': '511136ea3c5a'}
Expand Down
5 changes: 3 additions & 2 deletions docker/types/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class LogConfigTypesEnum(object):
'journald',
'gelf',
'fluentd',
'none'
'none',
'awslogs'
)
JSON, SYSLOG, JOURNALD, GELF, FLUENTD, NONE = _values
JSON, SYSLOG, JOURNALD, GELF, FLUENTD, NONE, AWSLOGS = _values


class LogConfig(DictType):
Expand Down
26 changes: 19 additions & 7 deletions tests/unit/dockertypes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,28 +268,40 @@ def test_ulimit_invalid_type(self):
Ulimit(name='hello', hard='456')


class LogConfigTest(unittest.TestCase):
def test_create_host_config_dict_logconfig(self):
dct = {'type': LogConfig.types.SYSLOG, 'config': {'key1': 'val1'}}
class LogConfigTest():
@pytest.mark.parametrize(
"log_config_type",
[LogConfig.types.SYSLOG, LogConfig.types.AWSLOGS]
)
def test_create_host_config_dict_logconfig(self, log_config_type):
dct = {'type': log_config_type, 'config': {'key1': 'val1'}}
config = create_host_config(
version=DEFAULT_DOCKER_API_VERSION, log_config=dct
)
assert 'LogConfig' in config
assert isinstance(config['LogConfig'], LogConfig)
assert dct['type'] == config['LogConfig'].type

def test_create_host_config_obj_logconfig(self):
obj = LogConfig(type=LogConfig.types.SYSLOG, config={'key1': 'val1'})
@pytest.mark.parametrize(
"log_config_type",
[LogConfig.types.SYSLOG, LogConfig.types.AWSLOGS]
)
def test_create_host_config_obj_logconfig(self, log_config_type):
obj = LogConfig(type=log_config_type, config={'key1': 'val1'})
config = create_host_config(
version=DEFAULT_DOCKER_API_VERSION, log_config=obj
)
assert 'LogConfig' in config
assert isinstance(config['LogConfig'], LogConfig)
assert obj == config['LogConfig']

def test_logconfig_invalid_config_type(self):
@pytest.mark.parametrize(
"log_config_type",
[LogConfig.types.JSON, LogConfig.types.AWSLOGS]
)
def test_logconfig_invalid_config_type(self, log_config_type):
with pytest.raises(ValueError):
LogConfig(type=LogConfig.types.JSON, config='helloworld')
LogConfig(type=log_config_type, config='helloworld')


class EndpointConfigTest(unittest.TestCase):
Expand Down