Kaydet (Commit) 76b138a0 authored tarafından Alessandro Baldo's avatar Alessandro Baldo Kaydeden (comit) Joffrey F

Improve docs for service list filters

- add "label" and "mode" to the list of available filter keys in the high-level service API
- add "label" and "mode" to the list of available filter keys in the low-level service API
- add integration tests
Signed-off-by: 's avatarAlessandro Baldo <git@baldoalessandro.net>
üst bb148380
...@@ -201,7 +201,8 @@ class ServiceApiMixin(object): ...@@ -201,7 +201,8 @@ class ServiceApiMixin(object):
Args: Args:
filters (dict): Filters to process on the nodes list. Valid filters (dict): Filters to process on the nodes list. Valid
filters: ``id`` and ``name``. Default: ``None``. filters: ``id``, ``name`` , ``label`` and ``mode``.
Default: ``None``.
Returns: Returns:
A list of dictionaries containing data about each service. A list of dictionaries containing data about each service.
......
...@@ -201,7 +201,8 @@ class ServiceCollection(Collection): ...@@ -201,7 +201,8 @@ class ServiceCollection(Collection):
Args: Args:
filters (dict): Filters to process on the nodes list. Valid filters (dict): Filters to process on the nodes list. Valid
filters: ``id`` and ``name``. Default: ``None``. filters: ``id``, ``name`` , ``label`` and ``mode``.
Default: ``None``.
Returns: Returns:
(list of :py:class:`Service`): The services. (list of :py:class:`Service`): The services.
......
...@@ -52,7 +52,7 @@ class ServiceTest(BaseAPIIntegrationTest): ...@@ -52,7 +52,7 @@ class ServiceTest(BaseAPIIntegrationTest):
return None return None
time.sleep(interval) time.sleep(interval)
def create_simple_service(self, name=None): def create_simple_service(self, name=None, labels=None):
if name: if name:
name = 'dockerpytest_{0}'.format(name) name = 'dockerpytest_{0}'.format(name)
else: else:
...@@ -62,7 +62,9 @@ class ServiceTest(BaseAPIIntegrationTest): ...@@ -62,7 +62,9 @@ class ServiceTest(BaseAPIIntegrationTest):
BUSYBOX, ['echo', 'hello'] BUSYBOX, ['echo', 'hello']
) )
task_tmpl = docker.types.TaskTemplate(container_spec) task_tmpl = docker.types.TaskTemplate(container_spec)
return name, self.client.create_service(task_tmpl, name=name) return name, self.client.create_service(
task_tmpl, name=name, labels=labels
)
@requires_api_version('1.24') @requires_api_version('1.24')
def test_list_services(self): def test_list_services(self):
...@@ -76,6 +78,15 @@ class ServiceTest(BaseAPIIntegrationTest): ...@@ -76,6 +78,15 @@ class ServiceTest(BaseAPIIntegrationTest):
assert len(test_services) == 1 assert len(test_services) == 1
assert 'dockerpytest_' in test_services[0]['Spec']['Name'] assert 'dockerpytest_' in test_services[0]['Spec']['Name']
@requires_api_version('1.24')
def test_list_services_filter_by_label(self):
test_services = self.client.services(filters={'label': 'test_label'})
assert len(test_services) == 0
self.create_simple_service(labels={'test_label': 'testing'})
test_services = self.client.services(filters={'label': 'test_label'})
assert len(test_services) == 1
assert test_services[0]['Spec']['Labels']['test_label'] == 'testing'
def test_inspect_service_by_id(self): def test_inspect_service_by_id(self):
svc_name, svc_id = self.create_simple_service() svc_name, svc_id = self.create_simple_service()
svc_info = self.client.inspect_service(svc_id) svc_info = self.client.inspect_service(svc_id)
......
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