From 96a92a73f1585deb6c936592d4602bf210109eed Mon Sep 17 00:00:00 2001 From: Mark Steve Samson Date: Tue, 4 Mar 2014 13:13:23 +0800 Subject: [PATCH 1/5] Fix KeyError when `-v` is not specified in `fig rm` --- fig/cli/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fig/cli/main.py b/fig/cli/main.py index e64769f03..178a61d0e 100644 --- a/fig/cli/main.py +++ b/fig/cli/main.py @@ -182,7 +182,7 @@ class TopLevelCommand(Command): print("Going to remove", list_containers(stopped_containers)) if yesno("Are you sure? [yN] ", default=False): self.project.remove_stopped(service_names=options['SERVICE'], - remove_volumes=options['-v']) + remove_volumes=options.get('-v', False)) else: print("No stopped containers") From 2ca0e7954a9208dce1bb501dd15972fbf7a7910d Mon Sep 17 00:00:00 2001 From: Ben Firshman Date: Tue, 4 Mar 2014 10:25:50 +0000 Subject: [PATCH 2/5] Add --force option to fig rm --- fig/cli/main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fig/cli/main.py b/fig/cli/main.py index 178a61d0e..668ef9e8a 100644 --- a/fig/cli/main.py +++ b/fig/cli/main.py @@ -170,17 +170,19 @@ class TopLevelCommand(Command): """ Remove stopped service containers. - Usage: rm [SERVICE...] + Usage: rm [options] [SERVICE...] Options: - -v Remove volumes associated with containers + --force Don't ask to confirm removal + -v Remove volumes associated with containers """ all_containers = self.project.containers(service_names=options['SERVICE'], stopped=True) stopped_containers = [c for c in all_containers if not c.is_running] if len(stopped_containers) > 0: print("Going to remove", list_containers(stopped_containers)) - if yesno("Are you sure? [yN] ", default=False): + if options.get('--force') \ + or yesno("Are you sure? [yN] ", default=False): self.project.remove_stopped(service_names=options['SERVICE'], remove_volumes=options.get('-v', False)) else: From 465c7d569ca1b5fb3ef4ddf1767e6c04c0ba8109 Mon Sep 17 00:00:00 2001 From: Ben Firshman Date: Tue, 4 Mar 2014 10:26:57 +0000 Subject: [PATCH 3/5] Improve CLI test names --- tests/cli_test.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/cli_test.py b/tests/cli_test.py index 61e30b7a2..c2040e633 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -32,7 +32,7 @@ class CLITestCase(DockerClientTestCase): self.assertIn('fig_simple_1', mock_stdout.getvalue()) @patch('sys.stdout', new_callable=StringIO) - def test_default_figfile(self, mock_stdout): + def test_ps_default_figfile(self, mock_stdout): self.command.base_dir = 'tests/fixtures/multiple-figfiles' self.command.dispatch(['up', '-d'], None) self.command.dispatch(['ps'], None) @@ -43,7 +43,7 @@ class CLITestCase(DockerClientTestCase): self.assertNotIn('fig_yetanother_1', output) @patch('sys.stdout', new_callable=StringIO) - def test_alternate_figfile(self, mock_stdout): + def test_ps_alternate_figfile(self, mock_stdout): self.command.base_dir = 'tests/fixtures/multiple-figfiles' self.command.dispatch(['-f', 'fig2.yml', 'up', '-d'], None) self.command.dispatch(['-f', 'fig2.yml', 'ps'], None) @@ -74,4 +74,3 @@ class CLITestCase(DockerClientTestCase): self.command.scale({'SERVICE=NUM': ['simple=0', 'another=0']}) self.assertEqual(len(project.get_service('simple').containers()), 0) self.assertEqual(len(project.get_service('another').containers()), 0) - From 044c348fafa63457548e886581c919df68b75762 Mon Sep 17 00:00:00 2001 From: Ben Firshman Date: Tue, 4 Mar 2014 10:49:07 +0000 Subject: [PATCH 4/5] Add test for fig rm --- tests/cli_test.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/cli_test.py b/tests/cli_test.py index c2040e633..2b81e26b0 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -53,6 +53,14 @@ class CLITestCase(DockerClientTestCase): self.assertNotIn('fig_another_1', output) self.assertIn('fig_yetanother_1', output) + def test_rm(self): + service = self.command.project.get_service('simple') + service.create_container() + service.kill() + self.assertEqual(len(service.containers(stopped=True)), 1) + self.command.dispatch(['rm', '--force'], None) + self.assertEqual(len(service.containers(stopped=True)), 0) + def test_scale(self): project = self.command.project From 5be8a37b7e14a0eaa37457751329ef4a7a0a2016 Mon Sep 17 00:00:00 2001 From: Ben Firshman Date: Tue, 4 Mar 2014 10:50:09 +0000 Subject: [PATCH 5/5] Pass through standard remove_container options --- fig/cli/main.py | 6 ++++-- fig/container.py | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fig/cli/main.py b/fig/cli/main.py index 668ef9e8a..4d65ce9e4 100644 --- a/fig/cli/main.py +++ b/fig/cli/main.py @@ -183,8 +183,10 @@ class TopLevelCommand(Command): print("Going to remove", list_containers(stopped_containers)) if options.get('--force') \ or yesno("Are you sure? [yN] ", default=False): - self.project.remove_stopped(service_names=options['SERVICE'], - remove_volumes=options.get('-v', False)) + self.project.remove_stopped( + service_names=options['SERVICE'], + v=options.get('-v', False) + ) else: print("No stopped containers") diff --git a/fig/container.py b/fig/container.py index a38828d0b..3b004b92e 100644 --- a/fig/container.py +++ b/fig/container.py @@ -112,8 +112,7 @@ class Container(object): return self.client.kill(self.id) def remove(self, **options): - v = options.get('remove_volumes', False) - return self.client.remove_container(self.id, v=v) + return self.client.remove_container(self.id, **options) def inspect_if_not_inspected(self): if not self.has_been_inspected: