summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-06-20 02:54:52 +0000
committerGerrit Code Review <review@openstack.org>2015-06-20 02:54:52 +0000
commitaf00dc4d207f2b27f66cd7c68cc4f0005f255448 (patch)
tree6e36ba3374876d913b299ea048eadedcd1d48697
parent2b7c63487d27099c7940c4a5cd1010912d379d3a (diff)
parentc15aec017b2ebe666ccfee4cbe088bc723d3ede6 (diff)
Merge "Huawei manila driver support Read-Only share"
-rw-r--r--manila/share/drivers/huawei/constants.py5
-rw-r--r--manila/share/drivers/huawei/v3/connection.py37
-rw-r--r--manila/share/drivers/huawei/v3/helper.py7
-rw-r--r--manila/tests/share/drivers/huawei/test_huawei_nas.py133
4 files changed, 166 insertions, 16 deletions
diff --git a/manila/share/drivers/huawei/constants.py b/manila/share/drivers/huawei/constants.py
index 1e4ebd2..075ba02 100644
--- a/manila/share/drivers/huawei/constants.py
+++ b/manila/share/drivers/huawei/constants.py
@@ -21,3 +21,8 @@ DEFAULT_TIMEOUT = 60
21MSG_SNAPSHOT_NOT_FOUND = 1073754118 21MSG_SNAPSHOT_NOT_FOUND = 1073754118
22IP_ALLOCATIONS = 0 22IP_ALLOCATIONS = 0
23SOCKET_TIMEOUT = 720 23SOCKET_TIMEOUT = 720
24
25ACCESS_NFS_RW = "1"
26ACCESS_NFS_RO = "0"
27ACCESS_CIFS_RW = "5"
28ACCESS_CIFS_RO = "0"
diff --git a/manila/share/drivers/huawei/v3/connection.py b/manila/share/drivers/huawei/v3/connection.py
index e91a4f0..8dedaa8 100644
--- a/manila/share/drivers/huawei/v3/connection.py
+++ b/manila/share/drivers/huawei/v3/connection.py
@@ -18,6 +18,7 @@ import time
18from oslo_log import log 18from oslo_log import log
19from oslo_utils import units 19from oslo_utils import units
20 20
21from manila.common import constants as common_constants
21from manila import exception 22from manila import exception
22from manila.i18n import _, _LI, _LW 23from manila.i18n import _, _LI, _LW
23from manila.share.drivers.huawei import base as driver 24from manila.share.drivers.huawei import base as driver
@@ -295,14 +296,32 @@ class V3StorageConnection(driver.HuaweiBase):
295 share_name = share['name'] 296 share_name = share['name']
296 share_type = self.helper._get_share_type(share_proto) 297 share_type = self.helper._get_share_type(share_proto)
297 access_type = access['access_type'] 298 access_type = access['access_type']
298 if share_proto == 'NFS' and access_type != 'ip': 299 access_level = access['access_level']
299 message = _('Only IP access type is allowed for NFS shares.')
300 raise exception.InvalidShareAccess(reason=message)
301 elif share_proto == 'CIFS' and access_type != 'user':
302 message = _('Only USER access type is allowed for CIFS shares.')
303 raise exception.InvalidShareAccess(reason=message)
304 300
305 access_to = access['access_to'] 301 if access_level not in common_constants.ACCESS_LEVELS:
302 raise exception.InvalidShareAccess(
303 reason=(_('Unsupported level of access was provided - %s') %
304 access_level))
305
306 if share_proto == 'NFS':
307 if access_type == 'ip':
308 if access_level == common_constants.ACCESS_LEVEL_RW:
309 access_level = constants.ACCESS_NFS_RW
310 else:
311 access_level = constants.ACCESS_NFS_RO
312 else:
313 message = _('Only IP access type is allowed for NFS shares.')
314 raise exception.InvalidShareAccess(reason=message)
315 elif share_proto == 'CIFS':
316 if access_type == 'user':
317 if access_level == common_constants.ACCESS_LEVEL_RW:
318 access_level = constants.ACCESS_CIFS_RW
319 else:
320 access_level = constants.ACCESS_CIFS_RO
321 else:
322 message = _('Only USER access type is allowed'
323 ' for CIFS shares.')
324 raise exception.InvalidShareAccess(reason=message)
306 325
307 share = self.helper._get_share_by_name(share_name, share_type) 326 share = self.helper._get_share_by_name(share_name, share_type)
308 if not share: 327 if not share:
@@ -312,7 +331,9 @@ class V3StorageConnection(driver.HuaweiBase):
312 raise exception.InvalidShareAccess(reason=err_msg) 331 raise exception.InvalidShareAccess(reason=err_msg)
313 332
314 share_id = share['ID'] 333 share_id = share['ID']
315 self.helper._allow_access_rest(share_id, access_to, share_proto) 334 access_to = access['access_to']
335 self.helper._allow_access_rest(share_id, access_to,
336 share_proto, access_level)
316 337
317 def allocate_container(self, share): 338 def allocate_container(self, share):
318 """Creates filesystem associated to share by name.""" 339 """Creates filesystem associated to share by name."""
diff --git a/manila/share/drivers/huawei/v3/helper.py b/manila/share/drivers/huawei/v3/helper.py
index 4834130..721ce8d 100644
--- a/manila/share/drivers/huawei/v3/helper.py
+++ b/manila/share/drivers/huawei/v3/helper.py
@@ -366,7 +366,8 @@ class RestHelper(object):
366 if access_to == item['NAME']: 366 if access_to == item['NAME']:
367 return item['ID'] 367 return item['ID']
368 368
369 def _allow_access_rest(self, share_id, access_to, share_proto): 369 def _allow_access_rest(self, share_id, access_to,
370 share_proto, access_level):
370 """Allow access to the share.""" 371 """Allow access to the share."""
371 access_type = self._get_share_client_type(share_proto) 372 access_type = self._get_share_client_type(share_proto)
372 url = self.url + "/" + access_type 373 url = self.url + "/" + access_type
@@ -377,7 +378,7 @@ class RestHelper(object):
377 "TYPE": "16409", 378 "TYPE": "16409",
378 "NAME": access_to, 379 "NAME": access_to,
379 "PARENTID": share_id, 380 "PARENTID": share_id,
380 "ACCESSVAL": "1", 381 "ACCESSVAL": access_level,
381 "SYNC": "0", 382 "SYNC": "0",
382 "ALLSQUASH": "1", 383 "ALLSQUASH": "1",
383 "ROOTSQUASH": "0", 384 "ROOTSQUASH": "0",
@@ -386,7 +387,7 @@ class RestHelper(object):
386 access = { 387 access = {
387 "NAME": access_to, 388 "NAME": access_to,
388 "PARENTID": share_id, 389 "PARENTID": share_id,
389 "PERMISSION": "5", 390 "PERMISSION": access_level,
390 "DOMAINTYPE": "2", 391 "DOMAINTYPE": "2",
391 } 392 }
392 data = jsonutils.dumps(access) 393 data = jsonutils.dumps(access)
diff --git a/manila/tests/share/drivers/huawei/test_huawei_nas.py b/manila/tests/share/drivers/huawei/test_huawei_nas.py
index a0e127d..9043fe0 100644
--- a/manila/tests/share/drivers/huawei/test_huawei_nas.py
+++ b/manila/tests/share/drivers/huawei/test_huawei_nas.py
@@ -73,6 +73,51 @@ def filesystem(method, data, fs_status_flag):
73 return (data, extend_share_flag) 73 return (data, extend_share_flag)
74 74
75 75
76def allow_access(type, method, data):
77 allow_ro_flag = False
78 allow_rw_flag = False
79 access_nfs = {
80 "TYPE": "16409",
81 "NAME": "1.2.3.4",
82 "PARENTID": "1",
83 "ACCESSVAL": "0",
84 "SYNC": "0",
85 "ALLSQUASH": "1",
86 "ROOTSQUASH": "0",
87 }
88 access_nfs_ro_data = jsonutils.dumps(access_nfs)
89 access_nfs["NAME"] = "100.112.0.1"
90 access_nfs["ACCESSVAL"] = "1"
91 access_nfs_rw_data = jsonutils.dumps(access_nfs)
92
93 access_cifs = {
94 "NAME": "user_name",
95 "PARENTID": "2",
96 "PERMISSION": "0",
97 "DOMAINTYPE": "2",
98 }
99 access_cifs_ro_data = jsonutils.dumps(access_cifs)
100
101 access_cifs["PERMISSION"] = "5"
102 access_cifs_rw_data = jsonutils.dumps(access_cifs)
103
104 if method != "POST":
105 data = """{"error":{"code":31755596}}"""
106 return data
107
108 if ((data == access_nfs_ro_data and type == "NFS")
109 or (data == access_cifs_ro_data and type == "CIFS")):
110 allow_ro_flag = True
111 data = """{"error":{"code":0}}"""
112 elif ((data == access_nfs_rw_data and type == 'NFS')
113 or (data == access_cifs_rw_data and type == 'CIFS')):
114 allow_rw_flag = True
115 data = """{"error":{"code":0}}"""
116 else:
117 data = """{"error":{"code":31755596}}"""
118 return (data, allow_ro_flag, allow_rw_flag)
119
120
76class FakeHuaweiNasHelper(helper.RestHelper): 121class FakeHuaweiNasHelper(helper.RestHelper):
77 122
78 def __init__(self, *args, **kwargs): 123 def __init__(self, *args, **kwargs):
@@ -91,6 +136,8 @@ class FakeHuaweiNasHelper(helper.RestHelper):
91 self.share_exist = True 136 self.share_exist = True
92 self.service_nfs_status_flag = True 137 self.service_nfs_status_flag = True
93 self.create_share_data_flag = False 138 self.create_share_data_flag = False
139 self.allow_ro_flag = False
140 self.allow_rw_flag = False
94 self.extend_share_flag = False 141 self.extend_share_flag = False
95 142
96 def _change_file_mode(self, filepath): 143 def _change_file_mode(self, filepath):
@@ -179,9 +226,14 @@ class FakeHuaweiNasHelper(helper.RestHelper):
179 data = """{"error":{"code":0}}""" 226 data = """{"error":{"code":0}}"""
180 self.delete_flag = True 227 self.delete_flag = True
181 228
182 if url == "NFS_SHARE_AUTH_CLIENT"\ 229 if url == "NFS_SHARE_AUTH_CLIENT":
183 or url == "CIFS_SHARE_AUTH_CLIENT": 230 data, self.allow_ro_flag, self.allow_rw_flag = \
184 data = """{"error":{"code":0}}""" 231 allow_access('NFS', method, data)
232 self.allow_flag = True
233
234 if url == "CIFS_SHARE_AUTH_CLIENT":
235 data, self.allow_ro_flag, self.allow_rw_flag = \
236 allow_access('CIFS', method, data)
185 self.allow_flag = True 237 self.allow_flag = True
186 238
187 if url == "FSSNAPSHOT?TYPE=48&PARENTID=4"\ 239 if url == "FSSNAPSHOT?TYPE=48&PARENTID=4"\
@@ -327,6 +379,17 @@ class HuaweiShareDriverTestCase(test.TestCase):
327 'share_server_id': 'fake-share-srv-id', 379 'share_server_id': 'fake-share-srv-id',
328 } 380 }
329 381
382 self.share_proto_fail = {
383 'id': 'fake_uuid',
384 'project_id': 'fake_tenant_id',
385 'display_name': 'fake',
386 'name': 'share-fake-uuid',
387 'size': 1,
388 'share_proto': 'proto_fail',
389 'share_network_id': 'fake_net_id',
390 'share_server_id': 'fake-share-srv-id',
391 }
392
330 self.share_cifs = { 393 self.share_cifs = {
331 'id': 'fake_uuid', 394 'id': 'fake_uuid',
332 'project_id': 'fake_tenant_id', 395 'project_id': 'fake_tenant_id',
@@ -371,11 +434,13 @@ class HuaweiShareDriverTestCase(test.TestCase):
371 self.access_ip = { 434 self.access_ip = {
372 'access_type': 'ip', 435 'access_type': 'ip',
373 'access_to': '100.112.0.1', 436 'access_to': '100.112.0.1',
437 'access_level': 'rw',
374 } 438 }
375 439
376 self.access_user = { 440 self.access_user = {
377 'access_type': 'user', 441 'access_type': 'user',
378 'access_to': 'user_name', 442 'access_to': 'user_name',
443 'access_level': 'rw',
379 } 444 }
380 445
381 self.share_server = None 446 self.share_server = None
@@ -677,21 +742,79 @@ class HuaweiShareDriverTestCase(test.TestCase):
677 self.assertEqual(2, capacity['TOTALCAPACITY']) 742 self.assertEqual(2, capacity['TOTALCAPACITY'])
678 self.assertEqual(1, capacity['CAPACITY']) 743 self.assertEqual(1, capacity['CAPACITY'])
679 744
680 def test_allow_access_ip_success(self): 745 def test_allow_access_proto_fail(self):
746 self.driver.plugin.helper.login()
747 self.assertRaises(exception.InvalidInput,
748 self.driver.allow_access,
749 self._context,
750 self.share_proto_fail,
751 self.access_ip,
752 self.share_server)
753
754 def test_allow_access_ip_rw_success(self):
681 self.driver.plugin.helper.login() 755 self.driver.plugin.helper.login()
682 self.allow_flag = False 756 self.allow_flag = False
757 self.allow_rw_flag = False
683 self.driver.allow_access(self._context, 758 self.driver.allow_access(self._context,
684 self.share_nfs, 759 self.share_nfs,
685 self.access_ip, 760 self.access_ip,
686 self.share_server) 761 self.share_server)
687 self.assertTrue(self.driver.plugin.helper.allow_flag) 762 self.assertTrue(self.driver.plugin.helper.allow_flag)
763 self.assertTrue(self.driver.plugin.helper.allow_rw_flag)
764
765 def test_allow_access_ip_ro_success(self):
766 access_ro = {
767 'access_type': 'ip',
768 'access_to': '1.2.3.4',
769 'access_level': 'ro',
770 }
771
772 self.driver.plugin.helper.login()
773 self.allow_flag = False
774 self.allow_ro_flag = False
775 self.driver.allow_access(self._context,
776 self.share_nfs,
777 access_ro,
778 self.share_server)
779 self.assertTrue(self.driver.plugin.helper.allow_flag)
780 self.assertTrue(self.driver.plugin.helper.allow_ro_flag)
688 781
689 def test_allow_access_user_success(self): 782 def test_allow_access_user_rw_success(self):
690 self.driver.plugin.helper.login() 783 self.driver.plugin.helper.login()
691 self.allow_flag = False 784 self.allow_flag = False
785 self.allow_rw_flag = False
692 self.driver.allow_access(self._context, self.share_cifs, 786 self.driver.allow_access(self._context, self.share_cifs,
693 self.access_user, self.share_server) 787 self.access_user, self.share_server)
694 self.assertTrue(self.driver.plugin.helper.allow_flag) 788 self.assertTrue(self.driver.plugin.helper.allow_flag)
789 self.assertTrue(self.driver.plugin.helper.allow_rw_flag)
790
791 def test_allow_access_user_ro_success(self):
792 access_ro = {
793 'access_type': 'user',
794 'access_to': 'user_name',
795 'access_level': 'ro',
796 }
797
798 self.driver.plugin.helper.login()
799 self.allow_flag = False
800 self.allow_ro_flag = False
801 self.driver.allow_access(self._context, self.share_cifs,
802 access_ro, self.share_server)
803 self.assertTrue(self.driver.plugin.helper.allow_flag)
804 self.assertTrue(self.driver.plugin.helper.allow_ro_flag)
805
806 def test_allow_access_level_fail(self):
807 access_fail = {
808 'access_type': 'user',
809 'access_to': 'user_name',
810 'access_level': 'fail',
811 }
812
813 self.driver.plugin.helper.login()
814 self.assertRaises(exception.InvalidShareAccess,
815 self.driver.allow_access,
816 self._context, self.share_cifs,
817 access_fail, self.share_server)
695 818
696 def test_get_share_client_type_fail(self): 819 def test_get_share_client_type_fail(self):
697 share_proto = 'fake_proto' 820 share_proto = 'fake_proto'