Windows SMB: use os-brick remotefs client
os-brick now contains a Windows remote fs client so we can remove duplicated code. The os-brick remotefs client also allows using local paths in case of local shares, which is mandatory in case of scale-out shares. Change-Id: I4724c87451ac6ddb04f3ca6246beb6dc0c83799e
This commit is contained in:
parent
52a3ee5186
commit
dea50f7587
|
@ -43,7 +43,7 @@ class WindowsSmbFsTestCase(test.TestCase):
|
|||
_FAKE_VOLUME_NAME + '.vhdx')
|
||||
|
||||
@mock.patch.object(smbfs, 'utilsfactory')
|
||||
@mock.patch.object(smbfs, 'remotefs')
|
||||
@mock.patch.object(smbfs, 'remotefs_brick')
|
||||
def setUp(self, mock_remotefs, mock_utilsfactory):
|
||||
super(WindowsSmbFsTestCase, self).setUp()
|
||||
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
# Copyright 2014 Cloudbase Solutions Srl
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from cinder import exception
|
||||
from cinder import test
|
||||
from cinder.volume.drivers.windows import remotefs
|
||||
|
||||
|
||||
class WindowsRemoteFsTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(WindowsRemoteFsTestCase, self).setUp()
|
||||
|
||||
with mock.patch.object(remotefs.WindowsRemoteFsClient,
|
||||
'__init__', lambda x: None):
|
||||
self._remotefs = remotefs.WindowsRemoteFsClient()
|
||||
|
||||
self._remotefs._mount_base = mock.sentinel.mnt_base
|
||||
self._remotefs._smbutils = mock.Mock()
|
||||
self._remotefs._pathutils = mock.Mock()
|
||||
|
||||
@mock.patch('os.path.isdir')
|
||||
@mock.patch('os.makedirs')
|
||||
@mock.patch('os.path.exists')
|
||||
@mock.patch('os.path.abspath')
|
||||
@mock.patch.object(remotefs.WindowsRemoteFsClient, 'get_mount_point')
|
||||
def _test_mount_share(self, mock_get_mnt_point, mock_abspath,
|
||||
mock_path_exists, mock_makedirs, mock_isdir,
|
||||
mnt_point_exists=False, is_mnt_point_slink=True):
|
||||
mount_options = dict(username=mock.sentinel.username,
|
||||
password=mock.sentinel.password)
|
||||
mock_isdir.return_value = False
|
||||
mock_get_mnt_point.return_value = mock.sentinel.mnt_point
|
||||
mock_abspath.return_value = mock.sentinel.norm_export_path
|
||||
mock_path_exists.return_value = mnt_point_exists
|
||||
|
||||
self._remotefs._pathutils.is_symlink.return_value = is_mnt_point_slink
|
||||
self._remotefs._smbutils.check_smb_mapping.return_value = False
|
||||
|
||||
if mnt_point_exists and not is_mnt_point_slink:
|
||||
self.assertRaises(exception.SmbfsException,
|
||||
self._remotefs.mount,
|
||||
mock.sentinel.export_path,
|
||||
mount_options)
|
||||
else:
|
||||
self._remotefs.mount(mock.sentinel.export_path, mount_options)
|
||||
|
||||
mock_makedirs.assert_called_once_with(mock.sentinel.mnt_base)
|
||||
mock_get_mnt_point.assert_called_once_with(mock.sentinel.export_path)
|
||||
self._remotefs._smbutils.check_smb_mapping.assert_called_once_with(
|
||||
mock.sentinel.norm_export_path, remove_unavailable_mapping=True)
|
||||
self._remotefs._smbutils.mount_smb_share.assert_called_once_with(
|
||||
mock.sentinel.norm_export_path, **mount_options)
|
||||
|
||||
if not mnt_point_exists:
|
||||
self._remotefs._pathutils.create_sym_link.assert_called_once_with(
|
||||
mock.sentinel.mnt_point, mock.sentinel.norm_export_path)
|
||||
|
||||
def test_mount_share(self):
|
||||
self._test_mount_share()
|
||||
|
||||
def test_mount_share_existing_mnt_point_not_symlink(self):
|
||||
self._test_mount_share(mnt_point_exists=True,
|
||||
is_mnt_point_slink=False)
|
|
@ -1,55 +0,0 @@
|
|||
# Copyright 2014 Cloudbase Solutions Srl
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
|
||||
from os_brick.remotefs import remotefs
|
||||
from os_win import utilsfactory
|
||||
|
||||
from cinder import exception
|
||||
from cinder.i18n import _
|
||||
|
||||
|
||||
class WindowsRemoteFsClient(remotefs.RemoteFsClient):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(WindowsRemoteFsClient, self).__init__(*args, **kwargs)
|
||||
self._smbutils = utilsfactory.get_smbutils()
|
||||
self._pathutils = utilsfactory.get_pathutils()
|
||||
|
||||
def mount(self, export_path, mnt_options=None):
|
||||
if not os.path.isdir(self._mount_base):
|
||||
os.makedirs(self._mount_base)
|
||||
|
||||
mnt_point = self.get_mount_point(export_path)
|
||||
norm_path = os.path.abspath(export_path)
|
||||
mnt_options = mnt_options or {}
|
||||
|
||||
username = (mnt_options.get('username') or
|
||||
mnt_options.get('user'))
|
||||
password = (mnt_options.get('password') or
|
||||
mnt_options.get('pass'))
|
||||
|
||||
if not self._smbutils.check_smb_mapping(
|
||||
norm_path,
|
||||
remove_unavailable_mapping=True):
|
||||
self._smbutils.mount_smb_share(norm_path,
|
||||
username=username,
|
||||
password=password)
|
||||
|
||||
if os.path.exists(mnt_point):
|
||||
if not self._pathutils.is_symlink(mnt_point):
|
||||
raise exception.SmbfsException(_("Link path already exists "
|
||||
"and its not a symlink"))
|
||||
else:
|
||||
self._pathutils.create_sym_link(mnt_point, norm_path)
|
|
@ -17,6 +17,7 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
from os_brick.remotefs import windows_remotefs as remotefs_brick
|
||||
from os_win import utilsfactory
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
@ -29,7 +30,6 @@ from cinder.image import image_utils
|
|||
from cinder import interface
|
||||
from cinder.volume.drivers import remotefs as remotefs_drv
|
||||
from cinder.volume.drivers import smbfs
|
||||
from cinder.volume.drivers.windows import remotefs
|
||||
|
||||
VERSION = '1.1.0'
|
||||
|
||||
|
@ -60,9 +60,9 @@ class WindowsSmbfsDriver(smbfs.SmbfsDriver):
|
|||
opts = getattr(self.configuration,
|
||||
'smbfs_mount_options',
|
||||
CONF.smbfs_mount_options)
|
||||
self._remotefsclient = remotefs.WindowsRemoteFsClient(
|
||||
self._remotefsclient = remotefs_brick.WindowsRemoteFsClient(
|
||||
'cifs', root_helper=None, smbfs_mount_point_base=self.base,
|
||||
smbfs_mount_options=opts)
|
||||
smbfs_mount_options=opts, local_path_for_loopback=True)
|
||||
|
||||
self._vhdutils = utilsfactory.get_vhdutils()
|
||||
self._pathutils = utilsfactory.get_pathutils()
|
||||
|
@ -95,11 +95,10 @@ class WindowsSmbfsDriver(smbfs.SmbfsDriver):
|
|||
self._vhdutils.create_dynamic_vhd(volume_path, volume_size_bytes)
|
||||
|
||||
def _ensure_share_mounted(self, smbfs_share):
|
||||
mnt_options = {}
|
||||
mnt_flags = None
|
||||
if self.shares.get(smbfs_share) is not None:
|
||||
mnt_flags = self.shares[smbfs_share]
|
||||
mnt_options = self.parse_options(mnt_flags)[1]
|
||||
self._remotefsclient.mount(smbfs_share, mnt_options)
|
||||
self._remotefsclient.mount(smbfs_share, mnt_flags)
|
||||
|
||||
def _delete(self, path):
|
||||
fileutils.delete_if_exists(path)
|
||||
|
|
Loading…
Reference in New Issue