From e824e8ba8d6a1352df44e393e3eef44b431086b0 Mon Sep 17 00:00:00 2001 From: Alyson Rosa Date: Thu, 2 Feb 2017 14:55:03 -0200 Subject: [PATCH] HNAS: Fix syntax to make shares read-only in snapshot create Fixing driver syntax to make NFS shares read-only while snapshots are being taken. Read/Write permission in HNAS can be added in 3 ways: rw, readwrite and read_write, all of them should be handled by the driver. Change-Id: Ib9ba3c1717c8000a5393ea7b8d731d66f7237b2e Closes-Bug: #1661271 --- manila/share/drivers/hitachi/hnas/driver.py | 4 +++- .../share/drivers/hitachi/hnas/test_driver.py | 22 ++++++++++++++++--- ...as-snapshot-readonly-4e50183100ed2b19.yaml | 5 +++++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/bug-1661271-hnas-snapshot-readonly-4e50183100ed2b19.yaml diff --git a/manila/share/drivers/hitachi/hnas/driver.py b/manila/share/drivers/hitachi/hnas/driver.py index 47da5bbc89..79d9d35302 100644 --- a/manila/share/drivers/hitachi/hnas/driver.py +++ b/manila/share/drivers/hitachi/hnas/driver.py @@ -969,7 +969,9 @@ class HitachiHNASDriver(driver.ShareDriver): saved_list = self.hnas.get_nfs_host_list(hnas_share_id) new_list = [] for access in saved_list: - new_list.append(access.replace('(rw)', '(ro)')) + for rw in ('read_write', 'readwrite', 'rw'): + access = access.replace(rw, 'ro') + new_list.append(access) self.hnas.update_nfs_access_rule(new_list, share_id=hnas_share_id) else: # CIFS if (self.hnas.is_cifs_in_use(hnas_share_id) and diff --git a/manila/tests/share/drivers/hitachi/hnas/test_driver.py b/manila/tests/share/drivers/hitachi/hnas/test_driver.py index 9ac864a425..9fd813a9e4 100644 --- a/manila/tests/share/drivers/hitachi/hnas/test_driver.py +++ b/manila/tests/share/drivers/hitachi/hnas/test_driver.py @@ -497,6 +497,22 @@ class HitachiHNASTestCase(test.TestCase): @ddt.data(snapshot_nfs, snapshot_cifs) def test_create_snapshot(self, snapshot): hnas_id = snapshot['share_id'] + access_list = ['172.24.44.200(rw,norootsquash)', + '172.24.49.180(all_squash,read_write,secure)', + '172.24.49.110(ro, secure)', + '172.24.49.112(secure,readwrite,norootsquash)', + '172.24.49.142(read_only, secure)', + '172.24.49.201(rw,read_write,readwrite)', + '172.24.49.218(rw)'] + + ro_list = ['172.24.44.200(ro,norootsquash)', + '172.24.49.180(all_squash,ro,secure)', + '172.24.49.110(ro, secure)', + '172.24.49.112(secure,ro,norootsquash)', + '172.24.49.142(read_only, secure)', + '172.24.49.201(ro,ro,ro)', + '172.24.49.218(ro)'] + export_locations = [ self._get_export( snapshot['id'], snapshot['share']['share_proto'], @@ -511,7 +527,7 @@ class HitachiHNASTestCase(test.TestCase): } self.mock_object(ssh.HNASSSHBackend, "get_nfs_host_list", mock.Mock( - return_value=['172.24.44.200(rw)'])) + return_value=access_list)) self.mock_object(ssh.HNASSSHBackend, "update_nfs_access_rule", mock.Mock()) self.mock_object(ssh.HNASSSHBackend, "is_cifs_in_use", mock.Mock( @@ -531,9 +547,9 @@ class HitachiHNASTestCase(test.TestCase): ssh.HNASSSHBackend.get_nfs_host_list.assert_called_once_with( hnas_id) ssh.HNASSSHBackend.update_nfs_access_rule.assert_any_call( - ['172.24.44.200(ro)'], share_id=hnas_id) + ro_list, share_id=hnas_id) ssh.HNASSSHBackend.update_nfs_access_rule.assert_any_call( - ['172.24.44.200(rw)'], share_id=hnas_id) + access_list, share_id=hnas_id) else: ssh.HNASSSHBackend.is_cifs_in_use.assert_called_once_with( hnas_id) diff --git a/releasenotes/notes/bug-1661271-hnas-snapshot-readonly-4e50183100ed2b19.yaml b/releasenotes/notes/bug-1661271-hnas-snapshot-readonly-4e50183100ed2b19.yaml new file mode 100644 index 0000000000..27495a90aa --- /dev/null +++ b/releasenotes/notes/bug-1661271-hnas-snapshot-readonly-4e50183100ed2b19.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - Fixed HNAS driver creating snapshots of NFS shares + without first changing it to read-only. +