Skip to content

Commit 4e7a973

Browse files
committed
Don't raise exception on inexistent services in 'down' command
When running 'podman-compose down <service>', if service is not part of the compose, a KeyError exception was raised it function 'get_excluded'. By only allowing evaluation of services that exist in the compose provides a cleaner and gentler exit for this case.
1 parent 84f1fbd commit 4e7a973

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

podman_compose.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,8 @@ def get_excluded(compose, args):
26002600
if args.services:
26012601
excluded = set(compose.services)
26022602
for service in args.services:
2603-
excluded -= set(x.name for x in compose.services[service]["_deps"])
2603+
if service in compose.services:
2604+
excluded -= set(x.name for x in compose.services[service]["_deps"])
26042605
excluded.discard(service)
26052606
log.debug("** excluding: %s", excluded)
26062607
return excluded

tests/integration/test_podman_compose_up_down.py

+18
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,21 @@ def test_up(self, profiles, expected_services):
8989
actual_services[service] = service in actual_output
9090

9191
self.assertEqual(expected_services, actual_services)
92+
93+
def test_down_inexistent_service(self):
94+
try:
95+
up_cmd = [
96+
podman_compose_path(), "-f", profile_compose_file(), "up", "-d"
97+
]
98+
self.run_subprocess_assert_returncode(up_cmd)
99+
finally:
100+
# run the test case
101+
down_cmd = [
102+
podman_compose_path(),
103+
"-f",
104+
profile_compose_file(),
105+
"down",
106+
"inexistent_service"
107+
]
108+
# This run should succeed
109+
self.run_subprocess_assert_returncode(down_cmd)

0 commit comments

Comments
 (0)