def test_set_share_winacls(self):
     put_response = 'Success'
     self._init_filer(put_response=put_response)
     shares.Shares(self._filer).set_share_winacls(self._share_name)
     self._filer.put.assert_called_once_with(
         '/config/fileservices/share/' + self._share_name + '/access',
         Acl.WindowsNT)
 def test_get_share(self):
     get_response = 'Success'
     self._init_filer(get_response=get_response)
     ret = shares.Shares(self._filer).get(self._share_name)
     self._filer.get.assert_called_once_with('/config/fileservices/share/' +
                                             self._share_name)
     self.assertEqual(ret, get_response)
 def test_block_files_success(self):
     get_response = self._get_share_object()
     self._init_filer(get_response=get_response)
     shares.Shares(self._filer).block_files(self._share_name,
                                            self._share_block_files)
     self._filer.get.assert_called_once_with('/config/fileservices/share/' +
                                             self._share_name)
     self._filer.put.assert_called_once_with(
         '/config/fileservices/share/' + self._share_name +
         '/screenedFileTypes', self._share_block_files)
 def test_block_files_invalid_share_access_type(self):
     get_response = self._get_share_object(access='Expected Failure')
     self._init_filer(get_response=get_response)
     with self.assertRaises(exception.CTERAException) as error:
         shares.Shares(self._filer).block_files(self._share_name,
                                                self._share_block_files)
     self._filer.get.assert_called_once_with('/config/fileservices/share/' +
                                             self._share_name)
     self.assertEqual(
         'Cannot block file types on non Windows-ACL enabled shares',
         error.exception.message)
    def test_list_physical_folders_input_error(self):
        execute_response = []
        self._init_filer(execute_response=execute_response)
        with self.assertRaises(exception.InputError) as error:
            shares.Shares(self._filer).add(self._share_name,
                                           self._share_fullpath, [])

        self._filer.execute.assert_called_once_with('/status/fileManager',
                                                    'listPhysicalFolders',
                                                    mock.ANY)
        expected_param = self._get_list_physical_folders_param()
        actual_param = self._filer.execute.call_args[0][2]
        self._assert_equal_objects(actual_param, expected_param)

        self.assertEqual('Invalid root directory.', error.exception.message)
    def test_add_cifs_share_default_config_with_acls(self):
        execute_response = self._get_list_physical_folders_response_object()
        self._init_filer(execute_response=execute_response)

        shares.Shares(self._filer).add(self._share_name, self._share_fullpath,
                                       self._share_acl)

        self._filer.execute.assert_called_once_with('/status/fileManager',
                                                    'listPhysicalFolders',
                                                    mock.ANY)
        expected_param = self._get_list_physical_folders_param()
        actual_param = self._filer.execute.call_args[0][2]
        self._assert_equal_objects(actual_param, expected_param)

        self._filer.add.assert_called_once_with(
            '/config/fileservices/share',
            mock.ANY)  # no verification call param _add_share_acl_rule()
    def test_add_share_failure(self):
        execute_response = self._get_list_physical_folders_response_object()
        self._init_filer(execute_response=execute_response)
        self._filer.add = mock.MagicMock(
            side_effect=exception.CTERAException())
        with self.assertRaises(exception.CTERAException) as error:
            shares.Shares(self._filer).add(self._share_name,
                                           self._share_fullpath, [])

        self._filer.execute.assert_called_once_with('/status/fileManager',
                                                    'listPhysicalFolders',
                                                    mock.ANY)
        expected_param = self._get_list_physical_folders_param()
        actual_param = self._filer.execute.call_args[0][2]
        self._assert_equal_objects(actual_param, expected_param)

        self._filer.add.assert_called_once_with('/config/fileservices/share',
                                                mock.ANY)
        expected_param = self._get_share_object(acl=[])
        actual_param = self._filer.add.call_args[0][1]
        self._assert_equal_objects(actual_param, expected_param)

        self.assertEqual('Share creation failed', error.exception.message)
 def test_modify(self):
     updated_comment = 'Test Modify'
     get_response = self._get_share_object()
     self._init_filer(get_response=get_response)
     modify_command_dict = dict(
         export_to_afp=True,
         export_to_ftp=True,
         export_to_nfs=True,
         export_to_pc_agent=True,
         export_to_rsync=True,
         indexed=True,
         comment=updated_comment,
         access=Acl.OnlyAuthenticatedUsers,
         dir_permissions=644,
     )
     expected_param = self._get_share_object(**modify_command_dict)
     shares.Shares(self._filer).modify(self._share_name,
                                       **modify_command_dict)
     self._filer.get.assert_called_once_with('/config/fileservices/share/' +
                                             self._share_name)
     self._filer.put.assert_called_once_with(
         '/config/fileservices/share/' + self._share_name, mock.ANY)
     actual_param = self._filer.put.call_args[0][1]
     self._assert_equal_objects(actual_param, expected_param)
 def test_delete_share_failure(self):
     self._filer.delete = mock.MagicMock(
         side_effect=exception.CTERAException())
     with self.assertRaises(exception.CTERAException) as error:
         shares.Shares(self._filer).delete(self._share_name)
     self.assertEqual('Share deletion failed', error.exception.message)
 def test_delete_share_success(self):
     self._init_filer()
     shares.Shares(self._filer).delete(self._share_name)
     self._filer.delete.assert_called_once_with(
         '/config/fileservices/share/' + self._share_name)