Skip to content

Commit 80985cb

Browse files
baldoalessandroshin-
authored andcommitted
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: Alessandro Baldo <[email protected]>
1 parent 2cb7806 commit 80985cb

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

docker/api/service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ def services(self, filters=None):
201201
202202
Args:
203203
filters (dict): Filters to process on the nodes list. Valid
204-
filters: ``id`` and ``name``. Default: ``None``.
204+
filters: ``id``, ``name`` , ``label`` and ``mode``.
205+
Default: ``None``.
205206
206207
Returns:
207208
A list of dictionaries containing data about each service.

docker/models/services.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ def list(self, **kwargs):
201201
202202
Args:
203203
filters (dict): Filters to process on the nodes list. Valid
204-
filters: ``id`` and ``name``. Default: ``None``.
204+
filters: ``id``, ``name`` , ``label`` and ``mode``.
205+
Default: ``None``.
205206
206207
Returns:
207208
(list of :py:class:`Service`): The services.

tests/integration/api_service_test.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_service_container(self, service_name, attempts=20, interval=0.5,
5252
return None
5353
time.sleep(interval)
5454

55-
def create_simple_service(self, name=None):
55+
def create_simple_service(self, name=None, labels=None):
5656
if name:
5757
name = 'dockerpytest_{0}'.format(name)
5858
else:
@@ -62,7 +62,9 @@ def create_simple_service(self, name=None):
6262
BUSYBOX, ['echo', 'hello']
6363
)
6464
task_tmpl = docker.types.TaskTemplate(container_spec)
65-
return name, self.client.create_service(task_tmpl, name=name)
65+
return name, self.client.create_service(
66+
task_tmpl, name=name, labels=labels
67+
)
6668

6769
@requires_api_version('1.24')
6870
def test_list_services(self):
@@ -76,6 +78,15 @@ def test_list_services(self):
7678
assert len(test_services) == 1
7779
assert 'dockerpytest_' in test_services[0]['Spec']['Name']
7880

81+
@requires_api_version('1.24')
82+
def test_list_services_filter_by_label(self):
83+
test_services = self.client.services(filters={'label': 'test_label'})
84+
assert len(test_services) == 0
85+
self.create_simple_service(labels={'test_label': 'testing'})
86+
test_services = self.client.services(filters={'label': 'test_label'})
87+
assert len(test_services) == 1
88+
assert test_services[0]['Spec']['Labels']['test_label'] == 'testing'
89+
7990
def test_inspect_service_by_id(self):
8091
svc_name, svc_id = self.create_simple_service()
8192
svc_info = self.client.inspect_service(svc_id)

0 commit comments

Comments
 (0)