From c8295d36cc840c788dd9dad249b49f7808b2b7d9 Mon Sep 17 00:00:00 2001 From: Aanand Prasad Date: Fri, 3 Jul 2015 16:22:48 +0100 Subject: [PATCH] Merge pull request #1644 from aanand/fix-rm-bug Stop 'rm' and 'ps' listing services not defined in the current file (cherry picked from commit d85688892cb64128093db98d6f03d97ff8bd0e40) Signed-off-by: Aanand Prasad --- compose/project.py | 5 +++-- tests/integration/project_test.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/compose/project.py b/compose/project.py index 907632276d..7c78401e4a 100644 --- a/compose/project.py +++ b/compose/project.py @@ -286,6 +286,9 @@ class Project(object): def containers(self, service_names=None, stopped=False, one_off=False): if service_names: self.validate_service_names(service_names) + else: + service_names = self.service_names + containers = [ Container.from_ps(self.client, container) for container in self.client.containers( @@ -293,8 +296,6 @@ class Project(object): filters={'label': self.labels(one_off=one_off)})] def matches_service_names(container): - if not service_names: - return True return container.labels.get(LABEL_SERVICE) in service_names if not containers: diff --git a/tests/integration/project_test.py b/tests/integration/project_test.py index 2976af823b..314daf7180 100644 --- a/tests/integration/project_test.py +++ b/tests/integration/project_test.py @@ -29,6 +29,21 @@ class ProjectTest(DockerClientTestCase): [c.name for c in containers], ['composetest_web_1']) + def test_containers_with_extra_service(self): + web = self.create_service('web') + web_1 = web.create_container() + + db = self.create_service('db') + db_1 = db.create_container() + + self.create_service('extra').create_container() + + project = Project('composetest', [web, db], self.client) + self.assertEqual( + set(project.containers(stopped=True)), + set([web_1, db_1]), + ) + def test_volumes_from_service(self): service_dicts = config.from_dictionary({ 'data': {