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.

6485 lines
237KB

  1. # Copyright (c) 2014 Alex Meade. All rights reserved.
  2. # Copyright (c) 2015 Clinton Knight. All rights reserved.
  3. # Copyright (c) 2015 Tom Barron. All rights reserved.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. # not use this file except in compliance with the License. You may obtain
  7. # a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. # License for the specific language governing permissions and limitations
  15. # under the License.
  16. import copy
  17. import hashlib
  18. import time
  19. import ddt
  20. import mock
  21. from oslo_log import log
  22. import six
  23. from manila import exception
  24. from manila.share.drivers.netapp.dataontap.client import api as netapp_api
  25. from manila.share.drivers.netapp.dataontap.client import client_base
  26. from manila.share.drivers.netapp.dataontap.client import client_cmode
  27. from manila import test
  28. from manila.tests.share.drivers.netapp.dataontap.client import fakes as fake
  29. @ddt.ddt
  30. class NetAppClientCmodeTestCase(test.TestCase):
  31. def setUp(self):
  32. super(NetAppClientCmodeTestCase, self).setUp()
  33. # Mock loggers as themselves to allow logger arg validation
  34. mock_logger = log.getLogger('mock_logger')
  35. self.mock_object(client_cmode.LOG,
  36. 'error',
  37. mock.Mock(side_effect=mock_logger.error))
  38. self.mock_object(client_cmode.LOG,
  39. 'warning',
  40. mock.Mock(side_effect=mock_logger.warning))
  41. self.mock_object(client_cmode.LOG,
  42. 'debug',
  43. mock.Mock(side_effect=mock_logger.debug))
  44. self.mock_object(client_base.NetAppBaseClient,
  45. 'get_ontapi_version',
  46. mock.Mock(return_value=(1, 20)))
  47. self.mock_object(client_base.NetAppBaseClient,
  48. 'get_system_version',
  49. mock.Mock(return_value={
  50. 'version-tuple': (8, 3, 0),
  51. 'version': fake.VERSION,
  52. }))
  53. self.client = client_cmode.NetAppCmodeClient(**fake.CONNECTION_INFO)
  54. self.client.connection = mock.MagicMock()
  55. self.vserver_client = client_cmode.NetAppCmodeClient(
  56. **fake.CONNECTION_INFO)
  57. self.vserver_client.set_vserver(fake.VSERVER_NAME)
  58. self.vserver_client.connection = mock.MagicMock()
  59. def _mock_api_error(self, code='fake', message='fake'):
  60. return mock.Mock(side_effect=netapp_api.NaApiError(code=code,
  61. message=message))
  62. def test_init_features_ontapi_1_21(self):
  63. self.mock_object(client_base.NetAppBaseClient,
  64. 'get_ontapi_version',
  65. mock.Mock(return_value=(1, 21)))
  66. self.client._init_features()
  67. self.assertFalse(self.client.features.BROADCAST_DOMAINS)
  68. self.assertFalse(self.client.features.IPSPACES)
  69. self.assertFalse(self.client.features.SUBNETS)
  70. self.assertFalse(self.client.features.FLEXVOL_ENCRYPTION)
  71. @ddt.data((1, 30), (1, 40), (2, 0))
  72. def test_init_features_ontapi_1_30(self, ontapi_version):
  73. self.mock_object(client_base.NetAppBaseClient,
  74. 'get_ontapi_version',
  75. mock.Mock(return_value=ontapi_version))
  76. self.client._init_features()
  77. self.assertTrue(self.client.features.BROADCAST_DOMAINS)
  78. self.assertTrue(self.client.features.IPSPACES)
  79. self.assertTrue(self.client.features.SUBNETS)
  80. @ddt.data((1, 110), (2, 0))
  81. def test_init_features_ontap_1_110(self, ontapi_version):
  82. self.mock_object(client_base.NetAppBaseClient,
  83. 'get_ontapi_version',
  84. mock.Mock(return_value=ontapi_version))
  85. self.client._init_features()
  86. self.assertTrue(self.client.features.BROADCAST_DOMAINS)
  87. self.assertTrue(self.client.features.IPSPACES)
  88. self.assertTrue(self.client.features.SUBNETS)
  89. self.assertTrue(self.client.features.FLEXVOL_ENCRYPTION)
  90. @ddt.data(((9, 1, 0), fake.VERSION_NO_DARE), ((8, 3, 2), fake.VERSION))
  91. @ddt.unpack
  92. def test_is_nve_supported_unsupported_release_or_platform(self, gen, ver):
  93. system_version = {'version-tuple': gen, 'version': ver}
  94. self.mock_object(client_base.NetAppBaseClient,
  95. 'get_system_version',
  96. mock.Mock(return_value=system_version))
  97. self.mock_object(self.client,
  98. 'get_security_key_manager_nve_support',
  99. mock.Mock(return_value=True))
  100. self.mock_object(self.client,
  101. 'list_cluster_nodes',
  102. mock.Mock(return_value=fake.NODE_NAMES))
  103. result = self.client.is_nve_supported()
  104. self.assertFalse(result)
  105. def test_is_nve_supported_valid_platform_and_supported_release(self):
  106. system_version = {
  107. 'version-tuple': (9, 1, 0),
  108. 'version': fake.VERSION,
  109. }
  110. self.mock_object(client_base.NetAppBaseClient,
  111. 'get_system_version',
  112. mock.Mock(return_value=system_version))
  113. self.mock_object(self.client,
  114. 'get_security_key_manager_nve_support',
  115. mock.Mock(return_value=True))
  116. self.mock_object(self.client,
  117. 'list_cluster_nodes',
  118. mock.Mock(return_value=fake.NODE_NAMES))
  119. result = self.client.is_nve_supported()
  120. self.assertTrue(result)
  121. def test_is_nve_supported_key_manager_not_enabled(self):
  122. system_version = {
  123. 'version-tuple': (9, 1, 0),
  124. 'version': fake.VERSION,
  125. }
  126. self.mock_object(client_base.NetAppBaseClient,
  127. 'get_system_version',
  128. mock.Mock(return_value=system_version))
  129. self.mock_object(self.client,
  130. 'get_security_key_manager_nve_support',
  131. mock.Mock(return_value=False))
  132. self.mock_object(self.client,
  133. 'list_cluster_nodes',
  134. mock.Mock(return_value=fake.NODE_NAMES))
  135. result = self.client.is_nve_supported()
  136. self.assertFalse(result)
  137. def test_get_security_key_manager_nve_support_enabled(self):
  138. api_response = netapp_api.NaElement(
  139. fake.SECUTITY_KEY_MANAGER_NVE_SUPPORT_RESPONSE_TRUE)
  140. self.mock_object(self.client,
  141. 'send_request',
  142. mock.Mock(return_value=api_response))
  143. result = self.client.get_security_key_manager_nve_support(
  144. fake.NODE_NAME)
  145. self.assertTrue(result)
  146. api_args = {'node': fake.NODE_NAME}
  147. self.client.send_request.assert_has_calls([
  148. mock.call('security-key-manager-volume-encryption-supported',
  149. api_args)])
  150. def test_get_security_key_manager_nve_support_disabled(self):
  151. api_response = netapp_api.NaElement(
  152. fake.SECUTITY_KEY_MANAGER_NVE_SUPPORT_RESPONSE_FALSE)
  153. self.mock_object(self.client,
  154. 'send_request',
  155. mock.Mock(return_value=api_response))
  156. result = self.client.get_security_key_manager_nve_support(
  157. fake.NODE_NAME)
  158. self.assertFalse(result)
  159. api_args = {'node': fake.NODE_NAME}
  160. self.client.send_request.assert_has_calls([
  161. mock.call('security-key-manager-volume-encryption-supported',
  162. api_args)])
  163. def test_get_security_key_manager_nve_support_disabled_no_license(self):
  164. self.mock_object(self.client,
  165. 'send_request',
  166. self._mock_api_error())
  167. result = self.client.get_security_key_manager_nve_support(
  168. fake.NODE_NAME)
  169. self.assertFalse(result)
  170. api_args = {'node': fake.NODE_NAME}
  171. self.client.send_request.assert_has_calls([
  172. mock.call('security-key-manager-volume-encryption-supported',
  173. api_args)])
  174. @ddt.data((True, True, True), (False, None, False))
  175. @ddt.unpack
  176. def test_send_volume_move_request_success(self, validation_only,
  177. encrypt_dst, fv_encryption):
  178. self.mock_object(self.client, 'features',
  179. mock.Mock(FLEXVOL_ENCRYPTION=fv_encryption))
  180. self.client._send_volume_move_request(fake.ROOT_VOLUME_NAME,
  181. fake.NODE_VSERVER_NAME,
  182. fake.SHARE_AGGREGATE_NAME,
  183. validation_only=validation_only,
  184. encrypt_destination=encrypt_dst)
  185. @ddt.data((True, True, False))
  186. @ddt.unpack
  187. def test_send_volume_move_request_failure(self, validation_only,
  188. encrypt_dst, fv_encrypt):
  189. self.mock_object(self.client, 'features',
  190. mock.Mock(FLEXVOL_ENCRYPTION=fv_encrypt))
  191. self.assertRaises(exception.NetAppException,
  192. self.client._send_volume_move_request,
  193. fake.ROOT_VOLUME_NAME,
  194. fake.NODE_VSERVER_NAME,
  195. fake.SHARE_AGGREGATE_NAME,
  196. validation_only=validation_only,
  197. encrypt_destination=encrypt_dst)
  198. def test_invoke_vserver_api(self):
  199. self.client._invoke_vserver_api('fake-api', 'fake_vserver')
  200. self.client.connection.set_vserver.assert_has_calls(
  201. [mock.call('fake_vserver')])
  202. self.client.connection.invoke_successfully.assert_has_calls(
  203. [mock.call('fake-api', True)])
  204. def test_has_records(self):
  205. self.assertTrue(self.client._has_records(
  206. netapp_api.NaElement(fake.VSERVER_GET_ITER_RESPONSE)))
  207. def test_has_records_not_found(self):
  208. self.assertFalse(self.client._has_records(
  209. netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)))
  210. @ddt.data((fake.VSERVER_GET_ITER_RESPONSE, 1),
  211. (fake.NO_RECORDS_RESPONSE, 0))
  212. @ddt.unpack
  213. def test_get_record_count(self, response, expected):
  214. api_response = netapp_api.NaElement(response)
  215. result = self.client._get_record_count(api_response)
  216. self.assertEqual(expected, result)
  217. def test_get_records_count_invalid(self):
  218. api_response = netapp_api.NaElement(
  219. fake.INVALID_GET_ITER_RESPONSE_NO_RECORDS)
  220. self.assertRaises(exception.NetAppException,
  221. self.client._get_record_count,
  222. api_response)
  223. def test_send_iter_request(self):
  224. api_responses = [
  225. netapp_api.NaElement(fake.STORAGE_DISK_GET_ITER_RESPONSE_PAGE_1),
  226. netapp_api.NaElement(fake.STORAGE_DISK_GET_ITER_RESPONSE_PAGE_2),
  227. netapp_api.NaElement(fake.STORAGE_DISK_GET_ITER_RESPONSE_PAGE_3),
  228. ]
  229. mock_send_request = self.mock_object(
  230. self.client, 'send_request',
  231. mock.Mock(side_effect=api_responses))
  232. storage_disk_get_iter_args = {
  233. 'desired-attributes': {
  234. 'storage-disk-info': {
  235. 'disk-name': None,
  236. }
  237. }
  238. }
  239. result = self.client.send_iter_request(
  240. 'storage-disk-get-iter', api_args=storage_disk_get_iter_args,
  241. max_page_length=10)
  242. num_records = result.get_child_content('num-records')
  243. self.assertEqual('28', num_records)
  244. next_tag = result.get_child_content('next-tag')
  245. self.assertEqual('', next_tag)
  246. args1 = copy.deepcopy(storage_disk_get_iter_args)
  247. args1['max-records'] = 10
  248. args2 = copy.deepcopy(storage_disk_get_iter_args)
  249. args2['max-records'] = 10
  250. args2['tag'] = 'next_tag_1'
  251. args3 = copy.deepcopy(storage_disk_get_iter_args)
  252. args3['max-records'] = 10
  253. args3['tag'] = 'next_tag_2'
  254. mock_send_request.assert_has_calls([
  255. mock.call('storage-disk-get-iter', args1),
  256. mock.call('storage-disk-get-iter', args2),
  257. mock.call('storage-disk-get-iter', args3),
  258. ])
  259. def test_send_iter_request_single_page(self):
  260. api_response = netapp_api.NaElement(
  261. fake.STORAGE_DISK_GET_ITER_RESPONSE)
  262. mock_send_request = self.mock_object(
  263. self.client, 'send_request',
  264. mock.Mock(return_value=api_response))
  265. storage_disk_get_iter_args = {
  266. 'desired-attributes': {
  267. 'storage-disk-info': {
  268. 'disk-name': None,
  269. }
  270. }
  271. }
  272. result = self.client.send_iter_request(
  273. 'storage-disk-get-iter', api_args=storage_disk_get_iter_args,
  274. max_page_length=10)
  275. num_records = result.get_child_content('num-records')
  276. self.assertEqual('4', num_records)
  277. args = copy.deepcopy(storage_disk_get_iter_args)
  278. args['max-records'] = 10
  279. mock_send_request.assert_has_calls([
  280. mock.call('storage-disk-get-iter', args),
  281. ])
  282. def test_send_iter_request_not_found(self):
  283. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  284. mock_send_request = self.mock_object(
  285. self.client, 'send_request',
  286. mock.Mock(return_value=api_response))
  287. result = self.client.send_iter_request('storage-disk-get-iter')
  288. num_records = result.get_child_content('num-records')
  289. self.assertEqual('0', num_records)
  290. args = {'max-records': client_cmode.DEFAULT_MAX_PAGE_LENGTH}
  291. mock_send_request.assert_has_calls([
  292. mock.call('storage-disk-get-iter', args),
  293. ])
  294. @ddt.data(fake.INVALID_GET_ITER_RESPONSE_NO_ATTRIBUTES,
  295. fake.INVALID_GET_ITER_RESPONSE_NO_RECORDS)
  296. def test_send_iter_request_invalid(self, fake_response):
  297. api_response = netapp_api.NaElement(fake_response)
  298. self.mock_object(self.client,
  299. 'send_request',
  300. mock.Mock(return_value=api_response))
  301. self.assertRaises(exception.NetAppException,
  302. self.client.send_iter_request,
  303. 'storage-disk-get-iter')
  304. def test_set_vserver(self):
  305. self.client.set_vserver(fake.VSERVER_NAME)
  306. self.client.connection.set_vserver.assert_has_calls(
  307. [mock.call('fake_vserver')])
  308. def test_vserver_exists(self):
  309. api_response = netapp_api.NaElement(fake.VSERVER_GET_ITER_RESPONSE)
  310. self.mock_object(self.client,
  311. 'send_iter_request',
  312. mock.Mock(return_value=api_response))
  313. vserver_get_args = {
  314. 'query': {'vserver-info': {'vserver-name': fake.VSERVER_NAME}},
  315. 'desired-attributes': {'vserver-info': {'vserver-name': None}}
  316. }
  317. result = self.client.vserver_exists(fake.VSERVER_NAME)
  318. self.client.send_iter_request.assert_has_calls([
  319. mock.call('vserver-get-iter', vserver_get_args)])
  320. self.assertTrue(result)
  321. def test_vserver_exists_not_found(self):
  322. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  323. self.mock_object(self.client,
  324. 'send_request',
  325. mock.Mock(return_value=api_response))
  326. result = self.client.vserver_exists(fake.VSERVER_NAME)
  327. self.assertFalse(result)
  328. def test_create_vserver_no_ipspace(self):
  329. self.mock_object(self.client, 'send_request')
  330. vserver_create_args = {
  331. 'vserver-name': fake.VSERVER_NAME,
  332. 'root-volume-security-style': 'unix',
  333. 'root-volume-aggregate': fake.ROOT_VOLUME_AGGREGATE_NAME,
  334. 'root-volume': fake.ROOT_VOLUME_NAME,
  335. 'name-server-switch': {'nsswitch': 'file'}
  336. }
  337. vserver_modify_args = {
  338. 'aggr-list': [{'aggr-name': aggr_name} for aggr_name
  339. in fake.SHARE_AGGREGATE_NAMES],
  340. 'vserver-name': fake.VSERVER_NAME
  341. }
  342. self.client.create_vserver(fake.VSERVER_NAME,
  343. fake.ROOT_VOLUME_AGGREGATE_NAME,
  344. fake.ROOT_VOLUME_NAME,
  345. fake.SHARE_AGGREGATE_NAMES,
  346. None)
  347. self.client.send_request.assert_has_calls([
  348. mock.call('vserver-create', vserver_create_args),
  349. mock.call('vserver-modify', vserver_modify_args)])
  350. def test_create_vserver_with_ipspace(self):
  351. self.client.features.add_feature('IPSPACES')
  352. self.mock_object(self.client, 'send_request')
  353. vserver_create_args = {
  354. 'vserver-name': fake.VSERVER_NAME,
  355. 'root-volume-security-style': 'unix',
  356. 'root-volume-aggregate': fake.ROOT_VOLUME_AGGREGATE_NAME,
  357. 'root-volume': fake.ROOT_VOLUME_NAME,
  358. 'name-server-switch': {'nsswitch': 'file'},
  359. 'ipspace': fake.IPSPACE_NAME,
  360. }
  361. vserver_modify_args = {
  362. 'aggr-list': [{'aggr-name': aggr_name} for aggr_name
  363. in fake.SHARE_AGGREGATE_NAMES],
  364. 'vserver-name': fake.VSERVER_NAME
  365. }
  366. self.client.create_vserver(fake.VSERVER_NAME,
  367. fake.ROOT_VOLUME_AGGREGATE_NAME,
  368. fake.ROOT_VOLUME_NAME,
  369. fake.SHARE_AGGREGATE_NAMES,
  370. fake.IPSPACE_NAME)
  371. self.client.send_request.assert_has_calls([
  372. mock.call('vserver-create', vserver_create_args),
  373. mock.call('vserver-modify', vserver_modify_args)])
  374. def test_create_vserver_ipspaces_not_supported(self):
  375. self.assertRaises(exception.NetAppException,
  376. self.client.create_vserver,
  377. fake.VSERVER_NAME,
  378. fake.ROOT_VOLUME_AGGREGATE_NAME,
  379. fake.ROOT_VOLUME_NAME,
  380. fake.SHARE_AGGREGATE_NAMES,
  381. fake.IPSPACE_NAME)
  382. def test_get_vserver_root_volume_name(self):
  383. api_response = netapp_api.NaElement(
  384. fake.VSERVER_GET_ROOT_VOLUME_NAME_RESPONSE)
  385. self.mock_object(self.client,
  386. 'send_iter_request',
  387. mock.Mock(return_value=api_response))
  388. vserver_get_args = {
  389. 'query': {'vserver-info': {'vserver-name': fake.VSERVER_NAME}},
  390. 'desired-attributes': {'vserver-info': {'root-volume': None}}
  391. }
  392. result = self.client.get_vserver_root_volume_name(fake.VSERVER_NAME)
  393. self.client.send_iter_request.assert_has_calls([
  394. mock.call('vserver-get-iter', vserver_get_args)])
  395. self.assertEqual(fake.ROOT_VOLUME_NAME, result)
  396. def test_get_vserver_root_volume_name_not_found(self):
  397. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  398. self.mock_object(self.client,
  399. 'send_iter_request',
  400. mock.Mock(return_value=api_response))
  401. self.assertRaises(exception.NetAppException,
  402. self.client.get_vserver_root_volume_name,
  403. fake.VSERVER_NAME)
  404. def test_get_vserver_ipspace(self):
  405. self.client.features.add_feature('IPSPACES')
  406. api_response = netapp_api.NaElement(
  407. fake.VSERVER_GET_IPSPACE_NAME_RESPONSE)
  408. self.mock_object(self.client,
  409. 'send_iter_request',
  410. mock.Mock(return_value=api_response))
  411. result = self.client.get_vserver_ipspace(fake.VSERVER_NAME)
  412. vserver_get_iter_args = {
  413. 'query': {
  414. 'vserver-info': {
  415. 'vserver-name': fake.VSERVER_NAME,
  416. },
  417. },
  418. 'desired-attributes': {
  419. 'vserver-info': {
  420. 'ipspace': None,
  421. },
  422. },
  423. }
  424. self.client.send_iter_request.assert_has_calls([
  425. mock.call('vserver-get-iter', vserver_get_iter_args)])
  426. self.assertEqual(fake.IPSPACE_NAME, result)
  427. def test_get_vserver_ipspace_not_supported(self):
  428. result = self.client.get_vserver_ipspace(fake.IPSPACE_NAME)
  429. self.assertIsNone(result)
  430. def test_get_vserver_ipspace_not_found(self):
  431. self.client.features.add_feature('IPSPACES')
  432. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  433. self.mock_object(self.client,
  434. 'send_iter_request',
  435. mock.Mock(return_value=api_response))
  436. self.assertRaises(exception.NetAppException,
  437. self.client.get_vserver_ipspace,
  438. fake.IPSPACE_NAME)
  439. def test_ipspace_has_data_vservers(self):
  440. self.client.features.add_feature('IPSPACES')
  441. api_response = netapp_api.NaElement(fake.VSERVER_GET_ITER_RESPONSE)
  442. self.mock_object(self.client,
  443. 'send_iter_request',
  444. mock.Mock(return_value=api_response))
  445. result = self.client.ipspace_has_data_vservers(fake.IPSPACE_NAME)
  446. vserver_get_iter_args = {
  447. 'query': {
  448. 'vserver-info': {
  449. 'ipspace': fake.IPSPACE_NAME,
  450. 'vserver-type': 'data'
  451. },
  452. },
  453. 'desired-attributes': {
  454. 'vserver-info': {
  455. 'vserver-name': None,
  456. },
  457. },
  458. }
  459. self.client.send_iter_request.assert_has_calls([
  460. mock.call('vserver-get-iter', vserver_get_iter_args)])
  461. self.assertTrue(result)
  462. def test_ipspace_has_data_vservers_not_supported(self):
  463. result = self.client.ipspace_has_data_vservers(fake.IPSPACE_NAME)
  464. self.assertFalse(result)
  465. def test_ipspace_has_data_vservers_not_found(self):
  466. self.client.features.add_feature('IPSPACES')
  467. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  468. self.mock_object(self.client,
  469. 'send_request',
  470. mock.Mock(return_value=api_response))
  471. result = self.client.ipspace_has_data_vservers(fake.IPSPACE_NAME)
  472. self.assertFalse(result)
  473. def test_list_vservers(self):
  474. api_response = netapp_api.NaElement(
  475. fake.VSERVER_DATA_LIST_RESPONSE)
  476. self.mock_object(self.client,
  477. 'send_iter_request',
  478. mock.Mock(return_value=api_response))
  479. result = self.client.list_vservers()
  480. vserver_get_iter_args = {
  481. 'query': {
  482. 'vserver-info': {
  483. 'vserver-type': 'data'
  484. }
  485. },
  486. 'desired-attributes': {
  487. 'vserver-info': {
  488. 'vserver-name': None
  489. }
  490. }
  491. }
  492. self.client.send_iter_request.assert_has_calls([
  493. mock.call('vserver-get-iter', vserver_get_iter_args)])
  494. self.assertListEqual([fake.VSERVER_NAME], result)
  495. def test_list_vservers_node_type(self):
  496. api_response = netapp_api.NaElement(
  497. fake.VSERVER_DATA_LIST_RESPONSE)
  498. self.mock_object(self.client,
  499. 'send_iter_request',
  500. mock.Mock(return_value=api_response))
  501. result = self.client.list_vservers(vserver_type='node')
  502. vserver_get_iter_args = {
  503. 'query': {
  504. 'vserver-info': {
  505. 'vserver-type': 'node'
  506. }
  507. },
  508. 'desired-attributes': {
  509. 'vserver-info': {
  510. 'vserver-name': None
  511. }
  512. }
  513. }
  514. self.client.send_iter_request.assert_has_calls([
  515. mock.call('vserver-get-iter', vserver_get_iter_args)])
  516. self.assertListEqual([fake.VSERVER_NAME], result)
  517. def test_list_vservers_not_found(self):
  518. api_response = netapp_api.NaElement(
  519. fake.NO_RECORDS_RESPONSE)
  520. self.mock_object(self.client,
  521. 'send_request',
  522. mock.Mock(return_value=api_response))
  523. result = self.client.list_vservers(vserver_type='data')
  524. self.assertListEqual([], result)
  525. def test_get_vserver_volume_count(self):
  526. api_response = netapp_api.NaElement(fake.VOLUME_COUNT_RESPONSE)
  527. self.mock_object(self.client,
  528. 'send_iter_request',
  529. mock.Mock(return_value=api_response))
  530. result = self.client.get_vserver_volume_count()
  531. self.assertEqual(2, result)
  532. def test_delete_vserver_no_volumes(self):
  533. self.mock_object(self.client,
  534. 'vserver_exists',
  535. mock.Mock(return_value=True))
  536. self.mock_object(self.client,
  537. 'get_vserver_root_volume_name',
  538. mock.Mock(return_value=fake.ROOT_VOLUME_NAME))
  539. self.mock_object(self.vserver_client,
  540. 'get_vserver_volume_count',
  541. mock.Mock(return_value=0))
  542. self.mock_object(self.client, '_terminate_vserver_services')
  543. self.mock_object(self.client, 'send_request')
  544. self.client.delete_vserver(
  545. fake.VSERVER_NAME,
  546. self.vserver_client,
  547. security_services=[fake.CIFS_SECURITY_SERVICE])
  548. self.client._terminate_vserver_services.assert_called_with(
  549. fake.VSERVER_NAME, self.vserver_client,
  550. [fake.CIFS_SECURITY_SERVICE])
  551. vserver_destroy_args = {'vserver-name': fake.VSERVER_NAME}
  552. self.client.send_request.assert_has_calls([
  553. mock.call('vserver-destroy', vserver_destroy_args)])
  554. def test_delete_vserver_one_volume(self):
  555. self.mock_object(self.client,
  556. 'vserver_exists',
  557. mock.Mock(return_value=True))
  558. self.mock_object(self.client,
  559. 'get_vserver_root_volume_name',
  560. mock.Mock(return_value=fake.ROOT_VOLUME_NAME))
  561. self.mock_object(self.vserver_client,
  562. 'get_vserver_volume_count',
  563. mock.Mock(return_value=1))
  564. self.mock_object(self.client, 'send_request')
  565. self.mock_object(self.vserver_client, 'offline_volume')
  566. self.mock_object(self.vserver_client, 'delete_volume')
  567. self.client.delete_vserver(fake.VSERVER_NAME,
  568. self.vserver_client)
  569. self.vserver_client.offline_volume.assert_called_with(
  570. fake.ROOT_VOLUME_NAME)
  571. self.vserver_client.delete_volume.assert_called_with(
  572. fake.ROOT_VOLUME_NAME)
  573. vserver_destroy_args = {'vserver-name': fake.VSERVER_NAME}
  574. self.client.send_request.assert_has_calls([
  575. mock.call('vserver-destroy', vserver_destroy_args)])
  576. def test_delete_vserver_one_volume_already_offline(self):
  577. self.mock_object(self.client,
  578. 'vserver_exists',
  579. mock.Mock(return_value=True))
  580. self.mock_object(self.client,
  581. 'get_vserver_root_volume_name',
  582. mock.Mock(return_value=fake.ROOT_VOLUME_NAME))
  583. self.mock_object(self.vserver_client,
  584. 'get_vserver_volume_count',
  585. mock.Mock(return_value=1))
  586. self.mock_object(self.client, 'send_request')
  587. self.mock_object(self.vserver_client,
  588. 'offline_volume',
  589. self._mock_api_error(code=netapp_api.EVOLUMEOFFLINE))
  590. self.mock_object(self.vserver_client, 'delete_volume')
  591. self.client.delete_vserver(fake.VSERVER_NAME,
  592. self.vserver_client)
  593. self.vserver_client.offline_volume.assert_called_with(
  594. fake.ROOT_VOLUME_NAME)
  595. self.vserver_client.delete_volume.assert_called_with(
  596. fake.ROOT_VOLUME_NAME)
  597. vserver_destroy_args = {'vserver-name': fake.VSERVER_NAME}
  598. self.client.send_request.assert_has_calls([
  599. mock.call('vserver-destroy', vserver_destroy_args)])
  600. self.assertEqual(1, client_cmode.LOG.error.call_count)
  601. def test_delete_vserver_one_volume_api_error(self):
  602. self.mock_object(self.client,
  603. 'vserver_exists',
  604. mock.Mock(return_value=True))
  605. self.mock_object(self.client,
  606. 'get_vserver_root_volume_name',
  607. mock.Mock(return_value=fake.ROOT_VOLUME_NAME))
  608. self.mock_object(self.vserver_client,
  609. 'get_vserver_volume_count',
  610. mock.Mock(return_value=1))
  611. self.mock_object(self.client, 'send_request')
  612. self.mock_object(self.vserver_client,
  613. 'offline_volume',
  614. self._mock_api_error())
  615. self.mock_object(self.vserver_client, 'delete_volume')
  616. self.assertRaises(netapp_api.NaApiError,
  617. self.client.delete_vserver,
  618. fake.VSERVER_NAME,
  619. self.vserver_client)
  620. def test_delete_vserver_multiple_volumes(self):
  621. self.mock_object(self.client,
  622. 'vserver_exists',
  623. mock.Mock(return_value=True))
  624. self.mock_object(self.client,
  625. 'get_vserver_root_volume_name',
  626. mock.Mock(return_value=fake.ROOT_VOLUME_NAME))
  627. self.mock_object(self.vserver_client,
  628. 'get_vserver_volume_count',
  629. mock.Mock(return_value=2))
  630. self.assertRaises(exception.NetAppException,
  631. self.client.delete_vserver,
  632. fake.VSERVER_NAME,
  633. self.vserver_client)
  634. def test_delete_vserver_not_found(self):
  635. self.mock_object(self.client,
  636. 'vserver_exists',
  637. mock.Mock(return_value=False))
  638. self.client.delete_vserver(fake.VSERVER_NAME,
  639. self.vserver_client)
  640. self.assertEqual(1, client_cmode.LOG.error.call_count)
  641. def test_terminate_vserver_services(self):
  642. self.mock_object(self.vserver_client, 'send_request')
  643. self.client._terminate_vserver_services(fake.VSERVER_NAME,
  644. self.vserver_client,
  645. [fake.CIFS_SECURITY_SERVICE])
  646. cifs_server_delete_args = {
  647. 'admin-password': fake.CIFS_SECURITY_SERVICE['password'],
  648. 'admin-username': fake.CIFS_SECURITY_SERVICE['user'],
  649. }
  650. self.vserver_client.send_request.assert_has_calls([
  651. mock.call('cifs-server-delete', cifs_server_delete_args)])
  652. def test_terminate_vserver_services_cifs_not_found(self):
  653. self.mock_object(self.vserver_client,
  654. 'send_request',
  655. self._mock_api_error(
  656. code=netapp_api.EOBJECTNOTFOUND))
  657. self.client._terminate_vserver_services(fake.VSERVER_NAME,
  658. self.vserver_client,
  659. [fake.CIFS_SECURITY_SERVICE])
  660. cifs_server_delete_args = {
  661. 'admin-password': fake.CIFS_SECURITY_SERVICE['password'],
  662. 'admin-username': fake.CIFS_SECURITY_SERVICE['user'],
  663. }
  664. self.vserver_client.send_request.assert_has_calls([
  665. mock.call('cifs-server-delete', cifs_server_delete_args)])
  666. self.assertEqual(1, client_cmode.LOG.error.call_count)
  667. def test_terminate_vserver_services_api_error(self):
  668. side_effects = [netapp_api.NaApiError(code='fake'), None]
  669. self.mock_object(self.vserver_client,
  670. 'send_request',
  671. mock.Mock(side_effect=side_effects))
  672. self.client._terminate_vserver_services(fake.VSERVER_NAME,
  673. self.vserver_client,
  674. [fake.CIFS_SECURITY_SERVICE])
  675. cifs_server_delete_args = {
  676. 'admin-password': fake.CIFS_SECURITY_SERVICE['password'],
  677. 'admin-username': fake.CIFS_SECURITY_SERVICE['user'],
  678. }
  679. self.vserver_client.send_request.assert_has_calls([
  680. mock.call('cifs-server-delete', cifs_server_delete_args),
  681. mock.call('cifs-server-delete')])
  682. self.assertEqual(0, client_cmode.LOG.error.call_count)
  683. def test_list_cluster_nodes(self):
  684. api_response = netapp_api.NaElement(
  685. fake.SYSTEM_NODE_GET_ITER_RESPONSE)
  686. self.mock_object(self.client,
  687. 'send_request',
  688. mock.Mock(return_value=api_response))
  689. result = self.client.list_cluster_nodes()
  690. self.assertListEqual([fake.NODE_NAME], result)
  691. def test_list_cluster_nodes_not_found(self):
  692. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  693. self.mock_object(self.client,
  694. 'send_request',
  695. mock.Mock(return_value=api_response))
  696. result = self.client.list_cluster_nodes()
  697. self.assertListEqual([], result)
  698. def test_list_node_data_ports(self):
  699. self.mock_object(self.client,
  700. 'get_node_data_ports',
  701. mock.Mock(return_value=fake.SPEED_SORTED_PORTS))
  702. result = self.client.list_node_data_ports(fake.NODE_NAME)
  703. self.assertSequenceEqual(fake.SPEED_SORTED_PORT_NAMES, result)
  704. def test_get_node_data_ports(self):
  705. api_response = netapp_api.NaElement(fake.NET_PORT_GET_ITER_RESPONSE)
  706. self.mock_object(self.client,
  707. 'send_iter_request',
  708. mock.Mock(return_value=api_response))
  709. result = self.client.get_node_data_ports(fake.NODE_NAME)
  710. net_port_get_iter_args = {
  711. 'query': {
  712. 'net-port-info': {
  713. 'node': fake.NODE_NAME,
  714. 'link-status': 'up',
  715. 'port-type': 'physical|if_group',
  716. 'role': 'data',
  717. },
  718. },
  719. 'desired-attributes': {
  720. 'net-port-info': {
  721. 'port': None,
  722. 'node': None,
  723. 'operational-speed': None,
  724. 'ifgrp-port': None,
  725. },
  726. },
  727. }
  728. self.assertSequenceEqual(fake.SPEED_SORTED_PORTS, result)
  729. self.client.send_iter_request.assert_has_calls([
  730. mock.call('net-port-get-iter', net_port_get_iter_args)])
  731. def test_get_node_data_ports_not_found(self):
  732. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  733. self.mock_object(self.client,
  734. 'send_iter_request',
  735. mock.Mock(return_value=api_response))
  736. result = self.client.get_node_data_ports(fake.NODE_NAME)
  737. self.assertSequenceEqual([], result)
  738. def test_sort_data_ports_by_speed(self):
  739. result = self.client._sort_data_ports_by_speed(
  740. fake.UNSORTED_PORTS_ALL_SPEEDS)
  741. self.assertSequenceEqual(fake.SORTED_PORTS_ALL_SPEEDS, result)
  742. def test_list_root_aggregates(self):
  743. api_response = netapp_api.NaElement(
  744. fake.AGGR_GET_ITER_ROOT_AGGR_RESPONSE)
  745. self.mock_object(self.client,
  746. 'send_iter_request',
  747. mock.Mock(return_value=api_response))
  748. result = self.client.list_root_aggregates()
  749. aggr_get_iter_args = {
  750. 'desired-attributes': {
  751. 'aggr-attributes': {
  752. 'aggregate-name': None,
  753. 'aggr-raid-attributes': {
  754. 'has-local-root': None,
  755. 'has-partner-root': None,
  756. },
  757. },
  758. }
  759. }
  760. self.assertSequenceEqual(fake.ROOT_AGGREGATE_NAMES, result)
  761. self.client.send_iter_request.assert_has_calls([
  762. mock.call('aggr-get-iter', aggr_get_iter_args)])
  763. def test_list_non_root_aggregates(self):
  764. api_response = netapp_api.NaElement(
  765. fake.AGGR_GET_ITER_NON_ROOT_AGGR_RESPONSE)
  766. self.mock_object(self.client,
  767. 'send_iter_request',
  768. mock.Mock(return_value=api_response))
  769. result = self.client.list_non_root_aggregates()
  770. aggr_get_iter_args = {
  771. 'query': {
  772. 'aggr-attributes': {
  773. 'aggr-raid-attributes': {
  774. 'has-local-root': 'false',
  775. 'has-partner-root': 'false',
  776. }
  777. },
  778. },
  779. 'desired-attributes': {
  780. 'aggr-attributes': {
  781. 'aggregate-name': None,
  782. },
  783. },
  784. }
  785. self.assertSequenceEqual(fake.SHARE_AGGREGATE_NAMES, result)
  786. self.client.send_iter_request.assert_has_calls([
  787. mock.call('aggr-get-iter', aggr_get_iter_args)])
  788. def test_list_aggregates(self):
  789. api_response = netapp_api.NaElement(fake.AGGR_GET_NAMES_RESPONSE)
  790. self.mock_object(self.client,
  791. 'send_iter_request',
  792. mock.Mock(return_value=api_response))
  793. result = self.client._list_aggregates()
  794. aggr_get_iter_args = {
  795. 'desired-attributes': {
  796. 'aggr-attributes': {
  797. 'aggregate-name': None,
  798. },
  799. },
  800. }
  801. self.assertSequenceEqual(
  802. fake.ROOT_AGGREGATE_NAMES + fake.SHARE_AGGREGATE_NAMES, result)
  803. self.client.send_iter_request.assert_has_calls([
  804. mock.call('aggr-get-iter', aggr_get_iter_args)])
  805. def test_list_aggregates_not_found(self):
  806. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  807. self.mock_object(self.client,
  808. 'send_request',
  809. mock.Mock(return_value=api_response))
  810. self.assertRaises(exception.NetAppException,
  811. self.client._list_aggregates)
  812. def test_list_vserver_aggregates(self):
  813. self.mock_object(self.vserver_client,
  814. 'get_vserver_aggregate_capacities',
  815. mock.Mock(return_value=fake.VSERVER_AGGREGATES))
  816. result = self.vserver_client.list_vserver_aggregates()
  817. self.assertListEqual(list(fake.VSERVER_AGGREGATES.keys()), result)
  818. def test_list_vserver_aggregates_none_found(self):
  819. self.mock_object(self.vserver_client,
  820. 'get_vserver_aggregate_capacities',
  821. mock.Mock(return_value={}))
  822. result = self.vserver_client.list_vserver_aggregates()
  823. self.assertListEqual([], result)
  824. @ddt.data((True, True), (True, False), (False, True), (False, False))
  825. @ddt.unpack
  826. def test_create_network_interface(self, broadcast_domains_supported,
  827. use_vlans):
  828. self.client.features.add_feature('BROADCAST_DOMAINS',
  829. broadcast_domains_supported)
  830. self.mock_object(self.client, '_ensure_broadcast_domain_for_port')
  831. self.mock_object(self.client, '_create_vlan')
  832. self.mock_object(self.client, 'send_request')
  833. lif_create_args = {
  834. 'address': fake.IP_ADDRESS,
  835. 'administrative-status': 'up',
  836. 'data-protocols': [
  837. {'data-protocol': 'nfs'},
  838. {'data-protocol': 'cifs'}
  839. ],
  840. 'home-node': fake.NODE_NAME,
  841. 'home-port': fake.VLAN_PORT if use_vlans else fake.PORT,
  842. 'netmask': fake.NETMASK,
  843. 'interface-name': fake.LIF_NAME,
  844. 'role': 'data',
  845. 'vserver': fake.VSERVER_NAME,
  846. }
  847. self.client.create_network_interface(fake.IP_ADDRESS,
  848. fake.NETMASK,
  849. fake.VLAN if use_vlans else None,
  850. fake.NODE_NAME,
  851. fake.PORT,
  852. fake.VSERVER_NAME,
  853. fake.LIF_NAME,
  854. fake.IPSPACE_NAME,
  855. fake.MTU)
  856. if use_vlans:
  857. self.client._create_vlan.assert_called_with(
  858. fake.NODE_NAME, fake.PORT, fake.VLAN)
  859. else:
  860. self.assertFalse(self.client._create_vlan.called)
  861. if broadcast_domains_supported:
  862. self.client._ensure_broadcast_domain_for_port.assert_called_with(
  863. fake.NODE_NAME, fake.VLAN_PORT if use_vlans else fake.PORT,
  864. fake.MTU, ipspace=fake.IPSPACE_NAME)
  865. else:
  866. self.assertFalse(
  867. self.client._ensure_broadcast_domain_for_port.called)
  868. self.client.send_request.assert_has_calls([
  869. mock.call('net-interface-create', lif_create_args)])
  870. def test_create_vlan(self):
  871. self.mock_object(self.client, 'send_request')
  872. vlan_create_args = {
  873. 'vlan-info': {
  874. 'parent-interface': fake.PORT,
  875. 'node': fake.NODE_NAME,
  876. 'vlanid': fake.VLAN
  877. }
  878. }
  879. self.client._create_vlan(fake.NODE_NAME, fake.PORT, fake.VLAN)
  880. self.client.send_request.assert_has_calls([
  881. mock.call('net-vlan-create', vlan_create_args)])
  882. def test_create_vlan_already_present(self):
  883. self.mock_object(self.client,
  884. 'send_request',
  885. self._mock_api_error(code=netapp_api.EDUPLICATEENTRY))
  886. vlan_create_args = {
  887. 'vlan-info': {
  888. 'parent-interface': fake.PORT,
  889. 'node': fake.NODE_NAME,
  890. 'vlanid': fake.VLAN
  891. }
  892. }
  893. self.client._create_vlan(fake.NODE_NAME, fake.PORT, fake.VLAN)
  894. self.client.send_request.assert_has_calls([
  895. mock.call('net-vlan-create', vlan_create_args)])
  896. self.assertEqual(1, client_cmode.LOG.debug.call_count)
  897. def test_create_vlan_api_error(self):
  898. self.mock_object(self.client, 'send_request', self._mock_api_error())
  899. self.assertRaises(exception.NetAppException,
  900. self.client._create_vlan,
  901. fake.NODE_NAME,
  902. fake.PORT,
  903. fake.VLAN)
  904. def test_delete_vlan(self):
  905. self.mock_object(self.client, 'send_request')
  906. vlan_delete_args = {
  907. 'vlan-info': {
  908. 'parent-interface': fake.PORT,
  909. 'node': fake.NODE_NAME,
  910. 'vlanid': fake.VLAN
  911. }
  912. }
  913. self.client.delete_vlan(fake.NODE_NAME, fake.PORT, fake.VLAN)
  914. self.client.send_request.assert_has_calls([
  915. mock.call('net-vlan-delete', vlan_delete_args)])
  916. def test_delete_vlan_still_used(self):
  917. self.mock_object(self.client,
  918. 'send_request',
  919. self._mock_api_error(code=netapp_api.EAPIERROR,
  920. message='Port already has a '
  921. 'lif bound. '))
  922. vlan_delete_args = {
  923. 'vlan-info': {
  924. 'parent-interface': fake.PORT,
  925. 'node': fake.NODE_NAME,
  926. 'vlanid': fake.VLAN
  927. }
  928. }
  929. self.client.delete_vlan(fake.NODE_NAME, fake.PORT, fake.VLAN)
  930. self.client.send_request.assert_has_calls([
  931. mock.call('net-vlan-delete', vlan_delete_args)])
  932. self.assertEqual(1, client_cmode.LOG.debug.call_count)
  933. def test_delete_vlan_api_error(self):
  934. self.mock_object(self.client, 'send_request', self._mock_api_error())
  935. self.assertRaises(exception.NetAppException,
  936. self.client.delete_vlan,
  937. fake.NODE_NAME,
  938. fake.PORT,
  939. fake.VLAN)
  940. @ddt.data(('10.10.10.0/24', '10.10.10.1', False),
  941. ('fc00::/7', 'fe80::1', False),
  942. ('0.0.0.0/0', '10.10.10.1', True),
  943. ('::/0', 'fe80::1', True))
  944. @ddt.unpack
  945. def test_create_route(self, subnet, gateway, omit_destination):
  946. api_response = netapp_api.NaElement(
  947. fake.NET_ROUTES_CREATE_RESPONSE)
  948. expected_api_args = {
  949. 'destination': subnet,
  950. 'gateway': gateway,
  951. 'return-record': 'true',
  952. }
  953. self.mock_object(
  954. self.client, 'send_request', mock.Mock(return_value=api_response))
  955. destination = None if omit_destination else subnet
  956. self.client.create_route(gateway, destination=destination)
  957. self.client.send_request.assert_called_once_with(
  958. 'net-routes-create', expected_api_args)
  959. def test_create_route_duplicate(self):
  960. self.mock_object(client_cmode.LOG, 'debug')
  961. expected_api_args = {
  962. 'destination': fake.SUBNET,
  963. 'gateway': fake.GATEWAY,
  964. 'return-record': 'true',
  965. }
  966. self.mock_object(
  967. self.client, 'send_request',
  968. mock.Mock(side_effect=self._mock_api_error(
  969. code=netapp_api.EAPIERROR, message='Duplicate route exists.')))
  970. self.client.create_route(fake.GATEWAY, destination=fake.SUBNET)
  971. self.client.send_request.assert_called_once_with(
  972. 'net-routes-create', expected_api_args)
  973. self.assertEqual(1, client_cmode.LOG.debug.call_count)
  974. def test_create_route_api_error(self):
  975. expected_api_args = {
  976. 'destination': fake.SUBNET,
  977. 'gateway': fake.GATEWAY,
  978. 'return-record': 'true',
  979. }
  980. self.mock_object(
  981. self.client, 'send_request',
  982. mock.Mock(side_effect=self._mock_api_error()))
  983. self.assertRaises(exception.NetAppException,
  984. self.client.create_route,
  985. fake.GATEWAY, destination=fake.SUBNET)
  986. self.client.send_request.assert_called_once_with(
  987. 'net-routes-create', expected_api_args)
  988. def test_create_route_without_gateway(self):
  989. self.mock_object(self.client, 'send_request')
  990. self.client.create_route(None, destination=fake.SUBNET)
  991. self.assertFalse(self.client.send_request.called)
  992. def test_ensure_broadcast_domain_for_port_domain_match(self):
  993. port_info = {
  994. 'ipspace': fake.IPSPACE_NAME,
  995. 'broadcast-domain': fake.BROADCAST_DOMAIN,
  996. }
  997. self.mock_object(self.client,
  998. '_get_broadcast_domain_for_port',
  999. mock.Mock(return_value=port_info))
  1000. self.mock_object(self.client,
  1001. '_broadcast_domain_exists',
  1002. mock.Mock(return_value=True))
  1003. self.mock_object(self.client, '_create_broadcast_domain')
  1004. self.mock_object(self.client, '_modify_broadcast_domain')
  1005. self.mock_object(self.client, '_add_port_to_broadcast_domain')
  1006. self.client._ensure_broadcast_domain_for_port(
  1007. fake.NODE_NAME, fake.PORT, fake.MTU, ipspace=fake.IPSPACE_NAME)
  1008. self.client._get_broadcast_domain_for_port.assert_called_once_with(
  1009. fake.NODE_NAME, fake.PORT)
  1010. self.client._modify_broadcast_domain.assert_called_once_with(
  1011. fake.BROADCAST_DOMAIN, fake.IPSPACE_NAME, fake.MTU)
  1012. self.assertFalse(self.client._broadcast_domain_exists.called)
  1013. self.assertFalse(self.client._create_broadcast_domain.called)
  1014. self.assertFalse(self.client._add_port_to_broadcast_domain.called)
  1015. @ddt.data(fake.IPSPACE_NAME, client_cmode.DEFAULT_IPSPACE)
  1016. def test_ensure_broadcast_domain_for_port_other_domain(self, ipspace):
  1017. port_info = {
  1018. 'ipspace': ipspace,
  1019. 'broadcast-domain': 'other_domain',
  1020. }
  1021. self.mock_object(self.client,
  1022. '_get_broadcast_domain_for_port',
  1023. mock.Mock(return_value=port_info))
  1024. self.mock_object(self.client,
  1025. '_broadcast_domain_exists',
  1026. mock.Mock(return_value=True))
  1027. self.mock_object(self.client, '_create_broadcast_domain')
  1028. self.mock_object(self.client, '_modify_broadcast_domain')
  1029. self.mock_object(self.client, '_remove_port_from_broadcast_domain')
  1030. self.mock_object(self.client, '_add_port_to_broadcast_domain')
  1031. self.client._ensure_broadcast_domain_for_port(
  1032. fake.NODE_NAME, fake.PORT, ipspace=fake.IPSPACE_NAME, mtu=fake.MTU)
  1033. self.client._get_broadcast_domain_for_port.assert_called_once_with(
  1034. fake.NODE_NAME, fake.PORT)
  1035. self.client._remove_port_from_broadcast_domain.assert_called_once_with(
  1036. fake.NODE_NAME, fake.PORT, 'other_domain', ipspace)
  1037. self.client._broadcast_domain_exists.assert_called_once_with(
  1038. fake.BROADCAST_DOMAIN, fake.IPSPACE_NAME)
  1039. self.assertFalse(self.client._create_broadcast_domain.called)
  1040. self.client._modify_broadcast_domain.assert_called_once_with(
  1041. fake.BROADCAST_DOMAIN, fake.IPSPACE_NAME, fake.MTU)
  1042. self.client._add_port_to_broadcast_domain.assert_called_once_with(
  1043. fake.NODE_NAME, fake.PORT, fake.BROADCAST_DOMAIN,
  1044. fake.IPSPACE_NAME)
  1045. def test_ensure_broadcast_domain_for_port_no_domain(self):
  1046. port_info = {
  1047. 'ipspace': fake.IPSPACE_NAME,
  1048. 'broadcast-domain': None,
  1049. }
  1050. self.mock_object(self.client,
  1051. '_get_broadcast_domain_for_port',
  1052. mock.Mock(return_value=port_info))
  1053. self.mock_object(self.client,
  1054. '_broadcast_domain_exists',
  1055. mock.Mock(return_value=False))
  1056. self.mock_object(self.client, '_create_broadcast_domain')
  1057. self.mock_object(self.client, '_modify_broadcast_domain')
  1058. self.mock_object(self.client, '_remove_port_from_broadcast_domain')
  1059. self.mock_object(self.client, '_add_port_to_broadcast_domain')
  1060. self.client._ensure_broadcast_domain_for_port(
  1061. fake.NODE_NAME, fake.PORT, ipspace=fake.IPSPACE_NAME, mtu=fake.MTU)
  1062. self.client._get_broadcast_domain_for_port.assert_called_once_with(
  1063. fake.NODE_NAME, fake.PORT)
  1064. self.assertFalse(self.client._remove_port_from_broadcast_domain.called)
  1065. self.client._broadcast_domain_exists.assert_called_once_with(
  1066. fake.BROADCAST_DOMAIN, fake.IPSPACE_NAME)
  1067. self.client._create_broadcast_domain.assert_called_once_with(
  1068. fake.BROADCAST_DOMAIN, fake.IPSPACE_NAME, fake.MTU)
  1069. self.assertFalse(self.client._modify_broadcast_domain.called)
  1070. self.client._add_port_to_broadcast_domain.assert_called_once_with(
  1071. fake.NODE_NAME, fake.PORT, fake.BROADCAST_DOMAIN,
  1072. fake.IPSPACE_NAME)
  1073. def test_get_broadcast_domain_for_port(self):
  1074. api_response = netapp_api.NaElement(
  1075. fake.NET_PORT_GET_ITER_BROADCAST_DOMAIN_RESPONSE)
  1076. self.mock_object(self.client,
  1077. 'send_iter_request',
  1078. mock.Mock(return_value=api_response))
  1079. net_port_get_iter_args = {
  1080. 'query': {
  1081. 'net-port-info': {
  1082. 'node': fake.NODE_NAME,
  1083. 'port': fake.PORT,
  1084. },
  1085. },
  1086. 'desired-attributes': {
  1087. 'net-port-info': {
  1088. 'broadcast-domain': None,
  1089. 'ipspace': None,
  1090. },
  1091. },
  1092. }
  1093. result = self.client._get_broadcast_domain_for_port(fake.NODE_NAME,
  1094. fake.PORT)
  1095. expected = {
  1096. 'broadcast-domain': fake.BROADCAST_DOMAIN,
  1097. 'ipspace': fake.IPSPACE_NAME,
  1098. }
  1099. self.client.send_iter_request.assert_has_calls([
  1100. mock.call('net-port-get-iter', net_port_get_iter_args)])
  1101. self.assertEqual(expected, result)
  1102. def test_get_broadcast_domain_for_port_port_not_found(self):
  1103. api_response = netapp_api.NaElement(
  1104. fake.NO_RECORDS_RESPONSE)
  1105. self.mock_object(self.client,
  1106. 'send_iter_request',
  1107. mock.Mock(return_value=api_response))
  1108. self.assertRaises(exception.NetAppException,
  1109. self.client._get_broadcast_domain_for_port,
  1110. fake.NODE_NAME,
  1111. fake.PORT)
  1112. def test_get_broadcast_domain_for_port_domain_not_found(self):
  1113. api_response = netapp_api.NaElement(
  1114. fake.NET_PORT_GET_ITER_BROADCAST_DOMAIN_MISSING_RESPONSE)
  1115. self.mock_object(self.client,
  1116. 'send_iter_request',
  1117. mock.Mock(return_value=api_response))
  1118. result = self.client._get_broadcast_domain_for_port(fake.NODE_NAME,
  1119. fake.PORT)
  1120. expected = {
  1121. 'broadcast-domain': None,
  1122. 'ipspace': fake.IPSPACE_NAME,
  1123. }
  1124. self.assertEqual(expected, result)
  1125. def test_broadcast_domain_exists(self):
  1126. api_response = netapp_api.NaElement(
  1127. fake.NET_PORT_BROADCAST_DOMAIN_GET_ITER_RESPONSE)
  1128. self.mock_object(self.client,
  1129. 'send_iter_request',
  1130. mock.Mock(return_value=api_response))
  1131. result = self.client._broadcast_domain_exists(fake.BROADCAST_DOMAIN,
  1132. fake.IPSPACE_NAME)
  1133. net_port_broadcast_domain_get_iter_args = {
  1134. 'query': {
  1135. 'net-port-broadcast-domain-info': {
  1136. 'ipspace': fake.IPSPACE_NAME,
  1137. 'broadcast-domain': fake.BROADCAST_DOMAIN,
  1138. },
  1139. },
  1140. 'desired-attributes': {
  1141. 'net-port-broadcast-domain-info': None,
  1142. },
  1143. }
  1144. self.client.send_iter_request.assert_has_calls([
  1145. mock.call('net-port-broadcast-domain-get-iter',
  1146. net_port_broadcast_domain_get_iter_args)])
  1147. self.assertTrue(result)
  1148. def test_broadcast_domain_exists_not_found(self):
  1149. api_response = netapp_api.NaElement(
  1150. fake.NO_RECORDS_RESPONSE)
  1151. self.mock_object(self.client,
  1152. 'send_request',
  1153. mock.Mock(return_value=api_response))
  1154. result = self.client._broadcast_domain_exists(fake.BROADCAST_DOMAIN,
  1155. fake.IPSPACE_NAME)
  1156. self.assertFalse(result)
  1157. def test_create_broadcast_domain(self):
  1158. self.mock_object(self.client, 'send_request')
  1159. result = self.client._create_broadcast_domain(fake.BROADCAST_DOMAIN,
  1160. fake.IPSPACE_NAME,
  1161. fake.MTU)
  1162. net_port_broadcast_domain_create_args = {
  1163. 'ipspace': fake.IPSPACE_NAME,
  1164. 'broadcast-domain': fake.BROADCAST_DOMAIN,
  1165. 'mtu': fake.MTU,
  1166. }
  1167. self.assertIsNone(result)
  1168. self.client.send_request.assert_has_calls([
  1169. mock.call('net-port-broadcast-domain-create',
  1170. net_port_broadcast_domain_create_args)])
  1171. def test_modify_broadcast_domain(self):
  1172. self.mock_object(self.client, 'send_request')
  1173. result = self.client._modify_broadcast_domain(fake.BROADCAST_DOMAIN,
  1174. fake.IPSPACE_NAME,
  1175. fake.MTU)
  1176. net_port_broadcast_domain_modify_args = {
  1177. 'ipspace': fake.IPSPACE_NAME,
  1178. 'broadcast-domain': fake.BROADCAST_DOMAIN,
  1179. 'mtu': fake.MTU,
  1180. }
  1181. self.assertIsNone(result)
  1182. self.client.send_request.assert_called_once_with(
  1183. 'net-port-broadcast-domain-modify',
  1184. net_port_broadcast_domain_modify_args)
  1185. def test_delete_broadcast_domain(self):
  1186. self.mock_object(self.client, 'send_request')
  1187. result = self.client._delete_broadcast_domain(fake.BROADCAST_DOMAIN,
  1188. fake.IPSPACE_NAME)
  1189. net_port_broadcast_domain_delete_args = {
  1190. 'ipspace': fake.IPSPACE_NAME,
  1191. 'broadcast-domain': fake.BROADCAST_DOMAIN,
  1192. }
  1193. self.assertIsNone(result)
  1194. self.client.send_request.assert_has_calls([
  1195. mock.call('net-port-broadcast-domain-destroy',
  1196. net_port_broadcast_domain_delete_args)])
  1197. def test_delete_broadcast_domains_for_ipspace_not_found(self):
  1198. self.mock_object(self.client,
  1199. 'get_ipspaces',
  1200. mock.Mock(return_value=[]))
  1201. self.mock_object(self.client, '_delete_broadcast_domain')
  1202. self.client._delete_broadcast_domains_for_ipspace(fake.IPSPACE_NAME)
  1203. self.client.get_ipspaces.assert_called_once_with(
  1204. ipspace_name=fake.IPSPACE_NAME)
  1205. self.assertFalse(self.client._delete_broadcast_domain.called)
  1206. def test_delete_broadcast_domains_for_ipspace(self):
  1207. self.mock_object(self.client,
  1208. 'get_ipspaces',
  1209. mock.Mock(return_value=fake.IPSPACES))
  1210. self.mock_object(self.client, '_delete_broadcast_domain')
  1211. self.client._delete_broadcast_domains_for_ipspace(fake.IPSPACE_NAME)
  1212. self.client.get_ipspaces.assert_called_once_with(
  1213. ipspace_name=fake.IPSPACE_NAME)
  1214. self.client._delete_broadcast_domain.assert_called_once_with(
  1215. fake.IPSPACES[0]['broadcast-domains'][0], fake.IPSPACE_NAME)
  1216. def test_add_port_to_broadcast_domain(self):
  1217. self.mock_object(self.client, 'send_request')
  1218. add_port_to_broadcast_domain_args = {
  1219. 'ipspace': fake.IPSPACE_NAME,
  1220. 'broadcast-domain': fake.BROADCAST_DOMAIN,
  1221. 'ports': {
  1222. 'net-qualified-port-name': ':'.join([fake.NODE_NAME,
  1223. fake.VLAN_PORT])
  1224. }
  1225. }
  1226. result = self.client._add_port_to_broadcast_domain(
  1227. fake.NODE_NAME, fake.VLAN_PORT, fake.BROADCAST_DOMAIN,
  1228. fake.IPSPACE_NAME)
  1229. self.assertIsNone(result)
  1230. self.client.send_request.assert_has_calls([
  1231. mock.call('net-port-broadcast-domain-add-ports',
  1232. add_port_to_broadcast_domain_args)])
  1233. def test_add_port_to_broadcast_domain_already_present(self):
  1234. self.mock_object(self.client, 'send_request', self._mock_api_error(
  1235. code=netapp_api.
  1236. E_VIFMGR_PORT_ALREADY_ASSIGNED_TO_BROADCAST_DOMAIN))
  1237. result = self.client._add_port_to_broadcast_domain(
  1238. fake.NODE_NAME, fake.VLAN_PORT, fake.BROADCAST_DOMAIN,
  1239. fake.IPSPACE_NAME)
  1240. self.assertIsNone(result)
  1241. def test_add_port_to_broadcast_domain_api_error(self):
  1242. self.mock_object(self.client, 'send_request', self._mock_api_error())
  1243. self.assertRaises(exception.NetAppException,
  1244. self.client._add_port_to_broadcast_domain,
  1245. fake.NODE_NAME,
  1246. fake.VLAN_PORT,
  1247. fake.BROADCAST_DOMAIN,
  1248. fake.IPSPACE_NAME)
  1249. def test_remove_port_from_broadcast_domain(self):
  1250. self.mock_object(self.client, 'send_request')
  1251. result = self.client._remove_port_from_broadcast_domain(
  1252. fake.NODE_NAME, fake.VLAN_PORT, fake.BROADCAST_DOMAIN,
  1253. fake.IPSPACE_NAME)
  1254. net_port_broadcast_domain_remove_ports_args = {
  1255. 'ipspace': fake.IPSPACE_NAME,
  1256. 'broadcast-domain': fake.BROADCAST_DOMAIN,
  1257. 'ports': {
  1258. 'net-qualified-port-name': ':'.join([fake.NODE_NAME,
  1259. fake.VLAN_PORT])
  1260. }
  1261. }
  1262. self.assertIsNone(result)
  1263. self.client.send_request.assert_has_calls([
  1264. mock.call('net-port-broadcast-domain-remove-ports',
  1265. net_port_broadcast_domain_remove_ports_args)])
  1266. def test_network_interface_exists(self):
  1267. api_response = netapp_api.NaElement(
  1268. fake.NET_INTERFACE_GET_ONE_RESPONSE)
  1269. self.mock_object(self.client,
  1270. 'send_iter_request',
  1271. mock.Mock(return_value=api_response))
  1272. net_interface_get_args = {
  1273. 'query': {
  1274. 'net-interface-info': {
  1275. 'address': fake.IP_ADDRESS,
  1276. 'home-node': fake.NODE_NAME,
  1277. 'home-port': fake.VLAN_PORT,
  1278. 'netmask': fake.NETMASK,
  1279. 'vserver': fake.VSERVER_NAME}
  1280. },
  1281. 'desired-attributes': {
  1282. 'net-interface-info': {
  1283. 'interface-name': None,
  1284. }
  1285. }
  1286. }
  1287. result = self.client.network_interface_exists(
  1288. fake.VSERVER_NAME, fake.NODE_NAME, fake.PORT, fake.IP_ADDRESS,
  1289. fake.NETMASK, fake.VLAN)
  1290. self.client.send_iter_request.assert_has_calls([
  1291. mock.call('net-interface-get-iter', net_interface_get_args)])
  1292. self.assertTrue(result)
  1293. def test_network_interface_exists_not_found(self):
  1294. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  1295. self.mock_object(self.client,
  1296. 'send_iter_request',
  1297. mock.Mock(return_value=api_response))
  1298. net_interface_get_args = {
  1299. 'query': {
  1300. 'net-interface-info': {
  1301. 'address': fake.IP_ADDRESS,
  1302. 'home-node': fake.NODE_NAME,
  1303. 'home-port': fake.PORT,
  1304. 'netmask': fake.NETMASK,
  1305. 'vserver': fake.VSERVER_NAME}
  1306. },
  1307. 'desired-attributes': {
  1308. 'net-interface-info': {
  1309. 'interface-name': None,
  1310. }
  1311. }
  1312. }
  1313. result = self.client.network_interface_exists(
  1314. fake.VSERVER_NAME, fake.NODE_NAME, fake.PORT, fake.IP_ADDRESS,
  1315. fake.NETMASK, None)
  1316. self.client.send_iter_request.assert_has_calls([
  1317. mock.call('net-interface-get-iter', net_interface_get_args)])
  1318. self.assertFalse(result)
  1319. def test_list_network_interfaces(self):
  1320. api_response = netapp_api.NaElement(
  1321. fake.NET_INTERFACE_GET_ITER_RESPONSE)
  1322. self.mock_object(self.client,
  1323. 'send_iter_request',
  1324. mock.Mock(return_value=api_response))
  1325. net_interface_get_args = {
  1326. 'desired-attributes': {
  1327. 'net-interface-info': {
  1328. 'interface-name': None,
  1329. }
  1330. }
  1331. }
  1332. result = self.client.list_network_interfaces()
  1333. self.client.send_iter_request.assert_has_calls([
  1334. mock.call('net-interface-get-iter', net_interface_get_args)])
  1335. self.assertSequenceEqual(fake.LIF_NAMES, result)
  1336. def test_list_network_interfaces_not_found(self):
  1337. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  1338. self.mock_object(self.client,
  1339. 'send_request',
  1340. mock.Mock(return_value=api_response))
  1341. result = self.client.list_network_interfaces()
  1342. self.assertListEqual([], result)
  1343. def test_get_network_interfaces(self):
  1344. api_response = netapp_api.NaElement(
  1345. fake.NET_INTERFACE_GET_ITER_RESPONSE)
  1346. self.mock_object(self.client,
  1347. 'send_iter_request',
  1348. mock.Mock(return_value=api_response))
  1349. result = self.client.get_network_interfaces()
  1350. self.client.send_iter_request.assert_has_calls([
  1351. mock.call('net-interface-get-iter', None)])
  1352. self.assertSequenceEqual(fake.LIFS, result)
  1353. def test_get_network_interfaces_filtered_by_protocol(self):
  1354. api_response = netapp_api.NaElement(
  1355. fake.NET_INTERFACE_GET_ITER_RESPONSE_NFS)
  1356. self.mock_object(self.client,
  1357. 'send_iter_request',
  1358. mock.Mock(return_value=api_response))
  1359. result = self.client.get_network_interfaces(protocols=['NFS'])
  1360. net_interface_get_args = {
  1361. 'query': {
  1362. 'net-interface-info': {
  1363. 'data-protocols': {
  1364. 'data-protocol': 'nfs',
  1365. }
  1366. }
  1367. }
  1368. }
  1369. self.client.send_iter_request.assert_has_calls([
  1370. mock.call('net-interface-get-iter', net_interface_get_args)])
  1371. self.assertListEqual(fake.NFS_LIFS, result)
  1372. def test_get_network_interfaces_not_found(self):
  1373. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  1374. self.mock_object(self.client,
  1375. 'send_iter_request',
  1376. mock.Mock(return_value=api_response))
  1377. result = self.client.get_network_interfaces()
  1378. self.client.send_iter_request.assert_has_calls([
  1379. mock.call('net-interface-get-iter', None)])
  1380. self.assertListEqual([], result)
  1381. def test_get_ipspaces(self):
  1382. self.client.features.add_feature('IPSPACES')
  1383. api_response = netapp_api.NaElement(
  1384. fake.NET_IPSPACES_GET_ITER_RESPONSE)
  1385. self.mock_object(self.client,
  1386. 'send_iter_request',
  1387. mock.Mock(return_value=api_response))
  1388. result = self.client.get_ipspaces(ipspace_name=fake.IPSPACE_NAME)
  1389. net_ipspaces_get_iter_args = {
  1390. 'query': {
  1391. 'net-ipspaces-info': {
  1392. 'ipspace': fake.IPSPACE_NAME,
  1393. },
  1394. },
  1395. }
  1396. self.client.send_iter_request.assert_has_calls([
  1397. mock.call('net-ipspaces-get-iter', net_ipspaces_get_iter_args)])
  1398. self.assertEqual(fake.IPSPACES, result)
  1399. def test_get_ipspaces_not_found(self):
  1400. self.client.features.add_feature('IPSPACES')
  1401. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  1402. self.mock_object(self.client,
  1403. 'send_iter_request',
  1404. mock.Mock(return_value=api_response))
  1405. result = self.client.get_ipspaces()
  1406. net_ipspaces_get_iter_args = {}
  1407. self.client.send_iter_request.assert_has_calls([
  1408. mock.call('net-ipspaces-get-iter', net_ipspaces_get_iter_args)])
  1409. self.assertEqual([], result)
  1410. def test_get_ipspaces_not_supported(self):
  1411. self.mock_object(self.client, 'send_iter_request')
  1412. result = self.client.get_ipspaces()
  1413. self.assertFalse(self.client.send_iter_request.called)
  1414. self.assertEqual([], result)
  1415. @ddt.data((fake.NET_IPSPACES_GET_ITER_RESPONSE, True),
  1416. (fake.NO_RECORDS_RESPONSE, False))
  1417. @ddt.unpack
  1418. def test_ipspace_exists(self, api_response, expected):
  1419. self.client.features.add_feature('IPSPACES')
  1420. api_response = netapp_api.NaElement(api_response)
  1421. self.mock_object(self.client,
  1422. 'send_iter_request',
  1423. mock.Mock(return_value=api_response))
  1424. result = self.client.ipspace_exists(fake.IPSPACE_NAME)
  1425. net_ipspaces_get_iter_args = {
  1426. 'query': {
  1427. 'net-ipspaces-info': {
  1428. 'ipspace': fake.IPSPACE_NAME,
  1429. },
  1430. },
  1431. 'desired-attributes': {
  1432. 'net-ipspaces-info': {
  1433. 'ipspace': None,
  1434. },
  1435. },
  1436. }
  1437. self.client.send_iter_request.assert_has_calls([
  1438. mock.call('net-ipspaces-get-iter', net_ipspaces_get_iter_args)])
  1439. self.assertEqual(expected, result)
  1440. def test_ipspace_exists_not_supported(self):
  1441. result = self.client.ipspace_exists(fake.IPSPACE_NAME)
  1442. self.assertFalse(result)
  1443. def test_create_ipspace(self):
  1444. self.mock_object(self.client, 'send_request')
  1445. self.client.create_ipspace(fake.IPSPACE_NAME)
  1446. net_ipspaces_create_args = {'ipspace': fake.IPSPACE_NAME}
  1447. self.client.send_request.assert_has_calls([
  1448. mock.call('net-ipspaces-create', net_ipspaces_create_args)])
  1449. def test_delete_ipspace(self):
  1450. mock_delete_broadcast_domains_for_ipspace = self.mock_object(
  1451. self.client, '_delete_broadcast_domains_for_ipspace')
  1452. self.mock_object(self.client, 'send_request')
  1453. self.client.delete_ipspace(fake.IPSPACE_NAME)
  1454. net_ipspaces_destroy_args = {'ipspace': fake.IPSPACE_NAME}
  1455. mock_delete_broadcast_domains_for_ipspace.assert_called_once_with(
  1456. fake.IPSPACE_NAME)
  1457. self.client.send_request.assert_has_calls([
  1458. mock.call('net-ipspaces-destroy', net_ipspaces_destroy_args)])
  1459. def test_add_vserver_to_ipspace(self):
  1460. self.mock_object(self.client, 'send_request')
  1461. self.client.add_vserver_to_ipspace(fake.IPSPACE_NAME,
  1462. fake.VSERVER_NAME)
  1463. net_ipspaces_assign_vserver_args = {
  1464. 'ipspace': fake.IPSPACE_NAME,
  1465. 'vserver': fake.VSERVER_NAME
  1466. }
  1467. self.client.send_request.assert_has_calls([
  1468. mock.call('net-ipspaces-assign-vserver',
  1469. net_ipspaces_assign_vserver_args)])
  1470. def test_get_node_for_aggregate(self):
  1471. api_response = netapp_api.NaElement(
  1472. fake.AGGR_GET_NODE_RESPONSE).get_child_by_name(
  1473. 'attributes-list').get_children()
  1474. self.mock_object(self.client,
  1475. '_get_aggregates',
  1476. mock.Mock(return_value=api_response))
  1477. result = self.client.get_node_for_aggregate(fake.SHARE_AGGREGATE_NAME)
  1478. desired_attributes = {
  1479. 'aggr-attributes': {
  1480. 'aggregate-name': None,
  1481. 'aggr-ownership-attributes': {
  1482. 'home-name': None,
  1483. },
  1484. },
  1485. }
  1486. self.client._get_aggregates.assert_has_calls([
  1487. mock.call(
  1488. aggregate_names=[fake.SHARE_AGGREGATE_NAME],
  1489. desired_attributes=desired_attributes)])
  1490. self.assertEqual(fake.NODE_NAME, result)
  1491. def test_get_node_for_aggregate_none_requested(self):
  1492. result = self.client.get_node_for_aggregate(None)
  1493. self.assertIsNone(result)
  1494. def test_get_node_for_aggregate_api_not_found(self):
  1495. self.mock_object(self.client,
  1496. 'send_iter_request',
  1497. mock.Mock(side_effect=self._mock_api_error(
  1498. netapp_api.EAPINOTFOUND)))
  1499. result = self.client.get_node_for_aggregate(fake.SHARE_AGGREGATE_NAME)
  1500. self.assertIsNone(result)
  1501. def test_get_node_for_aggregate_api_error(self):
  1502. self.mock_object(self.client,
  1503. 'send_iter_request',
  1504. self._mock_api_error())
  1505. self.assertRaises(netapp_api.NaApiError,
  1506. self.client.get_node_for_aggregate,
  1507. fake.SHARE_AGGREGATE_NAME)
  1508. def test_get_node_for_aggregate_not_found(self):
  1509. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  1510. self.mock_object(self.client,
  1511. 'send_iter_request',
  1512. mock.Mock(return_value=api_response))
  1513. result = self.client.get_node_for_aggregate(fake.SHARE_AGGREGATE_NAME)
  1514. self.assertIsNone(result)
  1515. def test_get_cluster_aggregate_capacities(self):
  1516. api_response = netapp_api.NaElement(
  1517. fake.AGGR_GET_SPACE_RESPONSE).get_child_by_name(
  1518. 'attributes-list').get_children()
  1519. self.mock_object(self.client,
  1520. '_get_aggregates',
  1521. mock.Mock(return_value=api_response))
  1522. result = self.client.get_cluster_aggregate_capacities(
  1523. fake.SHARE_AGGREGATE_NAMES)
  1524. desired_attributes = {
  1525. 'aggr-attributes': {
  1526. 'aggregate-name': None,
  1527. 'aggr-space-attributes': {
  1528. 'size-available': None,
  1529. 'size-total': None,
  1530. 'size-used': None,
  1531. }
  1532. }
  1533. }
  1534. self.client._get_aggregates.assert_has_calls([
  1535. mock.call(
  1536. aggregate_names=fake.SHARE_AGGREGATE_NAMES,
  1537. desired_attributes=desired_attributes)])
  1538. expected = {
  1539. fake.SHARE_AGGREGATE_NAMES[0]: {
  1540. 'available': 45670400,
  1541. 'total': 943718400,
  1542. 'used': 898048000,
  1543. },
  1544. fake.SHARE_AGGREGATE_NAMES[1]: {
  1545. 'available': 4267659264,
  1546. 'total': 7549747200,
  1547. 'used': 3282087936,
  1548. },
  1549. }
  1550. self.assertDictEqual(expected, result)
  1551. def test_get_cluster_aggregate_capacities_not_found(self):
  1552. api_response = netapp_api.NaElement('none').get_children()
  1553. self.mock_object(self.client,
  1554. '_get_aggregates',
  1555. mock.Mock(return_value=api_response))
  1556. result = self.client.get_cluster_aggregate_capacities(
  1557. fake.SHARE_AGGREGATE_NAMES)
  1558. self.assertEqual({}, result)
  1559. def test_get_cluster_aggregate_capacities_none_requested(self):
  1560. result = self.client.get_cluster_aggregate_capacities([])
  1561. self.assertEqual({}, result)
  1562. def test_get_vserver_aggregate_capacities(self):
  1563. api_response = netapp_api.NaElement(fake.VSERVER_GET_RESPONSE)
  1564. self.mock_object(self.vserver_client,
  1565. 'send_request',
  1566. mock.Mock(return_value=api_response))
  1567. result = self.vserver_client.get_vserver_aggregate_capacities()
  1568. vserver_args = {
  1569. 'desired-attributes': {
  1570. 'vserver-info': {
  1571. 'vserver-name': None,
  1572. 'vserver-aggr-info-list': {
  1573. 'vserver-aggr-info': {
  1574. 'aggr-name': None,
  1575. 'aggr-availsize': None
  1576. }
  1577. }
  1578. }
  1579. }
  1580. }
  1581. self.vserver_client.send_request.assert_has_calls([
  1582. mock.call('vserver-get', vserver_args)])
  1583. self.assertDictEqual(fake.VSERVER_AGGREGATES, result)
  1584. def test_get_vserver_aggregate_capacities_partial_request(self):
  1585. api_response = netapp_api.NaElement(fake.VSERVER_GET_RESPONSE)
  1586. self.mock_object(self.vserver_client,
  1587. 'send_request',
  1588. mock.Mock(return_value=api_response))
  1589. result = self.vserver_client.get_vserver_aggregate_capacities(
  1590. fake.SHARE_AGGREGATE_NAMES[0])
  1591. expected = {fake.SHARE_AGGREGATE_NAMES[0]:
  1592. fake.VSERVER_AGGREGATES[fake.SHARE_AGGREGATE_NAMES[0]]}
  1593. self.assertDictEqual(expected, result)
  1594. def test_get_vserver_aggregate_capacities_aggregate_not_found(self):
  1595. api_response = netapp_api.NaElement(
  1596. fake.VSERVER_GET_RESPONSE_NO_AGGREGATES)
  1597. self.mock_object(self.vserver_client,
  1598. 'send_request',
  1599. mock.Mock(return_value=api_response))
  1600. result = self.vserver_client.get_vserver_aggregate_capacities()
  1601. self.assertDictEqual({}, result)
  1602. self.assertEqual(1, client_cmode.LOG.warning.call_count)
  1603. def test_get_vserver_aggregate_capacities_vserver_not_found(self):
  1604. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  1605. self.mock_object(self.vserver_client,
  1606. 'send_request',
  1607. mock.Mock(return_value=api_response))
  1608. self.assertRaises(exception.NetAppException,
  1609. self.vserver_client.get_vserver_aggregate_capacities)
  1610. def test_get_vserver_aggregate_capacities_none_requested(self):
  1611. result = self.client.get_vserver_aggregate_capacities([])
  1612. self.assertEqual({}, result)
  1613. def test_get_aggregates(self):
  1614. api_response = netapp_api.NaElement(fake.AGGR_GET_ITER_RESPONSE)
  1615. self.mock_object(self.client,
  1616. 'send_iter_request',
  1617. mock.Mock(return_value=api_response))
  1618. result = self.client._get_aggregates()
  1619. self.client.send_iter_request.assert_has_calls([
  1620. mock.call('aggr-get-iter', {})])
  1621. self.assertListEqual(
  1622. [aggr.to_string() for aggr in api_response.get_child_by_name(
  1623. 'attributes-list').get_children()],
  1624. [aggr.to_string() for aggr in result])
  1625. def test_get_aggregates_with_filters(self):
  1626. api_response = netapp_api.NaElement(fake.AGGR_GET_SPACE_RESPONSE)
  1627. self.mock_object(self.client,
  1628. 'send_iter_request',
  1629. mock.Mock(return_value=api_response))
  1630. desired_attributes = {
  1631. 'aggr-attributes': {
  1632. 'aggregate-name': None,
  1633. 'aggr-space-attributes': {
  1634. 'size-total': None,
  1635. 'size-available': None,
  1636. }
  1637. }
  1638. }
  1639. result = self.client._get_aggregates(
  1640. aggregate_names=fake.SHARE_AGGREGATE_NAMES,
  1641. desired_attributes=desired_attributes)
  1642. aggr_get_iter_args = {
  1643. 'query': {
  1644. 'aggr-attributes': {
  1645. 'aggregate-name': '|'.join(fake.SHARE_AGGREGATE_NAMES),
  1646. }
  1647. },
  1648. 'desired-attributes': desired_attributes
  1649. }
  1650. self.client.send_iter_request.assert_has_calls([
  1651. mock.call('aggr-get-iter', aggr_get_iter_args)])
  1652. self.assertListEqual(
  1653. [aggr.to_string() for aggr in api_response.get_child_by_name(
  1654. 'attributes-list').get_children()],
  1655. [aggr.to_string() for aggr in result])
  1656. def test_get_aggregates_not_found(self):
  1657. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  1658. self.mock_object(self.client,
  1659. 'send_iter_request',
  1660. mock.Mock(return_value=api_response))
  1661. result = self.client._get_aggregates()
  1662. self.client.send_iter_request.assert_has_calls([
  1663. mock.call('aggr-get-iter', {})])
  1664. self.assertListEqual([], result)
  1665. def test_get_performance_instance_uuids(self):
  1666. api_response = netapp_api.NaElement(
  1667. fake.PERF_OBJECT_INSTANCE_LIST_INFO_ITER_RESPONSE)
  1668. self.mock_object(self.client,
  1669. 'send_request',
  1670. mock.Mock(return_value=api_response))
  1671. result = self.client.get_performance_instance_uuids(
  1672. 'system', fake.NODE_NAME)
  1673. expected = [fake.NODE_NAME + ':kernel:system']
  1674. self.assertEqual(expected, result)
  1675. perf_object_instance_list_info_iter_args = {
  1676. 'objectname': 'system',
  1677. 'query': {
  1678. 'instance-info': {
  1679. 'uuid': fake.NODE_NAME + ':*',
  1680. }
  1681. }
  1682. }
  1683. self.client.send_request.assert_called_once_with(
  1684. 'perf-object-instance-list-info-iter',
  1685. perf_object_instance_list_info_iter_args)
  1686. def test_get_performance_counter_info(self):
  1687. api_response = netapp_api.NaElement(
  1688. fake.PERF_OBJECT_COUNTER_LIST_INFO_WAFL_RESPONSE)
  1689. self.mock_object(self.client,
  1690. 'send_request',
  1691. mock.Mock(return_value=api_response))
  1692. result = self.client.get_performance_counter_info('wafl',
  1693. 'cp_phase_times')
  1694. expected = {
  1695. 'name': 'cp_phase_times',
  1696. 'base-counter': 'total_cp_msecs',
  1697. 'labels': fake.PERF_OBJECT_COUNTER_TOTAL_CP_MSECS_LABELS,
  1698. }
  1699. self.assertEqual(expected, result)
  1700. perf_object_counter_list_info_args = {'objectname': 'wafl'}
  1701. self.client.send_request.assert_called_once_with(
  1702. 'perf-object-counter-list-info',
  1703. perf_object_counter_list_info_args)
  1704. def test_get_performance_counter_info_not_found(self):
  1705. api_response = netapp_api.NaElement(
  1706. fake.PERF_OBJECT_COUNTER_LIST_INFO_WAFL_RESPONSE)
  1707. self.mock_object(self.client,
  1708. 'send_request',
  1709. mock.Mock(return_value=api_response))
  1710. self.assertRaises(exception.NotFound,
  1711. self.client.get_performance_counter_info,
  1712. 'wafl',
  1713. 'invalid')
  1714. def test_get_performance_counters(self):
  1715. api_response = netapp_api.NaElement(
  1716. fake.PERF_OBJECT_GET_INSTANCES_SYSTEM_RESPONSE_CMODE)
  1717. self.mock_object(self.client,
  1718. 'send_request',
  1719. mock.Mock(return_value=api_response))
  1720. instance_uuids = [
  1721. fake.NODE_NAMES[0] + ':kernel:system',
  1722. fake.NODE_NAMES[1] + ':kernel:system',
  1723. ]
  1724. counter_names = ['avg_processor_busy']
  1725. result = self.client.get_performance_counters('system',
  1726. instance_uuids,
  1727. counter_names)
  1728. expected = [
  1729. {
  1730. 'avg_processor_busy': '5674745133134',
  1731. 'instance-name': 'system',
  1732. 'instance-uuid': instance_uuids[0],
  1733. 'node-name': fake.NODE_NAMES[0],
  1734. 'timestamp': '1453412013',
  1735. }, {
  1736. 'avg_processor_busy': '4077649009234',
  1737. 'instance-name': 'system',
  1738. 'instance-uuid': instance_uuids[1],
  1739. 'node-name': fake.NODE_NAMES[1],
  1740. 'timestamp': '1453412013'
  1741. },
  1742. ]
  1743. self.assertEqual(expected, result)
  1744. perf_object_get_instances_args = {
  1745. 'objectname': 'system',
  1746. 'instance-uuids': [
  1747. {'instance-uuid': instance_uuid}
  1748. for instance_uuid in instance_uuids
  1749. ],
  1750. 'counters': [
  1751. {'counter': counter} for counter in counter_names
  1752. ],
  1753. }
  1754. self.client.send_request.assert_called_once_with(
  1755. 'perf-object-get-instances', perf_object_get_instances_args)
  1756. def test_setup_security_services_ldap(self):
  1757. self.mock_object(self.client, 'send_request')
  1758. self.mock_object(self.vserver_client, 'configure_ldap')
  1759. self.client.setup_security_services([fake.LDAP_SECURITY_SERVICE],
  1760. self.vserver_client,
  1761. fake.VSERVER_NAME)
  1762. vserver_modify_args = {
  1763. 'name-mapping-switch': [
  1764. {'nmswitch': 'ldap'},
  1765. {'nmswitch': 'file'},
  1766. ],
  1767. 'name-server-switch': [
  1768. {'nsswitch': 'ldap'},
  1769. {'nsswitch': 'file'},
  1770. ],
  1771. 'vserver-name': fake.VSERVER_NAME
  1772. }
  1773. self.client.send_request.assert_has_calls([
  1774. mock.call('vserver-modify', vserver_modify_args)])
  1775. self.vserver_client.configure_ldap.assert_has_calls([
  1776. mock.call(fake.LDAP_SECURITY_SERVICE)])
  1777. def test_setup_security_services_active_directory(self):
  1778. self.mock_object(self.client, 'send_request')
  1779. self.mock_object(self.vserver_client, 'configure_active_directory')
  1780. self.client.setup_security_services([fake.CIFS_SECURITY_SERVICE],
  1781. self.vserver_client,
  1782. fake.VSERVER_NAME)
  1783. vserver_modify_args = {
  1784. 'name-mapping-switch': [
  1785. {'nmswitch': 'ldap'},
  1786. {'nmswitch': 'file'},
  1787. ],
  1788. 'name-server-switch': [
  1789. {'nsswitch': 'ldap'},
  1790. {'nsswitch': 'file'},
  1791. ],
  1792. 'vserver-name': fake.VSERVER_NAME
  1793. }
  1794. self.client.send_request.assert_has_calls([
  1795. mock.call('vserver-modify', vserver_modify_args)])
  1796. self.vserver_client.configure_active_directory.assert_has_calls([
  1797. mock.call(fake.CIFS_SECURITY_SERVICE, fake.VSERVER_NAME)])
  1798. def test_setup_security_services_kerberos(self):
  1799. self.mock_object(self.client, 'send_request')
  1800. self.mock_object(self.client, 'create_kerberos_realm')
  1801. self.mock_object(self.vserver_client, 'configure_kerberos')
  1802. self.client.setup_security_services([fake.KERBEROS_SECURITY_SERVICE],
  1803. self.vserver_client,
  1804. fake.VSERVER_NAME)
  1805. vserver_modify_args = {
  1806. 'name-mapping-switch': [
  1807. {'nmswitch': 'ldap'},
  1808. {'nmswitch': 'file'},
  1809. ],
  1810. 'name-server-switch': [
  1811. {'nsswitch': 'ldap'},
  1812. {'nsswitch': 'file'},
  1813. ],
  1814. 'vserver-name': fake.VSERVER_NAME
  1815. }
  1816. self.client.send_request.assert_has_calls([
  1817. mock.call('vserver-modify', vserver_modify_args)])
  1818. self.client.create_kerberos_realm.assert_has_calls([
  1819. mock.call(fake.KERBEROS_SECURITY_SERVICE)])
  1820. self.vserver_client.configure_kerberos.assert_has_calls([
  1821. mock.call(fake.KERBEROS_SECURITY_SERVICE, fake.VSERVER_NAME)])
  1822. def test_setup_security_services_invalid(self):
  1823. self.mock_object(self.client, 'send_request')
  1824. self.assertRaises(exception.NetAppException,
  1825. self.client.setup_security_services,
  1826. [fake.INVALID_SECURITY_SERVICE],
  1827. self.vserver_client,
  1828. fake.VSERVER_NAME)
  1829. vserver_modify_args = {
  1830. 'name-mapping-switch': [
  1831. {'nmswitch': 'ldap'},
  1832. {'nmswitch': 'file'},
  1833. ],
  1834. 'name-server-switch': [
  1835. {'nsswitch': 'ldap'},
  1836. {'nsswitch': 'file'},
  1837. ],
  1838. 'vserver-name': fake.VSERVER_NAME
  1839. }
  1840. self.client.send_request.assert_has_calls([
  1841. mock.call('vserver-modify', vserver_modify_args)])
  1842. def test_enable_nfs(self):
  1843. self.mock_object(self.client, 'send_request')
  1844. self.mock_object(self.client, '_enable_nfs_protocols')
  1845. self.mock_object(self.client, '_create_default_nfs_export_rules')
  1846. self.client.enable_nfs(fake.NFS_VERSIONS)
  1847. self.client.send_request.assert_called_once_with('nfs-enable')
  1848. self.client._enable_nfs_protocols.assert_called_once_with(
  1849. fake.NFS_VERSIONS)
  1850. self.client._create_default_nfs_export_rules.assert_called_once_with()
  1851. @ddt.data((True, True, True), (True, False, False), (False, True, True))
  1852. @ddt.unpack
  1853. def test_enable_nfs_protocols(self, v3, v40, v41):
  1854. self.mock_object(self.client, 'send_request')
  1855. versions = []
  1856. if v3:
  1857. versions.append('nfs3')
  1858. if v40:
  1859. versions.append('nfs4.0')
  1860. if v41:
  1861. versions.append('nfs4.1')
  1862. self.client._enable_nfs_protocols(versions)
  1863. nfs_service_modify_args = {
  1864. 'is-nfsv3-enabled': 'true' if v3 else 'false',
  1865. 'is-nfsv40-enabled': 'true' if v40 else 'false',
  1866. 'is-nfsv41-enabled': 'true' if v41 else 'false',
  1867. }
  1868. self.client.send_request.assert_called_once_with(
  1869. 'nfs-service-modify', nfs_service_modify_args)
  1870. def test_create_default_nfs_export_rules(self):
  1871. class CopyingMock(mock.Mock):
  1872. def __call__(self, *args, **kwargs):
  1873. args = copy.deepcopy(args)
  1874. kwargs = copy.deepcopy(kwargs)
  1875. return super(CopyingMock, self).__call__(*args, **kwargs)
  1876. self.mock_object(self.client, 'send_request', CopyingMock())
  1877. self.client._create_default_nfs_export_rules()
  1878. export_rule_create_args = {
  1879. 'client-match': '0.0.0.0/0',
  1880. 'policy-name': 'default',
  1881. 'ro-rule': {
  1882. 'security-flavor': 'any'
  1883. },
  1884. 'rw-rule': {
  1885. 'security-flavor': 'never'
  1886. }
  1887. }
  1888. export_rule_create_args2 = export_rule_create_args.copy()
  1889. export_rule_create_args2['client-match'] = '::/0'
  1890. self.client.send_request.assert_has_calls([
  1891. mock.call('export-rule-create', export_rule_create_args),
  1892. mock.call('export-rule-create', export_rule_create_args2)])
  1893. def test_configure_ldap(self):
  1894. self.mock_object(self.client, 'send_request')
  1895. self.client.configure_ldap(fake.LDAP_SECURITY_SERVICE)
  1896. config_name = hashlib.md5(
  1897. six.b(fake.LDAP_SECURITY_SERVICE['id'])).hexdigest()
  1898. ldap_client_create_args = {
  1899. 'ldap-client-config': config_name,
  1900. 'servers': {'ip-address': fake.LDAP_SECURITY_SERVICE['server']},
  1901. 'tcp-port': '389',
  1902. 'schema': 'RFC-2307',
  1903. 'bind-password': fake.LDAP_SECURITY_SERVICE['password']
  1904. }
  1905. ldap_config_create_args = {
  1906. 'client-config': config_name,
  1907. 'client-enabled': 'true'
  1908. }
  1909. self.client.send_request.assert_has_calls([
  1910. mock.call('ldap-client-create', ldap_client_create_args),
  1911. mock.call('ldap-config-create', ldap_config_create_args)])
  1912. def test_configure_active_directory(self):
  1913. self.mock_object(self.client, 'send_request')
  1914. self.mock_object(self.client, 'configure_dns')
  1915. self.client.configure_active_directory(fake.CIFS_SECURITY_SERVICE,
  1916. fake.VSERVER_NAME)
  1917. cifs_server = (
  1918. fake.VSERVER_NAME[0:7] + '..' + fake.VSERVER_NAME[-6:]).upper()
  1919. cifs_server_create_args = {
  1920. 'admin-username': fake.CIFS_SECURITY_SERVICE['user'],
  1921. 'admin-password': fake.CIFS_SECURITY_SERVICE['password'],
  1922. 'force-account-overwrite': 'true',
  1923. 'cifs-server': cifs_server,
  1924. 'domain': fake.CIFS_SECURITY_SERVICE['domain'],
  1925. }
  1926. self.client.configure_dns.assert_called_with(
  1927. fake.CIFS_SECURITY_SERVICE)
  1928. self.client.send_request.assert_has_calls([
  1929. mock.call('cifs-server-create', cifs_server_create_args)])
  1930. def test_configure_active_directory_api_error(self):
  1931. self.mock_object(self.client, 'send_request', self._mock_api_error())
  1932. self.mock_object(self.client, 'configure_dns')
  1933. self.assertRaises(exception.NetAppException,
  1934. self.client.configure_active_directory,
  1935. fake.CIFS_SECURITY_SERVICE,
  1936. fake.VSERVER_NAME)
  1937. def test_create_kerberos_realm(self):
  1938. self.mock_object(self.client, 'send_request')
  1939. self.client.create_kerberos_realm(fake.KERBEROS_SECURITY_SERVICE)
  1940. kerberos_realm_create_args = {
  1941. 'admin-server-ip': fake.KERBEROS_SECURITY_SERVICE['server'],
  1942. 'admin-server-port': '749',
  1943. 'clock-skew': '5',
  1944. 'comment': '',
  1945. 'config-name': fake.KERBEROS_SECURITY_SERVICE['id'],
  1946. 'kdc-ip': fake.KERBEROS_SECURITY_SERVICE['server'],
  1947. 'kdc-port': '88',
  1948. 'kdc-vendor': 'other',
  1949. 'password-server-ip': fake.KERBEROS_SECURITY_SERVICE['server'],
  1950. 'password-server-port': '464',
  1951. 'realm': fake.KERBEROS_SECURITY_SERVICE['domain'].upper()
  1952. }
  1953. self.client.send_request.assert_has_calls([
  1954. mock.call('kerberos-realm-create', kerberos_realm_create_args)])
  1955. def test_create_kerberos_realm_already_present(self):
  1956. self.mock_object(self.client,
  1957. 'send_request',
  1958. self._mock_api_error(code=netapp_api.EDUPLICATEENTRY))
  1959. self.client.create_kerberos_realm(fake.KERBEROS_SECURITY_SERVICE)
  1960. kerberos_realm_create_args = {
  1961. 'admin-server-ip': fake.KERBEROS_SECURITY_SERVICE['server'],
  1962. 'admin-server-port': '749',
  1963. 'clock-skew': '5',
  1964. 'comment': '',
  1965. 'config-name': fake.KERBEROS_SECURITY_SERVICE['id'],
  1966. 'kdc-ip': fake.KERBEROS_SECURITY_SERVICE['server'],
  1967. 'kdc-port': '88',
  1968. 'kdc-vendor': 'other',
  1969. 'password-server-ip': fake.KERBEROS_SECURITY_SERVICE['server'],
  1970. 'password-server-port': '464',
  1971. 'realm': fake.KERBEROS_SECURITY_SERVICE['domain'].upper()
  1972. }
  1973. self.client.send_request.assert_has_calls([
  1974. mock.call('kerberos-realm-create', kerberos_realm_create_args)])
  1975. self.assertEqual(1, client_cmode.LOG.debug.call_count)
  1976. def test_create_kerberos_realm_api_error(self):
  1977. self.mock_object(self.client, 'send_request', self._mock_api_error())
  1978. self.assertRaises(exception.NetAppException,
  1979. self.client.create_kerberos_realm,
  1980. fake.KERBEROS_SECURITY_SERVICE)
  1981. def test_configure_kerberos(self):
  1982. self.mock_object(self.client, 'send_request')
  1983. self.mock_object(self.client, 'configure_dns')
  1984. self.mock_object(self.client,
  1985. 'list_network_interfaces',
  1986. mock.Mock(return_value=['lif1', 'lif2']))
  1987. self.client.configure_kerberos(
  1988. fake.KERBEROS_SECURITY_SERVICE, fake.VSERVER_NAME)
  1989. spn = self.client._get_kerberos_service_principal_name(
  1990. fake.KERBEROS_SECURITY_SERVICE, fake.VSERVER_NAME)
  1991. kerberos_config_modify_args1 = {
  1992. 'admin-password': fake.KERBEROS_SECURITY_SERVICE['password'],
  1993. 'admin-user-name': fake.KERBEROS_SECURITY_SERVICE['user'],
  1994. 'interface-name': 'lif1',
  1995. 'is-kerberos-enabled': 'true',
  1996. 'service-principal-name': spn
  1997. }
  1998. kerberos_config_modify_args2 = {
  1999. 'admin-password': fake.KERBEROS_SECURITY_SERVICE['password'],
  2000. 'admin-user-name': fake.KERBEROS_SECURITY_SERVICE['user'],
  2001. 'interface-name': 'lif2',
  2002. 'is-kerberos-enabled': 'true',
  2003. 'service-principal-name': spn
  2004. }
  2005. self.client.configure_dns.assert_called_with(
  2006. fake.KERBEROS_SECURITY_SERVICE)
  2007. self.client.send_request.assert_has_calls([
  2008. mock.call('kerberos-config-modify',
  2009. kerberos_config_modify_args1),
  2010. mock.call('kerberos-config-modify',
  2011. kerberos_config_modify_args2)])
  2012. def test_configure_kerberos_no_network_interfaces(self):
  2013. self.mock_object(self.client, 'send_request')
  2014. self.mock_object(self.client, 'configure_dns')
  2015. self.mock_object(self.client,
  2016. 'list_network_interfaces',
  2017. mock.Mock(return_value=[]))
  2018. self.assertRaises(exception.NetAppException,
  2019. self.client.configure_kerberos,
  2020. fake.KERBEROS_SECURITY_SERVICE,
  2021. fake.VSERVER_NAME)
  2022. self.client.configure_dns.assert_called_with(
  2023. fake.KERBEROS_SECURITY_SERVICE)
  2024. def test_get_kerberos_service_principal_name(self):
  2025. spn = self.client._get_kerberos_service_principal_name(
  2026. fake.KERBEROS_SECURITY_SERVICE, fake.VSERVER_NAME
  2027. )
  2028. self.assertEqual(fake.KERBEROS_SERVICE_PRINCIPAL_NAME, spn)
  2029. def test_configure_dns_for_active_directory(self):
  2030. self.mock_object(self.client, 'send_request')
  2031. self.client.configure_dns(fake.CIFS_SECURITY_SERVICE)
  2032. net_dns_create_args = {
  2033. 'domains': {'string': fake.CIFS_SECURITY_SERVICE['domain']},
  2034. 'name-servers': {
  2035. 'ip-address': fake.CIFS_SECURITY_SERVICE['dns_ip']
  2036. },
  2037. 'dns-state': 'enabled'
  2038. }
  2039. self.client.send_request.assert_has_calls([
  2040. mock.call('net-dns-create', net_dns_create_args)])
  2041. def test_configure_dns_for_kerberos(self):
  2042. self.mock_object(self.client, 'send_request')
  2043. self.client.configure_dns(fake.KERBEROS_SECURITY_SERVICE)
  2044. net_dns_create_args = {
  2045. 'domains': {'string': fake.KERBEROS_SECURITY_SERVICE['domain']},
  2046. 'name-servers': {
  2047. 'ip-address': fake.KERBEROS_SECURITY_SERVICE['dns_ip']
  2048. },
  2049. 'dns-state': 'enabled'
  2050. }
  2051. self.client.send_request.assert_has_calls([
  2052. mock.call('net-dns-create', net_dns_create_args)])
  2053. def test_configure_dns_already_present(self):
  2054. self.mock_object(self.client,
  2055. 'send_request',
  2056. self._mock_api_error(code=netapp_api.EDUPLICATEENTRY))
  2057. self.client.configure_dns(fake.KERBEROS_SECURITY_SERVICE)
  2058. net_dns_create_args = {
  2059. 'domains': {'string': fake.KERBEROS_SECURITY_SERVICE['domain']},
  2060. 'name-servers': {
  2061. 'ip-address': fake.KERBEROS_SECURITY_SERVICE['dns_ip']
  2062. },
  2063. 'dns-state': 'enabled'
  2064. }
  2065. self.client.send_request.assert_has_calls([
  2066. mock.call('net-dns-create', net_dns_create_args)])
  2067. self.assertEqual(1, client_cmode.LOG.error.call_count)
  2068. def test_configure_dns_api_error(self):
  2069. self.mock_object(self.client, 'send_request', self._mock_api_error())
  2070. self.assertRaises(exception.NetAppException,
  2071. self.client.configure_dns,
  2072. fake.KERBEROS_SECURITY_SERVICE)
  2073. def test_create_volume(self):
  2074. self.mock_object(self.client, 'send_request')
  2075. self.mock_object(self.client, 'update_volume_efficiency_attributes')
  2076. self.client.create_volume(
  2077. fake.SHARE_AGGREGATE_NAME, fake.SHARE_NAME, 100)
  2078. volume_create_args = {
  2079. 'containing-aggr-name': fake.SHARE_AGGREGATE_NAME,
  2080. 'size': '100g',
  2081. 'volume': fake.SHARE_NAME,
  2082. 'volume-type': 'rw',
  2083. 'junction-path': '/%s' % fake.SHARE_NAME,
  2084. }
  2085. self.client.send_request.assert_called_once_with('volume-create',
  2086. volume_create_args)
  2087. @ddt.data(None, fake.QOS_POLICY_GROUP_NAME)
  2088. def test_create_volume_with_extra_specs(self, qos_policy_group_name):
  2089. self.mock_object(self.client, 'set_volume_max_files')
  2090. self.mock_object(self.client, 'enable_dedup')
  2091. self.mock_object(self.client, 'enable_compression')
  2092. self.mock_object(self.client, 'send_request')
  2093. self.mock_object(
  2094. self.client,
  2095. 'get_volume_efficiency_status',
  2096. mock.Mock(return_value={'dedupe': False, 'compression': False}))
  2097. self.client.create_volume(
  2098. fake.SHARE_AGGREGATE_NAME, fake.SHARE_NAME, 100,
  2099. thin_provisioned=True, language='en-US',
  2100. snapshot_policy='default', dedup_enabled=True,
  2101. compression_enabled=True, max_files=5000, snapshot_reserve=15,
  2102. qos_policy_group=qos_policy_group_name)
  2103. volume_create_args = {
  2104. 'containing-aggr-name': fake.SHARE_AGGREGATE_NAME,
  2105. 'size': '100g',
  2106. 'volume': fake.SHARE_NAME,
  2107. 'junction-path': '/%s' % fake.SHARE_NAME,
  2108. 'space-reserve': 'none',
  2109. 'language-code': 'en-US',
  2110. 'volume-type': 'rw',
  2111. 'snapshot-policy': 'default',
  2112. 'percentage-snapshot-reserve': '15',
  2113. }
  2114. if qos_policy_group_name:
  2115. volume_create_args.update(
  2116. {'qos-policy-group-name': qos_policy_group_name})
  2117. self.client.send_request.assert_called_with('volume-create',
  2118. volume_create_args)
  2119. self.client.set_volume_max_files.assert_called_once_with(
  2120. fake.SHARE_NAME, fake.MAX_FILES)
  2121. self.client.enable_dedup.assert_called_once_with(fake.SHARE_NAME)
  2122. self.client.enable_compression.assert_called_once_with(fake.SHARE_NAME)
  2123. def test_create_encrypted_volume(self):
  2124. self.mock_object(self.client, 'send_request')
  2125. self.mock_object(self.client, 'update_volume_efficiency_attributes')
  2126. self.client.features.add_feature('FLEXVOL_ENCRYPTION')
  2127. self.client.create_volume(
  2128. fake.SHARE_AGGREGATE_NAME, fake.SHARE_NAME, 100, encrypt=True)
  2129. volume_create_args = {
  2130. 'containing-aggr-name': fake.SHARE_AGGREGATE_NAME,
  2131. 'size': '100g',
  2132. 'volume': fake.SHARE_NAME,
  2133. 'volume-type': 'rw',
  2134. 'junction-path': '/%s' % fake.SHARE_NAME,
  2135. 'encrypt': 'true',
  2136. }
  2137. self.client.send_request.assert_called_once_with('volume-create',
  2138. volume_create_args)
  2139. def test_create_non_encrypted_volume(self):
  2140. self.mock_object(self.client, 'send_request')
  2141. self.mock_object(self.client, 'update_volume_efficiency_attributes')
  2142. self.client.features.add_feature('FLEXVOL_ENCRYPTION')
  2143. self.client.create_volume(
  2144. fake.SHARE_AGGREGATE_NAME, fake.SHARE_NAME, 100, encrypt=False)
  2145. volume_create_args = {
  2146. 'containing-aggr-name': fake.SHARE_AGGREGATE_NAME,
  2147. 'size': '100g',
  2148. 'volume': fake.SHARE_NAME,
  2149. 'volume-type': 'rw',
  2150. 'junction-path': '/%s' % fake.SHARE_NAME,
  2151. }
  2152. self.client.send_request.assert_called_once_with('volume-create',
  2153. volume_create_args)
  2154. def test_create_encrypted_volume_not_supported(self):
  2155. self.assertRaises(exception.NetAppException,
  2156. self.client.create_volume,
  2157. fake.SHARE_AGGREGATE_NAME,
  2158. fake.SHARE_NAME,
  2159. 100,
  2160. encrypt=True)
  2161. def test_is_flexvol_encrypted_unsupported(self):
  2162. self.client.features.add_feature('FLEXVOL_ENCRYPTION', supported=False)
  2163. result = self.client.is_flexvol_encrypted(fake.SHARE_NAME,
  2164. fake.VSERVER_NAME)
  2165. self.assertFalse(result)
  2166. def test_is_flexvol_encrypted_no_records_found(self):
  2167. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2168. self.mock_object(self.client,
  2169. 'send_iter_request',
  2170. mock.Mock(return_value=api_response))
  2171. result = self.client.is_flexvol_encrypted(fake.SHARE_NAME,
  2172. fake.VSERVER_NAME)
  2173. self.assertFalse(result)
  2174. def test_is_flexvol_encrypted(self):
  2175. self.client.features.add_feature('FLEXVOL_ENCRYPTION', supported=True)
  2176. api_response = netapp_api.NaElement(
  2177. fake.GET_VOLUME_FOR_ENCRYPTED_RESPONSE)
  2178. self.mock_object(self.client,
  2179. 'send_iter_request',
  2180. mock.Mock(return_value=api_response))
  2181. result = self.client.is_flexvol_encrypted(fake.SHARE_NAME,
  2182. fake.VSERVER_NAME)
  2183. volume_get_iter_args = {
  2184. 'query': {
  2185. 'volume-attributes': {
  2186. 'encrypt': 'true',
  2187. 'volume-id-attributes': {
  2188. 'name': fake.SHARE_NAME,
  2189. 'owning-vserver-name': fake.VSERVER_NAME,
  2190. }
  2191. }
  2192. },
  2193. 'desired-attributes': {
  2194. 'volume-attributes': {
  2195. 'encrypt': None,
  2196. }
  2197. }
  2198. }
  2199. self.client.send_iter_request.assert_called_once_with(
  2200. 'volume-get-iter', volume_get_iter_args)
  2201. self.assertTrue(result)
  2202. def test_is_flexvol_encrypted_8_x_system_version_response(self):
  2203. self.client.features.add_feature('FLEXVOL_ENCRYPTION', supported=True)
  2204. api_response = netapp_api.NaElement(
  2205. fake.GET_VOLUME_FOR_ENCRYPTED_OLD_SYS_VERSION_RESPONSE)
  2206. self.mock_object(self.client,
  2207. 'send_iter_request',
  2208. mock.Mock(return_value=api_response))
  2209. result = self.client.is_flexvol_encrypted(fake.SHARE_NAME,
  2210. fake.VSERVER_NAME)
  2211. volume_get_iter_args = {
  2212. 'query': {
  2213. 'volume-attributes': {
  2214. 'encrypt': 'true',
  2215. 'volume-id-attributes': {
  2216. 'name': fake.SHARE_NAME,
  2217. 'owning-vserver-name': fake.VSERVER_NAME,
  2218. }
  2219. }
  2220. },
  2221. 'desired-attributes': {
  2222. 'volume-attributes': {
  2223. 'encrypt': None,
  2224. }
  2225. }
  2226. }
  2227. self.client.send_iter_request.assert_called_once_with(
  2228. 'volume-get-iter', volume_get_iter_args)
  2229. self.assertFalse(result)
  2230. def test_enable_dedup(self):
  2231. self.mock_object(self.client, 'send_request')
  2232. self.client.enable_dedup(fake.SHARE_NAME)
  2233. sis_enable_args = {'path': '/vol/%s' % fake.SHARE_NAME}
  2234. self.client.send_request.assert_called_once_with('sis-enable',
  2235. sis_enable_args)
  2236. def test_disable_dedup(self):
  2237. self.mock_object(self.client, 'send_request')
  2238. self.client.disable_dedup(fake.SHARE_NAME)
  2239. sis_disable_args = {'path': '/vol/%s' % fake.SHARE_NAME}
  2240. self.client.send_request.assert_called_once_with('sis-disable',
  2241. sis_disable_args)
  2242. def test_enable_compression(self):
  2243. self.mock_object(self.client, 'send_request')
  2244. self.client.enable_compression(fake.SHARE_NAME)
  2245. sis_set_config_args = {
  2246. 'path': '/vol/%s' % fake.SHARE_NAME,
  2247. 'enable-compression': 'true'
  2248. }
  2249. self.client.send_request.assert_called_once_with('sis-set-config',
  2250. sis_set_config_args)
  2251. def test_disable_compression(self):
  2252. self.mock_object(self.client, 'send_request')
  2253. self.client.disable_compression(fake.SHARE_NAME)
  2254. sis_set_config_args = {
  2255. 'path': '/vol/%s' % fake.SHARE_NAME,
  2256. 'enable-compression': 'false'
  2257. }
  2258. self.client.send_request.assert_called_once_with('sis-set-config',
  2259. sis_set_config_args)
  2260. def test_get_volume_efficiency_status(self):
  2261. api_response = netapp_api.NaElement(fake.SIS_GET_ITER_RESPONSE)
  2262. self.mock_object(self.client,
  2263. 'send_iter_request',
  2264. mock.Mock(return_value=api_response))
  2265. result = self.client.get_volume_efficiency_status(fake.SHARE_NAME)
  2266. sis_get_iter_args = {
  2267. 'query': {
  2268. 'sis-status-info': {
  2269. 'path': '/vol/%s' % fake.SHARE_NAME,
  2270. },
  2271. },
  2272. 'desired-attributes': {
  2273. 'sis-status-info': {
  2274. 'state': None,
  2275. 'is-compression-enabled': None,
  2276. },
  2277. },
  2278. }
  2279. self.client.send_iter_request.assert_has_calls([
  2280. mock.call('sis-get-iter', sis_get_iter_args)])
  2281. expected = {'dedupe': True, 'compression': True}
  2282. self.assertDictEqual(expected, result)
  2283. def test_get_volume_efficiency_status_not_found(self):
  2284. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2285. self.mock_object(self.client,
  2286. 'send_iter_request',
  2287. mock.Mock(return_value=api_response))
  2288. result = self.client.get_volume_efficiency_status(fake.SHARE_NAME)
  2289. expected = {'dedupe': False, 'compression': False}
  2290. self.assertDictEqual(expected, result)
  2291. def test_set_volume_max_files(self):
  2292. self.mock_object(self.client, 'send_request')
  2293. self.client.set_volume_max_files(fake.SHARE_NAME, fake.MAX_FILES)
  2294. volume_modify_iter_api_args = {
  2295. 'query': {
  2296. 'volume-attributes': {
  2297. 'volume-id-attributes': {
  2298. 'name': fake.SHARE_NAME,
  2299. },
  2300. },
  2301. },
  2302. 'attributes': {
  2303. 'volume-attributes': {
  2304. 'volume-inode-attributes': {
  2305. 'files-total': fake.MAX_FILES,
  2306. },
  2307. },
  2308. },
  2309. }
  2310. self.client.send_request.assert_called_once_with(
  2311. 'volume-modify-iter', volume_modify_iter_api_args)
  2312. def test_set_volume_name(self):
  2313. self.mock_object(self.client, 'send_request')
  2314. self.client.set_volume_name(fake.SHARE_NAME, 'new_name')
  2315. volume_rename_api_args = {
  2316. 'volume': fake.SHARE_NAME,
  2317. 'new-volume-name': 'new_name',
  2318. }
  2319. self.client.send_request.assert_called_once_with(
  2320. 'volume-rename', volume_rename_api_args)
  2321. def test_modify_volume_no_optional_args(self):
  2322. self.mock_object(self.client, 'send_request')
  2323. mock_update_volume_efficiency_attributes = self.mock_object(
  2324. self.client, 'update_volume_efficiency_attributes')
  2325. self.client.modify_volume(fake.SHARE_AGGREGATE_NAME, fake.SHARE_NAME)
  2326. volume_modify_iter_api_args = {
  2327. 'query': {
  2328. 'volume-attributes': {
  2329. 'volume-id-attributes': {
  2330. 'containing-aggregate-name': fake.SHARE_AGGREGATE_NAME,
  2331. 'name': fake.SHARE_NAME,
  2332. },
  2333. },
  2334. },
  2335. 'attributes': {
  2336. 'volume-attributes': {
  2337. 'volume-inode-attributes': {},
  2338. 'volume-language-attributes': {},
  2339. 'volume-snapshot-attributes': {},
  2340. 'volume-space-attributes': {
  2341. 'space-guarantee': 'volume',
  2342. },
  2343. },
  2344. },
  2345. }
  2346. self.client.send_request.assert_called_once_with(
  2347. 'volume-modify-iter', volume_modify_iter_api_args)
  2348. mock_update_volume_efficiency_attributes.assert_called_once_with(
  2349. fake.SHARE_NAME, False, False)
  2350. def test_modify_volume_all_optional_args(self):
  2351. self.mock_object(self.client, 'send_request')
  2352. mock_update_volume_efficiency_attributes = self.mock_object(
  2353. self.client, 'update_volume_efficiency_attributes')
  2354. self.client.modify_volume(fake.SHARE_AGGREGATE_NAME,
  2355. fake.SHARE_NAME,
  2356. thin_provisioned=True,
  2357. snapshot_policy=fake.SNAPSHOT_POLICY_NAME,
  2358. language=fake.LANGUAGE,
  2359. dedup_enabled=True,
  2360. compression_enabled=False,
  2361. max_files=fake.MAX_FILES,
  2362. qos_policy_group=fake.QOS_POLICY_GROUP_NAME)
  2363. volume_modify_iter_api_args = {
  2364. 'query': {
  2365. 'volume-attributes': {
  2366. 'volume-id-attributes': {
  2367. 'containing-aggregate-name': fake.SHARE_AGGREGATE_NAME,
  2368. 'name': fake.SHARE_NAME,
  2369. },
  2370. },
  2371. },
  2372. 'attributes': {
  2373. 'volume-attributes': {
  2374. 'volume-inode-attributes': {
  2375. 'files-total': fake.MAX_FILES,
  2376. },
  2377. 'volume-language-attributes': {
  2378. 'language': fake.LANGUAGE,
  2379. },
  2380. 'volume-snapshot-attributes': {
  2381. 'snapshot-policy': fake.SNAPSHOT_POLICY_NAME,
  2382. },
  2383. 'volume-space-attributes': {
  2384. 'space-guarantee': 'none',
  2385. },
  2386. 'volume-qos-attributes': {
  2387. 'policy-group-name': fake.QOS_POLICY_GROUP_NAME,
  2388. },
  2389. },
  2390. },
  2391. }
  2392. self.client.send_request.assert_called_once_with(
  2393. 'volume-modify-iter', volume_modify_iter_api_args)
  2394. mock_update_volume_efficiency_attributes.assert_called_once_with(
  2395. fake.SHARE_NAME, True, False)
  2396. @ddt.data(
  2397. {'existing': (True, True), 'desired': (True, True)},
  2398. {'existing': (True, True), 'desired': (False, False)},
  2399. {'existing': (True, True), 'desired': (True, False)},
  2400. {'existing': (True, False), 'desired': (True, False)},
  2401. {'existing': (True, False), 'desired': (False, False)},
  2402. {'existing': (True, False), 'desired': (True, True)},
  2403. {'existing': (False, False), 'desired': (False, False)},
  2404. {'existing': (False, False), 'desired': (True, False)},
  2405. {'existing': (False, False), 'desired': (True, True)},
  2406. )
  2407. @ddt.unpack
  2408. def test_update_volume_efficiency_attributes(self, existing, desired):
  2409. existing_dedupe = existing[0]
  2410. existing_compression = existing[1]
  2411. desired_dedupe = desired[0]
  2412. desired_compression = desired[1]
  2413. self.mock_object(
  2414. self.client,
  2415. 'get_volume_efficiency_status',
  2416. mock.Mock(return_value={'dedupe': existing_dedupe,
  2417. 'compression': existing_compression}))
  2418. mock_enable_compression = self.mock_object(self.client,
  2419. 'enable_compression')
  2420. mock_disable_compression = self.mock_object(self.client,
  2421. 'disable_compression')
  2422. mock_enable_dedup = self.mock_object(self.client, 'enable_dedup')
  2423. mock_disable_dedup = self.mock_object(self.client, 'disable_dedup')
  2424. self.client.update_volume_efficiency_attributes(
  2425. fake.SHARE_NAME, desired_dedupe, desired_compression)
  2426. if existing_dedupe == desired_dedupe:
  2427. self.assertFalse(mock_enable_dedup.called)
  2428. self.assertFalse(mock_disable_dedup.called)
  2429. elif existing_dedupe and not desired_dedupe:
  2430. self.assertFalse(mock_enable_dedup.called)
  2431. self.assertTrue(mock_disable_dedup.called)
  2432. elif not existing_dedupe and desired_dedupe:
  2433. self.assertTrue(mock_enable_dedup.called)
  2434. self.assertFalse(mock_disable_dedup.called)
  2435. if existing_compression == desired_compression:
  2436. self.assertFalse(mock_enable_compression.called)
  2437. self.assertFalse(mock_disable_compression.called)
  2438. elif existing_compression and not desired_compression:
  2439. self.assertFalse(mock_enable_compression.called)
  2440. self.assertTrue(mock_disable_compression.called)
  2441. elif not existing_compression and desired_compression:
  2442. self.assertTrue(mock_enable_compression.called)
  2443. self.assertFalse(mock_disable_compression.called)
  2444. def test_set_volume_size(self):
  2445. api_response = netapp_api.NaElement(fake.VOLUME_MODIFY_ITER_RESPONSE)
  2446. self.mock_object(self.client,
  2447. 'send_request',
  2448. mock.Mock(return_value=api_response))
  2449. self.client.set_volume_size(fake.SHARE_NAME, 10)
  2450. volume_modify_iter_args = {
  2451. 'query': {
  2452. 'volume-attributes': {
  2453. 'volume-id-attributes': {
  2454. 'name': fake.SHARE_NAME
  2455. }
  2456. }
  2457. },
  2458. 'attributes': {
  2459. 'volume-attributes': {
  2460. 'volume-space-attributes': {
  2461. 'size': 10737418240,
  2462. },
  2463. },
  2464. },
  2465. }
  2466. self.client.send_request.assert_has_calls([
  2467. mock.call('volume-modify-iter', volume_modify_iter_args)])
  2468. @ddt.data(True, False)
  2469. def test_set_volume_filesys_size_fixed(self, filesys_size_fixed):
  2470. api_response = netapp_api.NaElement(
  2471. fake.VOLUME_MODIFY_ITER_RESPONSE)
  2472. self.mock_object(self.client,
  2473. 'send_request',
  2474. mock.Mock(return_value=api_response))
  2475. self.client.set_volume_filesys_size_fixed(fake.SHARE_NAME,
  2476. filesys_size_fixed)
  2477. api_args = {
  2478. 'query': {
  2479. 'volume-attributes': {
  2480. 'volume-id-attributes': {
  2481. 'name': fake.SHARE_NAME
  2482. }
  2483. }
  2484. },
  2485. 'attributes': {
  2486. 'volume-attributes': {
  2487. 'volume-space-attributes': {
  2488. 'is-filesys-size-fixed': six.text_type(
  2489. filesys_size_fixed).lower(),
  2490. },
  2491. },
  2492. },
  2493. }
  2494. self.client.send_request.assert_called_once_with(
  2495. 'volume-modify-iter', api_args)
  2496. def test_set_volume_size_api_error(self):
  2497. api_response = netapp_api.NaElement(
  2498. fake.VOLUME_MODIFY_ITER_ERROR_RESPONSE)
  2499. self.mock_object(self.client,
  2500. 'send_request',
  2501. mock.Mock(return_value=api_response))
  2502. self.assertRaises(netapp_api.NaApiError,
  2503. self.client.set_volume_size,
  2504. fake.SHARE_NAME,
  2505. 10)
  2506. @ddt.data(None, 'ntfs')
  2507. def test_set_volume_security_style(self, security_style):
  2508. api_response = netapp_api.NaElement(fake.VOLUME_MODIFY_ITER_RESPONSE)
  2509. self.mock_object(self.client,
  2510. 'send_request',
  2511. mock.Mock(return_value=api_response))
  2512. kwargs = {'security_style': security_style} if security_style else {}
  2513. self.client.set_volume_security_style(fake.SHARE_NAME, **kwargs)
  2514. volume_modify_iter_args = {
  2515. 'query': {
  2516. 'volume-attributes': {
  2517. 'volume-id-attributes': {
  2518. 'name': fake.SHARE_NAME
  2519. }
  2520. }
  2521. },
  2522. 'attributes': {
  2523. 'volume-attributes': {
  2524. 'volume-security-attributes': {
  2525. 'style': security_style or 'unix',
  2526. },
  2527. },
  2528. },
  2529. }
  2530. self.client.send_request.assert_called_once_with(
  2531. 'volume-modify-iter', volume_modify_iter_args)
  2532. def test_set_volume_security_style_api_error(self):
  2533. api_response = netapp_api.NaElement(
  2534. fake.VOLUME_MODIFY_ITER_ERROR_RESPONSE)
  2535. self.mock_object(self.client,
  2536. 'send_request',
  2537. mock.Mock(return_value=api_response))
  2538. self.assertRaises(netapp_api.NaApiError,
  2539. self.client.set_volume_security_style,
  2540. fake.SHARE_NAME,
  2541. 'ntfs')
  2542. def test_volume_exists(self):
  2543. api_response = netapp_api.NaElement(fake.VOLUME_GET_NAME_RESPONSE)
  2544. self.mock_object(self.client,
  2545. 'send_iter_request',
  2546. mock.Mock(return_value=api_response))
  2547. result = self.client.volume_exists(fake.SHARE_NAME)
  2548. volume_get_iter_args = {
  2549. 'query': {
  2550. 'volume-attributes': {
  2551. 'volume-id-attributes': {
  2552. 'name': fake.SHARE_NAME
  2553. }
  2554. }
  2555. },
  2556. 'desired-attributes': {
  2557. 'volume-attributes': {
  2558. 'volume-id-attributes': {
  2559. 'name': None
  2560. }
  2561. }
  2562. }
  2563. }
  2564. self.client.send_iter_request.assert_has_calls([
  2565. mock.call('volume-get-iter', volume_get_iter_args)])
  2566. self.assertTrue(result)
  2567. def test_volume_exists_not_found(self):
  2568. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2569. self.mock_object(self.client,
  2570. 'send_request',
  2571. mock.Mock(return_value=api_response))
  2572. self.assertFalse(self.client.volume_exists(fake.SHARE_NAME))
  2573. def test_snapshot_exists(self):
  2574. api_response = netapp_api.NaElement(fake.VOLUME_GET_NAME_RESPONSE)
  2575. self.mock_object(self.client,
  2576. 'send_request',
  2577. mock.Mock(return_value=api_response))
  2578. result = self.client.snapshot_exists(fake.SNAPSHOT_NAME,
  2579. fake.SHARE_NAME)
  2580. snapshot_get_iter_args = {
  2581. 'query': {
  2582. 'snapshot-info': {
  2583. 'name': fake.SNAPSHOT_NAME,
  2584. 'volume': fake.SHARE_NAME,
  2585. }
  2586. },
  2587. 'desired-attributes': {
  2588. 'snapshot-info': {
  2589. 'name': None,
  2590. 'volume': None,
  2591. 'busy': None,
  2592. 'snapshot-owners-list': {
  2593. 'snapshot-owner': None,
  2594. }
  2595. }
  2596. }
  2597. }
  2598. self.client.send_request.assert_has_calls([
  2599. mock.call('snapshot-get-iter', snapshot_get_iter_args)])
  2600. self.assertTrue(result)
  2601. def test_snapshot_exists_not_found(self):
  2602. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2603. self.mock_object(self.client,
  2604. 'send_request',
  2605. mock.Mock(return_value=api_response))
  2606. self.assertFalse(self.client.snapshot_exists(fake.SNAPSHOT_NAME,
  2607. fake.SHARE_NAME))
  2608. @ddt.data({
  2609. 'api_response_xml': fake.SNAPSHOT_GET_ITER_UNAVAILABLE_RESPONSE,
  2610. 'raised_exception': exception.SnapshotUnavailable,
  2611. }, {
  2612. 'api_response_xml': fake.SNAPSHOT_GET_ITER_OTHER_ERROR_RESPONSE,
  2613. 'raised_exception': exception.NetAppException,
  2614. })
  2615. @ddt.unpack
  2616. def test_snapshot_exists_error(self, api_response_xml, raised_exception):
  2617. api_response = netapp_api.NaElement(api_response_xml)
  2618. self.mock_object(self.client,
  2619. 'send_request',
  2620. mock.Mock(return_value=api_response))
  2621. self.assertRaises(raised_exception,
  2622. self.client.snapshot_exists,
  2623. fake.SNAPSHOT_NAME,
  2624. fake.SHARE_NAME)
  2625. def test_get_aggregate_for_volume(self):
  2626. api_response = netapp_api.NaElement(
  2627. fake.GET_AGGREGATE_FOR_VOLUME_RESPONSE)
  2628. self.mock_object(self.client,
  2629. 'send_iter_request',
  2630. mock.Mock(return_value=api_response))
  2631. result = self.client.get_aggregate_for_volume(fake.SHARE_NAME)
  2632. volume_get_iter_args = {
  2633. 'query': {
  2634. 'volume-attributes': {
  2635. 'volume-id-attributes': {
  2636. 'name': fake.SHARE_NAME
  2637. }
  2638. }
  2639. },
  2640. 'desired-attributes': {
  2641. 'volume-attributes': {
  2642. 'volume-id-attributes': {
  2643. 'containing-aggregate-name': None,
  2644. 'name': None
  2645. }
  2646. }
  2647. }
  2648. }
  2649. self.client.send_iter_request.assert_has_calls([
  2650. mock.call('volume-get-iter', volume_get_iter_args)])
  2651. self.assertEqual(fake.SHARE_AGGREGATE_NAME, result)
  2652. def test_get_aggregate_for_volume_not_found(self):
  2653. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2654. self.mock_object(self.client,
  2655. 'send_iter_request',
  2656. mock.Mock(return_value=api_response))
  2657. self.assertRaises(exception.NetAppException,
  2658. self.client.get_aggregate_for_volume,
  2659. fake.SHARE_NAME)
  2660. def test_volume_has_luns(self):
  2661. api_response = netapp_api.NaElement(fake.LUN_GET_ITER_RESPONSE)
  2662. self.mock_object(self.client,
  2663. 'send_iter_request',
  2664. mock.Mock(return_value=api_response))
  2665. result = self.client.volume_has_luns(fake.SHARE_NAME)
  2666. lun_get_iter_args = {
  2667. 'query': {
  2668. 'lun-info': {
  2669. 'volume': fake.SHARE_NAME,
  2670. },
  2671. },
  2672. 'desired-attributes': {
  2673. 'lun-info': {
  2674. 'path': None,
  2675. },
  2676. },
  2677. }
  2678. self.client.send_iter_request.assert_has_calls([
  2679. mock.call('lun-get-iter', lun_get_iter_args)])
  2680. self.assertTrue(result)
  2681. def test_volume_has_luns_not_found(self):
  2682. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2683. self.mock_object(self.client,
  2684. 'send_request',
  2685. mock.Mock(return_value=api_response))
  2686. result = self.client.volume_has_luns(fake.SHARE_NAME)
  2687. self.assertFalse(result)
  2688. def test_volume_has_junctioned_volumes(self):
  2689. api_response = netapp_api.NaElement(
  2690. fake.VOLUME_GET_ITER_JUNCTIONED_VOLUMES_RESPONSE)
  2691. self.mock_object(self.client,
  2692. 'send_iter_request',
  2693. mock.Mock(return_value=api_response))
  2694. fake_junction_path = '/%s' % fake.SHARE_NAME
  2695. self.mock_object(self.client,
  2696. 'get_volume_junction_path',
  2697. mock.Mock(return_value=fake_junction_path))
  2698. result = self.client.volume_has_junctioned_volumes(fake.SHARE_NAME)
  2699. volume_get_iter_args = {
  2700. 'query': {
  2701. 'volume-attributes': {
  2702. 'volume-id-attributes': {
  2703. 'junction-path': fake_junction_path + '/*',
  2704. },
  2705. },
  2706. },
  2707. 'desired-attributes': {
  2708. 'volume-attributes': {
  2709. 'volume-id-attributes': {
  2710. 'name': None,
  2711. },
  2712. },
  2713. },
  2714. }
  2715. self.client.send_iter_request.assert_has_calls([
  2716. mock.call('volume-get-iter', volume_get_iter_args)])
  2717. self.assertTrue(result)
  2718. def test_volume_has_junctioned_volumes_no_junction_path(self):
  2719. self.mock_object(self.client,
  2720. 'get_volume_junction_path',
  2721. mock.Mock(return_value=''))
  2722. result = self.client.volume_has_junctioned_volumes(fake.SHARE_NAME)
  2723. self.assertFalse(result)
  2724. def test_volume_has_junctioned_volumes_not_found(self):
  2725. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2726. self.mock_object(self.client,
  2727. 'send_request',
  2728. mock.Mock(return_value=api_response))
  2729. fake_junction_path = '/%s' % fake.SHARE_NAME
  2730. self.mock_object(self.client,
  2731. 'get_volume_junction_path',
  2732. mock.Mock(return_value=fake_junction_path))
  2733. result = self.client.volume_has_junctioned_volumes(fake.SHARE_NAME)
  2734. self.assertFalse(result)
  2735. def test_get_volume(self):
  2736. api_response = netapp_api.NaElement(
  2737. fake.VOLUME_GET_ITER_VOLUME_TO_MANAGE_RESPONSE)
  2738. self.mock_object(self.client,
  2739. 'send_request',
  2740. mock.Mock(return_value=api_response))
  2741. result = self.client.get_volume(fake.SHARE_NAME)
  2742. volume_get_iter_args = {
  2743. 'query': {
  2744. 'volume-attributes': {
  2745. 'volume-id-attributes': {
  2746. 'name': fake.SHARE_NAME,
  2747. },
  2748. },
  2749. },
  2750. 'desired-attributes': {
  2751. 'volume-attributes': {
  2752. 'volume-id-attributes': {
  2753. 'containing-aggregate-name': None,
  2754. 'junction-path': None,
  2755. 'name': None,
  2756. 'owning-vserver-name': None,
  2757. 'type': None,
  2758. 'style': None,
  2759. },
  2760. 'volume-space-attributes': {
  2761. 'size': None,
  2762. },
  2763. 'volume-qos-attributes': {
  2764. 'policy-group-name': None,
  2765. },
  2766. },
  2767. },
  2768. }
  2769. expected = {
  2770. 'aggregate': fake.SHARE_AGGREGATE_NAME,
  2771. 'junction-path': '/%s' % fake.SHARE_NAME,
  2772. 'name': fake.SHARE_NAME,
  2773. 'type': 'rw',
  2774. 'style': 'flex',
  2775. 'size': fake.SHARE_SIZE,
  2776. 'owning-vserver-name': fake.VSERVER_NAME,
  2777. 'qos-policy-group-name': fake.QOS_POLICY_GROUP_NAME,
  2778. }
  2779. self.client.send_request.assert_has_calls([
  2780. mock.call('volume-get-iter', volume_get_iter_args)])
  2781. self.assertDictEqual(expected, result)
  2782. def test_get_volume_no_qos(self):
  2783. api_response = netapp_api.NaElement(
  2784. fake.VOLUME_GET_ITER_NO_QOS_RESPONSE)
  2785. self.mock_object(self.client,
  2786. 'send_request',
  2787. mock.Mock(return_value=api_response))
  2788. result = self.client.get_volume(fake.SHARE_NAME)
  2789. volume_get_iter_args = {
  2790. 'query': {
  2791. 'volume-attributes': {
  2792. 'volume-id-attributes': {
  2793. 'name': fake.SHARE_NAME,
  2794. },
  2795. },
  2796. },
  2797. 'desired-attributes': {
  2798. 'volume-attributes': {
  2799. 'volume-id-attributes': {
  2800. 'containing-aggregate-name': None,
  2801. 'junction-path': None,
  2802. 'name': None,
  2803. 'owning-vserver-name': None,
  2804. 'type': None,
  2805. 'style': None,
  2806. },
  2807. 'volume-space-attributes': {
  2808. 'size': None,
  2809. },
  2810. 'volume-qos-attributes': {
  2811. 'policy-group-name': None,
  2812. },
  2813. },
  2814. },
  2815. }
  2816. expected = {
  2817. 'aggregate': fake.SHARE_AGGREGATE_NAME,
  2818. 'junction-path': '/%s' % fake.SHARE_NAME,
  2819. 'name': fake.SHARE_NAME,
  2820. 'type': 'rw',
  2821. 'style': 'flex',
  2822. 'size': fake.SHARE_SIZE,
  2823. 'owning-vserver-name': fake.VSERVER_NAME,
  2824. 'qos-policy-group-name': None,
  2825. }
  2826. self.client.send_request.assert_has_calls([
  2827. mock.call('volume-get-iter', volume_get_iter_args)])
  2828. self.assertDictEqual(expected, result)
  2829. def test_get_volume_not_found(self):
  2830. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2831. self.mock_object(self.client,
  2832. 'send_request',
  2833. mock.Mock(return_value=api_response))
  2834. self.assertRaises(exception.StorageResourceNotFound,
  2835. self.client.get_volume,
  2836. fake.SHARE_NAME)
  2837. def test_get_volume_not_unique(self):
  2838. api_response = netapp_api.NaElement(
  2839. fake.VOLUME_GET_ITER_NOT_UNIQUE_RESPONSE)
  2840. self.mock_object(self.client,
  2841. 'send_request',
  2842. mock.Mock(return_value=api_response))
  2843. self.assertRaises(exception.NetAppException,
  2844. self.client.get_volume,
  2845. fake.SHARE_NAME)
  2846. def test_get_volume_at_junction_path(self):
  2847. api_response = netapp_api.NaElement(
  2848. fake.VOLUME_GET_ITER_VOLUME_TO_MANAGE_RESPONSE)
  2849. self.mock_object(self.client,
  2850. 'send_iter_request',
  2851. mock.Mock(return_value=api_response))
  2852. fake_junction_path = '/%s' % fake.SHARE_NAME
  2853. result = self.client.get_volume_at_junction_path(fake_junction_path)
  2854. volume_get_iter_args = {
  2855. 'query': {
  2856. 'volume-attributes': {
  2857. 'volume-id-attributes': {
  2858. 'junction-path': fake_junction_path,
  2859. },
  2860. },
  2861. },
  2862. 'desired-attributes': {
  2863. 'volume-attributes': {
  2864. 'volume-id-attributes': {
  2865. 'containing-aggregate-name': None,
  2866. 'junction-path': None,
  2867. 'name': None,
  2868. 'type': None,
  2869. 'style': None,
  2870. },
  2871. 'volume-space-attributes': {
  2872. 'size': None,
  2873. }
  2874. },
  2875. },
  2876. }
  2877. expected = {
  2878. 'aggregate': fake.SHARE_AGGREGATE_NAME,
  2879. 'junction-path': fake_junction_path,
  2880. 'name': fake.SHARE_NAME,
  2881. 'type': 'rw',
  2882. 'style': 'flex',
  2883. 'size': fake.SHARE_SIZE,
  2884. }
  2885. self.client.send_iter_request.assert_has_calls([
  2886. mock.call('volume-get-iter', volume_get_iter_args)])
  2887. self.assertDictEqual(expected, result)
  2888. def test_get_volume_at_junction_path_not_specified(self):
  2889. result = self.client.get_volume_at_junction_path(None)
  2890. self.assertIsNone(result)
  2891. def test_get_volume_at_junction_path_not_found(self):
  2892. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2893. self.mock_object(self.client,
  2894. 'send_iter_request',
  2895. mock.Mock(return_value=api_response))
  2896. fake_junction_path = '/%s' % fake.SHARE_NAME
  2897. result = self.client.get_volume_at_junction_path(fake_junction_path)
  2898. self.assertIsNone(result)
  2899. def test_get_volume_to_manage(self):
  2900. api_response = netapp_api.NaElement(
  2901. fake.VOLUME_GET_ITER_VOLUME_TO_MANAGE_RESPONSE)
  2902. self.mock_object(self.client,
  2903. 'send_iter_request',
  2904. mock.Mock(return_value=api_response))
  2905. result = self.client.get_volume_to_manage(fake.SHARE_AGGREGATE_NAME,
  2906. fake.SHARE_NAME)
  2907. volume_get_iter_args = {
  2908. 'query': {
  2909. 'volume-attributes': {
  2910. 'volume-id-attributes': {
  2911. 'containing-aggregate-name': fake.SHARE_AGGREGATE_NAME,
  2912. 'name': fake.SHARE_NAME,
  2913. },
  2914. },
  2915. },
  2916. 'desired-attributes': {
  2917. 'volume-attributes': {
  2918. 'volume-id-attributes': {
  2919. 'containing-aggregate-name': None,
  2920. 'junction-path': None,
  2921. 'name': None,
  2922. 'type': None,
  2923. 'style': None,
  2924. 'owning-vserver-name': None,
  2925. },
  2926. 'volume-space-attributes': {
  2927. 'size': None,
  2928. },
  2929. 'volume-qos-attributes': {
  2930. 'policy-group-name': None,
  2931. },
  2932. },
  2933. },
  2934. }
  2935. expected = {
  2936. 'aggregate': fake.SHARE_AGGREGATE_NAME,
  2937. 'junction-path': '/%s' % fake.SHARE_NAME,
  2938. 'name': fake.SHARE_NAME,
  2939. 'type': 'rw',
  2940. 'style': 'flex',
  2941. 'size': fake.SHARE_SIZE,
  2942. 'owning-vserver-name': fake.VSERVER_NAME,
  2943. 'qos-policy-group-name': fake.QOS_POLICY_GROUP_NAME,
  2944. }
  2945. self.client.send_iter_request.assert_has_calls([
  2946. mock.call('volume-get-iter', volume_get_iter_args)])
  2947. self.assertDictEqual(expected, result)
  2948. def test_get_volume_to_manage_not_found(self):
  2949. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2950. self.mock_object(self.client,
  2951. 'send_iter_request',
  2952. mock.Mock(return_value=api_response))
  2953. result = self.client.get_volume_to_manage(fake.SHARE_AGGREGATE_NAME,
  2954. fake.SHARE_NAME)
  2955. self.assertIsNone(result)
  2956. @ddt.data(None, fake.QOS_POLICY_GROUP_NAME)
  2957. def test_create_volume_clone(self, qos_policy_group_name):
  2958. self.mock_object(self.client, 'send_request')
  2959. self.mock_object(self.client, 'split_volume_clone')
  2960. self.client.create_volume_clone(fake.SHARE_NAME,
  2961. fake.PARENT_SHARE_NAME,
  2962. fake.PARENT_SNAPSHOT_NAME,
  2963. qos_policy_group=qos_policy_group_name)
  2964. volume_clone_create_args = {
  2965. 'volume': fake.SHARE_NAME,
  2966. 'parent-volume': fake.PARENT_SHARE_NAME,
  2967. 'parent-snapshot': fake.PARENT_SNAPSHOT_NAME,
  2968. 'junction-path': '/%s' % fake.SHARE_NAME
  2969. }
  2970. if qos_policy_group_name:
  2971. volume_clone_create_args.update(
  2972. {'qos-policy-group-name': fake.QOS_POLICY_GROUP_NAME})
  2973. self.client.send_request.assert_has_calls([
  2974. mock.call('volume-clone-create', volume_clone_create_args)])
  2975. self.assertFalse(self.client.split_volume_clone.called)
  2976. @ddt.data(True, False)
  2977. def test_create_volume_clone_split(self, split):
  2978. self.mock_object(self.client, 'send_request')
  2979. self.mock_object(self.client, 'split_volume_clone')
  2980. self.client.create_volume_clone(fake.SHARE_NAME,
  2981. fake.PARENT_SHARE_NAME,
  2982. fake.PARENT_SNAPSHOT_NAME,
  2983. split=split)
  2984. volume_clone_create_args = {
  2985. 'volume': fake.SHARE_NAME,
  2986. 'parent-volume': fake.PARENT_SHARE_NAME,
  2987. 'parent-snapshot': fake.PARENT_SNAPSHOT_NAME,
  2988. 'junction-path': '/%s' % fake.SHARE_NAME
  2989. }
  2990. self.client.send_request.assert_has_calls([
  2991. mock.call('volume-clone-create', volume_clone_create_args)])
  2992. if split:
  2993. self.client.split_volume_clone.assert_called_once_with(
  2994. fake.SHARE_NAME)
  2995. else:
  2996. self.assertFalse(self.client.split_volume_clone.called)
  2997. @ddt.data(None,
  2998. mock.Mock(side_effect=netapp_api.NaApiError(
  2999. code=netapp_api.EVOL_CLONE_BEING_SPLIT)))
  3000. def test_split_volume_clone(self, side_effect):
  3001. self.mock_object(
  3002. self.client, 'send_request',
  3003. mock.Mock(side_effect=side_effect))
  3004. self.client.split_volume_clone(fake.SHARE_NAME)
  3005. volume_clone_split_args = {'volume': fake.SHARE_NAME}
  3006. self.client.send_request.assert_has_calls([
  3007. mock.call('volume-clone-split-start', volume_clone_split_args)])
  3008. def test_split_volume_clone_api_error(self):
  3009. self.mock_object(self.client,
  3010. 'send_request',
  3011. mock.Mock(side_effect=self._mock_api_error()))
  3012. self.assertRaises(netapp_api.NaApiError,
  3013. self.client.split_volume_clone,
  3014. fake.SHARE_NAME)
  3015. def test_get_clone_children_for_snapshot(self):
  3016. api_response = netapp_api.NaElement(
  3017. fake.VOLUME_GET_ITER_CLONE_CHILDREN_RESPONSE)
  3018. self.mock_object(self.client,
  3019. 'send_iter_request',
  3020. mock.Mock(return_value=api_response))
  3021. result = self.client.get_clone_children_for_snapshot(
  3022. fake.SHARE_NAME, fake.SNAPSHOT_NAME)
  3023. volume_get_iter_args = {
  3024. 'query': {
  3025. 'volume-attributes': {
  3026. 'volume-clone-attributes': {
  3027. 'volume-clone-parent-attributes': {
  3028. 'name': fake.SHARE_NAME,
  3029. 'snapshot-name': fake.SNAPSHOT_NAME,
  3030. },
  3031. },
  3032. },
  3033. },
  3034. 'desired-attributes': {
  3035. 'volume-attributes': {
  3036. 'volume-id-attributes': {
  3037. 'name': None,
  3038. },
  3039. },
  3040. },
  3041. }
  3042. self.client.send_iter_request.assert_has_calls([
  3043. mock.call('volume-get-iter', volume_get_iter_args)])
  3044. expected = [
  3045. {'name': fake.CLONE_CHILD_1},
  3046. {'name': fake.CLONE_CHILD_2},
  3047. ]
  3048. self.assertEqual(expected, result)
  3049. def test_get_clone_children_for_snapshot_not_found(self):
  3050. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  3051. self.mock_object(self.client,
  3052. 'send_iter_request',
  3053. mock.Mock(return_value=api_response))
  3054. result = self.client.get_clone_children_for_snapshot(
  3055. fake.SHARE_NAME, fake.SNAPSHOT_NAME)
  3056. self.assertEqual([], result)
  3057. def test_get_volume_junction_path(self):
  3058. api_response = netapp_api.NaElement(
  3059. fake.VOLUME_GET_VOLUME_PATH_RESPONSE)
  3060. self.mock_object(self.client,
  3061. 'send_request',
  3062. mock.Mock(return_value=api_response))
  3063. result = self.client.get_volume_junction_path(fake.SHARE_NAME)
  3064. volume_get_volume_path_args = {
  3065. 'volume': fake.SHARE_NAME,
  3066. 'is-style-cifs': 'false'
  3067. }
  3068. self.client.send_request.assert_has_calls([
  3069. mock.call('volume-get-volume-path', volume_get_volume_path_args)])
  3070. self.assertEqual(fake.VOLUME_JUNCTION_PATH, result)
  3071. def test_get_volume_junction_path_cifs(self):
  3072. api_response = netapp_api.NaElement(
  3073. fake.VOLUME_GET_VOLUME_PATH_CIFS_RESPONSE)
  3074. self.mock_object(self.client,
  3075. 'send_request',
  3076. mock.Mock(return_value=api_response))
  3077. result = self.client.get_volume_junction_path(fake.SHARE_NAME,
  3078. is_style_cifs=True)
  3079. volume_get_volume_path_args = {
  3080. 'volume': fake.SHARE_NAME,
  3081. 'is-style-cifs': 'true'
  3082. }
  3083. self.client.send_request.assert_has_calls([
  3084. mock.call('volume-get-volume-path', volume_get_volume_path_args)])
  3085. self.assertEqual(fake.VOLUME_JUNCTION_PATH_CIFS, result)
  3086. def test_mount_volume_default_junction_path(self):
  3087. self.mock_object(self.client, 'send_request')
  3088. self.client.mount_volume(fake.SHARE_NAME)
  3089. volume_mount_args = {
  3090. 'volume-name': fake.SHARE_NAME,
  3091. 'junction-path': '/%s' % fake.SHARE_NAME,
  3092. }
  3093. self.client.send_request.assert_has_calls([
  3094. mock.call('volume-mount', volume_mount_args)])
  3095. def test_mount_volume(self):
  3096. self.mock_object(self.client, 'send_request')
  3097. fake_path = '/fake_path'
  3098. self.client.mount_volume(fake.SHARE_NAME, junction_path=fake_path)
  3099. volume_mount_args = {
  3100. 'volume-name': fake.SHARE_NAME,
  3101. 'junction-path': fake_path,
  3102. }
  3103. self.client.send_request.assert_has_calls([
  3104. mock.call('volume-mount', volume_mount_args)])
  3105. def test_offline_volume(self):
  3106. self.mock_object(self.client, 'send_request')
  3107. self.client.offline_volume(fake.SHARE_NAME)
  3108. volume_offline_args = {'name': fake.SHARE_NAME}
  3109. self.client.send_request.assert_has_calls([
  3110. mock.call('volume-offline', volume_offline_args)])
  3111. def test_offline_volume_already_offline(self):
  3112. self.mock_object(self.client,
  3113. 'send_request',
  3114. mock.Mock(side_effect=self._mock_api_error(
  3115. netapp_api.EVOLUMEOFFLINE)))
  3116. self.client.offline_volume(fake.SHARE_NAME)
  3117. volume_offline_args = {'name': fake.SHARE_NAME}
  3118. self.client.send_request.assert_has_calls([
  3119. mock.call('volume-offline', volume_offline_args)])
  3120. def test_offline_volume_api_error(self):
  3121. self.mock_object(self.client,
  3122. 'send_request',
  3123. mock.Mock(side_effect=self._mock_api_error()))
  3124. self.assertRaises(netapp_api.NaApiError,
  3125. self.client.offline_volume,
  3126. fake.SHARE_NAME)
  3127. def test__unmount_volume(self):
  3128. self.mock_object(self.client, 'send_request')
  3129. self.client._unmount_volume(fake.SHARE_NAME)
  3130. volume_unmount_args = {
  3131. 'volume-name': fake.SHARE_NAME,
  3132. 'force': 'false'
  3133. }
  3134. self.client.send_request.assert_has_calls([
  3135. mock.call('volume-unmount', volume_unmount_args)])
  3136. def test__unmount_volume_force(self):
  3137. self.mock_object(self.client, 'send_request')
  3138. self.client._unmount_volume(fake.SHARE_NAME, force=True)
  3139. volume_unmount_args = {'volume-name': fake.SHARE_NAME, 'force': 'true'}
  3140. self.client.send_request.assert_has_calls([
  3141. mock.call('volume-unmount', volume_unmount_args)])
  3142. def test__unmount_volume_already_unmounted(self):
  3143. self.mock_object(self.client,
  3144. 'send_request',
  3145. mock.Mock(side_effect=self._mock_api_error(
  3146. netapp_api.EVOL_NOT_MOUNTED)))
  3147. self.client._unmount_volume(fake.SHARE_NAME, force=True)
  3148. volume_unmount_args = {'volume-name': fake.SHARE_NAME, 'force': 'true'}
  3149. self.client.send_request.assert_has_calls([
  3150. mock.call('volume-unmount', volume_unmount_args)])
  3151. def test__unmount_volume_api_error(self):
  3152. self.mock_object(self.client,
  3153. 'send_request',
  3154. mock.Mock(side_effect=self._mock_api_error()))
  3155. self.assertRaises(netapp_api.NaApiError,
  3156. self.client._unmount_volume,
  3157. fake.SHARE_NAME,
  3158. force=True)
  3159. def test_unmount_volume(self):
  3160. self.mock_object(self.client, '_unmount_volume')
  3161. self.client.unmount_volume(fake.SHARE_NAME)
  3162. self.client._unmount_volume.assert_called_once_with(fake.SHARE_NAME,
  3163. force=False)
  3164. self.assertEqual(1, client_cmode.LOG.debug.call_count)
  3165. self.assertEqual(0, client_cmode.LOG.warning.call_count)
  3166. def test_unmount_volume_api_error(self):
  3167. self.mock_object(self.client,
  3168. '_unmount_volume',
  3169. self._mock_api_error())
  3170. self.assertRaises(netapp_api.NaApiError,
  3171. self.client.unmount_volume,
  3172. fake.SHARE_NAME)
  3173. self.assertEqual(1, self.client._unmount_volume.call_count)
  3174. self.assertEqual(0, client_cmode.LOG.debug.call_count)
  3175. self.assertEqual(0, client_cmode.LOG.warning.call_count)
  3176. def test_unmount_volume_with_retries(self):
  3177. side_effect = [netapp_api.NaApiError(code=netapp_api.EAPIERROR,
  3178. message='...job ID...')] * 5
  3179. side_effect.append(None)
  3180. self.mock_object(self.client,
  3181. '_unmount_volume',
  3182. mock.Mock(side_effect=side_effect))
  3183. self.mock_object(time, 'sleep')
  3184. self.client.unmount_volume(fake.SHARE_NAME)
  3185. self.assertEqual(6, self.client._unmount_volume.call_count)
  3186. self.assertEqual(1, client_cmode.LOG.debug.call_count)
  3187. self.assertEqual(5, client_cmode.LOG.warning.call_count)
  3188. def test_unmount_volume_with_max_retries(self):
  3189. side_effect = [netapp_api.NaApiError(code=netapp_api.EAPIERROR,
  3190. message='...job ID...')] * 30
  3191. self.mock_object(self.client,
  3192. '_unmount_volume',
  3193. mock.Mock(side_effect=side_effect))
  3194. self.mock_object(time, 'sleep')
  3195. self.assertRaises(exception.NetAppException,
  3196. self.client.unmount_volume,
  3197. fake.SHARE_NAME)
  3198. self.assertEqual(10, self.client._unmount_volume.call_count)
  3199. self.assertEqual(0, client_cmode.LOG.debug.call_count)
  3200. self.assertEqual(10, client_cmode.LOG.warning.call_count)
  3201. def test_delete_volume(self):
  3202. self.mock_object(self.client, 'send_request')
  3203. self.client.delete_volume(fake.SHARE_NAME)
  3204. volume_destroy_args = {'name': fake.SHARE_NAME}
  3205. self.client.send_request.assert_has_calls([
  3206. mock.call('volume-destroy', volume_destroy_args)])
  3207. def test_create_snapshot(self):
  3208. self.mock_object(self.client, 'send_request')
  3209. self.client.create_snapshot(fake.SHARE_NAME, fake.SNAPSHOT_NAME)
  3210. snapshot_create_args = {
  3211. 'volume': fake.SHARE_NAME,
  3212. 'snapshot': fake.SNAPSHOT_NAME
  3213. }
  3214. self.client.send_request.assert_has_calls([
  3215. mock.call('snapshot-create', snapshot_create_args)])
  3216. @ddt.data({
  3217. 'mock_return': fake.SNAPSHOT_GET_ITER_NOT_BUSY_RESPONSE,
  3218. 'expected': {
  3219. 'access-time': fake.SNAPSHOT_ACCESS_TIME,
  3220. 'name': fake.SNAPSHOT_NAME,
  3221. 'volume': fake.SHARE_NAME,
  3222. 'busy': False,
  3223. 'owners': set(),
  3224. }
  3225. }, {
  3226. 'mock_return': fake.SNAPSHOT_GET_ITER_BUSY_RESPONSE,
  3227. 'expected': {
  3228. 'access-time': fake.SNAPSHOT_ACCESS_TIME,
  3229. 'name': fake.SNAPSHOT_NAME,
  3230. 'volume': fake.SHARE_NAME,
  3231. 'busy': True,
  3232. 'owners': {'volume clone'},
  3233. }
  3234. })
  3235. @ddt.unpack
  3236. def test_get_snapshot(self, mock_return, expected):
  3237. api_response = netapp_api.NaElement(mock_return)
  3238. self.mock_object(self.client,
  3239. 'send_request',
  3240. mock.Mock(return_value=api_response))
  3241. result = self.client.get_snapshot(fake.SHARE_NAME, fake.SNAPSHOT_NAME)
  3242. snapshot_get_iter_args = {
  3243. 'query': {
  3244. 'snapshot-info': {
  3245. 'name': fake.SNAPSHOT_NAME,
  3246. 'volume': fake.SHARE_NAME,
  3247. },
  3248. },
  3249. 'desired-attributes': {
  3250. 'snapshot-info': {
  3251. 'access-time': None,
  3252. 'name': None,
  3253. 'volume': None,
  3254. 'busy': None,
  3255. 'snapshot-owners-list': {
  3256. 'snapshot-owner': None,
  3257. }
  3258. },
  3259. },
  3260. }
  3261. self.client.send_request.assert_has_calls([
  3262. mock.call('snapshot-get-iter', snapshot_get_iter_args)])
  3263. self.assertDictEqual(expected, result)
  3264. @ddt.data({
  3265. 'api_response_xml': fake.NO_RECORDS_RESPONSE,
  3266. 'raised_exception': exception.SnapshotResourceNotFound,
  3267. }, {
  3268. 'api_response_xml': fake.SNAPSHOT_GET_ITER_NOT_UNIQUE_RESPONSE,
  3269. 'raised_exception': exception.NetAppException,
  3270. }, {
  3271. 'api_response_xml': fake.SNAPSHOT_GET_ITER_UNAVAILABLE_RESPONSE,
  3272. 'raised_exception': exception.SnapshotUnavailable,
  3273. }, {
  3274. 'api_response_xml': fake.SNAPSHOT_GET_ITER_OTHER_ERROR_RESPONSE,
  3275. 'raised_exception': exception.NetAppException,
  3276. })
  3277. @ddt.unpack
  3278. def test_get_snapshot_error(self, api_response_xml, raised_exception):
  3279. api_response = netapp_api.NaElement(api_response_xml)
  3280. self.mock_object(self.client,
  3281. 'send_request',
  3282. mock.Mock(return_value=api_response))
  3283. self.assertRaises(raised_exception,
  3284. self.client.get_snapshot,
  3285. fake.SHARE_NAME,
  3286. fake.SNAPSHOT_NAME)
  3287. def test_rename_snapshot(self):
  3288. self.mock_object(self.client, 'send_request')
  3289. self.client.rename_snapshot(fake.SHARE_NAME,
  3290. fake.SNAPSHOT_NAME,
  3291. 'new_snapshot_name')
  3292. snapshot_rename_args = {
  3293. 'volume': fake.SHARE_NAME,
  3294. 'current-name': fake.SNAPSHOT_NAME,
  3295. 'new-name': 'new_snapshot_name'
  3296. }
  3297. self.client.send_request.assert_has_calls([
  3298. mock.call('snapshot-rename', snapshot_rename_args)])
  3299. def test_restore_snapshot(self):
  3300. self.mock_object(self.client, 'send_request')
  3301. self.client.restore_snapshot(fake.SHARE_NAME,
  3302. fake.SNAPSHOT_NAME)
  3303. snapshot_restore_args = {
  3304. 'volume': fake.SHARE_NAME,
  3305. 'snapshot': fake.SNAPSHOT_NAME,
  3306. }
  3307. self.client.send_request.assert_has_calls([
  3308. mock.call('snapshot-restore-volume', snapshot_restore_args)])
  3309. @ddt.data(True, False)
  3310. def test_delete_snapshot(self, ignore_owners):
  3311. self.mock_object(self.client, 'send_request')
  3312. self.client.delete_snapshot(
  3313. fake.SHARE_NAME, fake.SNAPSHOT_NAME, ignore_owners=ignore_owners)
  3314. snapshot_delete_args = {
  3315. 'volume': fake.SHARE_NAME,
  3316. 'snapshot': fake.SNAPSHOT_NAME,
  3317. 'ignore-owners': 'true' if ignore_owners else 'false',
  3318. }
  3319. self.client.send_request.assert_has_calls([
  3320. mock.call('snapshot-delete', snapshot_delete_args)])
  3321. def test_soft_delete_snapshot(self):
  3322. mock_delete_snapshot = self.mock_object(self.client, 'delete_snapshot')
  3323. mock_rename_snapshot = self.mock_object(self.client, 'rename_snapshot')
  3324. self.client.soft_delete_snapshot(fake.SHARE_NAME, fake.SNAPSHOT_NAME)
  3325. mock_delete_snapshot.assert_called_once_with(
  3326. fake.SHARE_NAME, fake.SNAPSHOT_NAME)
  3327. self.assertFalse(mock_rename_snapshot.called)
  3328. def test_soft_delete_snapshot_api_error(self):
  3329. mock_delete_snapshot = self.mock_object(
  3330. self.client, 'delete_snapshot', self._mock_api_error())
  3331. mock_rename_snapshot = self.mock_object(self.client, 'rename_snapshot')
  3332. self.client.soft_delete_snapshot(fake.SHARE_NAME, fake.SNAPSHOT_NAME)
  3333. mock_delete_snapshot.assert_called_once_with(
  3334. fake.SHARE_NAME, fake.SNAPSHOT_NAME)
  3335. mock_rename_snapshot.assert_called_once_with(
  3336. fake.SHARE_NAME, fake.SNAPSHOT_NAME,
  3337. 'deleted_manila_' + fake.SNAPSHOT_NAME)
  3338. def test_prune_deleted_snapshots(self):
  3339. deleted_snapshots_map = {
  3340. 'vserver1': [{
  3341. 'name': 'deleted_snap_1',
  3342. 'volume': 'fake_volume_1',
  3343. 'vserver': 'vserver1',
  3344. }],
  3345. 'vserver2': [{
  3346. 'name': 'deleted_snap_2',
  3347. 'volume': 'fake_volume_2',
  3348. 'vserver': 'vserver2',
  3349. }],
  3350. }
  3351. mock_get_deleted_snapshots = self.mock_object(
  3352. self.client, '_get_deleted_snapshots',
  3353. mock.Mock(return_value=deleted_snapshots_map))
  3354. mock_delete_snapshot = self.mock_object(
  3355. self.client, 'delete_snapshot',
  3356. mock.Mock(side_effect=[None, netapp_api.NaApiError]))
  3357. self.mock_object(
  3358. copy, 'deepcopy', mock.Mock(return_value=self.client))
  3359. self.client.prune_deleted_snapshots()
  3360. mock_get_deleted_snapshots.assert_called_once_with()
  3361. mock_delete_snapshot.assert_has_calls([
  3362. mock.call('fake_volume_1', 'deleted_snap_1'),
  3363. mock.call('fake_volume_2', 'deleted_snap_2'),
  3364. ], any_order=True)
  3365. def test_get_deleted_snapshots(self):
  3366. api_response = netapp_api.NaElement(
  3367. fake.SNAPSHOT_GET_ITER_DELETED_RESPONSE)
  3368. self.mock_object(self.client,
  3369. 'send_iter_request',
  3370. mock.Mock(return_value=api_response))
  3371. result = self.client._get_deleted_snapshots()
  3372. snapshot_get_iter_args = {
  3373. 'query': {
  3374. 'snapshot-info': {
  3375. 'name': 'deleted_manila_*',
  3376. 'busy': 'false',
  3377. },
  3378. },
  3379. 'desired-attributes': {
  3380. 'snapshot-info': {
  3381. 'name': None,
  3382. 'vserver': None,
  3383. 'volume': None,
  3384. },
  3385. },
  3386. }
  3387. self.client.send_iter_request.assert_has_calls([
  3388. mock.call('snapshot-get-iter', snapshot_get_iter_args)])
  3389. expected = {
  3390. fake.VSERVER_NAME: [{
  3391. 'name': 'deleted_manila_' + fake.SNAPSHOT_NAME,
  3392. 'volume': fake.SHARE_NAME,
  3393. 'vserver': fake.VSERVER_NAME,
  3394. }],
  3395. }
  3396. self.assertDictEqual(expected, result)
  3397. def test_create_cg_snapshot(self):
  3398. mock_start_cg_snapshot = self.mock_object(
  3399. self.client, '_start_cg_snapshot',
  3400. mock.Mock(return_value=fake.CG_SNAPSHOT_ID))
  3401. mock_commit_cg_snapshot = self.mock_object(
  3402. self.client, '_commit_cg_snapshot')
  3403. self.client.create_cg_snapshot([fake.SHARE_NAME, fake.SHARE_NAME_2],
  3404. fake.SNAPSHOT_NAME)
  3405. mock_start_cg_snapshot.assert_called_once_with(
  3406. [fake.SHARE_NAME, fake.SHARE_NAME_2], fake.SNAPSHOT_NAME)
  3407. mock_commit_cg_snapshot.assert_called_once_with(fake.CG_SNAPSHOT_ID)
  3408. def test_create_cg_snapshot_no_id(self):
  3409. mock_start_cg_snapshot = self.mock_object(
  3410. self.client, '_start_cg_snapshot', mock.Mock(return_value=None))
  3411. mock_commit_cg_snapshot = self.mock_object(
  3412. self.client, '_commit_cg_snapshot')
  3413. self.assertRaises(exception.NetAppException,
  3414. self.client.create_cg_snapshot,
  3415. [fake.SHARE_NAME, fake.SHARE_NAME_2],
  3416. fake.SNAPSHOT_NAME)
  3417. mock_start_cg_snapshot.assert_called_once_with(
  3418. [fake.SHARE_NAME, fake.SHARE_NAME_2], fake.SNAPSHOT_NAME)
  3419. self.assertFalse(mock_commit_cg_snapshot.called)
  3420. def test_start_cg_snapshot(self):
  3421. self.mock_object(self.client, 'send_request')
  3422. self.client._start_cg_snapshot([fake.SHARE_NAME, fake.SHARE_NAME_2],
  3423. fake.SNAPSHOT_NAME)
  3424. cg_start_args = {
  3425. 'snapshot': fake.SNAPSHOT_NAME,
  3426. 'timeout': 'relaxed',
  3427. 'volumes': [
  3428. {'volume-name': fake.SHARE_NAME},
  3429. {'volume-name': fake.SHARE_NAME_2},
  3430. ],
  3431. }
  3432. self.client.send_request.assert_has_calls([
  3433. mock.call('cg-start', cg_start_args)])
  3434. def test_commit_cg_snapshot(self):
  3435. self.mock_object(self.client, 'send_request')
  3436. self.client._commit_cg_snapshot(fake.CG_SNAPSHOT_ID)
  3437. cg_commit_args = {'cg-id': fake.CG_SNAPSHOT_ID}
  3438. self.client.send_request.assert_has_calls([
  3439. mock.call('cg-commit', cg_commit_args)])
  3440. def test_create_cifs_share(self):
  3441. self.mock_object(self.client, 'send_request')
  3442. self.client.create_cifs_share(fake.SHARE_NAME)
  3443. cifs_share_create_args = {
  3444. 'path': '/%s' % fake.SHARE_NAME,
  3445. 'share-name': fake.SHARE_NAME
  3446. }
  3447. self.client.send_request.assert_has_calls([
  3448. mock.call('cifs-share-create', cifs_share_create_args)])
  3449. def test_get_cifs_share_access(self):
  3450. api_response = netapp_api.NaElement(
  3451. fake.CIFS_SHARE_ACCESS_CONTROL_GET_ITER)
  3452. self.mock_object(self.client,
  3453. 'send_iter_request',
  3454. mock.Mock(return_value=api_response))
  3455. result = self.client.get_cifs_share_access(fake.SHARE_NAME)
  3456. cifs_share_access_control_get_iter_args = {
  3457. 'query': {
  3458. 'cifs-share-access-control': {
  3459. 'share': fake.SHARE_NAME,
  3460. },
  3461. },
  3462. 'desired-attributes': {
  3463. 'cifs-share-access-control': {
  3464. 'user-or-group': None,
  3465. 'permission': None,
  3466. },
  3467. },
  3468. }
  3469. self.client.send_iter_request.assert_has_calls([
  3470. mock.call('cifs-share-access-control-get-iter',
  3471. cifs_share_access_control_get_iter_args)])
  3472. expected = {
  3473. 'Administrator': 'full_control',
  3474. 'Administrators': 'change',
  3475. 'Power Users': 'read',
  3476. 'Users': 'no_access',
  3477. }
  3478. self.assertDictEqual(expected, result)
  3479. def test_get_cifs_share_access_not_found(self):
  3480. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  3481. self.mock_object(self.client,
  3482. 'send_iter_request',
  3483. mock.Mock(return_value=api_response))
  3484. result = self.client.get_cifs_share_access(fake.SHARE_NAME)
  3485. self.assertEqual({}, result)
  3486. @ddt.data(True, False)
  3487. def test_add_cifs_share_access(self, readonly):
  3488. self.mock_object(self.client, 'send_request')
  3489. self.client.add_cifs_share_access(fake.SHARE_NAME,
  3490. fake.USER_NAME,
  3491. readonly)
  3492. cifs_share_access_control_create_args = {
  3493. 'permission': 'read' if readonly else 'full_control',
  3494. 'share': fake.SHARE_NAME,
  3495. 'user-or-group': fake.USER_NAME
  3496. }
  3497. self.client.send_request.assert_has_calls([
  3498. mock.call(
  3499. 'cifs-share-access-control-create',
  3500. cifs_share_access_control_create_args)])
  3501. @ddt.data(True, False)
  3502. def test_modify_cifs_share_access(self, readonly):
  3503. self.mock_object(self.client, 'send_request')
  3504. self.client.modify_cifs_share_access(fake.SHARE_NAME,
  3505. fake.USER_NAME,
  3506. readonly)
  3507. cifs_share_access_control_modify_args = {
  3508. 'permission': 'read' if readonly else 'full_control',
  3509. 'share': fake.SHARE_NAME,
  3510. 'user-or-group': fake.USER_NAME
  3511. }
  3512. self.client.send_request.assert_has_calls([
  3513. mock.call(
  3514. 'cifs-share-access-control-modify',
  3515. cifs_share_access_control_modify_args)])
  3516. def test_remove_cifs_share_access(self):
  3517. self.mock_object(self.client, 'send_request')
  3518. self.client.remove_cifs_share_access(fake.SHARE_NAME, fake.USER_NAME)
  3519. cifs_share_access_control_delete_args = {
  3520. 'user-or-group': fake.USER_NAME,
  3521. 'share': fake.SHARE_NAME
  3522. }
  3523. self.client.send_request.assert_has_calls([
  3524. mock.call(
  3525. 'cifs-share-access-control-delete',
  3526. cifs_share_access_control_delete_args)])
  3527. def test_remove_cifs_share(self):
  3528. self.mock_object(self.client, 'send_request')
  3529. self.client.remove_cifs_share(fake.SHARE_NAME)
  3530. cifs_share_delete_args = {'share-name': fake.SHARE_NAME}
  3531. self.client.send_request.assert_has_calls([
  3532. mock.call('cifs-share-delete', cifs_share_delete_args)])
  3533. def test_add_nfs_export_rule(self):
  3534. mock_get_nfs_export_rule_indices = self.mock_object(
  3535. self.client, '_get_nfs_export_rule_indices',
  3536. mock.Mock(return_value=[]))
  3537. mock_add_nfs_export_rule = self.mock_object(
  3538. self.client, '_add_nfs_export_rule')
  3539. mock_update_nfs_export_rule = self.mock_object(
  3540. self.client, '_update_nfs_export_rule')
  3541. self.client.add_nfs_export_rule(fake.EXPORT_POLICY_NAME,
  3542. fake.IP_ADDRESS,
  3543. False)
  3544. mock_get_nfs_export_rule_indices.assert_called_once_with(
  3545. fake.EXPORT_POLICY_NAME, fake.IP_ADDRESS)
  3546. mock_add_nfs_export_rule.assert_called_once_with(
  3547. fake.EXPORT_POLICY_NAME, fake.IP_ADDRESS, False)
  3548. self.assertFalse(mock_update_nfs_export_rule.called)
  3549. def test_add_nfs_export_rule_single_existing(self):
  3550. mock_get_nfs_export_rule_indices = self.mock_object(
  3551. self.client, '_get_nfs_export_rule_indices',
  3552. mock.Mock(return_value=['1']))
  3553. mock_add_nfs_export_rule = self.mock_object(
  3554. self.client, '_add_nfs_export_rule')
  3555. mock_update_nfs_export_rule = self.mock_object(
  3556. self.client, '_update_nfs_export_rule')
  3557. mock_remove_nfs_export_rules = self.mock_object(
  3558. self.client, '_remove_nfs_export_rules')
  3559. self.client.add_nfs_export_rule(fake.EXPORT_POLICY_NAME,
  3560. fake.IP_ADDRESS,
  3561. False)
  3562. mock_get_nfs_export_rule_indices.assert_called_once_with(
  3563. fake.EXPORT_POLICY_NAME, fake.IP_ADDRESS)
  3564. self.assertFalse(mock_add_nfs_export_rule.called)
  3565. mock_update_nfs_export_rule.assert_called_once_with(
  3566. fake.EXPORT_POLICY_NAME, fake.IP_ADDRESS, False, '1')
  3567. mock_remove_nfs_export_rules.assert_called_once_with(
  3568. fake.EXPORT_POLICY_NAME, [])
  3569. def test_add_nfs_export_rule_multiple_existing(self):
  3570. mock_get_nfs_export_rule_indices = self.mock_object(
  3571. self.client, '_get_nfs_export_rule_indices',
  3572. mock.Mock(return_value=['2', '4', '6']))
  3573. mock_add_nfs_export_rule = self.mock_object(
  3574. self.client, '_add_nfs_export_rule')
  3575. mock_update_nfs_export_rule = self.mock_object(
  3576. self.client, '_update_nfs_export_rule')
  3577. mock_remove_nfs_export_rules = self.mock_object(
  3578. self.client, '_remove_nfs_export_rules')
  3579. self.client.add_nfs_export_rule(fake.EXPORT_POLICY_NAME,
  3580. fake.IP_ADDRESS,
  3581. False)
  3582. mock_get_nfs_export_rule_indices.assert_called_once_with(
  3583. fake.EXPORT_POLICY_NAME, fake.IP_ADDRESS)
  3584. self.assertFalse(mock_add_nfs_export_rule.called)
  3585. mock_update_nfs_export_rule.assert_called_once_with(
  3586. fake.EXPORT_POLICY_NAME, fake.IP_ADDRESS, False, '2')
  3587. mock_remove_nfs_export_rules.assert_called_once_with(
  3588. fake.EXPORT_POLICY_NAME, ['4', '6'])
  3589. @ddt.data({'readonly': False, 'rw_security_flavor': 'sys'},
  3590. {'readonly': True, 'rw_security_flavor': 'never'})
  3591. @ddt.unpack
  3592. def test__add_nfs_export_rule(self, readonly, rw_security_flavor):
  3593. self.mock_object(self.client, 'send_request')
  3594. self.client._add_nfs_export_rule(fake.EXPORT_POLICY_NAME,
  3595. fake.IP_ADDRESS,
  3596. readonly)
  3597. export_rule_create_args = {
  3598. 'policy-name': fake.EXPORT_POLICY_NAME,
  3599. 'client-match': fake.IP_ADDRESS,
  3600. 'ro-rule': {
  3601. 'security-flavor': 'sys',
  3602. },
  3603. 'rw-rule': {
  3604. 'security-flavor': rw_security_flavor,
  3605. },
  3606. 'super-user-security': {
  3607. 'security-flavor': 'sys',
  3608. },
  3609. }
  3610. self.client.send_request.assert_has_calls(
  3611. [mock.call('export-rule-create', export_rule_create_args)])
  3612. @ddt.data({'readonly': False, 'rw_security_flavor': 'sys', 'index': '2'},
  3613. {'readonly': True, 'rw_security_flavor': 'never', 'index': '4'})
  3614. @ddt.unpack
  3615. def test_update_nfs_export_rule(self, readonly, rw_security_flavor, index):
  3616. self.mock_object(self.client, 'send_request')
  3617. self.client._update_nfs_export_rule(fake.EXPORT_POLICY_NAME,
  3618. fake.IP_ADDRESS,
  3619. readonly,
  3620. index)
  3621. export_rule_modify_args = {
  3622. 'policy-name': fake.EXPORT_POLICY_NAME,
  3623. 'rule-index': index,
  3624. 'client-match': fake.IP_ADDRESS,
  3625. 'ro-rule': {
  3626. 'security-flavor': 'sys',
  3627. },
  3628. 'rw-rule': {
  3629. 'security-flavor': rw_security_flavor,
  3630. },
  3631. 'super-user-security': {
  3632. 'security-flavor': 'sys',
  3633. },
  3634. }
  3635. self.client.send_request.assert_has_calls(
  3636. [mock.call('export-rule-modify', export_rule_modify_args)])
  3637. def test_get_nfs_export_rule_indices(self):
  3638. api_response = netapp_api.NaElement(fake.EXPORT_RULE_GET_ITER_RESPONSE)
  3639. self.mock_object(self.client,
  3640. 'send_iter_request',
  3641. mock.Mock(return_value=api_response))
  3642. result = self.client._get_nfs_export_rule_indices(
  3643. fake.EXPORT_POLICY_NAME, fake.IP_ADDRESS)
  3644. export_rule_get_iter_args = {
  3645. 'query': {
  3646. 'export-rule-info': {
  3647. 'policy-name': fake.EXPORT_POLICY_NAME,
  3648. 'client-match': fake.IP_ADDRESS,
  3649. },
  3650. },
  3651. 'desired-attributes': {
  3652. 'export-rule-info': {
  3653. 'vserver-name': None,
  3654. 'policy-name': None,
  3655. 'client-match': None,
  3656. 'rule-index': None,
  3657. },
  3658. },
  3659. }
  3660. self.assertListEqual(['1', '3'], result)
  3661. self.client.send_iter_request.assert_has_calls([
  3662. mock.call('export-rule-get-iter', export_rule_get_iter_args)])
  3663. def test_remove_nfs_export_rule(self):
  3664. fake_indices = ['1', '3', '4']
  3665. mock_get_nfs_export_rule_indices = self.mock_object(
  3666. self.client, '_get_nfs_export_rule_indices',
  3667. mock.Mock(return_value=fake_indices))
  3668. mock_remove_nfs_export_rules = self.mock_object(
  3669. self.client, '_remove_nfs_export_rules')
  3670. self.client.remove_nfs_export_rule(fake.EXPORT_POLICY_NAME,
  3671. fake.IP_ADDRESS)
  3672. mock_get_nfs_export_rule_indices.assert_called_once_with(
  3673. fake.EXPORT_POLICY_NAME, fake.IP_ADDRESS)
  3674. mock_remove_nfs_export_rules.assert_called_once_with(
  3675. fake.EXPORT_POLICY_NAME, fake_indices)
  3676. def test_remove_nfs_export_rules(self):
  3677. fake_indices = ['1', '3']
  3678. self.mock_object(self.client, 'send_request')
  3679. self.client._remove_nfs_export_rules(fake.EXPORT_POLICY_NAME,
  3680. fake_indices)
  3681. self.client.send_request.assert_has_calls([
  3682. mock.call(
  3683. 'export-rule-destroy',
  3684. {'policy-name': fake.EXPORT_POLICY_NAME, 'rule-index': '1'}),
  3685. mock.call(
  3686. 'export-rule-destroy',
  3687. {'policy-name': fake.EXPORT_POLICY_NAME, 'rule-index': '3'})])
  3688. def test_remove_nfs_export_rules_not_found(self):
  3689. self.mock_object(self.client,
  3690. 'send_request',
  3691. self._mock_api_error(code=netapp_api.EOBJECTNOTFOUND))
  3692. self.client._remove_nfs_export_rules(fake.EXPORT_POLICY_NAME, ['1'])
  3693. self.client.send_request.assert_has_calls([
  3694. mock.call(
  3695. 'export-rule-destroy',
  3696. {'policy-name': fake.EXPORT_POLICY_NAME, 'rule-index': '1'})])
  3697. def test_remove_nfs_export_rules_api_error(self):
  3698. self.mock_object(self.client, 'send_request', self._mock_api_error())
  3699. self.assertRaises(netapp_api.NaApiError,
  3700. self.client._remove_nfs_export_rules,
  3701. fake.EXPORT_POLICY_NAME,
  3702. ['1'])
  3703. def test_clear_nfs_export_policy_for_volume(self):
  3704. mock_set_nfs_export_policy_for_volume = self.mock_object(
  3705. self.client, 'set_nfs_export_policy_for_volume')
  3706. self.client.clear_nfs_export_policy_for_volume(fake.SHARE_NAME)
  3707. mock_set_nfs_export_policy_for_volume.assert_called_once_with(
  3708. fake.SHARE_NAME, 'default')
  3709. def test_set_nfs_export_policy_for_volume(self):
  3710. self.mock_object(self.client, 'send_request')
  3711. self.client.set_nfs_export_policy_for_volume(fake.SHARE_NAME,
  3712. fake.EXPORT_POLICY_NAME)
  3713. volume_modify_iter_args = {
  3714. 'query': {
  3715. 'volume-attributes': {
  3716. 'volume-id-attributes': {
  3717. 'name': fake.SHARE_NAME,
  3718. },
  3719. },
  3720. },
  3721. 'attributes': {
  3722. 'volume-attributes': {
  3723. 'volume-export-attributes': {
  3724. 'policy': fake.EXPORT_POLICY_NAME,
  3725. },
  3726. },
  3727. },
  3728. }
  3729. self.client.send_request.assert_has_calls([
  3730. mock.call('volume-modify-iter', volume_modify_iter_args)])
  3731. def test_set_qos_policy_group_for_volume(self):
  3732. self.mock_object(self.client, 'send_request')
  3733. self.client.set_qos_policy_group_for_volume(fake.SHARE_NAME,
  3734. fake.QOS_POLICY_GROUP_NAME)
  3735. volume_modify_iter_args = {
  3736. 'query': {
  3737. 'volume-attributes': {
  3738. 'volume-id-attributes': {
  3739. 'name': fake.SHARE_NAME,
  3740. },
  3741. },
  3742. },
  3743. 'attributes': {
  3744. 'volume-attributes': {
  3745. 'volume-qos-attributes': {
  3746. 'policy-group-name': fake.QOS_POLICY_GROUP_NAME,
  3747. },
  3748. },
  3749. },
  3750. }
  3751. self.client.send_request.assert_called_once_with(
  3752. 'volume-modify-iter', volume_modify_iter_args)
  3753. def test_get_nfs_export_policy_for_volume(self):
  3754. api_response = netapp_api.NaElement(
  3755. fake.VOLUME_GET_EXPORT_POLICY_RESPONSE)
  3756. self.mock_object(self.client,
  3757. 'send_iter_request',
  3758. mock.Mock(return_value=api_response))
  3759. result = self.client.get_nfs_export_policy_for_volume(fake.SHARE_NAME)
  3760. volume_get_iter_args = {
  3761. 'query': {
  3762. 'volume-attributes': {
  3763. 'volume-id-attributes': {
  3764. 'name': fake.SHARE_NAME,
  3765. },
  3766. },
  3767. },
  3768. 'desired-attributes': {
  3769. 'volume-attributes': {
  3770. 'volume-export-attributes': {
  3771. 'policy': None,
  3772. },
  3773. },
  3774. },
  3775. }
  3776. self.assertEqual(fake.EXPORT_POLICY_NAME, result)
  3777. self.client.send_iter_request.assert_has_calls([
  3778. mock.call('volume-get-iter', volume_get_iter_args)])
  3779. def test_get_nfs_export_policy_for_volume_not_found(self):
  3780. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  3781. self.mock_object(self.client,
  3782. 'send_iter_request',
  3783. mock.Mock(return_value=api_response))
  3784. self.assertRaises(exception.NetAppException,
  3785. self.client.get_nfs_export_policy_for_volume,
  3786. fake.SHARE_NAME)
  3787. def test_create_nfs_export_policy(self):
  3788. self.mock_object(self.client, 'send_request')
  3789. self.client.create_nfs_export_policy(fake.EXPORT_POLICY_NAME)
  3790. export_policy_create_args = {'policy-name': fake.EXPORT_POLICY_NAME}
  3791. self.client.send_request.assert_has_calls([
  3792. mock.call('export-policy-create', export_policy_create_args)])
  3793. def test_create_nfs_export_policy_already_present(self):
  3794. self.mock_object(self.client,
  3795. 'send_request',
  3796. self._mock_api_error(code=netapp_api.EDUPLICATEENTRY))
  3797. self.client.create_nfs_export_policy(fake.EXPORT_POLICY_NAME)
  3798. export_policy_create_args = {'policy-name': fake.EXPORT_POLICY_NAME}
  3799. self.client.send_request.assert_has_calls([
  3800. mock.call('export-policy-create', export_policy_create_args)])
  3801. def test_create_nfs_export_policy_api_error(self):
  3802. self.mock_object(self.client, 'send_request', self._mock_api_error())
  3803. self.assertRaises(netapp_api.NaApiError,
  3804. self.client.create_nfs_export_policy,
  3805. fake.EXPORT_POLICY_NAME)
  3806. def test_soft_delete_nfs_export_policy(self):
  3807. self.mock_object(self.client, 'delete_nfs_export_policy')
  3808. self.mock_object(self.client, 'rename_nfs_export_policy')
  3809. self.client.soft_delete_nfs_export_policy(fake.EXPORT_POLICY_NAME)
  3810. self.client.delete_nfs_export_policy.assert_has_calls([
  3811. mock.call(fake.EXPORT_POLICY_NAME)])
  3812. self.assertFalse(self.client.rename_nfs_export_policy.called)
  3813. def test_soft_delete_nfs_export_policy_api_error(self):
  3814. self.mock_object(self.client,
  3815. 'delete_nfs_export_policy',
  3816. self._mock_api_error())
  3817. self.mock_object(self.client, 'rename_nfs_export_policy')
  3818. self.client.soft_delete_nfs_export_policy(fake.EXPORT_POLICY_NAME)
  3819. self.client.delete_nfs_export_policy.assert_has_calls([
  3820. mock.call(fake.EXPORT_POLICY_NAME)])
  3821. self.assertTrue(self.client.rename_nfs_export_policy.called)
  3822. def test_delete_nfs_export_policy(self):
  3823. self.mock_object(self.client, 'send_request')
  3824. self.client.delete_nfs_export_policy(fake.EXPORT_POLICY_NAME)
  3825. export_policy_destroy_args = {'policy-name': fake.EXPORT_POLICY_NAME}
  3826. self.client.send_request.assert_has_calls([
  3827. mock.call('export-policy-destroy', export_policy_destroy_args)])
  3828. def test_delete_nfs_export_policy_not_found(self):
  3829. self.mock_object(self.client,
  3830. 'send_request',
  3831. self._mock_api_error(code=netapp_api.EOBJECTNOTFOUND))
  3832. self.client.delete_nfs_export_policy(fake.EXPORT_POLICY_NAME)
  3833. export_policy_destroy_args = {'policy-name': fake.EXPORT_POLICY_NAME}
  3834. self.client.send_request.assert_has_calls([
  3835. mock.call('export-policy-destroy', export_policy_destroy_args)])
  3836. def test_delete_nfs_export_policy_api_error(self):
  3837. self.mock_object(self.client, 'send_request', self._mock_api_error())
  3838. self.assertRaises(netapp_api.NaApiError,
  3839. self.client.delete_nfs_export_policy,
  3840. fake.EXPORT_POLICY_NAME)
  3841. def test_rename_nfs_export_policy(self):
  3842. self.mock_object(self.client, 'send_request')
  3843. self.client.rename_nfs_export_policy(fake.EXPORT_POLICY_NAME,
  3844. 'new_policy_name')
  3845. export_policy_rename_args = {
  3846. 'policy-name': fake.EXPORT_POLICY_NAME,
  3847. 'new-policy-name': 'new_policy_name'
  3848. }
  3849. self.client.send_request.assert_has_calls([
  3850. mock.call('export-policy-rename', export_policy_rename_args)])
  3851. def test_prune_deleted_nfs_export_policies(self):
  3852. # Mock client lest we not be able to see calls on its copy.
  3853. self.mock_object(copy,
  3854. 'deepcopy',
  3855. mock.Mock(return_value=self.client))
  3856. self.mock_object(self.client,
  3857. '_get_deleted_nfs_export_policies',
  3858. mock.Mock(return_value=fake.DELETED_EXPORT_POLICIES))
  3859. self.mock_object(self.client, 'delete_nfs_export_policy')
  3860. self.client.prune_deleted_nfs_export_policies()
  3861. self.assertTrue(self.client.delete_nfs_export_policy.called)
  3862. self.client.delete_nfs_export_policy.assert_has_calls(
  3863. [mock.call(policy) for policy in
  3864. fake.DELETED_EXPORT_POLICIES[fake.VSERVER_NAME]])
  3865. def test_prune_deleted_nfs_export_policies_api_error(self):
  3866. self.mock_object(copy,
  3867. 'deepcopy',
  3868. mock.Mock(return_value=self.client))
  3869. self.mock_object(self.client,
  3870. '_get_deleted_nfs_export_policies',
  3871. mock.Mock(return_value=fake.DELETED_EXPORT_POLICIES))
  3872. self.mock_object(self.client,
  3873. 'delete_nfs_export_policy',
  3874. self._mock_api_error())
  3875. self.client.prune_deleted_nfs_export_policies()
  3876. self.assertTrue(self.client.delete_nfs_export_policy.called)
  3877. self.client.delete_nfs_export_policy.assert_has_calls(
  3878. [mock.call(policy) for policy in
  3879. fake.DELETED_EXPORT_POLICIES[fake.VSERVER_NAME]])
  3880. def test_get_deleted_nfs_export_policies(self):
  3881. api_response = netapp_api.NaElement(
  3882. fake.DELETED_EXPORT_POLICY_GET_ITER_RESPONSE)
  3883. self.mock_object(self.client,
  3884. 'send_iter_request',
  3885. mock.Mock(return_value=api_response))
  3886. result = self.client._get_deleted_nfs_export_policies()
  3887. export_policy_get_iter_args = {
  3888. 'query': {
  3889. 'export-policy-info': {
  3890. 'policy-name': 'deleted_manila_*',
  3891. },
  3892. },
  3893. 'desired-attributes': {
  3894. 'export-policy-info': {
  3895. 'policy-name': None,
  3896. 'vserver': None,
  3897. },
  3898. },
  3899. }
  3900. self.assertSequenceEqual(fake.DELETED_EXPORT_POLICIES, result)
  3901. self.client.send_iter_request.assert_has_calls([
  3902. mock.call('export-policy-get-iter', export_policy_get_iter_args)])
  3903. def test_get_ems_log_destination_vserver(self):
  3904. self.mock_object(self.client,
  3905. 'get_ontapi_version',
  3906. mock.Mock(return_value=(1, 21)))
  3907. mock_list_vservers = self.mock_object(
  3908. self.client,
  3909. 'list_vservers',
  3910. mock.Mock(return_value=[fake.ADMIN_VSERVER_NAME]))
  3911. result = self.client._get_ems_log_destination_vserver()
  3912. mock_list_vservers.assert_called_once_with(vserver_type='admin')
  3913. self.assertEqual(fake.ADMIN_VSERVER_NAME, result)
  3914. def test_get_ems_log_destination_vserver_future(self):
  3915. self.mock_object(self.client,
  3916. 'get_ontapi_version',
  3917. mock.Mock(return_value=(2, 0)))
  3918. mock_list_vservers = self.mock_object(
  3919. self.client,
  3920. 'list_vservers',
  3921. mock.Mock(return_value=[fake.ADMIN_VSERVER_NAME]))
  3922. result = self.client._get_ems_log_destination_vserver()
  3923. mock_list_vservers.assert_called_once_with(vserver_type='admin')
  3924. self.assertEqual(fake.ADMIN_VSERVER_NAME, result)
  3925. def test_get_ems_log_destination_vserver_legacy(self):
  3926. self.mock_object(self.client,
  3927. 'get_ontapi_version',
  3928. mock.Mock(return_value=(1, 15)))
  3929. mock_list_vservers = self.mock_object(
  3930. self.client,
  3931. 'list_vservers',
  3932. mock.Mock(return_value=[fake.NODE_VSERVER_NAME]))
  3933. result = self.client._get_ems_log_destination_vserver()
  3934. mock_list_vservers.assert_called_once_with(vserver_type='node')
  3935. self.assertEqual(fake.NODE_VSERVER_NAME, result)
  3936. def test_get_ems_log_destination_no_cluster_creds(self):
  3937. self.mock_object(self.client,
  3938. 'get_ontapi_version',
  3939. mock.Mock(return_value=(1, 21)))
  3940. mock_list_vservers = self.mock_object(
  3941. self.client,
  3942. 'list_vservers',
  3943. mock.Mock(side_effect=[[], [fake.VSERVER_NAME]]))
  3944. result = self.client._get_ems_log_destination_vserver()
  3945. mock_list_vservers.assert_has_calls([
  3946. mock.call(vserver_type='admin'),
  3947. mock.call(vserver_type='data')])
  3948. self.assertEqual(fake.VSERVER_NAME, result)
  3949. def test_get_ems_log_destination_vserver_not_found(self):
  3950. self.mock_object(self.client,
  3951. 'get_ontapi_version',
  3952. mock.Mock(return_value=(1, 21)))
  3953. mock_list_vservers = self.mock_object(
  3954. self.client,
  3955. 'list_vservers',
  3956. mock.Mock(return_value=[]))
  3957. self.assertRaises(exception.NotFound,
  3958. self.client._get_ems_log_destination_vserver)
  3959. mock_list_vservers.assert_has_calls([
  3960. mock.call(vserver_type='admin'),
  3961. mock.call(vserver_type='data'),
  3962. mock.call(vserver_type='node')])
  3963. def test_send_ems_log_message(self):
  3964. # Mock client lest we not be able to see calls on its copy.
  3965. self.mock_object(
  3966. copy, 'copy',
  3967. mock.Mock(side_effect=[self.client, self.client.connection]))
  3968. self.mock_object(self.client,
  3969. '_get_ems_log_destination_vserver',
  3970. mock.Mock(return_value=fake.ADMIN_VSERVER_NAME))
  3971. self.mock_object(self.client, 'send_request')
  3972. self.client.send_ems_log_message(fake.EMS_MESSAGE)
  3973. self.client.send_request.assert_has_calls([
  3974. mock.call('ems-autosupport-log', fake.EMS_MESSAGE)])
  3975. self.assertEqual(1, client_cmode.LOG.debug.call_count)
  3976. def test_send_ems_log_message_api_error(self):
  3977. # Mock client lest we not be able to see calls on its copy.
  3978. self.mock_object(
  3979. copy, 'copy',
  3980. mock.Mock(side_effect=[self.client, self.client.connection]))
  3981. self.mock_object(self.client,
  3982. '_get_ems_log_destination_vserver',
  3983. mock.Mock(return_value=fake.ADMIN_VSERVER_NAME))
  3984. self.mock_object(self.client, 'send_request', self._mock_api_error())
  3985. self.client.send_ems_log_message(fake.EMS_MESSAGE)
  3986. self.client.send_request.assert_has_calls([
  3987. mock.call('ems-autosupport-log', fake.EMS_MESSAGE)])
  3988. self.assertEqual(1, client_cmode.LOG.warning.call_count)
  3989. def test_get_aggregate_none_specified(self):
  3990. result = self.client.get_aggregate('')
  3991. self.assertEqual({}, result)
  3992. def test_get_aggregate(self):
  3993. api_response = netapp_api.NaElement(
  3994. fake.AGGR_GET_ITER_SSC_RESPONSE).get_child_by_name(
  3995. 'attributes-list').get_children()
  3996. self.mock_object(self.client,
  3997. '_get_aggregates',
  3998. mock.Mock(return_value=api_response))
  3999. result = self.client.get_aggregate(fake.SHARE_AGGREGATE_NAME)
  4000. desired_attributes = {
  4001. 'aggr-attributes': {
  4002. 'aggregate-name': None,
  4003. 'aggr-raid-attributes': {
  4004. 'raid-type': None,
  4005. 'is-hybrid': None,
  4006. },
  4007. },
  4008. }
  4009. self.client._get_aggregates.assert_has_calls([
  4010. mock.call(
  4011. aggregate_names=[fake.SHARE_AGGREGATE_NAME],
  4012. desired_attributes=desired_attributes)])
  4013. expected = {
  4014. 'name': fake.SHARE_AGGREGATE_NAME,
  4015. 'raid-type': 'raid_dp',
  4016. 'is-hybrid': False,
  4017. }
  4018. self.assertEqual(expected, result)
  4019. def test_get_aggregate_not_found(self):
  4020. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  4021. self.mock_object(self.client,
  4022. 'send_request',
  4023. mock.Mock(return_value=api_response))
  4024. result = self.client.get_aggregate(fake.SHARE_AGGREGATE_NAME)
  4025. self.assertEqual({}, result)
  4026. def test_get_aggregate_api_error(self):
  4027. self.mock_object(self.client,
  4028. 'send_request',
  4029. mock.Mock(side_effect=self._mock_api_error()))
  4030. result = self.client.get_aggregate(fake.SHARE_AGGREGATE_NAME)
  4031. self.assertEqual({}, result)
  4032. @ddt.data({'types': {'FCAL'}, 'expected': ['FCAL']},
  4033. {'types': {'SATA', 'SSD'}, 'expected': ['SATA', 'SSD']},)
  4034. @ddt.unpack
  4035. def test_get_aggregate_disk_types(self, types, expected):
  4036. mock_get_aggregate_disk_types = self.mock_object(
  4037. self.client, '_get_aggregate_disk_types',
  4038. mock.Mock(return_value=types))
  4039. result = self.client.get_aggregate_disk_types(
  4040. fake.SHARE_AGGREGATE_NAME)
  4041. self.assertItemsEqual(expected, result)
  4042. mock_get_aggregate_disk_types.assert_called_once_with(
  4043. fake.SHARE_AGGREGATE_NAME)
  4044. def test_get_aggregate_disk_types_not_found(self):
  4045. mock_get_aggregate_disk_types = self.mock_object(
  4046. self.client, '_get_aggregate_disk_types',
  4047. mock.Mock(return_value=set()))
  4048. result = self.client.get_aggregate_disk_types(
  4049. fake.SHARE_AGGREGATE_NAME)
  4050. self.assertIsNone(result)
  4051. mock_get_aggregate_disk_types.assert_called_once_with(
  4052. fake.SHARE_AGGREGATE_NAME)
  4053. def test_get_aggregate_disk_types_shared(self):
  4054. self.client.features.add_feature('ADVANCED_DISK_PARTITIONING')
  4055. mock_get_aggregate_disk_types = self.mock_object(
  4056. self.client, '_get_aggregate_disk_types',
  4057. mock.Mock(side_effect=[set(['SSD']), set(['SATA'])]))
  4058. result = self.client.get_aggregate_disk_types(
  4059. fake.SHARE_AGGREGATE_NAME)
  4060. self.assertIsInstance(result, list)
  4061. self.assertItemsEqual(['SATA', 'SSD'], result)
  4062. mock_get_aggregate_disk_types.assert_has_calls([
  4063. mock.call(fake.SHARE_AGGREGATE_NAME),
  4064. mock.call(fake.SHARE_AGGREGATE_NAME, shared=True),
  4065. ])
  4066. @ddt.data({
  4067. 'shared': False,
  4068. 'query_disk_raid_info': {
  4069. 'disk-aggregate-info': {
  4070. 'aggregate-name': fake.SHARE_AGGREGATE_NAME,
  4071. },
  4072. },
  4073. }, {
  4074. 'shared': True,
  4075. 'query_disk_raid_info': {
  4076. 'disk-shared-info': {
  4077. 'aggregate-list': {
  4078. 'shared-aggregate-info': {
  4079. 'aggregate-name':
  4080. fake.SHARE_AGGREGATE_NAME,
  4081. },
  4082. },
  4083. },
  4084. },
  4085. })
  4086. @ddt.unpack
  4087. def test__get_aggregate_disk_types_ddt(self, shared, query_disk_raid_info):
  4088. api_response = netapp_api.NaElement(
  4089. fake.STORAGE_DISK_GET_ITER_RESPONSE)
  4090. self.mock_object(self.client,
  4091. 'send_iter_request',
  4092. mock.Mock(return_value=api_response))
  4093. result = self.client._get_aggregate_disk_types(
  4094. fake.SHARE_AGGREGATE_NAME, shared=shared)
  4095. storage_disk_get_iter_args = {
  4096. 'query': {
  4097. 'storage-disk-info': {
  4098. 'disk-raid-info': query_disk_raid_info,
  4099. },
  4100. },
  4101. 'desired-attributes': {
  4102. 'storage-disk-info': {
  4103. 'disk-raid-info': {
  4104. 'effective-disk-type': None,
  4105. },
  4106. },
  4107. },
  4108. }
  4109. self.client.send_iter_request.assert_called_once_with(
  4110. 'storage-disk-get-iter', storage_disk_get_iter_args)
  4111. expected = set(fake.SHARE_AGGREGATE_DISK_TYPES)
  4112. self.assertEqual(expected, result)
  4113. def test__get_aggregate_disk_types_not_found(self):
  4114. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  4115. self.mock_object(self.client,
  4116. 'send_iter_request',
  4117. mock.Mock(return_value=api_response))
  4118. result = self.client._get_aggregate_disk_types(
  4119. fake.SHARE_AGGREGATE_NAME)
  4120. self.assertEqual(set(), result)
  4121. def test__get_aggregate_disk_types_api_error(self):
  4122. self.mock_object(self.client,
  4123. 'send_iter_request',
  4124. mock.Mock(side_effect=self._mock_api_error()))
  4125. result = self.client._get_aggregate_disk_types(
  4126. fake.SHARE_AGGREGATE_NAME)
  4127. self.assertEqual(set([]), result)
  4128. def test_check_for_cluster_credentials(self):
  4129. api_response = netapp_api.NaElement(fake.SYSTEM_NODE_GET_ITER_RESPONSE)
  4130. self.mock_object(self.client,
  4131. 'send_iter_request',
  4132. mock.Mock(return_value=api_response))
  4133. result = self.client.check_for_cluster_credentials()
  4134. self.assertTrue(result)
  4135. def test_check_for_cluster_credentials_not_cluster(self):
  4136. self.mock_object(self.client,
  4137. 'send_iter_request',
  4138. mock.Mock(side_effect=self._mock_api_error(
  4139. netapp_api.EAPINOTFOUND)))
  4140. result = self.client.check_for_cluster_credentials()
  4141. self.assertFalse(result)
  4142. def test_check_for_cluster_credentials_api_error(self):
  4143. self.mock_object(self.client,
  4144. 'send_iter_request',
  4145. self._mock_api_error())
  4146. self.assertRaises(netapp_api.NaApiError,
  4147. self.client.check_for_cluster_credentials)
  4148. def test_create_cluster_peer(self):
  4149. self.mock_object(self.client, 'send_request')
  4150. self.client.create_cluster_peer(['fake_address_1', 'fake_address_2'],
  4151. 'fake_user', 'fake_password',
  4152. 'fake_passphrase')
  4153. cluster_peer_create_args = {
  4154. 'peer-addresses': [
  4155. {'remote-inet-address': 'fake_address_1'},
  4156. {'remote-inet-address': 'fake_address_2'},
  4157. ],
  4158. 'user-name': 'fake_user',
  4159. 'password': 'fake_password',
  4160. 'passphrase': 'fake_passphrase',
  4161. }
  4162. self.client.send_request.assert_has_calls([
  4163. mock.call('cluster-peer-create', cluster_peer_create_args)])
  4164. def test_get_cluster_peers(self):
  4165. api_response = netapp_api.NaElement(
  4166. fake.CLUSTER_PEER_GET_ITER_RESPONSE)
  4167. self.mock_object(self.client,
  4168. 'send_iter_request',
  4169. mock.Mock(return_value=api_response))
  4170. result = self.client.get_cluster_peers()
  4171. cluster_peer_get_iter_args = {}
  4172. self.client.send_iter_request.assert_has_calls([
  4173. mock.call('cluster-peer-get-iter', cluster_peer_get_iter_args)])
  4174. expected = [{
  4175. 'active-addresses': [
  4176. fake.CLUSTER_ADDRESS_1,
  4177. fake.CLUSTER_ADDRESS_2
  4178. ],
  4179. 'availability': 'available',
  4180. 'cluster-name': fake.CLUSTER_NAME,
  4181. 'cluster-uuid': 'fake_uuid',
  4182. 'peer-addresses': [fake.CLUSTER_ADDRESS_1],
  4183. 'remote-cluster-name': fake.REMOTE_CLUSTER_NAME,
  4184. 'serial-number': 'fake_serial_number',
  4185. 'timeout': '60',
  4186. }]
  4187. self.assertEqual(expected, result)
  4188. def test_get_cluster_peers_single(self):
  4189. api_response = netapp_api.NaElement(
  4190. fake.CLUSTER_PEER_GET_ITER_RESPONSE)
  4191. self.mock_object(self.client,
  4192. 'send_iter_request',
  4193. mock.Mock(return_value=api_response))
  4194. self.client.get_cluster_peers(remote_cluster_name=fake.CLUSTER_NAME)
  4195. cluster_peer_get_iter_args = {
  4196. 'query': {
  4197. 'cluster-peer-info': {
  4198. 'remote-cluster-name': fake.CLUSTER_NAME,
  4199. }
  4200. },
  4201. }
  4202. self.client.send_iter_request.assert_has_calls([
  4203. mock.call('cluster-peer-get-iter', cluster_peer_get_iter_args)])
  4204. def test_get_cluster_peers_not_found(self):
  4205. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  4206. self.mock_object(self.client,
  4207. 'send_iter_request',
  4208. mock.Mock(return_value=api_response))
  4209. result = self.client.get_cluster_peers(
  4210. remote_cluster_name=fake.CLUSTER_NAME)
  4211. self.assertEqual([], result)
  4212. self.assertTrue(self.client.send_iter_request.called)
  4213. def test_delete_cluster_peer(self):
  4214. self.mock_object(self.client, 'send_request')
  4215. self.client.delete_cluster_peer(fake.CLUSTER_NAME)
  4216. cluster_peer_delete_args = {'cluster-name': fake.CLUSTER_NAME}
  4217. self.client.send_request.assert_has_calls([
  4218. mock.call('cluster-peer-delete', cluster_peer_delete_args)])
  4219. def test_get_cluster_peer_policy(self):
  4220. self.client.features.add_feature('CLUSTER_PEER_POLICY')
  4221. api_response = netapp_api.NaElement(
  4222. fake.CLUSTER_PEER_POLICY_GET_RESPONSE)
  4223. self.mock_object(self.client,
  4224. 'send_request',
  4225. mock.Mock(return_value=api_response))
  4226. result = self.client.get_cluster_peer_policy()
  4227. expected = {
  4228. 'is-unauthenticated-access-permitted': False,
  4229. 'passphrase-minimum-length': 8
  4230. }
  4231. self.assertEqual(expected, result)
  4232. self.assertTrue(self.client.send_request.called)
  4233. def test_get_cluster_peer_policy_not_supported(self):
  4234. result = self.client.get_cluster_peer_policy()
  4235. self.assertEqual({}, result)
  4236. def test_set_cluster_peer_policy_not_supported(self):
  4237. self.mock_object(self.client, 'send_request')
  4238. self.client.set_cluster_peer_policy()
  4239. self.assertFalse(self.client.send_request.called)
  4240. def test_set_cluster_peer_policy_no_arguments(self):
  4241. self.client.features.add_feature('CLUSTER_PEER_POLICY')
  4242. self.mock_object(self.client, 'send_request')
  4243. self.client.set_cluster_peer_policy()
  4244. self.assertFalse(self.client.send_request.called)
  4245. def test_set_cluster_peer_policy(self):
  4246. self.client.features.add_feature('CLUSTER_PEER_POLICY')
  4247. self.mock_object(self.client, 'send_request')
  4248. self.client.set_cluster_peer_policy(
  4249. is_unauthenticated_access_permitted=True,
  4250. passphrase_minimum_length=12)
  4251. cluster_peer_policy_modify_args = {
  4252. 'is-unauthenticated-access-permitted': 'true',
  4253. 'passphrase-minlength': '12',
  4254. }
  4255. self.client.send_request.assert_has_calls([
  4256. mock.call('cluster-peer-policy-modify',
  4257. cluster_peer_policy_modify_args)])
  4258. def test_create_vserver_peer(self):
  4259. self.mock_object(self.client, 'send_request')
  4260. self.client.create_vserver_peer('fake_vserver', 'fake_vserver_peer')
  4261. vserver_peer_create_args = {
  4262. 'vserver': 'fake_vserver',
  4263. 'peer-vserver': 'fake_vserver_peer',
  4264. 'applications': [
  4265. {'vserver-peer-application': 'snapmirror'},
  4266. ],
  4267. }
  4268. self.client.send_request.assert_has_calls([
  4269. mock.call('vserver-peer-create', vserver_peer_create_args)])
  4270. def test_delete_vserver_peer(self):
  4271. self.mock_object(self.client, 'send_request')
  4272. self.client.delete_vserver_peer('fake_vserver', 'fake_vserver_peer')
  4273. vserver_peer_delete_args = {
  4274. 'vserver': 'fake_vserver',
  4275. 'peer-vserver': 'fake_vserver_peer',
  4276. }
  4277. self.client.send_request.assert_has_calls([
  4278. mock.call('vserver-peer-delete', vserver_peer_delete_args)])
  4279. def test_accept_vserver_peer(self):
  4280. self.mock_object(self.client, 'send_request')
  4281. self.client.accept_vserver_peer('fake_vserver', 'fake_vserver_peer')
  4282. vserver_peer_accept_args = {
  4283. 'vserver': 'fake_vserver',
  4284. 'peer-vserver': 'fake_vserver_peer',
  4285. }
  4286. self.client.send_request.assert_has_calls([
  4287. mock.call('vserver-peer-accept', vserver_peer_accept_args)])
  4288. def test_get_vserver_peers(self):
  4289. api_response = netapp_api.NaElement(
  4290. fake.VSERVER_PEER_GET_ITER_RESPONSE)
  4291. self.mock_object(self.client,
  4292. 'send_iter_request',
  4293. mock.Mock(return_value=api_response))
  4294. result = self.client.get_vserver_peers(
  4295. vserver_name=fake.VSERVER_NAME,
  4296. peer_vserver_name=fake.VSERVER_NAME_2)
  4297. vserver_peer_get_iter_args = {
  4298. 'query': {
  4299. 'vserver-peer-info': {
  4300. 'vserver': fake.VSERVER_NAME,
  4301. 'peer-vserver': fake.VSERVER_NAME_2,
  4302. }
  4303. },
  4304. }
  4305. self.client.send_iter_request.assert_has_calls([
  4306. mock.call('vserver-peer-get-iter', vserver_peer_get_iter_args)])
  4307. expected = [{
  4308. 'vserver': 'fake_vserver',
  4309. 'peer-vserver': 'fake_vserver_2',
  4310. 'peer-state': 'peered',
  4311. 'peer-cluster': 'fake_cluster'
  4312. }]
  4313. self.assertEqual(expected, result)
  4314. def test_get_vserver_peers_not_found(self):
  4315. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  4316. self.mock_object(self.client,
  4317. 'send_iter_request',
  4318. mock.Mock(return_value=api_response))
  4319. result = self.client.get_vserver_peers(
  4320. vserver_name=fake.VSERVER_NAME,
  4321. peer_vserver_name=fake.VSERVER_NAME_2)
  4322. self.assertEqual([], result)
  4323. self.assertTrue(self.client.send_iter_request.called)
  4324. def test_ensure_snapmirror_v2(self):
  4325. self.assertIsNone(self.client._ensure_snapmirror_v2())
  4326. def test_ensure_snapmirror_v2_not_supported(self):
  4327. self.client.features.add_feature('SNAPMIRROR_V2', supported=False)
  4328. self.assertRaises(exception.NetAppException,
  4329. self.client._ensure_snapmirror_v2)
  4330. @ddt.data({'schedule': 'fake_schedule', 'policy': 'fake_policy'},
  4331. {'schedule': None, 'policy': None})
  4332. @ddt.unpack
  4333. def test_create_snapmirror(self, schedule, policy):
  4334. self.mock_object(self.client, 'send_request')
  4335. self.client.create_snapmirror(
  4336. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4337. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME,
  4338. schedule=schedule, policy=policy)
  4339. snapmirror_create_args = {
  4340. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4341. 'source-volume': fake.SM_SOURCE_VOLUME,
  4342. 'destination-vserver': fake.SM_DEST_VSERVER,
  4343. 'destination-volume': fake.SM_DEST_VOLUME,
  4344. 'relationship-type': 'data_protection',
  4345. }
  4346. if schedule:
  4347. snapmirror_create_args['schedule'] = schedule
  4348. if policy:
  4349. snapmirror_create_args['policy'] = policy
  4350. self.client.send_request.assert_has_calls([
  4351. mock.call('snapmirror-create', snapmirror_create_args)])
  4352. def test_create_snapmirror_already_exists(self):
  4353. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(
  4354. code=netapp_api.ERELATION_EXISTS))
  4355. self.mock_object(self.client, 'send_request', mock_send_req)
  4356. self.client.create_snapmirror(
  4357. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4358. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4359. snapmirror_create_args = {
  4360. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4361. 'source-volume': fake.SM_SOURCE_VOLUME,
  4362. 'destination-vserver': fake.SM_DEST_VSERVER,
  4363. 'destination-volume': fake.SM_DEST_VOLUME,
  4364. 'relationship-type': 'data_protection',
  4365. }
  4366. self.client.send_request.assert_has_calls([
  4367. mock.call('snapmirror-create', snapmirror_create_args)])
  4368. def test_create_snapmirror_error(self):
  4369. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(
  4370. code=0))
  4371. self.mock_object(self.client, 'send_request', mock_send_req)
  4372. self.assertRaises(netapp_api.NaApiError, self.client.create_snapmirror,
  4373. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4374. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4375. self.assertTrue(self.client.send_request.called)
  4376. @ddt.data(
  4377. {
  4378. 'source_snapshot': 'fake_snapshot',
  4379. 'transfer_priority': 'fake_priority'
  4380. },
  4381. {
  4382. 'source_snapshot': None,
  4383. 'transfer_priority': None
  4384. }
  4385. )
  4386. @ddt.unpack
  4387. def test_initialize_snapmirror(self, source_snapshot, transfer_priority):
  4388. api_response = netapp_api.NaElement(fake.SNAPMIRROR_INITIALIZE_RESULT)
  4389. self.mock_object(self.client,
  4390. 'send_request',
  4391. mock.Mock(return_value=api_response))
  4392. result = self.client.initialize_snapmirror(
  4393. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4394. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME,
  4395. source_snapshot=source_snapshot,
  4396. transfer_priority=transfer_priority)
  4397. snapmirror_initialize_args = {
  4398. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4399. 'source-volume': fake.SM_SOURCE_VOLUME,
  4400. 'destination-vserver': fake.SM_DEST_VSERVER,
  4401. 'destination-volume': fake.SM_DEST_VOLUME,
  4402. }
  4403. if source_snapshot:
  4404. snapmirror_initialize_args['source-snapshot'] = source_snapshot
  4405. if transfer_priority:
  4406. snapmirror_initialize_args['transfer-priority'] = transfer_priority
  4407. self.client.send_request.assert_has_calls([
  4408. mock.call('snapmirror-initialize', snapmirror_initialize_args)])
  4409. expected = {
  4410. 'operation-id': None,
  4411. 'status': 'succeeded',
  4412. 'jobid': None,
  4413. 'error-code': None,
  4414. 'error-message': None
  4415. }
  4416. self.assertEqual(expected, result)
  4417. @ddt.data(True, False)
  4418. def test_release_snapmirror(self, relationship_info_only):
  4419. self.mock_object(self.client, 'send_request')
  4420. self.client.release_snapmirror(
  4421. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4422. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME,
  4423. relationship_info_only=relationship_info_only)
  4424. snapmirror_release_args = {
  4425. 'query': {
  4426. 'snapmirror-destination-info': {
  4427. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4428. 'source-volume': fake.SM_SOURCE_VOLUME,
  4429. 'destination-vserver': fake.SM_DEST_VSERVER,
  4430. 'destination-volume': fake.SM_DEST_VOLUME,
  4431. 'relationship-info-only': ('true' if relationship_info_only
  4432. else 'false'),
  4433. }
  4434. }
  4435. }
  4436. self.client.send_request.assert_has_calls([
  4437. mock.call('snapmirror-release-iter', snapmirror_release_args)])
  4438. def test_quiesce_snapmirror(self):
  4439. self.mock_object(self.client, 'send_request')
  4440. self.client.quiesce_snapmirror(
  4441. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4442. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4443. snapmirror_quiesce_args = {
  4444. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4445. 'source-volume': fake.SM_SOURCE_VOLUME,
  4446. 'destination-vserver': fake.SM_DEST_VSERVER,
  4447. 'destination-volume': fake.SM_DEST_VOLUME,
  4448. }
  4449. self.client.send_request.assert_has_calls([
  4450. mock.call('snapmirror-quiesce', snapmirror_quiesce_args)])
  4451. @ddt.data(True, False)
  4452. def test_abort_snapmirror(self, clear_checkpoint):
  4453. self.mock_object(self.client, 'send_request')
  4454. self.client.abort_snapmirror(
  4455. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4456. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME,
  4457. clear_checkpoint=clear_checkpoint)
  4458. snapmirror_abort_args = {
  4459. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4460. 'source-volume': fake.SM_SOURCE_VOLUME,
  4461. 'destination-vserver': fake.SM_DEST_VSERVER,
  4462. 'destination-volume': fake.SM_DEST_VOLUME,
  4463. 'clear-checkpoint': 'true' if clear_checkpoint else 'false',
  4464. }
  4465. self.client.send_request.assert_has_calls([
  4466. mock.call('snapmirror-abort', snapmirror_abort_args)])
  4467. def test_abort_snapmirror_no_transfer_in_progress(self):
  4468. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(
  4469. code=netapp_api.ENOTRANSFER_IN_PROGRESS))
  4470. self.mock_object(self.client, 'send_request', mock_send_req)
  4471. self.client.abort_snapmirror(
  4472. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4473. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4474. snapmirror_abort_args = {
  4475. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4476. 'source-volume': fake.SM_SOURCE_VOLUME,
  4477. 'destination-vserver': fake.SM_DEST_VSERVER,
  4478. 'destination-volume': fake.SM_DEST_VOLUME,
  4479. 'clear-checkpoint': 'false',
  4480. }
  4481. self.client.send_request.assert_has_calls([
  4482. mock.call('snapmirror-abort', snapmirror_abort_args)])
  4483. def test_abort_snapmirror_error(self):
  4484. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(code=0))
  4485. self.mock_object(self.client, 'send_request', mock_send_req)
  4486. self.assertRaises(netapp_api.NaApiError, self.client.abort_snapmirror,
  4487. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4488. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4489. def test_break_snapmirror(self):
  4490. self.mock_object(self.client, 'send_request')
  4491. self.client.break_snapmirror(
  4492. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4493. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4494. snapmirror_break_args = {
  4495. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4496. 'source-volume': fake.SM_SOURCE_VOLUME,
  4497. 'destination-vserver': fake.SM_DEST_VSERVER,
  4498. 'destination-volume': fake.SM_DEST_VOLUME,
  4499. }
  4500. self.client.send_request.assert_has_calls([
  4501. mock.call('snapmirror-break', snapmirror_break_args)])
  4502. @ddt.data(
  4503. {
  4504. 'schedule': 'fake_schedule',
  4505. 'policy': 'fake_policy',
  4506. 'tries': 5,
  4507. 'max_transfer_rate': 1024,
  4508. },
  4509. {
  4510. 'schedule': None,
  4511. 'policy': None,
  4512. 'tries': None,
  4513. 'max_transfer_rate': None,
  4514. }
  4515. )
  4516. @ddt.unpack
  4517. def test_modify_snapmirror(self, schedule, policy, tries,
  4518. max_transfer_rate):
  4519. self.mock_object(self.client, 'send_request')
  4520. self.client.modify_snapmirror(
  4521. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4522. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME,
  4523. schedule=schedule, policy=policy, tries=tries,
  4524. max_transfer_rate=max_transfer_rate)
  4525. snapmirror_modify_args = {
  4526. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4527. 'source-volume': fake.SM_SOURCE_VOLUME,
  4528. 'destination-vserver': fake.SM_DEST_VSERVER,
  4529. 'destination-volume': fake.SM_DEST_VOLUME,
  4530. }
  4531. if schedule:
  4532. snapmirror_modify_args['schedule'] = schedule
  4533. if policy:
  4534. snapmirror_modify_args['policy'] = policy
  4535. if tries:
  4536. snapmirror_modify_args['tries'] = tries
  4537. if max_transfer_rate:
  4538. snapmirror_modify_args['max-transfer-rate'] = max_transfer_rate
  4539. self.client.send_request.assert_has_calls([
  4540. mock.call('snapmirror-modify', snapmirror_modify_args)])
  4541. def test_update_snapmirror(self):
  4542. self.mock_object(self.client, 'send_request')
  4543. self.client.update_snapmirror(
  4544. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4545. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4546. snapmirror_update_args = {
  4547. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4548. 'source-volume': fake.SM_SOURCE_VOLUME,
  4549. 'destination-vserver': fake.SM_DEST_VSERVER,
  4550. 'destination-volume': fake.SM_DEST_VOLUME,
  4551. }
  4552. self.client.send_request.assert_has_calls([
  4553. mock.call('snapmirror-update', snapmirror_update_args)])
  4554. def test_update_snapmirror_already_transferring(self):
  4555. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(
  4556. code=netapp_api.ETRANSFER_IN_PROGRESS))
  4557. self.mock_object(self.client, 'send_request', mock_send_req)
  4558. self.client.update_snapmirror(
  4559. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4560. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4561. snapmirror_update_args = {
  4562. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4563. 'source-volume': fake.SM_SOURCE_VOLUME,
  4564. 'destination-vserver': fake.SM_DEST_VSERVER,
  4565. 'destination-volume': fake.SM_DEST_VOLUME,
  4566. }
  4567. self.client.send_request.assert_has_calls([
  4568. mock.call('snapmirror-update', snapmirror_update_args)])
  4569. def test_update_snapmirror_already_transferring_two(self):
  4570. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(
  4571. code=netapp_api.EANOTHER_OP_ACTIVE))
  4572. self.mock_object(self.client, 'send_request', mock_send_req)
  4573. self.client.update_snapmirror(
  4574. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4575. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4576. snapmirror_update_args = {
  4577. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4578. 'source-volume': fake.SM_SOURCE_VOLUME,
  4579. 'destination-vserver': fake.SM_DEST_VSERVER,
  4580. 'destination-volume': fake.SM_DEST_VOLUME,
  4581. }
  4582. self.client.send_request.assert_has_calls([
  4583. mock.call('snapmirror-update', snapmirror_update_args)])
  4584. def test_update_snapmirror_error(self):
  4585. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(code=0))
  4586. self.mock_object(self.client, 'send_request', mock_send_req)
  4587. self.assertRaises(netapp_api.NaApiError, self.client.update_snapmirror,
  4588. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4589. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4590. def test_delete_snapmirror(self):
  4591. self.mock_object(self.client, 'send_request')
  4592. self.client.delete_snapmirror(
  4593. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4594. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4595. snapmirror_delete_args = {
  4596. 'query': {
  4597. 'snapmirror-info': {
  4598. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4599. 'source-volume': fake.SM_SOURCE_VOLUME,
  4600. 'destination-vserver': fake.SM_DEST_VSERVER,
  4601. 'destination-volume': fake.SM_DEST_VOLUME,
  4602. }
  4603. }
  4604. }
  4605. self.client.send_request.assert_has_calls([
  4606. mock.call('snapmirror-destroy-iter', snapmirror_delete_args)])
  4607. def test__get_snapmirrors(self):
  4608. api_response = netapp_api.NaElement(fake.SNAPMIRROR_GET_ITER_RESPONSE)
  4609. self.mock_object(self.client,
  4610. 'send_iter_request',
  4611. mock.Mock(return_value=api_response))
  4612. desired_attributes = {
  4613. 'snapmirror-info': {
  4614. 'source-vserver': None,
  4615. 'source-volume': None,
  4616. 'destination-vserver': None,
  4617. 'destination-volume': None,
  4618. 'is-healthy': None,
  4619. }
  4620. }
  4621. result = self.client._get_snapmirrors(
  4622. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4623. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME,
  4624. desired_attributes=desired_attributes)
  4625. snapmirror_get_iter_args = {
  4626. 'query': {
  4627. 'snapmirror-info': {
  4628. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4629. 'source-volume': fake.SM_SOURCE_VOLUME,
  4630. 'destination-vserver': fake.SM_DEST_VSERVER,
  4631. 'destination-volume': fake.SM_DEST_VOLUME,
  4632. },
  4633. },
  4634. 'desired-attributes': {
  4635. 'snapmirror-info': {
  4636. 'source-vserver': None,
  4637. 'source-volume': None,
  4638. 'destination-vserver': None,
  4639. 'destination-volume': None,
  4640. 'is-healthy': None,
  4641. },
  4642. },
  4643. }
  4644. self.client.send_iter_request.assert_has_calls([
  4645. mock.call('snapmirror-get-iter', snapmirror_get_iter_args)])
  4646. self.assertEqual(1, len(result))
  4647. def test__get_snapmirrors_not_found(self):
  4648. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  4649. self.mock_object(self.client,
  4650. 'send_iter_request',
  4651. mock.Mock(return_value=api_response))
  4652. result = self.client._get_snapmirrors()
  4653. self.client.send_iter_request.assert_has_calls([
  4654. mock.call('snapmirror-get-iter', {})])
  4655. self.assertEqual([], result)
  4656. def test_get_snapmirrors(self):
  4657. api_response = netapp_api.NaElement(
  4658. fake.SNAPMIRROR_GET_ITER_FILTERED_RESPONSE)
  4659. self.mock_object(self.client,
  4660. 'send_iter_request',
  4661. mock.Mock(return_value=api_response))
  4662. desired_attributes = ['source-vserver', 'source-volume',
  4663. 'destination-vserver', 'destination-volume',
  4664. 'is-healthy', 'mirror-state', 'schedule']
  4665. result = self.client.get_snapmirrors(
  4666. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4667. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME,
  4668. desired_attributes=desired_attributes)
  4669. snapmirror_get_iter_args = {
  4670. 'query': {
  4671. 'snapmirror-info': {
  4672. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4673. 'source-volume': fake.SM_SOURCE_VOLUME,
  4674. 'destination-vserver': fake.SM_DEST_VSERVER,
  4675. 'destination-volume': fake.SM_DEST_VOLUME,
  4676. },
  4677. },
  4678. 'desired-attributes': {
  4679. 'snapmirror-info': {
  4680. 'source-vserver': None,
  4681. 'source-volume': None,
  4682. 'destination-vserver': None,
  4683. 'destination-volume': None,
  4684. 'is-healthy': None,
  4685. 'mirror-state': None,
  4686. 'schedule': None,
  4687. },
  4688. },
  4689. }
  4690. expected = [{
  4691. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4692. 'source-volume': fake.SM_SOURCE_VOLUME,
  4693. 'destination-vserver': fake.SM_DEST_VSERVER,
  4694. 'destination-volume': fake.SM_DEST_VOLUME,
  4695. 'is-healthy': 'true',
  4696. 'mirror-state': 'snapmirrored',
  4697. 'schedule': 'daily',
  4698. }]
  4699. self.client.send_iter_request.assert_has_calls([
  4700. mock.call('snapmirror-get-iter', snapmirror_get_iter_args)])
  4701. self.assertEqual(expected, result)
  4702. def test_resume_snapmirror(self):
  4703. self.mock_object(self.client, 'send_request')
  4704. self.client.resume_snapmirror(
  4705. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4706. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4707. snapmirror_resume_args = {
  4708. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4709. 'source-volume': fake.SM_SOURCE_VOLUME,
  4710. 'destination-vserver': fake.SM_DEST_VSERVER,
  4711. 'destination-volume': fake.SM_DEST_VOLUME,
  4712. }
  4713. self.client.send_request.assert_has_calls([
  4714. mock.call('snapmirror-resume', snapmirror_resume_args)])
  4715. def test_resume_snapmirror_not_quiesed(self):
  4716. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(
  4717. code=netapp_api.ERELATION_NOT_QUIESCED))
  4718. self.mock_object(self.client, 'send_request', mock_send_req)
  4719. self.client.resume_snapmirror(
  4720. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4721. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4722. snapmirror_resume_args = {
  4723. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4724. 'source-volume': fake.SM_SOURCE_VOLUME,
  4725. 'destination-vserver': fake.SM_DEST_VSERVER,
  4726. 'destination-volume': fake.SM_DEST_VOLUME,
  4727. }
  4728. self.client.send_request.assert_has_calls([
  4729. mock.call('snapmirror-resume', snapmirror_resume_args)])
  4730. def test_resume_snapmirror_error(self):
  4731. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(code=0))
  4732. self.mock_object(self.client, 'send_request', mock_send_req)
  4733. self.assertRaises(netapp_api.NaApiError, self.client.resume_snapmirror,
  4734. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4735. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4736. def test_resync_snapmirror(self):
  4737. self.mock_object(self.client, 'send_request')
  4738. self.client.resync_snapmirror(
  4739. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4740. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4741. snapmirror_resync_args = {
  4742. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4743. 'source-volume': fake.SM_SOURCE_VOLUME,
  4744. 'destination-vserver': fake.SM_DEST_VSERVER,
  4745. 'destination-volume': fake.SM_DEST_VOLUME,
  4746. }
  4747. self.client.send_request.assert_has_calls([
  4748. mock.call('snapmirror-resync', snapmirror_resync_args)])
  4749. @ddt.data('source', 'destination', None)
  4750. def test_volume_has_snapmirror_relationships(self, snapmirror_rel_type):
  4751. """Snapmirror relationships can be both ways."""
  4752. vol = fake.FAKE_MANAGE_VOLUME
  4753. snapmirror = {
  4754. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4755. 'source-volume': fake.SM_SOURCE_VOLUME,
  4756. 'destination-vserver': fake.SM_DEST_VSERVER,
  4757. 'destination-volume': fake.SM_DEST_VOLUME,
  4758. 'is-healthy': 'true',
  4759. 'mirror-state': 'snapmirrored',
  4760. 'schedule': 'daily',
  4761. }
  4762. expected_get_snapmirrors_call_count = 2
  4763. expected_get_snapmirrors_calls = [
  4764. mock.call(vol['owning-vserver-name'], vol['name'], None, None),
  4765. mock.call(None, None, vol['owning-vserver-name'], vol['name']),
  4766. ]
  4767. if snapmirror_rel_type is None:
  4768. side_effect = ([], [])
  4769. elif snapmirror_rel_type == 'source':
  4770. snapmirror['source-vserver'] = vol['owning-vserver-name']
  4771. snapmirror['source-volume'] = vol['name']
  4772. side_effect = ([snapmirror], None)
  4773. expected_get_snapmirrors_call_count = 1
  4774. expected_get_snapmirrors_calls.pop()
  4775. else:
  4776. snapmirror['destination-vserver'] = vol['owning-vserver-name']
  4777. snapmirror['destination-volume'] = vol['name']
  4778. side_effect = (None, [snapmirror])
  4779. mock_get_snapmirrors_call = self.mock_object(
  4780. self.client, 'get_snapmirrors', mock.Mock(side_effect=side_effect))
  4781. mock_exc_log = self.mock_object(client_cmode.LOG, 'exception')
  4782. expected_retval = True if snapmirror_rel_type else False
  4783. retval = self.client.volume_has_snapmirror_relationships(vol)
  4784. self.assertEqual(expected_retval, retval)
  4785. self.assertEqual(expected_get_snapmirrors_call_count,
  4786. mock_get_snapmirrors_call.call_count)
  4787. mock_get_snapmirrors_call.assert_has_calls(
  4788. expected_get_snapmirrors_calls)
  4789. self.assertFalse(mock_exc_log.called)
  4790. def test_volume_has_snapmirror_relationships_api_error(self):
  4791. vol = fake.FAKE_MANAGE_VOLUME
  4792. expected_get_snapmirrors_calls = [
  4793. mock.call(vol['owning-vserver-name'], vol['name'], None, None),
  4794. ]
  4795. mock_get_snapmirrors_call = self.mock_object(
  4796. self.client, 'get_snapmirrors', mock.Mock(
  4797. side_effect=self._mock_api_error(netapp_api.EINTERNALERROR)))
  4798. mock_exc_log = self.mock_object(client_cmode.LOG, 'exception')
  4799. retval = self.client.volume_has_snapmirror_relationships(vol)
  4800. self.assertFalse(retval)
  4801. self.assertEqual(1, mock_get_snapmirrors_call.call_count)
  4802. mock_get_snapmirrors_call.assert_has_calls(
  4803. expected_get_snapmirrors_calls)
  4804. self.assertTrue(mock_exc_log.called)
  4805. @ddt.data(None, '12345')
  4806. def test_list_snapmirror_snapshots(self, newer_than):
  4807. api_response = netapp_api.NaElement(
  4808. fake.SNAPSHOT_GET_ITER_SNAPMIRROR_RESPONSE)
  4809. self.mock_object(self.client,
  4810. 'send_iter_request',
  4811. mock.Mock(return_value=api_response))
  4812. result = self.client.list_snapmirror_snapshots(fake.SHARE_NAME,
  4813. newer_than=newer_than)
  4814. snapshot_get_iter_args = {
  4815. 'query': {
  4816. 'snapshot-info': {
  4817. 'dependency': 'snapmirror',
  4818. 'volume': fake.SHARE_NAME,
  4819. },
  4820. },
  4821. }
  4822. if newer_than:
  4823. snapshot_get_iter_args['query']['snapshot-info']['access-time'] = (
  4824. '>' + newer_than)
  4825. self.client.send_iter_request.assert_has_calls([
  4826. mock.call('snapshot-get-iter', snapshot_get_iter_args)])
  4827. expected = [fake.SNAPSHOT_NAME]
  4828. self.assertEqual(expected, result)
  4829. @ddt.data('start_volume_move', 'check_volume_move')
  4830. def test_volume_move_method(self, method_name):
  4831. method = getattr(self.client, method_name)
  4832. self.mock_object(self.client, 'send_request')
  4833. retval = method(fake.SHARE_NAME, fake.VSERVER_NAME,
  4834. fake.SHARE_AGGREGATE_NAME)
  4835. expected_api_args = {
  4836. 'source-volume': fake.SHARE_NAME,
  4837. 'vserver': fake.VSERVER_NAME,
  4838. 'dest-aggr': fake.SHARE_AGGREGATE_NAME,
  4839. 'cutover-action': 'wait',
  4840. 'encrypt-destination': 'false'
  4841. }
  4842. if method_name.startswith('check'):
  4843. expected_api_args['perform-validation-only'] = 'true'
  4844. self.assertIsNone(retval)
  4845. self.client.send_request.assert_called_once_with(
  4846. 'volume-move-start', expected_api_args)
  4847. def test_abort_volume_move(self):
  4848. self.mock_object(self.client, 'send_request')
  4849. retval = self.client.abort_volume_move(
  4850. fake.SHARE_NAME, fake.VSERVER_NAME)
  4851. expected_api_args = {
  4852. 'source-volume': fake.SHARE_NAME,
  4853. 'vserver': fake.VSERVER_NAME,
  4854. }
  4855. self.assertIsNone(retval)
  4856. self.client.send_request.assert_called_once_with(
  4857. 'volume-move-trigger-abort', expected_api_args)
  4858. @ddt.data(True, False)
  4859. def test_trigger_volume_move_cutover_force(self, forced):
  4860. self.mock_object(self.client, 'send_request')
  4861. retval = self.client.trigger_volume_move_cutover(
  4862. fake.SHARE_NAME, fake.VSERVER_NAME, force=forced)
  4863. expected_api_args = {
  4864. 'source-volume': fake.SHARE_NAME,
  4865. 'vserver': fake.VSERVER_NAME,
  4866. 'force': 'true' if forced else 'false',
  4867. }
  4868. self.assertIsNone(retval)
  4869. self.client.send_request.assert_called_once_with(
  4870. 'volume-move-trigger-cutover', expected_api_args)
  4871. def test_get_volume_move_status_no_records(self):
  4872. self.mock_object(self.client, 'send_iter_request')
  4873. self.mock_object(self.client, '_has_records',
  4874. mock.Mock(return_value=False))
  4875. self.assertRaises(exception.NetAppException,
  4876. self.client.get_volume_move_status,
  4877. fake.SHARE_NAME, fake.VSERVER_NAME)
  4878. expected_api_args = {
  4879. 'query': {
  4880. 'volume-move-info': {
  4881. 'volume': fake.SHARE_NAME,
  4882. 'vserver': fake.VSERVER_NAME,
  4883. },
  4884. },
  4885. 'desired-attributes': {
  4886. 'volume-move-info': {
  4887. 'percent-complete': None,
  4888. 'estimated-completion-time': None,
  4889. 'state': None,
  4890. 'details': None,
  4891. 'cutover-action': None,
  4892. 'phase': None,
  4893. },
  4894. },
  4895. }
  4896. self.client.send_iter_request.assert_called_once_with(
  4897. 'volume-move-get-iter', expected_api_args)
  4898. def test_get_volume_move_status(self):
  4899. move_status = netapp_api.NaElement(fake.VOLUME_MOVE_GET_ITER_RESULT)
  4900. self.mock_object(self.client, 'send_iter_request',
  4901. mock.Mock(return_value=move_status))
  4902. actual_status_info = self.client.get_volume_move_status(
  4903. fake.SHARE_NAME, fake.VSERVER_NAME)
  4904. expected_api_args = {
  4905. 'query': {
  4906. 'volume-move-info': {
  4907. 'volume': fake.SHARE_NAME,
  4908. 'vserver': fake.VSERVER_NAME,
  4909. },
  4910. },
  4911. 'desired-attributes': {
  4912. 'volume-move-info': {
  4913. 'percent-complete': None,
  4914. 'estimated-completion-time': None,
  4915. 'state': None,
  4916. 'details': None,
  4917. 'cutover-action': None,
  4918. 'phase': None,
  4919. },
  4920. },
  4921. }
  4922. expected_status_info = {
  4923. 'percent-complete': '82',
  4924. 'estimated-completion-time': '1481919246',
  4925. 'state': 'healthy',
  4926. 'details': 'Cutover Completed::Volume move job finishing move',
  4927. 'cutover-action': 'retry_on_failure',
  4928. 'phase': 'finishing',
  4929. }
  4930. self.assertDictMatch(expected_status_info, actual_status_info)
  4931. self.client.send_iter_request.assert_called_once_with(
  4932. 'volume-move-get-iter', expected_api_args)
  4933. def test_qos_policy_group_exists_no_records(self):
  4934. self.mock_object(self.client, 'qos_policy_group_get', mock.Mock(
  4935. side_effect=exception.NetAppException))
  4936. policy_exists = self.client.qos_policy_group_exists(
  4937. 'i-dont-exist-but-i-am')
  4938. self.assertIs(False, policy_exists)
  4939. def test_qos_policy_group_exists(self):
  4940. self.mock_object(self.client, 'qos_policy_group_get',
  4941. mock.Mock(return_value=fake.QOS_POLICY_GROUP))
  4942. policy_exists = self.client.qos_policy_group_exists(
  4943. fake.QOS_POLICY_GROUP_NAME)
  4944. self.assertIs(True, policy_exists)
  4945. def test_qos_policy_group_get_no_permissions_to_execute_zapi(self):
  4946. naapi_error = self._mock_api_error(code=netapp_api.EAPINOTFOUND,
  4947. message='13005:Unable to find API')
  4948. self.mock_object(self.client, 'send_request', naapi_error)
  4949. self.assertRaises(exception.NetAppException,
  4950. self.client.qos_policy_group_get,
  4951. 'possibly-valid-qos-policy')
  4952. def test_qos_policy_group_get_other_zapi_errors(self):
  4953. naapi_error = self._mock_api_error(code=netapp_api.EINTERNALERROR,
  4954. message='13114:Internal error')
  4955. self.mock_object(self.client, 'send_request', naapi_error)
  4956. self.assertRaises(netapp_api.NaApiError,
  4957. self.client.qos_policy_group_get,
  4958. 'possibly-valid-qos-policy')
  4959. def test_qos_policy_group_get_none_found(self):
  4960. no_records_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  4961. self.mock_object(self.client, 'send_request',
  4962. mock.Mock(return_value=no_records_response))
  4963. self.assertRaises(exception.NetAppException,
  4964. self.client.qos_policy_group_get,
  4965. 'non-existent-qos-policy')
  4966. qos_policy_group_get_iter_args = {
  4967. 'query': {
  4968. 'qos-policy-group-info': {
  4969. 'policy-group': 'non-existent-qos-policy',
  4970. },
  4971. },
  4972. 'desired-attributes': {
  4973. 'qos-policy-group-info': {
  4974. 'policy-group': None,
  4975. 'vserver': None,
  4976. 'max-throughput': None,
  4977. 'num-workloads': None
  4978. },
  4979. },
  4980. }
  4981. self.client.send_request.assert_called_once_with(
  4982. 'qos-policy-group-get-iter', qos_policy_group_get_iter_args, False)
  4983. def test_qos_policy_group_get(self):
  4984. api_response = netapp_api.NaElement(
  4985. fake.QOS_POLICY_GROUP_GET_ITER_RESPONSE)
  4986. self.mock_object(self.client, 'send_request',
  4987. mock.Mock(return_value=api_response))
  4988. qos_info = self.client.qos_policy_group_get(fake.QOS_POLICY_GROUP_NAME)
  4989. qos_policy_group_get_iter_args = {
  4990. 'query': {
  4991. 'qos-policy-group-info': {
  4992. 'policy-group': fake.QOS_POLICY_GROUP_NAME,
  4993. },
  4994. },
  4995. 'desired-attributes': {
  4996. 'qos-policy-group-info': {
  4997. 'policy-group': None,
  4998. 'vserver': None,
  4999. 'max-throughput': None,
  5000. 'num-workloads': None
  5001. },
  5002. },
  5003. }
  5004. self.client.send_request.assert_called_once_with(
  5005. 'qos-policy-group-get-iter', qos_policy_group_get_iter_args, False)
  5006. self.assertDictMatch(fake.QOS_POLICY_GROUP, qos_info)
  5007. @ddt.data(None, fake.QOS_MAX_THROUGHPUT)
  5008. def test_qos_policy_group_create(self, max_throughput):
  5009. self.mock_object(self.client, 'send_request',
  5010. mock.Mock(return_value=fake.PASSED_RESPONSE))
  5011. self.client.qos_policy_group_create(
  5012. fake.QOS_POLICY_GROUP_NAME, fake.VSERVER_NAME,
  5013. max_throughput=max_throughput)
  5014. qos_policy_group_create_args = {
  5015. 'policy-group': fake.QOS_POLICY_GROUP_NAME,
  5016. 'vserver': fake.VSERVER_NAME,
  5017. }
  5018. if max_throughput:
  5019. qos_policy_group_create_args.update(
  5020. {'max-throughput': max_throughput})
  5021. self.client.send_request.assert_called_once_with(
  5022. 'qos-policy-group-create', qos_policy_group_create_args, False)
  5023. def test_qos_policy_group_modify(self):
  5024. self.mock_object(self.client, 'send_request',
  5025. mock.Mock(return_value=fake.PASSED_RESPONSE))
  5026. self.client.qos_policy_group_modify(fake.QOS_POLICY_GROUP_NAME,
  5027. '3000iops')
  5028. qos_policy_group_modify_args = {
  5029. 'policy-group': fake.QOS_POLICY_GROUP_NAME,
  5030. 'max-throughput': '3000iops',
  5031. }
  5032. self.client.send_request.assert_called_once_with(
  5033. 'qos-policy-group-modify', qos_policy_group_modify_args, False)
  5034. def test_qos_policy_group_delete(self):
  5035. self.mock_object(self.client, 'send_request',
  5036. mock.Mock(return_value=fake.PASSED_RESPONSE))
  5037. self.client.qos_policy_group_delete(fake.QOS_POLICY_GROUP_NAME)
  5038. qos_policy_group_delete_args = {
  5039. 'policy-group': fake.QOS_POLICY_GROUP_NAME,
  5040. }
  5041. self.client.send_request.assert_called_once_with(
  5042. 'qos-policy-group-delete', qos_policy_group_delete_args, False)
  5043. def test_qos_policy_group_rename(self):
  5044. self.mock_object(self.client, 'send_request',
  5045. mock.Mock(return_value=fake.PASSED_RESPONSE))
  5046. self.client.qos_policy_group_rename(
  5047. fake.QOS_POLICY_GROUP_NAME, 'new_' + fake.QOS_POLICY_GROUP_NAME)
  5048. qos_policy_group_rename_args = {
  5049. 'policy-group-name': fake.QOS_POLICY_GROUP_NAME,
  5050. 'new-name': 'new_' + fake.QOS_POLICY_GROUP_NAME,
  5051. }
  5052. self.client.send_request.assert_called_once_with(
  5053. 'qos-policy-group-rename', qos_policy_group_rename_args, False)
  5054. def test_mark_qos_policy_group_for_deletion_rename_failure(self):
  5055. self.mock_object(self.client, 'qos_policy_group_exists',
  5056. mock.Mock(return_value=True))
  5057. self.mock_object(self.client, 'qos_policy_group_rename',
  5058. mock.Mock(side_effect=netapp_api.NaApiError))
  5059. self.mock_object(client_cmode.LOG, 'warning')
  5060. self.mock_object(self.client, 'remove_unused_qos_policy_groups')
  5061. retval = self.client.mark_qos_policy_group_for_deletion(
  5062. fake.QOS_POLICY_GROUP_NAME)
  5063. self.assertIsNone(retval)
  5064. client_cmode.LOG.warning.assert_called_once()
  5065. self.client.qos_policy_group_exists.assert_called_once_with(
  5066. fake.QOS_POLICY_GROUP_NAME)
  5067. self.client.qos_policy_group_rename.assert_called_once_with(
  5068. fake.QOS_POLICY_GROUP_NAME,
  5069. client_cmode.DELETED_PREFIX + fake.QOS_POLICY_GROUP_NAME)
  5070. self.client.remove_unused_qos_policy_groups.assert_called_once_with()
  5071. @ddt.data(True, False)
  5072. def test_mark_qos_policy_group_for_deletion_policy_exists(self, exists):
  5073. self.mock_object(self.client, 'qos_policy_group_exists',
  5074. mock.Mock(return_value=exists))
  5075. self.mock_object(self.client, 'qos_policy_group_rename')
  5076. mock_remove_unused_policies = self.mock_object(
  5077. self.client, 'remove_unused_qos_policy_groups')
  5078. self.mock_object(client_cmode.LOG, 'warning')
  5079. retval = self.client.mark_qos_policy_group_for_deletion(
  5080. fake.QOS_POLICY_GROUP_NAME)
  5081. self.assertIsNone(retval)
  5082. if exists:
  5083. self.client.qos_policy_group_rename.assert_called_once_with(
  5084. fake.QOS_POLICY_GROUP_NAME,
  5085. client_cmode.DELETED_PREFIX + fake.QOS_POLICY_GROUP_NAME)
  5086. mock_remove_unused_policies.assert_called_once_with()
  5087. else:
  5088. self.assertFalse(self.client.qos_policy_group_rename.called)
  5089. self.assertFalse(
  5090. self.client.remove_unused_qos_policy_groups.called)
  5091. self.assertFalse(client_cmode.LOG.warning.called)
  5092. @ddt.data(True, False)
  5093. def test_remove_unused_qos_policy_groups_with_failure(self, failed):
  5094. if failed:
  5095. args = mock.Mock(side_effect=netapp_api.NaApiError)
  5096. else:
  5097. args = mock.Mock(return_value=fake.PASSED_FAILED_ITER_RESPONSE)
  5098. self.mock_object(self.client, 'send_request', args)
  5099. self.mock_object(client_cmode.LOG, 'debug')
  5100. retval = self.client.remove_unused_qos_policy_groups()
  5101. qos_policy_group_delete_iter_args = {
  5102. 'query': {
  5103. 'qos-policy-group-info': {
  5104. 'policy-group': '%s*' % client_cmode.DELETED_PREFIX,
  5105. }
  5106. },
  5107. 'max-records': 3500,
  5108. 'continue-on-failure': 'true',
  5109. 'return-success-list': 'false',
  5110. 'return-failure-list': 'false',
  5111. }
  5112. self.assertIsNone(retval)
  5113. self.client.send_request.assert_called_once_with(
  5114. 'qos-policy-group-delete-iter',
  5115. qos_policy_group_delete_iter_args, False)
  5116. self.assertIs(failed, client_cmode.LOG.debug.called)