Exemple #1
0
    def test_create_share(self):
        self.driver.configuration.netapp_nas_server_hostname\
            = 'fake-netapp-location'
        root = naapi.NaElement('root')
        aggregates = naapi.NaElement('aggregates')
        for i in range(1, 4):
            aggregates.add_node_with_children(
                'aggr-attributes', **{
                    'name': 'fake%s' % i,
                    'size-available': '%s' % i,
                    'size-total': '%s' % i
                })
        root.add_child_elem(aggregates)

        self.driver._client.send_request = mock.Mock(return_value=root)
        self.helper.create_share = mock.Mock(return_value="fake-location")
        export_location = self.driver.create_share(self._context, self.share)

        args = {
            'containing-aggr-name': 'fake3',
            'size': '1g',
            'volume': 'share_fake_uuid'
        }
        self.driver._client.send_request.assert_called_with(
            'volume-create', args)
        self.helper.create_share.assert_called_once_with(
            "share_%s" % self.share['id'], 'fake-netapp-location')
        self.assertEqual(export_location, "fake-location")
Exemple #2
0
    def test_update_share_stats(self):
        """Retrieve status info from share volume group."""
        fake_aggr1_struct = {
            'aggr-space-attributes': {
                'size-total': '3774873600',
                'size-available': '3688566784'
            }
        }
        fake_aggr2_struct = {
            'aggr-space-attributes': {
                'size-total': '943718400',
                'size-available': '45506560'
            }
        }

        fake_aggr1 = naapi.NaElement('root')
        fake_aggr1.translate_struct(fake_aggr1_struct)

        fake_aggr2 = naapi.NaElement('root')
        fake_aggr2.translate_struct(fake_aggr2_struct)
        self.driver._find_match_aggregates = mock.Mock(
            return_value=[fake_aggr1, fake_aggr2])
        self.driver._update_share_status()
        res = self.driver._stats

        expected = {}
        expected["share_backend_name"] = self.driver.backend_name
        expected["vendor_name"] = 'NetApp'
        expected["driver_version"] = '1.0'
        expected["storage_protocol"] = 'NFS_CIFS'
        expected['total_capacity_gb'] = 4
        expected['free_capacity_gb'] = 3
        expected['reserved_percentage'] = 0
        expected['QoS_support'] = False
        self.assertDictMatch(res, expected)
Exemple #3
0
 def test_allocate_container(self):
     root = naapi.NaElement('root')
     attributes = naapi.NaElement('attributes')
     vserver_info = naapi.NaElement('vserver-info')
     vserver_aggr_info_list = naapi.NaElement('vserver-aggr-info-list')
     for i in range(1, 4):
         vserver_aggr_info_list.add_node_with_children(
             'aggr-attributes', **{
                 'aggr-name': 'fake%s' % i,
                 'aggr-availsize': '%s' % i
             })
     vserver_info.add_child_elem(vserver_aggr_info_list)
     attributes.add_child_elem(vserver_info)
     root.add_child_elem(attributes)
     root.add_new_child('attributes', None)
     self._vserver_client.send_request = mock.Mock(return_value=root)
     self.driver._allocate_container(self.share, 'vserver',
                                     self._vserver_client)
     args = {
         'containing-aggr-name': 'fake3',
         'size': '1g',
         'volume': 'share_fake_uuid',
         'junction-path': '/share_fake_uuid'
     }
     self._vserver_client.send_request.assert_called_with(
         'volume-create', args)
Exemple #4
0
 def test_deny_access(self):
     access = {'access_to': '1.2.3.4', 'access_type': 'ip'}
     root = naapi.NaElement('root')
     rules = naapi.NaElement('rules')
     root.add_child_elem(rules)
     self.helper._client.send_request = mock.Mock(return_value=root)
     self.helper.allow_access(self._context, self.share, access)
     self.helper._client.send_request.assert_has_calls([
         mock.call('nfs-exportfs-list-rules-2', mock.ANY),
         mock.call('nfs-exportfs-append-rules-2', mock.ANY)
     ])
Exemple #5
0
 def test_check_licenses(self):
     root = naapi.NaElement('fake')
     elem = naapi.NaElement('licenses')
     licenses = ['l1', 'l2']
     for license in licenses:
         el = naapi.NaElement('license')
         el['package'] = license
         elem.add_child_elem(el)
     root.add_child_elem(elem)
     self.driver._client.send_request = mock.Mock(return_value=root)
     self.driver._check_licenses()
     self.assertEqual(self.driver._licenses, licenses)
Exemple #6
0
 def test_create_vserver(self):
     res = naapi.NaElement('fake')
     res.add_new_child('aggregate-name', 'aggr')
     self.driver.configuration.netapp_root_volume_aggregate = 'root'
     fake_aggrs = mock.Mock()
     fake_aggrs.get_child_by_name.return_value = fake_aggrs
     fake_aggrs.get_children.return_value = [res]
     self.driver._client.send_request = mock.Mock(return_value=fake_aggrs)
     vserver_create_args = {
         'vserver-name': 'os_fake_net_id',
         'root-volume-security-style': 'unix',
         'root-volume-aggregate': 'root',
         'root-volume': 'root',
         'name-server-switch': {
             'nsswitch': 'file'
         }
     }
     vserver_modify_args = {
         'aggr-list': [{
             'aggr-name': 'aggr'
         }],
         'vserver-name': 'os_fake_net_id'
     }
     self.driver._create_vserver('os_fake_net_id')
     self.driver._client.send_request.assert_has_calls([
         mock.call('vserver-create', vserver_create_args),
         mock.call('aggr-get-iter'),
         mock.call('vserver-modify', vserver_modify_args),
     ])
Exemple #7
0
 def send_request(self, api_name, args=None):
     """Sends request to Ontapi."""
     elem = naapi.NaElement(api_name)
     if args:
         elem.translate_struct(args)
     LOG.debug("NaElement: %s", elem.to_string(pretty=True))
     return self._client.invoke_successfully(elem, enable_tunneling=True)
Exemple #8
0
 def test_delete_vserver_has_shares(self):
     el = naapi.NaElement('fake')
     el['num-records'] = 3
     self.driver._vserver_exists = mock.Mock(return_value=True)
     self._vserver_client.send_request = mock.Mock(return_value=el)
     self.assertRaises(exception.NetAppException,
                       self.driver._delete_vserver, 'fake',
                       self._vserver_client)
Exemple #9
0
 def test_delete_vserver_without_root_volume(self):
     el = naapi.NaElement('fake')
     el['num-records'] = '0'
     self.driver._vserver_exists = mock.Mock(return_value=True)
     self._vserver_client.send_request = mock.Mock(return_value=el)
     self.driver._delete_vserver('fake', self._vserver_client)
     self.driver._client.send_request.assert_called_once_with(
         'vserver-destroy', {'vserver-name': 'fake'})
Exemple #10
0
 def test_delete_snapshot(self):
     res = mock.Mock()
     res.get_child_by_name.return_value = res
     snap = naapi.NaElement('snap')
     snap.add_new_child('busy', 'true')
     snap.add_new_child('name', 'share_snapshot_fake_snapshot_uuid')
     res.get_children = mock.Mock(return_value=[snap])
     self.driver._client.send_request = mock.Mock(return_value=res)
     self.assertRaises(exception.ShareSnapshotIsBusy,
                       self.driver.delete_snapshot, self._context,
                       self.snapshot)
Exemple #11
0
 def test_vserver_exists_false(self):
     el = naapi.NaElement('fake')
     el['num-records'] = '1'
     self.driver._client.send_request = mock.Mock(return_value=el)
     self.assertEqual(self.driver._vserver_exists('fake_vserver'), True)
     self.driver._client.send_request.assert_called_once_with(
         'vserver-get-iter',
         {'query': {
             'vserver-info': {
                 'vserver-name': 'fake_vserver'
             }
         }})
Exemple #12
0
 def test_delete_vserver_without_net_info(self):
     el = naapi.NaElement('fake')
     el['num-records'] = 1
     self.driver._vserver_exists = mock.Mock(return_value=True)
     self._vserver_client.send_request = mock.Mock(return_value=el)
     self.driver._delete_vserver('fake', self._vserver_client)
     self._vserver_client.send_request.assert_has_calls([
         mock.call('volume-offline', {'name': 'root'}),
         mock.call('volume-destroy', {'name': 'root'})
     ])
     self.driver._client.send_request.assert_called_once_with(
         'vserver-destroy', {'vserver-name': 'fake'})
Exemple #13
0
 def test_delete_snapshot_busy(self):
     res = mock.Mock()
     res.get_child_by_name.return_value = res
     snap = naapi.NaElement('snap')
     snap.add_new_child('busy', 'false')
     snap.add_new_child('name', 'share_fake_uuid')
     res.get_children = mock.Mock(return_value=[snap])
     self.driver._client.send_request = mock.Mock(return_value=res)
     self.driver.delete_snapshot(self._context, self.snapshot)
     self.driver._client.send_request.assert_called_with(
         'snapshot-delete', {
             'volume': 'share_fake_share_id',
             'snapshot': 'share_snapshot_fake_snapshot_uuid'
         })
 def test_create_export(self):
     self.helper.create_share = mock.Mock(return_value="fake-location")
     net_info = {
         'attributes-list': {
             'net-interface-info': {'address': 'ip'}},
         'num-records': '1'}
     ifaces = naapi.NaElement('root')
     ifaces.translate_struct(net_info)
     self._vserver_client.send_request = mock.Mock(return_value=ifaces)
     export_location = self.driver._create_export(
         self.share, 'vserver', self._vserver_client)
     self.helper.create_share.assert_called_once_with(
         "share_%s" % self.share['id'], 'ip')
     self.assertEqual(export_location, "fake-location")
 def test_delete_vserver_with_net_info(self):
     el = naapi.NaElement('fake')
     el['num-records'] = 1
     self.driver._vserver_exists = mock.Mock(return_value=True)
     self._vserver_client.send_request = mock.Mock(return_value=el)
     security_services = [
         {'user': '******',
          'password': '******',
          'type': 'active_directory'}
     ]
     self.driver._delete_vserver('fake',
                                 self._vserver_client,
                                 security_services=security_services)
     self._vserver_client.send_request.assert_has_calls([
         mock.call('volume-get-iter'),
         mock.call('volume-offline', {'name': 'root'}),
         mock.call('volume-destroy', {'name': 'root'}),
         mock.call('cifs-server-delete', {'admin-username': '******',
                                          'admin-password': '******'})
     ])
     self.driver._client.send_request.assert_called_once_with(
         'vserver-destroy', {'vserver-name': 'fake'})
    def test_licenses(self):
        licenses_dict = {
            'licenses': {
                'fake_license_1': {
                    'package': 'Fake_License_1',
                },
                'fake_license_2': {
                    'package': 'Fake_License_2',
                },
            },
        }
        licenses = naapi.NaElement('fake_licenses_as_response')
        licenses.translate_struct(licenses_dict)

        self.stubs.Set(self.driver._client, 'send_request',
                       mock.Mock(return_value=licenses))
        self.stubs.Set(driver.LOG, 'info', mock.Mock())

        response = self.driver._check_licenses()

        self.driver._client.send_request.assert_called_once_with(
            'license-v2-list-info')
        driver.LOG.info.assert_called_once_with(mock.ANY, mock.ANY)
        self.assertEqual(response, ['fake_license_1', 'fake_license_2'])
Exemple #17
0
 def test_check_vfiler_exists(self):
     elem = naapi.NaElement('fake')
     elem['status'] = 'running'
     self.driver._client.send_request = mock.Mock(return_value=elem)
     self.driver._check_vfiler_exists()
Exemple #18
0
 def test_check_vfiler_exists_error(self):
     elem = naapi.NaElement('fake')
     elem['status'] = 'error'
     self.driver._client.send_request = mock.Mock(return_value=elem)
     self.assertRaises(exception.NetAppException,
                       self.driver._check_vfiler_exists)