Shared filesystem management project for OpenStack.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_qnap.py 66KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588
  1. # Copyright (c) 2016 QNAP Systems, Inc.
  2. # All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. try:
  16. import xml.etree.cElementTree as ET
  17. except ImportError:
  18. import xml.etree.ElementTree as ET
  19. import ddt
  20. import mock
  21. from oslo_config import cfg
  22. import six
  23. import time
  24. from eventlet import greenthread
  25. from manila import exception
  26. from manila.share.drivers.qnap import api
  27. from manila.share.drivers.qnap import qnap
  28. from manila.share import share_types
  29. from manila import test
  30. from manila.tests import fake_share
  31. from manila.tests.share.drivers.qnap import fakes
  32. CONF = cfg.CONF
  33. def create_configuration(management_url, qnap_share_ip, qnap_nas_login,
  34. qnap_nas_password, qnap_poolname):
  35. """Create configuration."""
  36. configuration = mock.Mock()
  37. configuration.qnap_management_url = management_url
  38. configuration.qnap_share_ip = qnap_share_ip
  39. configuration.qnap_nas_login = qnap_nas_login
  40. configuration.qnap_nas_password = qnap_nas_password
  41. configuration.qnap_poolname = qnap_poolname
  42. configuration.safe_get.return_value = False
  43. return configuration
  44. class QnapShareDriverBaseTestCase(test.TestCase):
  45. """Base Class for the QnapShareDriver Tests."""
  46. def setUp(self):
  47. """Setup the Qnap Driver Base TestCase."""
  48. super(QnapShareDriverBaseTestCase, self).setUp()
  49. self.driver = None
  50. self.share_api = None
  51. def _do_setup(self, management_url, share_ip, nas_login,
  52. nas_password, poolname, **kwargs):
  53. """Config do setup configurations."""
  54. self.driver = qnap.QnapShareDriver(
  55. configuration=create_configuration(
  56. management_url,
  57. share_ip,
  58. nas_login,
  59. nas_password,
  60. poolname),
  61. private_storage=kwargs.get('private_storage'))
  62. self.driver.do_setup('context')
  63. @ddt.ddt
  64. class QnapShareDriverLoginTestCase(QnapShareDriverBaseTestCase):
  65. """Tests do_setup api."""
  66. def setUp(self):
  67. """Setup the Qnap Share Driver login TestCase."""
  68. super(QnapShareDriverLoginTestCase, self).setUp()
  69. self.mock_object(six.moves.http_client, 'HTTPConnection')
  70. self.mock_object(six.moves.http_client, 'HTTPSConnection')
  71. @ddt.unpack
  72. @ddt.data({'mng_url': 'http://1.2.3.4:8080', 'port': '8080', 'ssl': False},
  73. {'mng_url': 'https://1.2.3.4:443', 'port': '443', 'ssl': True})
  74. def test_do_setup_positive(self, mng_url, port, ssl):
  75. """Test do_setup with http://1.2.3.4:8080."""
  76. fake_login_response = fakes.FakeLoginResponse()
  77. fake_get_basic_info_response_es = (
  78. fakes.FakeGetBasicInfoResponseEs_1_1_3())
  79. if ssl:
  80. mock_connection = six.moves.http_client.HTTPSConnection
  81. else:
  82. mock_connection = six.moves.http_client.HTTPConnection
  83. mock_connection.return_value.getresponse.side_effect = [
  84. fake_login_response,
  85. fake_get_basic_info_response_es,
  86. fake_login_response]
  87. self._do_setup(mng_url, '1.2.3.4', 'admin',
  88. 'qnapadmin', 'Storage Pool 1')
  89. self.assertEqual(
  90. mng_url,
  91. self.driver.configuration.qnap_management_url)
  92. self.assertEqual(
  93. '1.2.3.4', self.driver.configuration.qnap_share_ip)
  94. self.assertEqual(
  95. 'admin', self.driver.configuration.qnap_nas_login)
  96. self.assertEqual(
  97. 'qnapadmin', self.driver.configuration.qnap_nas_password)
  98. self.assertEqual(
  99. 'Storage Pool 1', self.driver.configuration.qnap_poolname)
  100. self.assertEqual('fakeSid', self.driver.api_executor.sid)
  101. self.assertEqual('admin', self.driver.api_executor.username)
  102. self.assertEqual('qnapadmin', self.driver.api_executor.password)
  103. self.assertEqual('1.2.3.4', self.driver.api_executor.ip)
  104. self.assertEqual(port, self.driver.api_executor.port)
  105. self.assertEqual(ssl, self.driver.api_executor.ssl)
  106. @ddt.data(fakes.FakeGetBasicInfoResponseTs_4_3_0(),
  107. fakes.FakeGetBasicInfoResponseTesTs_4_3_0(),
  108. fakes.FakeGetBasicInfoResponseTesEs_1_1_3())
  109. def test_do_setup_positive_with_diff_nas(self, fake_basic_info):
  110. """Test do_setup with different NAS model."""
  111. fake_login_response = fakes.FakeLoginResponse()
  112. mock_connection = six.moves.http_client.HTTPSConnection
  113. mock_connection.return_value.getresponse.side_effect = [
  114. fake_login_response,
  115. fake_basic_info,
  116. fake_login_response]
  117. self._do_setup('https://1.2.3.4:443', '1.2.3.4', 'admin',
  118. 'qnapadmin', 'Storage Pool 1')
  119. self.assertEqual('fakeSid', self.driver.api_executor.sid)
  120. self.assertEqual('admin', self.driver.api_executor.username)
  121. self.assertEqual('qnapadmin', self.driver.api_executor.password)
  122. self.assertEqual('1.2.3.4', self.driver.api_executor.ip)
  123. self.assertEqual('443', self.driver.api_executor.port)
  124. self.assertTrue(self.driver.api_executor.ssl)
  125. @ddt.data({
  126. 'fake_basic_info': fakes.FakeGetBasicInfoResponseTs_4_3_0(),
  127. 'expect_result': api.QnapAPIExecutorTS
  128. }, {
  129. 'fake_basic_info': fakes.FakeGetBasicInfoResponseTesTs_4_3_0(),
  130. 'expect_result': api.QnapAPIExecutorTS
  131. }, {
  132. 'fake_basic_info': fakes.FakeGetBasicInfoResponseTesEs_1_1_3(),
  133. 'expect_result': api.QnapAPIExecutor
  134. }, {
  135. 'fake_basic_info': fakes.FakeGetBasicInfoResponseTesEs_2_0_0(),
  136. 'expect_result': api.QnapAPIExecutor
  137. }, {
  138. 'fake_basic_info': fakes.FakeGetBasicInfoResponseTesEs_2_1_0(),
  139. 'expect_result': api.QnapAPIExecutor
  140. }, {
  141. 'fake_basic_info': fakes.FakeGetBasicInfoResponseTdsTs_4_3_0(),
  142. 'expect_result': api.QnapAPIExecutorTS
  143. }, {
  144. 'fake_basic_info': fakes.FakeGetBasicInfoResponseTdsEs_2_1_0(),
  145. 'expect_result': api.QnapAPIExecutor
  146. }, {
  147. 'fake_basic_info': fakes.FakeGetBasicInfoResponseEs_1_1_3(),
  148. 'expect_result': api.QnapAPIExecutor
  149. }, {
  150. 'fake_basic_info': fakes.FakeGetBasicInfoResponseEs_2_0_0(),
  151. 'expect_result': api.QnapAPIExecutor
  152. }, {
  153. 'fake_basic_info': fakes.FakeGetBasicInfoResponseEs_2_1_0(),
  154. 'expect_result': api.QnapAPIExecutor
  155. })
  156. @ddt.unpack
  157. def test_create_api_executor(self, fake_basic_info, expect_result):
  158. """Test do_setup with different NAS model."""
  159. fake_login_response = fakes.FakeLoginResponse()
  160. mock_connection = six.moves.http_client.HTTPSConnection
  161. mock_connection.return_value.getresponse.side_effect = [
  162. fake_login_response,
  163. fake_basic_info,
  164. fake_login_response]
  165. self._do_setup('https://1.2.3.4:443', '1.2.3.4', 'admin',
  166. 'qnapadmin', 'Storage Pool 1')
  167. self.assertIsInstance(self.driver.api_executor, expect_result)
  168. @ddt.data({
  169. 'fake_basic_info': fakes.FakeGetBasicInfoResponseTs_4_0_0(),
  170. 'expect_result': exception.ShareBackendException
  171. }, {
  172. 'fake_basic_info': fakes.FakeGetBasicInfoResponseTesTs_4_0_0(),
  173. 'expect_result': exception.ShareBackendException
  174. }, {
  175. 'fake_basic_info': fakes.FakeGetBasicInfoResponseTesEs_1_1_1(),
  176. 'expect_result': exception.ShareBackendException
  177. }, {
  178. 'fake_basic_info': fakes.FakeGetBasicInfoResponseTesEs_2_2_0(),
  179. 'expect_result': exception.ShareBackendException
  180. }, {
  181. 'fake_basic_info': fakes.FakeGetBasicInfoResponseTdsTs_4_0_0(),
  182. 'expect_result': exception.ShareBackendException
  183. }, {
  184. 'fake_basic_info': fakes.FakeGetBasicInfoResponseTdsEs_1_1_1(),
  185. 'expect_result': exception.ShareBackendException
  186. }, {
  187. 'fake_basic_info': fakes.FakeGetBasicInfoResponseTdsEs_2_2_0(),
  188. 'expect_result': exception.ShareBackendException
  189. }, {
  190. 'fake_basic_info': fakes.FakeGetBasicInfoResponseEs_1_1_1(),
  191. 'expect_result': exception.ShareBackendException
  192. }, {
  193. 'fake_basic_info': fakes.FakeGetBasicInfoResponseEs_2_2_0(),
  194. 'expect_result': exception.ShareBackendException
  195. })
  196. @ddt.unpack
  197. def test_create_api_executor_negative(self,
  198. fake_basic_info, expect_result):
  199. """Test do_setup with different NAS model."""
  200. fake_login_response = fakes.FakeLoginResponse()
  201. mock_connection = six.moves.http_client.HTTPSConnection
  202. mock_connection.return_value.getresponse.side_effect = [
  203. fake_login_response,
  204. fake_basic_info,
  205. fake_login_response]
  206. self.assertRaises(
  207. exception.ShareBackendException,
  208. self._do_setup,
  209. 'https://1.2.3.4:443',
  210. '1.2.3.4',
  211. 'admin',
  212. 'qnapadmin',
  213. 'Storage Pool 1')
  214. def test_do_setup_with_exception(self):
  215. """Test do_setup with exception."""
  216. fake_login_response = fakes.FakeLoginResponse()
  217. fake_get_basic_info_response_error = (
  218. fakes.FakeGetBasicInfoResponseError())
  219. mock_connection = six.moves.http_client.HTTPSConnection
  220. mock_connection.return_value.getresponse.side_effect = [
  221. fake_login_response,
  222. fake_get_basic_info_response_error,
  223. fake_login_response]
  224. self.driver = qnap.QnapShareDriver(
  225. configuration=create_configuration(
  226. 'https://1.2.3.4:443', '1.2.3.4', 'admin',
  227. 'qnapadmin', 'Pool1'))
  228. self.assertRaises(
  229. exception.ShareBackendException,
  230. self.driver.do_setup,
  231. context='context')
  232. def test_check_for_setup_error(self):
  233. """Test do_setup with exception."""
  234. self.driver = qnap.QnapShareDriver(
  235. configuration=create_configuration(
  236. 'https://1.2.3.4:443', '1.2.3.4', 'admin',
  237. 'qnapadmin', 'Pool1'))
  238. self.assertRaises(
  239. exception.ShareBackendException,
  240. self.driver.check_for_setup_error)
  241. @ddt.ddt
  242. class QnapShareDriverTestCase(QnapShareDriverBaseTestCase):
  243. """Tests share driver functions."""
  244. def setUp(self):
  245. """Setup the Qnap Driver Base TestCase."""
  246. super(QnapShareDriverTestCase, self).setUp()
  247. self.mock_object(qnap.QnapShareDriver, '_create_api_executor')
  248. self.share = fake_share.fake_share(
  249. share_proto='NFS',
  250. id='shareId',
  251. display_name='fakeDisplayName',
  252. export_locations=[{'path': '1.2.3.4:/share/fakeShareName'}],
  253. host='QnapShareDriver',
  254. size=10)
  255. def get_share_info_return_value(self):
  256. """Return the share info form get_share_info method."""
  257. root = ET.fromstring(fakes.FAKE_RES_DETAIL_DATA_SHARE_INFO)
  258. share_list = root.find('Volume_Info')
  259. share_info_tree = share_list.findall('row')
  260. for share in share_info_tree:
  261. return share
  262. def get_snapshot_info_return_value(self):
  263. """Return the snapshot info form get_snapshot_info method."""
  264. root = ET.fromstring(fakes.FAKE_RES_DETAIL_DATA_SNAPSHOT)
  265. snapshot_list = root.find('SnapshotList')
  266. snapshot_info_tree = snapshot_list.findall('row')
  267. for snapshot in snapshot_info_tree:
  268. return snapshot
  269. def get_specific_volinfo_return_value(self):
  270. """Return the volume info form get_specific_volinfo method."""
  271. root = ET.fromstring(fakes.FAKE_RES_DETAIL_DATA_VOLUME_INFO)
  272. volume_list = root.find('Volume_Info')
  273. volume_info_tree = volume_list.findall('row')
  274. for volume in volume_info_tree:
  275. return volume
  276. def get_specific_poolinfo_return_value(self):
  277. """Get specific pool info."""
  278. root = ET.fromstring(fakes.FAKE_RES_DETAIL_DATA_SPECIFIC_POOL_INFO)
  279. pool_list = root.find('Pool_Index')
  280. pool_info_tree = pool_list.findall('row')
  281. for pool in pool_info_tree:
  282. return pool
  283. def get_host_list_return_value(self):
  284. """Get host list."""
  285. root = ET.fromstring(fakes.FAKE_RES_DETAIL_DATA_GET_HOST_LIST)
  286. hosts = []
  287. host_list = root.find('host_list')
  288. host_tree = host_list.findall('host')
  289. for host in host_tree:
  290. hosts.append(host)
  291. return hosts
  292. @ddt.data({
  293. 'fake_extra_spec': {},
  294. 'expect_extra_spec': {
  295. 'qnap_thin_provision': True,
  296. 'qnap_compression': True,
  297. 'qnap_deduplication': False,
  298. 'qnap_ssd_cache': False
  299. }
  300. }, {
  301. 'fake_extra_spec': {
  302. 'thin_provisioning': u'true',
  303. 'compression': u'true',
  304. 'qnap_ssd_cache': u'true'
  305. },
  306. 'expect_extra_spec': {
  307. 'qnap_thin_provision': True,
  308. 'qnap_compression': True,
  309. 'qnap_deduplication': False,
  310. 'qnap_ssd_cache': True
  311. }
  312. }, {
  313. 'fake_extra_spec': {
  314. 'thin_provisioning': u'<is> False',
  315. 'compression': u'<is> True',
  316. 'qnap_ssd_cache': u'<is> True'
  317. },
  318. 'expect_extra_spec': {
  319. 'qnap_thin_provision': False,
  320. 'qnap_compression': True,
  321. 'qnap_deduplication': False,
  322. 'qnap_ssd_cache': True
  323. }
  324. }, {
  325. 'fake_extra_spec': {
  326. 'thin_provisioning': u'true',
  327. 'dedupe': u'<is> True',
  328. 'qnap_ssd_cache': u'False'
  329. },
  330. 'expect_extra_spec': {
  331. 'qnap_thin_provision': True,
  332. 'qnap_compression': True,
  333. 'qnap_deduplication': True,
  334. 'qnap_ssd_cache': False
  335. }
  336. }, {
  337. 'fake_extra_spec': {
  338. 'thin_provisioning': u'<is> False',
  339. 'compression': u'false',
  340. 'dedupe': u'<is> False',
  341. 'qnap_ssd_cache': u'<is> False'
  342. },
  343. 'expect_extra_spec': {
  344. 'qnap_thin_provision': False,
  345. 'qnap_compression': False,
  346. 'qnap_deduplication': False,
  347. 'qnap_ssd_cache': False
  348. }
  349. })
  350. @ddt.unpack
  351. @mock.patch.object(qnap.QnapShareDriver, '_get_location_path')
  352. @mock.patch.object(qnap.QnapShareDriver, '_gen_random_name')
  353. def test_create_share_positive(
  354. self,
  355. mock_gen_random_name,
  356. mock_get_location_path,
  357. fake_extra_spec, expect_extra_spec):
  358. """Test create share."""
  359. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  360. mock_api_executor.return_value.get_share_info.side_effect = [
  361. None, self.get_share_info_return_value()]
  362. mock_gen_random_name.return_value = 'fakeShareName'
  363. mock_api_executor.return_value.create_share.return_value = (
  364. 'fakeCreateShareId')
  365. mock_get_location_path.return_value = None
  366. mock_private_storage = mock.Mock()
  367. self.mock_object(greenthread, 'sleep')
  368. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  369. 'qnapadmin', 'Storage Pool 1',
  370. private_storage=mock_private_storage)
  371. self.mock_object(share_types, 'get_extra_specs_from_share',
  372. mock.Mock(return_value=fake_extra_spec))
  373. self.driver.create_share('context', self.share)
  374. mock_api_return = mock_api_executor.return_value
  375. expected_call_list = [
  376. mock.call('Storage Pool 1', vol_label='fakeShareName'),
  377. mock.call('Storage Pool 1', vol_label='fakeShareName')]
  378. self.assertEqual(
  379. expected_call_list,
  380. mock_api_return.get_share_info.call_args_list)
  381. mock_api_executor.return_value.create_share.assert_called_once_with(
  382. self.share,
  383. self.driver.configuration.qnap_poolname,
  384. 'fakeShareName',
  385. 'NFS',
  386. **expect_extra_spec)
  387. mock_get_location_path.assert_called_once_with(
  388. 'fakeShareName', 'NFS', '1.2.3.4', 'fakeNo')
  389. @mock.patch.object(qnap.QnapShareDriver, '_get_location_path')
  390. @mock.patch.object(qnap.QnapShareDriver, '_gen_random_name')
  391. def test_create_share_negative_share_exist(
  392. self,
  393. mock_gen_random_name,
  394. mock_get_location_path):
  395. """Test create share."""
  396. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  397. mock_api_executor.return_value.get_share_info.return_value = (
  398. self.get_share_info_return_value())
  399. mock_gen_random_name.return_value = 'fakeShareName'
  400. mock_get_location_path.return_value = None
  401. mock_private_storage = mock.Mock()
  402. self.mock_object(time, 'sleep')
  403. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  404. 'qnapadmin', 'Storage Pool 1',
  405. private_storage=mock_private_storage)
  406. self.mock_object(share_types, 'get_extra_specs_from_share',
  407. mock.Mock(return_value={}))
  408. self.assertRaises(
  409. exception.ShareBackendException,
  410. self.driver.create_share,
  411. context='context',
  412. share=self.share)
  413. @mock.patch.object(qnap.QnapShareDriver, '_get_location_path')
  414. @mock.patch.object(qnap.QnapShareDriver, '_gen_random_name')
  415. def test_create_share_negative_create_fail(
  416. self,
  417. mock_gen_random_name,
  418. mock_get_location_path):
  419. """Test create share."""
  420. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  421. mock_api_executor.return_value.get_share_info.return_value = None
  422. mock_gen_random_name.return_value = 'fakeShareName'
  423. mock_get_location_path.return_value = None
  424. mock_private_storage = mock.Mock()
  425. self.mock_object(time, 'sleep')
  426. self.mock_object(greenthread, 'sleep')
  427. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  428. 'qnapadmin', 'Storage Pool 1',
  429. private_storage=mock_private_storage)
  430. self.mock_object(share_types, 'get_extra_specs_from_share',
  431. mock.Mock(return_value={}))
  432. self.assertRaises(
  433. exception.ShareBackendException,
  434. self.driver.create_share,
  435. context='context',
  436. share=self.share)
  437. @mock.patch.object(qnap.QnapShareDriver, '_get_location_path')
  438. @mock.patch.object(qnap.QnapShareDriver, '_gen_random_name')
  439. def test_create_share_negative_configutarion(
  440. self,
  441. mock_gen_random_name,
  442. mock_get_location_path):
  443. """Test create share."""
  444. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  445. mock_api_executor.return_value.get_share_info.side_effect = [
  446. None, self.get_share_info_return_value()]
  447. mock_gen_random_name.return_value = 'fakeShareName'
  448. mock_get_location_path.return_value = None
  449. mock_private_storage = mock.Mock()
  450. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  451. 'qnapadmin', 'Storage Pool 1',
  452. private_storage=mock_private_storage)
  453. self.mock_object(share_types, 'get_extra_specs_from_share',
  454. mock.Mock(return_value={
  455. 'dedupe': 'true',
  456. 'thin_provisioning': 'false'}))
  457. self.assertRaises(
  458. exception.InvalidExtraSpec,
  459. self.driver.create_share,
  460. context='context',
  461. share=self.share)
  462. def test_delete_share_positive(self):
  463. """Test delete share with fake_share."""
  464. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  465. mock_api_executor.return_value.get_share_info.return_value = (
  466. self.get_share_info_return_value())
  467. mock_api_executor.return_value.delete_share.return_value = (
  468. 'fakeCreateShareId')
  469. mock_private_storage = mock.Mock()
  470. mock_private_storage.get.return_value = 'fakeVolNo'
  471. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  472. 'qnapadmin', 'Storage Pool 1',
  473. private_storage=mock_private_storage)
  474. self.driver.delete_share('context', self.share, share_server=None)
  475. mock_api_executor.return_value.get_share_info.assert_called_once_with(
  476. 'Storage Pool 1', vol_no='fakeVolNo')
  477. mock_api_executor.return_value.delete_share.assert_called_once_with(
  478. 'fakeNo')
  479. def test_delete_share_no_volid(self):
  480. """Test delete share with fake_share and no volID."""
  481. mock_private_storage = mock.Mock()
  482. mock_private_storage.get.return_value = None
  483. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  484. 'qnapadmin', 'Storage Pool 1',
  485. private_storage=mock_private_storage)
  486. self.driver.delete_share('context', self.share, share_server=None)
  487. mock_private_storage.get.assert_called_once_with(
  488. 'shareId', 'volID')
  489. def test_delete_share_no_delete_share(self):
  490. """Test delete share with fake_share."""
  491. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  492. mock_api_executor.return_value.get_share_info.return_value = None
  493. mock_api_executor.return_value.delete_share.return_value = (
  494. 'fakeCreateShareId')
  495. mock_private_storage = mock.Mock()
  496. mock_private_storage.get.return_value = 'fakeVolNo'
  497. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  498. 'qnapadmin', 'Storage Pool 1',
  499. private_storage=mock_private_storage)
  500. self.driver.delete_share('context', self.share, share_server=None)
  501. mock_api_executor.return_value.get_share_info.assert_called_once_with(
  502. 'Storage Pool 1', vol_no='fakeVolNo')
  503. def test_extend_share(self):
  504. """Test extend share with fake_share."""
  505. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  506. mock_api_executor.return_value.get_share_info.return_value = (
  507. self.get_share_info_return_value())
  508. mock_api_executor.return_value.edit_share.return_value = None
  509. mock_private_storage = mock.Mock()
  510. mock_private_storage.get.side_effect = [
  511. 'fakeVolName',
  512. 'True',
  513. 'True',
  514. 'False',
  515. 'False']
  516. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  517. 'qnapadmin', 'Storage Pool 1',
  518. private_storage=mock_private_storage)
  519. self.driver.extend_share(self.share, 100, share_server=None)
  520. expect_share_dict = {
  521. 'sharename': 'fakeVolName',
  522. 'old_sharename': 'fakeVolName',
  523. 'new_size': 100,
  524. 'thin_provision': True,
  525. 'compression': True,
  526. 'deduplication': False,
  527. 'ssd_cache': False,
  528. 'share_proto': 'NFS'
  529. }
  530. mock_api_executor.return_value.edit_share.assert_called_once_with(
  531. expect_share_dict)
  532. def test_extend_share_without_share_name(self):
  533. """Test extend share without share name."""
  534. mock_private_storage = mock.Mock()
  535. mock_private_storage.get.return_value = None
  536. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  537. 'qnapadmin', 'Storage Pool 1',
  538. private_storage=mock_private_storage)
  539. self.assertRaises(
  540. exception.ShareResourceNotFound,
  541. self.driver.extend_share,
  542. share=self.share,
  543. new_size=100,
  544. share_server=None)
  545. @mock.patch.object(qnap.QnapShareDriver, '_gen_random_name')
  546. def test_create_snapshot(
  547. self,
  548. mock_gen_random_name):
  549. """Test create snapshot with fake_snapshot."""
  550. fake_snapshot = fakes.SnapshotClass(
  551. 10, 'fakeShareName@fakeSnapshotName')
  552. mock_gen_random_name.return_value = 'fakeSnapshotName'
  553. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  554. mock_api_executor.return_value.get_snapshot_info.side_effect = [
  555. None, self.get_snapshot_info_return_value()]
  556. mock_api_executor.return_value.create_snapshot_api.return_value = (
  557. 'fakeCreateShareId')
  558. mock_private_storage = mock.Mock()
  559. mock_private_storage.get.return_value = 'fakeVolId'
  560. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  561. 'qnapadmin', 'Storage Pool 1',
  562. private_storage=mock_private_storage)
  563. self.driver.create_snapshot(
  564. 'context', fake_snapshot, share_server=None)
  565. mock_api_return = mock_api_executor.return_value
  566. expected_call_list = [
  567. mock.call(volID='fakeVolId', snapshot_name='fakeSnapshotName'),
  568. mock.call(volID='fakeVolId', snapshot_name='fakeSnapshotName')]
  569. self.assertEqual(
  570. expected_call_list,
  571. mock_api_return.get_snapshot_info.call_args_list)
  572. mock_api_return.create_snapshot_api.assert_called_once_with(
  573. 'fakeVolId', 'fakeSnapshotName')
  574. def test_create_snapshot_without_volid(self):
  575. """Test create snapshot with fake_snapshot."""
  576. fake_snapshot = fakes.SnapshotClass(10, None)
  577. mock_private_storage = mock.Mock()
  578. mock_private_storage.get.return_value = None
  579. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  580. 'qnapadmin', 'Storage Pool 1',
  581. private_storage=mock_private_storage)
  582. self.assertRaises(
  583. exception.ShareResourceNotFound,
  584. self.driver.create_snapshot,
  585. context='context',
  586. snapshot=fake_snapshot,
  587. share_server=None)
  588. def test_delete_snapshot(self):
  589. """Test delete snapshot with fakeSnapshot."""
  590. fake_snapshot = fakes.SnapshotClass(
  591. 10, 'fakeShareName@fakeSnapshotName')
  592. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  593. mock_api_executor.return_value.delete_snapshot_api.return_value = (
  594. 'fakeCreateShareId')
  595. mock_private_storage = mock.Mock()
  596. mock_private_storage.get.return_value = 'fakeSnapshotId'
  597. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  598. 'qnapadmin', 'Storage Pool 1',
  599. private_storage=mock_private_storage)
  600. self.driver.delete_snapshot(
  601. 'context', fake_snapshot, share_server=None)
  602. mock_api_return = mock_api_executor.return_value
  603. mock_api_return.delete_snapshot_api.assert_called_once_with(
  604. 'fakeShareName@fakeSnapshotName')
  605. def test_delete_snapshot_without_snapshot_id(self):
  606. """Test delete snapshot with fakeSnapshot and no snapshot id."""
  607. fake_snapshot = fakes.SnapshotClass(10, None)
  608. mock_private_storage = mock.Mock()
  609. mock_private_storage.get.return_value = None
  610. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  611. 'qnapadmin', 'Storage Pool 1',
  612. private_storage=mock_private_storage)
  613. self.driver.delete_snapshot(
  614. 'context', fake_snapshot, share_server=None)
  615. mock_private_storage.get.assert_called_once_with(
  616. 'fakeSnapshotId', 'snapshot_id')
  617. @mock.patch.object(qnap.QnapShareDriver, '_get_location_path')
  618. @mock.patch('manila.share.API')
  619. @mock.patch.object(qnap.QnapShareDriver, '_gen_random_name')
  620. def test_create_share_from_snapshot(
  621. self,
  622. mock_gen_random_name,
  623. mock_share_api,
  624. mock_get_location_path):
  625. """Test create share from snapshot."""
  626. fake_snapshot = fakes.SnapshotClass(
  627. 10, 'fakeShareName@fakeSnapshotName')
  628. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  629. mock_gen_random_name.return_value = 'fakeShareName'
  630. mock_api_executor.return_value.get_share_info.side_effect = [
  631. None, self.get_share_info_return_value()]
  632. mock_private_storage = mock.Mock()
  633. mock_private_storage.get.return_value = 'fakeSnapshotId'
  634. mock_share_api.return_value.get.return_value = {'size': 10}
  635. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  636. 'qnapadmin', 'Storage Pool 1',
  637. private_storage=mock_private_storage)
  638. self.driver.create_share_from_snapshot(
  639. 'context', self.share, fake_snapshot, share_server=None)
  640. mock_gen_random_name.assert_called_once_with(
  641. 'share')
  642. mock_api_return = mock_api_executor.return_value
  643. expected_call_list = [
  644. mock.call('Storage Pool 1', vol_label='fakeShareName'),
  645. mock.call('Storage Pool 1', vol_label='fakeShareName')]
  646. self.assertEqual(
  647. expected_call_list,
  648. mock_api_return.get_share_info.call_args_list)
  649. mock_api_return.clone_snapshot.assert_called_once_with(
  650. 'fakeShareName@fakeSnapshotName', 'fakeShareName')
  651. @mock.patch.object(qnap.QnapShareDriver, '_get_location_path')
  652. @mock.patch('manila.share.API')
  653. @mock.patch.object(qnap.QnapShareDriver, '_gen_random_name')
  654. def test_create_share_from_snapshot_diff_size(
  655. self,
  656. mock_gen_random_name,
  657. mock_share_api,
  658. mock_get_location_path):
  659. """Test create share from snapshot."""
  660. fake_snapshot = fakes.SnapshotClass(
  661. 10, 'fakeShareName@fakeSnapshotName')
  662. mock_gen_random_name.return_value = 'fakeShareName'
  663. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  664. mock_api_executor.return_value.get_share_info.side_effect = [
  665. None, self.get_share_info_return_value()]
  666. mock_private_storage = mock.Mock()
  667. mock_private_storage.get.side_effect = [
  668. 'True',
  669. 'True',
  670. 'False',
  671. 'False',
  672. 'fakeVolName']
  673. mock_share_api.return_value.get.return_value = {'size': 5}
  674. mock_api_executor.return_value.edit_share.return_value = (
  675. None)
  676. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  677. 'qnapadmin', 'Storage Pool 1',
  678. private_storage=mock_private_storage)
  679. self.driver.create_share_from_snapshot(
  680. 'context', self.share, fake_snapshot, share_server=None)
  681. mock_gen_random_name.assert_called_once_with(
  682. 'share')
  683. mock_api_return = mock_api_executor.return_value
  684. expected_call_list = [
  685. mock.call('Storage Pool 1', vol_label='fakeShareName'),
  686. mock.call('Storage Pool 1', vol_label='fakeShareName')]
  687. self.assertEqual(
  688. expected_call_list,
  689. mock_api_return.get_share_info.call_args_list)
  690. mock_api_return.clone_snapshot.assert_called_once_with(
  691. 'fakeShareName@fakeSnapshotName', 'fakeShareName')
  692. expect_share_dict = {
  693. 'sharename': 'fakeShareName',
  694. 'old_sharename': 'fakeShareName',
  695. 'new_size': 10,
  696. 'thin_provision': True,
  697. 'compression': True,
  698. 'deduplication': False,
  699. 'ssd_cache': False,
  700. 'share_proto': 'NFS'
  701. }
  702. mock_api_return.edit_share.assert_called_once_with(
  703. expect_share_dict)
  704. def test_create_share_from_snapshot_without_snapshot_id(self):
  705. """Test create share from snapshot."""
  706. fake_snapshot = fakes.SnapshotClass(10, None)
  707. mock_private_storage = mock.Mock()
  708. mock_private_storage.get.return_value = None
  709. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  710. 'qnapadmin', 'Storage Pool 1',
  711. private_storage=mock_private_storage)
  712. self.assertRaises(
  713. exception.SnapshotResourceNotFound,
  714. self.driver.create_share_from_snapshot,
  715. context='context',
  716. share=self.share,
  717. snapshot=fake_snapshot,
  718. share_server=None)
  719. @mock.patch.object(qnap.QnapShareDriver, '_get_location_path')
  720. @mock.patch('manila.share.API')
  721. @mock.patch.object(qnap.QnapShareDriver, '_gen_random_name')
  722. def test_create_share_from_snapshot_negative_name_exist(
  723. self,
  724. mock_gen_random_name,
  725. mock_share_api,
  726. mock_get_location_path):
  727. """Test create share from snapshot."""
  728. fake_snapshot = fakes.SnapshotClass(
  729. 10, 'fakeShareName@fakeSnapshotName')
  730. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  731. mock_gen_random_name.return_value = 'fakeShareName'
  732. mock_api_executor.return_value.get_share_info.return_value = (
  733. self.get_share_info_return_value())
  734. mock_private_storage = mock.Mock()
  735. mock_private_storage.get.return_value = 'fakeSnapshotId'
  736. mock_share_api.return_value.get.return_value = {'size': 10}
  737. self.mock_object(time, 'sleep')
  738. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  739. 'qnapadmin', 'Storage Pool 1',
  740. private_storage=mock_private_storage)
  741. self.assertRaises(
  742. exception.ShareBackendException,
  743. self.driver.create_share_from_snapshot,
  744. context='context',
  745. share=self.share,
  746. snapshot=fake_snapshot,
  747. share_server=None)
  748. @mock.patch.object(qnap.QnapShareDriver, '_get_location_path')
  749. @mock.patch('manila.share.API')
  750. @mock.patch.object(qnap.QnapShareDriver, '_gen_random_name')
  751. def test_create_share_from_snapshot_negative_clone_fail(
  752. self,
  753. mock_gen_random_name,
  754. mock_share_api,
  755. mock_get_location_path):
  756. """Test create share from snapshot."""
  757. fake_snapshot = fakes.SnapshotClass(
  758. 10, 'fakeShareName@fakeSnapshotName')
  759. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  760. mock_gen_random_name.return_value = 'fakeShareName'
  761. mock_api_executor.return_value.get_share_info.return_value = None
  762. mock_private_storage = mock.Mock()
  763. mock_private_storage.get.return_value = 'fakeSnapshotId'
  764. mock_share_api.return_value.get.return_value = {'size': 10}
  765. self.mock_object(time, 'sleep')
  766. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  767. 'qnapadmin', 'Storage Pool 1',
  768. private_storage=mock_private_storage)
  769. self.assertRaises(
  770. exception.ShareBackendException,
  771. self.driver.create_share_from_snapshot,
  772. context='context',
  773. share=self.share,
  774. snapshot=fake_snapshot,
  775. share_server=None)
  776. @mock.patch.object(qnap.QnapShareDriver, '_get_timestamp_from_vol_name')
  777. @mock.patch.object(qnap.QnapShareDriver, '_allow_access')
  778. @ddt.data('fakeHostName', 'fakeHostNameNotMatch')
  779. def test_update_access_allow_access(
  780. self, fakeHostName, mock_allow_access,
  781. mock_get_timestamp_from_vol_name):
  782. """Test update access with allow access rules."""
  783. mock_private_storage = mock.Mock()
  784. mock_private_storage.get.return_value = 'fakeVolName'
  785. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  786. mock_api_executor.return_value.get_host_list.return_value = (
  787. self.get_host_list_return_value())
  788. mock_api_executor.return_value.set_nfs_access.return_value = None
  789. mock_api_executor.return_value.delete_host.return_value = None
  790. mock_allow_access.return_value = None
  791. mock_get_timestamp_from_vol_name.return_value = fakeHostName
  792. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  793. 'qnapadmin', 'Storage Pool 1',
  794. private_storage=mock_private_storage)
  795. self.driver.update_access(
  796. 'context', self.share, 'access_rules',
  797. None, None, share_server=None)
  798. mock_api_executor.return_value.set_nfs_access.assert_called_once_with(
  799. 'fakeVolName', 2, 'all')
  800. @mock.patch.object(qnap.QnapShareDriver, '_allow_access')
  801. @mock.patch.object(qnap.QnapShareDriver, '_deny_access')
  802. def test_update_access_deny_and_allow_access(
  803. self,
  804. mock_deny_access,
  805. mock_allow_access):
  806. """Test update access with deny and allow access rules."""
  807. mock_private_storage = mock.Mock()
  808. mock_private_storage.get.return_value = 'fakeVolName'
  809. mock_deny_access.return_value = None
  810. mock_allow_access.return_value = None
  811. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  812. 'qnapadmin', 'Storage Pool 1',
  813. private_storage=mock_private_storage)
  814. delete_rules = []
  815. delete_rules.append('access1')
  816. add_rules = []
  817. add_rules.append('access1')
  818. self.driver.update_access(
  819. 'context', self.share, None,
  820. add_rules, delete_rules, share_server=None)
  821. mock_deny_access.assert_called_once_with(
  822. 'context', self.share, 'access1', None)
  823. mock_allow_access.assert_called_once_with(
  824. 'context', self.share, 'access1', None)
  825. def test_update_access_without_volname(self):
  826. """Test update access without volName."""
  827. mock_private_storage = mock.Mock()
  828. mock_private_storage.get.return_value = None
  829. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  830. 'qnapadmin', 'Storage Pool 1',
  831. private_storage=mock_private_storage)
  832. self.assertRaises(
  833. exception.ShareResourceNotFound,
  834. self.driver.update_access,
  835. context='context',
  836. share=self.share,
  837. access_rules='access_rules',
  838. add_rules=None,
  839. delete_rules=None,
  840. share_server=None)
  841. @mock.patch.object(qnap.QnapShareDriver, '_get_location_path')
  842. def test_manage_existing_nfs(
  843. self,
  844. mock_get_location_path):
  845. """Test manage existing."""
  846. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  847. mock_api_executor.return_value.get_share_info.return_value = (
  848. self.get_share_info_return_value())
  849. mock_private_storage = mock.Mock()
  850. mock_private_storage.update.return_value = None
  851. mock_private_storage.get.side_effect = [
  852. 'fakeVolId',
  853. 'fakeVolName']
  854. mock_api_executor.return_value.get_specific_volinfo.return_value = (
  855. self.get_specific_volinfo_return_value())
  856. mock_api_executor.return_value.get_share_info.return_value = (
  857. self.get_share_info_return_value())
  858. mock_get_location_path.return_value = None
  859. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  860. 'qnapadmin', 'Storage Pool 1',
  861. private_storage=mock_private_storage)
  862. self.mock_object(share_types, 'get_extra_specs_from_share',
  863. mock.Mock(return_value={}))
  864. self.driver.manage_existing(self.share, 'driver_options')
  865. mock_api_return = mock_api_executor.return_value
  866. mock_api_return.get_share_info.assert_called_once_with(
  867. 'Storage Pool 1', vol_label='fakeShareName')
  868. mock_api_return.get_specific_volinfo.assert_called_once_with(
  869. 'fakeNo')
  870. mock_get_location_path.assert_called_once_with(
  871. 'fakeShareName', 'NFS', '1.2.3.4', 'fakeNo')
  872. @mock.patch.object(qnap.QnapShareDriver, '_get_location_path')
  873. def test_manage_existing_nfs_negative_configutarion(
  874. self,
  875. mock_get_location_path):
  876. """Test manage existing."""
  877. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  878. mock_api_executor.return_value.get_share_info.return_value = (
  879. self.get_share_info_return_value())
  880. mock_private_storage = mock.Mock()
  881. mock_private_storage.update.return_value = None
  882. mock_private_storage.get.side_effect = [
  883. 'fakeVolId',
  884. 'fakeVolName']
  885. mock_api_executor.return_value.get_specific_volinfo.return_value = (
  886. self.get_specific_volinfo_return_value())
  887. mock_api_executor.return_value.get_share_info.return_value = (
  888. self.get_share_info_return_value())
  889. mock_get_location_path.return_value = None
  890. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  891. 'qnapadmin', 'Storage Pool 1',
  892. private_storage=mock_private_storage)
  893. self.mock_object(share_types, 'get_extra_specs_from_share',
  894. mock.Mock(return_value={
  895. 'dedupe': 'true',
  896. 'thin_provisioning': 'false'}))
  897. self.assertRaises(
  898. exception.InvalidExtraSpec,
  899. self.driver.manage_existing,
  900. share=self.share,
  901. driver_options='driver_options')
  902. def test_manage_invalid_protocol(self):
  903. """Test manage existing."""
  904. share = fake_share.fake_share(
  905. share_proto='fakeProtocol',
  906. id='fakeId',
  907. display_name='fakeDisplayName',
  908. export_locations=[{'path': ''}],
  909. host='QnapShareDriver',
  910. size=10)
  911. mock_private_storage = mock.Mock()
  912. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  913. 'qnapadmin', 'Storage Pool 1',
  914. private_storage=mock_private_storage)
  915. self.assertRaises(
  916. exception.InvalidInput,
  917. self.driver.manage_existing,
  918. share=share,
  919. driver_options='driver_options')
  920. def test_manage_existing_nfs_without_export_locations(self):
  921. share = fake_share.fake_share(
  922. share_proto='NFS',
  923. id='fakeId',
  924. display_name='fakeDisplayName',
  925. export_locations=[{'path': ''}],
  926. host='QnapShareDriver',
  927. size=10)
  928. mock_private_storage = mock.Mock()
  929. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  930. 'qnapadmin', 'Storage Pool 1',
  931. private_storage=mock_private_storage)
  932. self.assertRaises(
  933. exception.ShareBackendException,
  934. self.driver.manage_existing,
  935. share=share,
  936. driver_options='driver_options')
  937. @mock.patch.object(qnap.QnapShareDriver, '_get_location_path')
  938. def test_manage_existing_nfs_ip_not_equel_share_ip(
  939. self,
  940. mock_get_location_path):
  941. """Test manage existing with nfs ip not equel to share ip."""
  942. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  943. mock_api_executor.return_value.get_share_info.return_value = (
  944. self.get_share_info_return_value())
  945. mock_private_storage = mock.Mock()
  946. mock_private_storage.update.return_value = None
  947. mock_private_storage.get.side_effect = [
  948. 'fakeVolId',
  949. 'fakeVolName']
  950. mock_api_executor.return_value.get_specific_volinfo.return_value = (
  951. self.get_specific_volinfo_return_value())
  952. mock_api_executor.return_value.get_share_info.return_value = (
  953. self.get_share_info_return_value())
  954. mock_get_location_path.return_value = None
  955. self._do_setup('http://1.2.3.4:8080', '1.1.1.1', 'admin',
  956. 'qnapadmin', 'Storage Pool 1',
  957. private_storage=mock_private_storage)
  958. self.assertRaises(
  959. exception.ShareBackendException,
  960. self.driver.manage_existing,
  961. share=self.share,
  962. driver_options='driver_options')
  963. @mock.patch.object(qnap.QnapShareDriver, '_get_location_path')
  964. def test_manage_existing_nfs_without_existing_share(
  965. self,
  966. mock_get_location_path):
  967. """Test manage existing nfs without existing share."""
  968. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  969. mock_api_executor.return_value.get_share_info.return_value = (
  970. self.get_share_info_return_value())
  971. mock_private_storage = mock.Mock()
  972. mock_private_storage.update.return_value = None
  973. mock_private_storage.get.side_effect = [
  974. 'fakeVolId',
  975. 'fakeVolName']
  976. mock_api_executor.return_value.get_specific_volinfo.return_value = (
  977. self.get_specific_volinfo_return_value())
  978. mock_api_executor.return_value.get_share_info.return_value = (
  979. None)
  980. mock_get_location_path.return_value = None
  981. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  982. 'qnapadmin', 'Storage Pool 1',
  983. private_storage=mock_private_storage)
  984. self.assertRaises(
  985. exception.ManageInvalidShare,
  986. self.driver.manage_existing,
  987. share=self.share,
  988. driver_options='driver_options')
  989. def test_unmanage(self):
  990. """Test unmanage."""
  991. mock_private_storage = mock.Mock()
  992. mock_private_storage.delete.return_value = None
  993. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  994. 'qnapadmin', 'Storage Pool 1',
  995. private_storage=mock_private_storage)
  996. self.driver.unmanage(self.share)
  997. mock_private_storage.delete.assert_called_once_with(
  998. 'shareId')
  999. @mock.patch.object(qnap.QnapShareDriver, '_get_location_path')
  1000. def test_manage_existing_snapshot(
  1001. self,
  1002. mock_get_location_path):
  1003. """Test manage existing snapshot snapshot."""
  1004. fake_snapshot = fakes.SnapshotClass(
  1005. 10, 'fakeShareName@fakeSnapshotName')
  1006. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  1007. mock_api_executor.return_value.get_share_info.return_value = (
  1008. self.get_share_info_return_value())
  1009. mock_private_storage = mock.Mock()
  1010. mock_private_storage.update.return_value = None
  1011. mock_private_storage.get.side_effect = [
  1012. 'fakeVolId', 'fakeVolName']
  1013. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1014. 'qnapadmin', 'Storage Pool 1',
  1015. private_storage=mock_private_storage)
  1016. self.driver.manage_existing_snapshot(fake_snapshot, 'driver_options')
  1017. mock_api_return = mock_api_executor.return_value
  1018. mock_api_return.get_share_info.assert_called_once_with(
  1019. 'Storage Pool 1', vol_no='fakeVolId')
  1020. fake_metadata = {
  1021. 'snapshot_id': 'fakeShareName@fakeSnapshotName'}
  1022. mock_private_storage.update.assert_called_once_with(
  1023. 'fakeSnapshotId', fake_metadata)
  1024. @mock.patch.object(qnap.QnapShareDriver, '_get_location_path')
  1025. def test_manage_existing_snapshot_not_exist(
  1026. self,
  1027. mock_get_location_path):
  1028. """Test manage existing snapshot with snapshot which does not exist."""
  1029. fake_snapshot = fakes.SnapshotClass(
  1030. 10, 'fakeShareName@fakeSnapshotName')
  1031. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  1032. mock_api_executor.return_value.get_share_info.return_value = (
  1033. self.get_share_info_return_value())
  1034. mock_api_executor.return_value.get_snapshot_info.return_value = None
  1035. mock_private_storage = mock.Mock()
  1036. mock_private_storage.get.side_effect = [
  1037. 'fakeVolId', 'fakeVolName']
  1038. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1039. 'qnapadmin', 'Storage Pool 1',
  1040. private_storage=mock_private_storage)
  1041. mock_api_return = mock_api_executor.return_value
  1042. self.assertRaises(
  1043. exception.InvalidParameterValue,
  1044. self.driver.manage_existing_snapshot,
  1045. snapshot=fake_snapshot,
  1046. driver_options='driver_options')
  1047. mock_api_return.get_share_info.assert_called_once_with(
  1048. 'Storage Pool 1', vol_no='fakeVolId')
  1049. def test_unmanage_snapshot(self):
  1050. """Test unmanage snapshot."""
  1051. fake_snapshot = fakes.SnapshotClass(
  1052. 10, 'fakeShareName@fakeSnapshotName')
  1053. mock_private_storage = mock.Mock()
  1054. mock_private_storage.delete.return_value = None
  1055. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1056. 'qnapadmin', 'Storage Pool 1',
  1057. private_storage=mock_private_storage)
  1058. self.driver.unmanage_snapshot(fake_snapshot)
  1059. mock_private_storage.delete.assert_called_once_with(
  1060. 'fakeSnapshotId')
  1061. @ddt.data(
  1062. {'expect_result': 'manila-shr-fake_time', 'test_string': 'share'},
  1063. {'expect_result': 'manila-snp-fake_time', 'test_string': 'snapshot'},
  1064. {'expect_result': 'manila-hst-fake_time', 'test_string': 'host'},
  1065. {'expect_result': 'manila-fake_time', 'test_string': ''})
  1066. @ddt.unpack
  1067. @mock.patch('oslo_utils.timeutils.utcnow')
  1068. def test_gen_random_name(
  1069. self, mock_utcnow, expect_result, test_string):
  1070. """Test gen random name."""
  1071. mock_private_storage = mock.Mock()
  1072. mock_utcnow.return_value.strftime.return_value = 'fake_time'
  1073. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1074. 'qnapadmin', 'Storage Pool 1',
  1075. private_storage=mock_private_storage)
  1076. self.assertEqual(
  1077. expect_result, self.driver._gen_random_name(test_string))
  1078. def test_get_location_path(self):
  1079. """Test get location path name."""
  1080. mock_private_storage = mock.Mock()
  1081. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  1082. mock_api_executor.return_value.get_share_info.return_value = (
  1083. self.get_share_info_return_value())
  1084. mock_api_executor.return_value.get_specific_volinfo.return_value = (
  1085. self.get_specific_volinfo_return_value())
  1086. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1087. 'qnapadmin', 'Storage Pool 1',
  1088. private_storage=mock_private_storage)
  1089. location = 'fakeIp:fakeMountPath'
  1090. expect_result = {
  1091. 'path': location,
  1092. 'is_admin_only': False,
  1093. }
  1094. self.assertEqual(
  1095. expect_result, self.driver._get_location_path(
  1096. 'fakeShareName', 'NFS', 'fakeIp', 'fakeVolId'))
  1097. self.assertRaises(
  1098. exception.InvalidInput,
  1099. self.driver._get_location_path,
  1100. share_name='fakeShareName',
  1101. share_proto='fakeProto',
  1102. ip='fakeIp',
  1103. vol_id='fakeVolId')
  1104. def test_update_share_stats(self):
  1105. """Test update share stats."""
  1106. mock_private_storage = mock.Mock()
  1107. mock_api_return = (
  1108. qnap.QnapShareDriver._create_api_executor.return_value)
  1109. mock_api_return.get_specific_poolinfo.return_value = (
  1110. self.get_specific_poolinfo_return_value())
  1111. mock_api_return.get_share_info.return_value = (
  1112. self.get_share_info_return_value())
  1113. mock_api_return.get_specific_volinfo.return_value = (
  1114. self.get_specific_volinfo_return_value())
  1115. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1116. 'qnapadmin', 'Storage Pool 1',
  1117. private_storage=mock_private_storage)
  1118. self.driver._update_share_stats()
  1119. mock_api_return.get_specific_poolinfo.assert_called_once_with(
  1120. self.driver.configuration.qnap_poolname)
  1121. def test_get_vol_host(self):
  1122. """Test get manila host IPV4s."""
  1123. mock_private_storage = mock.Mock()
  1124. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1125. 'qnapadmin', 'Storage Pool 1',
  1126. private_storage=mock_private_storage)
  1127. expect_host_dict_ips = []
  1128. host_list = self.get_host_list_return_value()
  1129. for host in host_list:
  1130. host_dict = {
  1131. 'index': host.find('index').text,
  1132. 'hostid': host.find('hostid').text,
  1133. 'name': host.find('name').text,
  1134. 'ipv4': [host.find('netaddrs').find('ipv4').text]
  1135. }
  1136. expect_host_dict_ips.append(host_dict)
  1137. self.assertEqual(
  1138. expect_host_dict_ips, self.driver._get_vol_host(
  1139. host_list, 'fakeHostName'))
  1140. @mock.patch.object(qnap.QnapShareDriver, '_gen_host_name')
  1141. @mock.patch.object(qnap.QnapShareDriver, '_get_timestamp_from_vol_name')
  1142. @mock.patch.object(qnap.QnapShareDriver, '_check_share_access')
  1143. def test_allow_access_ro(
  1144. self,
  1145. mock_check_share_access,
  1146. mock_get_timestamp_from_vol_name,
  1147. mock_gen_host_name):
  1148. """Test allow_access with access type ro."""
  1149. fake_access = fakes.AccessClass('fakeAccessType', 'ro', 'fakeIp')
  1150. mock_private_storage = mock.Mock()
  1151. mock_private_storage.get.return_value = 'fakeVolName'
  1152. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  1153. mock_api_executor.return_value.get_host_list.return_value = []
  1154. mock_get_timestamp_from_vol_name.return_value = 'fakeHostName'
  1155. mock_gen_host_name.return_value = 'manila-fakeHostName-ro'
  1156. mock_api_executor.return_value.add_host.return_value = None
  1157. mock_api_executor.return_value.set_nfs_access.return_value = None
  1158. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1159. 'qnapadmin', 'Storage Pool 1',
  1160. private_storage=mock_private_storage)
  1161. self.driver._allow_access(
  1162. 'context', self.share, fake_access, share_server=None)
  1163. mock_check_share_access.assert_called_once_with(
  1164. 'NFS', 'fakeAccessType')
  1165. mock_api_executor.return_value.add_host.assert_called_once_with(
  1166. 'manila-fakeHostName-ro', 'fakeIp')
  1167. @mock.patch.object(qnap.QnapShareDriver, '_gen_host_name')
  1168. @mock.patch.object(qnap.QnapShareDriver, '_get_timestamp_from_vol_name')
  1169. @mock.patch.object(qnap.QnapShareDriver, '_check_share_access')
  1170. def test_allow_access_ro_with_hostlist(
  1171. self,
  1172. mock_check_share_access,
  1173. mock_get_timestamp_from_vol_name,
  1174. mock_gen_host_name):
  1175. """Test allow_access_ro_with_hostlist."""
  1176. host_dict_ips = []
  1177. for host in self.get_host_list_return_value():
  1178. if host.find('netaddrs/ipv4').text is not None:
  1179. host_dict = {
  1180. 'index': host.find('index').text,
  1181. 'hostid': host.find('hostid').text,
  1182. 'name': host.find('name').text,
  1183. 'ipv4': [host.find('netaddrs').find('ipv4').text]}
  1184. host_dict_ips.append(host_dict)
  1185. for host in host_dict_ips:
  1186. fake_access_to = host['ipv4']
  1187. fake_access = fakes.AccessClass(
  1188. 'fakeAccessType', 'ro', fake_access_to)
  1189. mock_private_storage = mock.Mock()
  1190. mock_private_storage.get.return_value = 'fakeVolName'
  1191. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  1192. mock_api_executor.return_value.get_host_list.return_value = (
  1193. self.get_host_list_return_value())
  1194. mock_get_timestamp_from_vol_name.return_value = 'fakeHostName'
  1195. mock_gen_host_name.return_value = 'manila-fakeHostName'
  1196. mock_api_executor.return_value.set_nfs_access.return_value = None
  1197. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1198. 'qnapadmin', 'Storage Pool 1',
  1199. private_storage=mock_private_storage)
  1200. self.driver._allow_access(
  1201. 'context', self.share, fake_access, share_server=None)
  1202. mock_check_share_access.assert_called_once_with(
  1203. 'NFS', 'fakeAccessType')
  1204. @mock.patch.object(qnap.QnapShareDriver, '_gen_host_name')
  1205. @mock.patch.object(qnap.QnapShareDriver, '_get_timestamp_from_vol_name')
  1206. @mock.patch.object(qnap.QnapShareDriver, '_check_share_access')
  1207. def test_allow_access_rw_with_hostlist_invalid_access(
  1208. self,
  1209. mock_check_share_access,
  1210. mock_get_timestamp_from_vol_name,
  1211. mock_gen_host_name):
  1212. """Test allow_access_rw_invalid_access."""
  1213. host_dict_ips = []
  1214. for host in self.get_host_list_return_value():
  1215. if host.find('netaddrs/ipv4').text is not None:
  1216. host_dict = {
  1217. 'index': host.find('index').text,
  1218. 'hostid': host.find('hostid').text,
  1219. 'name': host.find('name').text,
  1220. 'ipv4': [host.find('netaddrs').find('ipv4').text]}
  1221. host_dict_ips.append(host_dict)
  1222. for host in host_dict_ips:
  1223. fake_access_to = host['ipv4']
  1224. fake_access = fakes.AccessClass(
  1225. 'fakeAccessType', 'rw', fake_access_to)
  1226. mock_private_storage = mock.Mock()
  1227. mock_private_storage.get.return_value = 'fakeVolName'
  1228. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  1229. mock_api_executor.return_value.get_host_list.return_value = (
  1230. self.get_host_list_return_value())
  1231. mock_get_timestamp_from_vol_name.return_value = 'fakeHostName'
  1232. mock_gen_host_name.return_value = 'manila-fakeHostName-rw'
  1233. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1234. 'qnapadmin', 'Storage Pool 1',
  1235. private_storage=mock_private_storage)
  1236. self.assertRaises(
  1237. exception.InvalidShareAccess,
  1238. self.driver._allow_access,
  1239. context='context',
  1240. share=self.share,
  1241. access=fake_access,
  1242. share_server=None)
  1243. @mock.patch.object(qnap.QnapShareDriver, '_get_timestamp_from_vol_name')
  1244. @mock.patch.object(qnap.QnapShareDriver, '_check_share_access')
  1245. def test_allow_access_rw(
  1246. self,
  1247. mock_check_share_access,
  1248. mock_get_timestamp_from_vol_name):
  1249. """Test allow_access with access type rw."""
  1250. fake_access = fakes.AccessClass('fakeAccessType', 'rw', 'fakeIp')
  1251. mock_private_storage = mock.Mock()
  1252. mock_private_storage.get.return_value = 'fakeVolName'
  1253. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  1254. mock_api_executor.return_value.get_host_list.return_value = []
  1255. mock_get_timestamp_from_vol_name.return_value = 'fakeHostName'
  1256. mock_api_executor.return_value.add_host.return_value = None
  1257. mock_api_executor.return_value.set_nfs_access.return_value = None
  1258. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1259. 'qnapadmin', 'Storage Pool 1',
  1260. private_storage=mock_private_storage)
  1261. self.driver._allow_access(
  1262. 'context', self.share, fake_access, share_server=None)
  1263. mock_check_share_access.assert_called_once_with(
  1264. 'NFS', 'fakeAccessType')
  1265. mock_api_executor.return_value.add_host.assert_called_once_with(
  1266. 'manila-fakeHostName-rw', 'fakeIp')
  1267. @mock.patch.object(qnap.QnapShareDriver, '_gen_host_name')
  1268. @mock.patch.object(qnap.QnapShareDriver, '_check_share_access')
  1269. def test_allow_access_ro_without_hostlist(
  1270. self,
  1271. mock_check_share_access,
  1272. mock_gen_host_name):
  1273. """Test allow access without host list."""
  1274. fake_access = fakes.AccessClass('fakeAccessType', 'ro', 'fakeIp')
  1275. mock_private_storage = mock.Mock()
  1276. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  1277. mock_api_executor.return_value.get_host_list.return_value = None
  1278. mock_gen_host_name.return_value = 'fakeHostName'
  1279. mock_api_executor.return_value.add_host.return_value = None
  1280. mock_api_executor.return_value.set_nfs_access.return_value = None
  1281. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1282. 'qnapadmin', 'Storage Pool 1',
  1283. private_storage=mock_private_storage)
  1284. share_name = self.driver._gen_random_name('share')
  1285. mock_private_storage.get.return_value = share_name
  1286. self.driver._allow_access(
  1287. 'context', self.share, fake_access, share_server=None)
  1288. mock_check_share_access.assert_called_once_with(
  1289. 'NFS', 'fakeAccessType')
  1290. mock_api_executor.return_value.add_host.assert_called_once_with(
  1291. 'fakeHostName', 'fakeIp')
  1292. @mock.patch.object(qnap.QnapShareDriver, '_get_vol_host')
  1293. @mock.patch.object(qnap.QnapShareDriver, '_gen_host_name')
  1294. @mock.patch.object(qnap.QnapShareDriver, '_get_timestamp_from_vol_name')
  1295. @mock.patch.object(qnap.QnapShareDriver, '_check_share_access')
  1296. def test_deny_access_with_hostlist(
  1297. self,
  1298. mock_check_share_access,
  1299. mock_get_timestamp_from_vol_name,
  1300. mock_gen_host_name,
  1301. mock_get_vol_host):
  1302. """Test deny access."""
  1303. host_dict_ips = []
  1304. for host in self.get_host_list_return_value():
  1305. if host.find('netaddrs/ipv4').text is not None:
  1306. host_dict = {
  1307. 'index': host.find('index').text,
  1308. 'hostid': host.find('hostid').text,
  1309. 'name': host.find('name').text,
  1310. 'ipv4': [host.find('netaddrs').find('ipv4').text]}
  1311. host_dict_ips.append(host_dict)
  1312. for host in host_dict_ips:
  1313. fake_access_to = host['ipv4'][0]
  1314. fake_access = fakes.AccessClass('fakeAccessType', 'ro', fake_access_to)
  1315. mock_private_storage = mock.Mock()
  1316. mock_private_storage.get.return_value = 'vol_name'
  1317. mock_api_return = (
  1318. qnap.QnapShareDriver._create_api_executor.return_value)
  1319. mock_api_return.get_host_list.return_value = (
  1320. self.get_host_list_return_value())
  1321. mock_get_timestamp_from_vol_name.return_value = 'fakeTimeStamp'
  1322. mock_gen_host_name.return_value = 'manila-fakeHostName'
  1323. mock_get_vol_host.return_value = host_dict_ips
  1324. mock_api_return.add_host.return_value = None
  1325. mock_api_return.set_nfs_access.return_value = None
  1326. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1327. 'qnapadmin', 'Storage Pool 1',
  1328. private_storage=mock_private_storage)
  1329. self.driver._deny_access(
  1330. 'context', self.share, fake_access, share_server=None)
  1331. mock_check_share_access.assert_called_once_with(
  1332. 'NFS', 'fakeAccessType')
  1333. @mock.patch.object(qnap.QnapShareDriver, '_get_timestamp_from_vol_name')
  1334. @mock.patch.object(qnap.QnapShareDriver, '_check_share_access')
  1335. def test_deny_access_with_hostlist_not_equel_access_to(
  1336. self,
  1337. mock_check_share_access,
  1338. mock_get_timestamp_from_vol_name):
  1339. """Test deny access."""
  1340. fake_access = fakes.AccessClass('fakeAccessType', 'ro', 'fakeIp')
  1341. mock_private_storage = mock.Mock()
  1342. mock_private_storage.get.return_value = 'vol_name'
  1343. mock_api_return = (
  1344. qnap.QnapShareDriver._create_api_executor.return_value)
  1345. mock_api_return.get_host_list.return_value = (
  1346. self.get_host_list_return_value())
  1347. mock_api_return.add_host.return_value = None
  1348. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1349. 'qnapadmin', 'Storage Pool 1',
  1350. private_storage=mock_private_storage)
  1351. self.driver._deny_access(
  1352. 'context', self.share, fake_access, share_server=None)
  1353. mock_check_share_access.assert_called_once_with(
  1354. 'NFS', 'fakeAccessType')
  1355. @mock.patch.object(qnap.QnapShareDriver, '_get_timestamp_from_vol_name')
  1356. @mock.patch.object(qnap.QnapShareDriver, '_check_share_access')
  1357. def test_deny_access_without_hostlist(
  1358. self,
  1359. mock_check_share_access,
  1360. mock_get_timestamp_from_vol_name):
  1361. """Test deny access without hostlist."""
  1362. fake_access = fakes.AccessClass('fakeAccessType', 'ro', 'fakeIp')
  1363. mock_private_storage = mock.Mock()
  1364. mock_private_storage.get.return_value = 'fakeVolName'
  1365. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  1366. mock_api_executor.return_value.get_host_list.return_value = None
  1367. mock_get_timestamp_from_vol_name.return_value = 'fakeHostName'
  1368. mock_api_executor.return_value.add_host.return_value = None
  1369. mock_api_executor.return_value.set_nfs_access.return_value = None
  1370. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1371. 'qnapadmin', 'Storage Pool 1',
  1372. private_storage=mock_private_storage)
  1373. self.driver._deny_access(
  1374. 'context', self.share, fake_access, share_server=None)
  1375. mock_check_share_access.assert_called_once_with(
  1376. 'NFS', 'fakeAccessType')
  1377. @ddt.data('NFS', 'CIFS', 'proto')
  1378. def test_check_share_access(self, test_proto):
  1379. """Test check_share_access."""
  1380. mock_private_storage = mock.Mock()
  1381. mock_api_executor = qnap.QnapShareDriver._create_api_executor
  1382. mock_api_executor.return_value.get_host_list.return_value = None
  1383. mock_api_executor.return_value.add_host.return_value = None
  1384. mock_api_executor.return_value.set_nfs_access.return_value = None
  1385. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1386. 'qnapadmin', 'Storage Pool 1',
  1387. private_storage=mock_private_storage)
  1388. self.assertRaises(
  1389. exception.InvalidShareAccess,
  1390. self.driver._check_share_access,
  1391. share_proto=test_proto,
  1392. access_type='notser')
  1393. def test_get_ts_model_pool_id(self):
  1394. """Test get ts model pool id."""
  1395. mock_private_storage = mock.Mock()
  1396. self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin',
  1397. 'qnapadmin', '1',
  1398. private_storage=mock_private_storage)
  1399. self.assertEqual('1', self.driver._get_ts_model_pool_id('1'))