mirror of https://github.com/docker/compose.git
v2 custom volume name support
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
8c30971299
commit
22d9a258f4
|
@ -371,7 +371,8 @@
|
|||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"labels": {"$ref": "#/definitions/list_or_dict"}
|
||||
"labels": {"$ref": "#/definitions/list_or_dict"},
|
||||
"name": {"type": "string"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
|
|
|
@ -378,7 +378,8 @@
|
|||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"labels": {"$ref": "#/definitions/list_or_dict"}
|
||||
"labels": {"$ref": "#/definitions/list_or_dict"},
|
||||
"name": {"type": "string"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
|
|
|
@ -379,7 +379,8 @@
|
|||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"labels": {"$ref": "#/definitions/list_or_dict"}
|
||||
"labels": {"$ref": "#/definitions/list_or_dict"},
|
||||
"name": {"type": "string"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
|
|
|
@ -65,8 +65,11 @@ def denormalize_config(config, image_digests=None):
|
|||
if 'external_name' in conf:
|
||||
del conf['external_name']
|
||||
|
||||
if 'name' in conf and config.version < V3_4:
|
||||
del conf['name']
|
||||
if 'name' in conf:
|
||||
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
|
||||
|
||||
|
|
|
@ -291,10 +291,12 @@ class CLITestCase(DockerClientTestCase):
|
|||
assert 'volumes' in json_result
|
||||
assert json_result['volumes'] == {
|
||||
'foo': {
|
||||
'external': True
|
||||
'external': True,
|
||||
'name': 'foo',
|
||||
},
|
||||
'bar': {
|
||||
'external': {'name': 'some_bar'}
|
||||
'external': True,
|
||||
'name': 'some_bar',
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1412,7 +1412,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
'command': 'top'
|
||||
}],
|
||||
volumes={
|
||||
vol_name: {'external': True, 'external_name': vol_name}
|
||||
vol_name: {'external': True, 'name': vol_name}
|
||||
},
|
||||
)
|
||||
project = Project.from_config(
|
||||
|
@ -1436,7 +1436,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
'command': 'top'
|
||||
}],
|
||||
volumes={
|
||||
vol_name: {'external': True, 'external_name': vol_name}
|
||||
vol_name: {'external': True, 'name': vol_name}
|
||||
},
|
||||
)
|
||||
project = Project.from_config(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import six
|
||||
from docker.errors import DockerException
|
||||
|
||||
from .testcases import DockerClientTestCase
|
||||
|
@ -23,12 +24,15 @@ class VolumeTest(DockerClientTestCase):
|
|||
del self.tmp_volumes
|
||||
super(VolumeTest, self).tearDown()
|
||||
|
||||
def create_volume(self, name, driver=None, opts=None, external=None):
|
||||
if external and isinstance(external, bool):
|
||||
external = name
|
||||
def create_volume(self, name, driver=None, opts=None, external=None, custom_name=False):
|
||||
if external:
|
||||
custom_name = True
|
||||
if isinstance(external, six.text_type):
|
||||
name = external
|
||||
|
||||
vol = Volume(
|
||||
self.client, 'composetest', name, driver=driver, driver_opts=opts,
|
||||
external_name=external
|
||||
external=bool(external), custom_name=custom_name
|
||||
)
|
||||
self.tmp_volumes.append(vol)
|
||||
return vol
|
||||
|
@ -39,6 +43,13 @@ class VolumeTest(DockerClientTestCase):
|
|||
info = self.get_volume_data(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):
|
||||
vol = self.create_volume('volume01')
|
||||
|
||||
|
|
Loading…
Reference in New Issue