v2 custom volume name support

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2017-08-10 12:09:05 -07:00 committed by Joffrey F
parent 8c30971299
commit 22d9a258f4
7 changed files with 32 additions and 13 deletions

View File

@ -371,7 +371,8 @@
}, },
"additionalProperties": false "additionalProperties": false
}, },
"labels": {"$ref": "#/definitions/list_or_dict"} "labels": {"$ref": "#/definitions/list_or_dict"},
"name": {"type": "string"}
}, },
"additionalProperties": false "additionalProperties": false
}, },

View File

@ -378,7 +378,8 @@
}, },
"additionalProperties": false "additionalProperties": false
}, },
"labels": {"$ref": "#/definitions/list_or_dict"} "labels": {"$ref": "#/definitions/list_or_dict"},
"name": {"type": "string"}
}, },
"additionalProperties": false "additionalProperties": false
}, },

View File

@ -379,7 +379,8 @@
}, },
"additionalProperties": false "additionalProperties": false
}, },
"labels": {"$ref": "#/definitions/list_or_dict"} "labels": {"$ref": "#/definitions/list_or_dict"},
"name": {"type": "string"}
}, },
"additionalProperties": false "additionalProperties": false
}, },

View File

@ -65,8 +65,11 @@ def denormalize_config(config, image_digests=None):
if 'external_name' in conf: if 'external_name' in conf:
del conf['external_name'] del conf['external_name']
if 'name' in conf and config.version < V3_4: if 'name' in conf:
del conf['name'] if config.version < V2_1 or (config.version > V3_0 and config.version < V3_4):
del conf['name']
elif 'external' in conf:
conf['external'] = True
return result return result

View File

@ -291,10 +291,12 @@ class CLITestCase(DockerClientTestCase):
assert 'volumes' in json_result assert 'volumes' in json_result
assert json_result['volumes'] == { assert json_result['volumes'] == {
'foo': { 'foo': {
'external': True 'external': True,
'name': 'foo',
}, },
'bar': { 'bar': {
'external': {'name': 'some_bar'} 'external': True,
'name': 'some_bar',
} }
} }

View File

@ -1412,7 +1412,7 @@ class ProjectTest(DockerClientTestCase):
'command': 'top' 'command': 'top'
}], }],
volumes={ volumes={
vol_name: {'external': True, 'external_name': vol_name} vol_name: {'external': True, 'name': vol_name}
}, },
) )
project = Project.from_config( project = Project.from_config(
@ -1436,7 +1436,7 @@ class ProjectTest(DockerClientTestCase):
'command': 'top' 'command': 'top'
}], }],
volumes={ volumes={
vol_name: {'external': True, 'external_name': vol_name} vol_name: {'external': True, 'name': vol_name}
}, },
) )
project = Project.from_config( project = Project.from_config(

View File

@ -1,6 +1,7 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import unicode_literals from __future__ import unicode_literals
import six
from docker.errors import DockerException from docker.errors import DockerException
from .testcases import DockerClientTestCase from .testcases import DockerClientTestCase
@ -23,12 +24,15 @@ class VolumeTest(DockerClientTestCase):
del self.tmp_volumes del self.tmp_volumes
super(VolumeTest, self).tearDown() super(VolumeTest, self).tearDown()
def create_volume(self, name, driver=None, opts=None, external=None): def create_volume(self, name, driver=None, opts=None, external=None, custom_name=False):
if external and isinstance(external, bool): if external:
external = name custom_name = True
if isinstance(external, six.text_type):
name = external
vol = Volume( vol = Volume(
self.client, 'composetest', name, driver=driver, driver_opts=opts, self.client, 'composetest', name, driver=driver, driver_opts=opts,
external_name=external external=bool(external), custom_name=custom_name
) )
self.tmp_volumes.append(vol) self.tmp_volumes.append(vol)
return vol return vol
@ -39,6 +43,13 @@ class VolumeTest(DockerClientTestCase):
info = self.get_volume_data(vol.full_name) info = self.get_volume_data(vol.full_name)
assert info['Name'].split('/')[-1] == vol.full_name assert info['Name'].split('/')[-1] == vol.full_name
def test_create_volume_custom_name(self):
vol = self.create_volume('volume01', custom_name=True)
assert vol.name == vol.full_name
vol.create()
info = self.get_volume_data(vol.full_name)
assert info['Name'].split('/')[-1] == vol.name
def test_recreate_existing_volume(self): def test_recreate_existing_volume(self):
vol = self.create_volume('volume01') vol = self.create_volume('volume01')