From 326438b1706f62c74b703813d6fdd5ec0253b3ba Mon Sep 17 00:00:00 2001 From: Ben Firshman Date: Fri, 20 Dec 2013 12:55:45 +0000 Subject: [PATCH] Pick correct numbers for one off containers --- plum/service.py | 6 +++--- tests/service_test.py | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/plum/service.py b/plum/service.py index 8b829ace..6fab273b 100644 --- a/plum/service.py +++ b/plum/service.py @@ -108,10 +108,10 @@ class Service(object): bits = [self.project, self.name] if one_off: bits.append('run') - return '_'.join(bits + [unicode(self.next_container_number())]) + return '_'.join(bits + [unicode(self.next_container_number(one_off=one_off))]) - def next_container_number(self): - numbers = [parse_name(c.name)[2] for c in self.containers(stopped=True)] + def next_container_number(self, one_off=False): + numbers = [parse_name(c.name)[2] for c in self.containers(stopped=True, one_off=one_off)] if len(numbers) == 0: return 1 diff --git a/tests/service_test.py b/tests/service_test.py index c09e17e3..2fdfba7d 100644 --- a/tests/service_test.py +++ b/tests/service_test.py @@ -79,6 +79,12 @@ class ServiceTest(DockerClientTestCase): container = db.create_container(one_off=True) self.assertEqual(container.name, '/default_db_run_1') + def test_create_container_with_one_off_when_existing_container_is_running(self): + db = self.create_service('db') + db.start() + container = db.create_container(one_off=True) + self.assertEqual(container.name, '/default_db_run_1') + def test_start_container_passes_through_options(self): db = self.create_service('db') db.start_container(environment={'FOO': 'BAR'})