From 51b92e9fa64baa3d362dd704ef064d042ef9541e Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Thu, 19 Nov 2020 11:21:57 -0500 Subject: [PATCH] API validation: Add cinder_host type to support ipv6 in manage This will fail due to overly restrictive regex validation: cinder manage hostgroup@cloud#[dead:beef::cafe]:/cinder01 abcd This is because validation for this call checks for a valid hostname but needs to check for any string that would be a valid "host" in Cinder, which is not the same thing. Closes-Bug: #1904892 Change-Id: I1349e8d3eb422f9dcd533c54f922f7ab8133b753 (cherry picked from commit 8687925ce7b0e8f707006394f762a8f0a2ee60f3) --- cinder/api/schemas/volume_manage.py | 2 +- cinder/api/validation/parameter_types.py | 12 ++++++++++++ cinder/tests/unit/api/contrib/test_volume_manage.py | 3 ++- ...bug-1904892-ipv6-nfs-manage-391118115dfaaf54.yaml | 7 +++++++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/bug-1904892-ipv6-nfs-manage-391118115dfaaf54.yaml diff --git a/cinder/api/schemas/volume_manage.py b/cinder/api/schemas/volume_manage.py index 544214c4944..858d8b95010 100644 --- a/cinder/api/schemas/volume_manage.py +++ b/cinder/api/schemas/volume_manage.py @@ -33,7 +33,7 @@ volume_manage_create = { "bootable": parameter_types.boolean, "volume_type": parameter_types.name_allow_zero_min_length, "name": parameter_types.name_allow_zero_min_length, - "host": parameter_types.hostname, + "host": parameter_types.cinder_host, "ref": {'type': ['object', 'string']}, "metadata": parameter_types.metadata_allows_null, }, diff --git a/cinder/api/validation/parameter_types.py b/cinder/api/validation/parameter_types.py index f174b58a7b0..6620ccbaeb9 100644 --- a/cinder/api/validation/parameter_types.py +++ b/cinder/api/validation/parameter_types.py @@ -232,6 +232,18 @@ hostname = { 'pattern': '^[a-zA-Z0-9-._#@:/+]*$' } +cinder_host = { + # A string that represents a cinder host. + # Examples: + # hostname + # hostname.domain + # hostname.domain@backend + # hostname.domain@backend#pool + # hostname.domain@backend#[dead:beef::cafe]:/complex_ipv6_pool_w_share + 'type': ['string', 'null'], 'minLength': 1, 'maxLength': 255, + 'pattern': r'^[a-zA-Z0-9-._#@:/+\[\]]*$' # hostname plus brackets +} + resource_type = {'type': ['string', 'null'], 'minLength': 0, 'maxLength': 40} diff --git a/cinder/tests/unit/api/contrib/test_volume_manage.py b/cinder/tests/unit/api/contrib/test_volume_manage.py index 47de0c558bb..c874cbadfa7 100644 --- a/cinder/tests/unit/api/contrib/test_volume_manage.py +++ b/cinder/tests/unit/api/contrib/test_volume_manage.py @@ -205,7 +205,8 @@ class VolumeManageTest(test.TestCase): @ddt.data({'host': 'host_ok'}, {'host': 'user@host#backend:/vol_path'}, - {'host': 'host@backend#parts+of+pool'}) + {'host': 'host@backend#parts+of+pool'}, + {'host': 'host@backend#[dead:beef::cafe]:/vol01'}) @ddt.unpack @mock.patch('cinder.volume.api.API.manage_existing', wraps=api_manage) def test_manage_volume_ok(self, mock_api_manage, host): diff --git a/releasenotes/notes/bug-1904892-ipv6-nfs-manage-391118115dfaaf54.yaml b/releasenotes/notes/bug-1904892-ipv6-nfs-manage-391118115dfaaf54.yaml new file mode 100644 index 00000000000..8fc2e89c51e --- /dev/null +++ b/releasenotes/notes/bug-1904892-ipv6-nfs-manage-391118115dfaaf54.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + `Bug #1904892 `_: + Fix cinder manage operations for NFS backends using IPv6 addresses + in the NFS server address. These were previously rejected by the + Cinder API.