Pick correct numbers for one off containers

This commit is contained in:
Ben Firshman 2013-12-20 12:55:45 +00:00
parent 15f12c6e2c
commit 326438b170
2 changed files with 9 additions and 3 deletions

View File

@ -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

View File

@ -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'})