Upgrade tests to use new Mounts in container inspect.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2015-10-02 19:04:39 -04:00 committed by Joffrey F
parent 4017ea99fe
commit 73de81b51c
5 changed files with 25 additions and 13 deletions

View File

@ -9,7 +9,7 @@ from ..const import HTTP_TIMEOUT
log = logging.getLogger(__name__)
DEFAULT_API_VERSION = '1.19'
DEFAULT_API_VERSION = '1.20'
def docker_client(version=None):

View File

@ -177,6 +177,12 @@ class Container(object):
port = self.ports.get("%s/%s" % (port, protocol))
return "{HostIp}:{HostPort}".format(**port[0]) if port else None
def get_mount(self, mount_dest):
for mount in self.get('Mounts'):
if mount['Destination'] == mount_dest:
return mount
return None
def start(self, **options):
return self.client.start(self.id, **options)

View File

@ -871,7 +871,7 @@ class CLITestCase(DockerClientTestCase):
self.dispatch(['up', '-d'], None)
container = self.project.containers(stopped=True)[0]
actual_host_path = container.get('Volumes')['/container-path']
actual_host_path = container.get_mount('/container-path')['Source']
components = actual_host_path.split('/')
assert components[-2:] == ['home-dir', 'my-volume']

View File

@ -331,15 +331,19 @@ class ProjectTest(DockerClientTestCase):
project.up(['db'])
self.assertEqual(len(project.containers()), 1)
old_db_id = project.containers()[0].id
db_volume_path = project.containers()[0].inspect()['Volumes']['/var/db']
container, = project.containers()
db_volume_path = container.get_mount('/var/db')['Source']
project.up(strategy=ConvergenceStrategy.never)
self.assertEqual(len(project.containers()), 2)
db_container = [c for c in project.containers() if 'db' in c.name][0]
self.assertEqual(db_container.id, old_db_id)
self.assertEqual(db_container.inspect()['Volumes']['/var/db'],
db_volume_path)
mount, = db_container.get('Mounts')
self.assertEqual(
db_container.get_mount('/var/db')['Source'],
db_volume_path)
def test_project_up_with_no_recreate_stopped(self):
web = self.create_service('web')
@ -354,8 +358,9 @@ class ProjectTest(DockerClientTestCase):
old_containers = project.containers(stopped=True)
self.assertEqual(len(old_containers), 1)
old_db_id = old_containers[0].id
db_volume_path = old_containers[0].inspect()['Volumes']['/var/db']
old_container, = old_containers
old_db_id = old_container.id
db_volume_path = old_container.get_mount('/var/db')['Source']
project.up(strategy=ConvergenceStrategy.never)
@ -365,8 +370,9 @@ class ProjectTest(DockerClientTestCase):
db_container = [c for c in new_containers if 'db' in c.name][0]
self.assertEqual(db_container.id, old_db_id)
self.assertEqual(db_container.inspect()['Volumes']['/var/db'],
db_volume_path)
self.assertEqual(
db_container.get_mount('/var/db')['Source'],
db_volume_path)
def test_project_up_without_all_services(self):
console = self.create_service('console')

View File

@ -18,12 +18,12 @@ class ResilienceTest(DockerClientTestCase):
container = self.db.create_container()
container.start()
self.host_path = container.get('Volumes')['/var/db']
self.host_path = container.get_mount('/var/db')['Source']
def test_successful_recreate(self):
self.project.up(strategy=ConvergenceStrategy.always)
container = self.db.containers()[0]
self.assertEqual(container.get('Volumes')['/var/db'], self.host_path)
self.assertEqual(container.get_mount('/var/db')['Source'], self.host_path)
def test_create_failure(self):
with mock.patch('compose.service.Service.create_container', crash):
@ -32,7 +32,7 @@ class ResilienceTest(DockerClientTestCase):
self.project.up()
container = self.db.containers()[0]
self.assertEqual(container.get('Volumes')['/var/db'], self.host_path)
self.assertEqual(container.get_mount('/var/db')['Source'], self.host_path)
def test_start_failure(self):
with mock.patch('compose.container.Container.start', crash):
@ -41,7 +41,7 @@ class ResilienceTest(DockerClientTestCase):
self.project.up()
container = self.db.containers()[0]
self.assertEqual(container.get('Volumes')['/var/db'], self.host_path)
self.assertEqual(container.get_mount('/var/db')['Source'], self.host_path)
class Crash(Exception):