瀏覽代碼

v2 custom volume name support

Signed-off-by: Joffrey F <[email protected]>
Joffrey F 8 年之前
父節點
當前提交
41a5a4a321

+ 2 - 1
compose/config/config_schema_v2.1.json

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

+ 2 - 1
compose/config/config_schema_v2.2.json

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

+ 2 - 1
compose/config/config_schema_v2.3.json

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

+ 5 - 2
compose/config/serialize.py

@@ -66,8 +66,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
 

+ 4 - 2
tests/acceptance/cli_test.py

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

+ 2 - 2
tests/integration/project_test.py

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

+ 15 - 4
tests/integration/volume_test.py

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