Merge "Move vzstorage related code out of RemoteFsClient"
This commit is contained in:
commit
c454d1c63a
@ -45,6 +45,8 @@ class RemoteFsConnector(base.BaseLinuxConnector):
|
||||
|
||||
if mount_type_lower == 'scality':
|
||||
cls = remotefs.ScalityRemoteFsClient
|
||||
elif mount_type_lower == 'vzstorage':
|
||||
cls = remotefs.VZStorageRemoteFSClient
|
||||
else:
|
||||
cls = remotefs.RemoteFsClient
|
||||
self._remotefsclient = cls(mount_type, root_helper, execute=execute,
|
||||
|
@ -105,8 +105,6 @@ class RemoteFsClient(executor.Executor):
|
||||
self._execute('mkdir', '-p', mount_path, check_exit_code=0)
|
||||
if self._mount_type == 'nfs':
|
||||
self._mount_nfs(share, mount_path, flags)
|
||||
elif self._mount_type == 'vzstorage':
|
||||
self._mount_vzstorage(share, mount_path, flags)
|
||||
else:
|
||||
self._do_mount(self._mount_type, share, mount_path,
|
||||
self._mount_options, flags)
|
||||
@ -146,53 +144,6 @@ class RemoteFsClient(executor.Executor):
|
||||
% {'sh': nfs_share,
|
||||
'error': mnt_errors})
|
||||
|
||||
def _vzstorage_write_mds_list(self, cluster_name, mdss):
|
||||
tmp_dir = tempfile.mkdtemp(prefix='vzstorage-')
|
||||
tmp_bs_path = os.path.join(tmp_dir, 'bs_list')
|
||||
with open(tmp_bs_path, 'w') as f:
|
||||
for mds in mdss:
|
||||
f.write(mds + "\n")
|
||||
|
||||
conf_dir = os.path.join('/etc/pstorage/clusters', cluster_name)
|
||||
if os.path.exists(conf_dir):
|
||||
bs_path = os.path.join(conf_dir, 'bs_list')
|
||||
self._execute('cp', '-f', tmp_bs_path, bs_path,
|
||||
root_helper=self._root_helper, run_as_root=True)
|
||||
else:
|
||||
self._execute('cp', '-rf', tmp_dir, conf_dir,
|
||||
root_helper=self._root_helper, run_as_root=True)
|
||||
self._execute('chown', '-R', 'root:root', conf_dir,
|
||||
root_helper=self._root_helper, run_as_root=True)
|
||||
|
||||
def _mount_vzstorage(self, vz_share, mount_path, flags=None):
|
||||
m = re.search("(?:(\S+):\/)?([a-zA-Z0-9_-]+)(?::(\S+))?", vz_share)
|
||||
if not m:
|
||||
msg = (_("Invalid Virtuozzo Storage share specification: %r."
|
||||
"Must be: [MDS1[,MDS2],...:/]<CLUSTER NAME>[:PASSWORD].")
|
||||
% vz_share)
|
||||
raise exception.BrickException(msg)
|
||||
|
||||
mdss = m.group(1)
|
||||
cluster_name = m.group(2)
|
||||
passwd = m.group(3)
|
||||
|
||||
if mdss:
|
||||
mdss = mdss.split(',')
|
||||
self._vzstorage_write_mds_list(cluster_name, mdss)
|
||||
|
||||
if passwd:
|
||||
self._execute('pstorage', '-c', cluster_name, 'auth-node', '-P',
|
||||
process_input=passwd,
|
||||
root_helper=self._root_helper, run_as_root=True)
|
||||
|
||||
mnt_cmd = ['pstorage-mount', '-c', cluster_name]
|
||||
if flags:
|
||||
mnt_cmd.extend(flags)
|
||||
mnt_cmd.extend([mount_path])
|
||||
|
||||
self._execute(*mnt_cmd, root_helper=self._root_helper,
|
||||
run_as_root=True, check_exit_code=0)
|
||||
|
||||
def _check_nfs_options(self):
|
||||
"""Checks and prepares nfs mount type options."""
|
||||
self._nfs_mount_type_opts = {'nfs': self._mount_options}
|
||||
@ -261,3 +212,53 @@ class ScalityRemoteFsClient(RemoteFsClient):
|
||||
self._execute('mkdir', '-p', self._mount_base, check_exit_code=0)
|
||||
super(ScalityRemoteFsClient, self)._do_mount(
|
||||
'sofs', '/etc/sfused.conf', self._mount_base)
|
||||
|
||||
|
||||
class VZStorageRemoteFSClient(RemoteFsClient):
|
||||
def _vzstorage_write_mds_list(self, cluster_name, mdss):
|
||||
tmp_dir = tempfile.mkdtemp(prefix='vzstorage-')
|
||||
tmp_bs_path = os.path.join(tmp_dir, 'bs_list')
|
||||
with open(tmp_bs_path, 'w') as f:
|
||||
for mds in mdss:
|
||||
f.write(mds + "\n")
|
||||
|
||||
conf_dir = os.path.join('/etc/pstorage/clusters', cluster_name)
|
||||
if os.path.exists(conf_dir):
|
||||
bs_path = os.path.join(conf_dir, 'bs_list')
|
||||
self._execute('cp', '-f', tmp_bs_path, bs_path,
|
||||
root_helper=self._root_helper, run_as_root=True)
|
||||
else:
|
||||
self._execute('cp', '-rf', tmp_dir, conf_dir,
|
||||
root_helper=self._root_helper, run_as_root=True)
|
||||
self._execute('chown', '-R', 'root:root', conf_dir,
|
||||
root_helper=self._root_helper, run_as_root=True)
|
||||
|
||||
def _do_mount(self, mount_type, vz_share, mount_path,
|
||||
mount_options=None, flags=None):
|
||||
m = re.search("(?:(\S+):\/)?([a-zA-Z0-9_-]+)(?::(\S+))?", vz_share)
|
||||
if not m:
|
||||
msg = (_("Invalid Virtuozzo Storage share specification: %r."
|
||||
"Must be: [MDS1[,MDS2],...:/]<CLUSTER NAME>[:PASSWORD].")
|
||||
% vz_share)
|
||||
raise exception.BrickException(msg)
|
||||
|
||||
mdss = m.group(1)
|
||||
cluster_name = m.group(2)
|
||||
passwd = m.group(3)
|
||||
|
||||
if mdss:
|
||||
mdss = mdss.split(',')
|
||||
self._vzstorage_write_mds_list(cluster_name, mdss)
|
||||
|
||||
if passwd:
|
||||
self._execute('pstorage', '-c', cluster_name, 'auth-node', '-P',
|
||||
process_input=passwd,
|
||||
root_helper=self._root_helper, run_as_root=True)
|
||||
|
||||
mnt_cmd = ['pstorage-mount', '-c', cluster_name]
|
||||
if flags:
|
||||
mnt_cmd.extend(flags)
|
||||
mnt_cmd.extend([mount_path])
|
||||
|
||||
self._execute(*mnt_cmd, root_helper=self._root_helper,
|
||||
run_as_root=True, check_exit_code=0)
|
||||
|
@ -44,85 +44,6 @@ class RemoteFsClientTestCase(base.TestCase):
|
||||
check_exit_code=0)]
|
||||
self.mock_execute.assert_has_calls(calls)
|
||||
|
||||
@mock.patch.object(remotefs.RemoteFsClient, '_read_mounts',
|
||||
return_value=[])
|
||||
def test_vzstorage_by_cluster_name(self, mock_read_mounts):
|
||||
client = remotefs.RemoteFsClient("vzstorage", root_helper='true',
|
||||
vzstorage_mount_point_base='/mnt')
|
||||
share = 'qwe'
|
||||
cluster_name = share
|
||||
mount_point = client.get_mount_point(share)
|
||||
client.mount(share)
|
||||
calls = [mock.call('mkdir', '-p', mount_point, check_exit_code=0),
|
||||
mock.call('pstorage-mount', '-c', cluster_name, mount_point,
|
||||
root_helper='true', check_exit_code=0,
|
||||
run_as_root=True)]
|
||||
self.mock_execute.assert_has_calls(calls)
|
||||
|
||||
@mock.patch.object(remotefs.RemoteFsClient, '_read_mounts',
|
||||
return_value=[])
|
||||
def test_vzstorage_with_auth(self, mock_read_mounts):
|
||||
client = remotefs.RemoteFsClient("vzstorage", root_helper='true',
|
||||
vzstorage_mount_point_base='/mnt')
|
||||
cluster_name = 'qwe'
|
||||
password = '123456'
|
||||
share = '%s:%s' % (cluster_name, password)
|
||||
mount_point = client.get_mount_point(share)
|
||||
client.mount(share)
|
||||
calls = [mock.call('mkdir', '-p', mount_point, check_exit_code=0),
|
||||
mock.call('pstorage', '-c', cluster_name, 'auth-node', '-P',
|
||||
process_input=password, root_helper='true',
|
||||
run_as_root=True),
|
||||
mock.call('pstorage-mount', '-c', cluster_name, mount_point,
|
||||
root_helper='true', check_exit_code=0,
|
||||
run_as_root=True)]
|
||||
self.mock_execute.assert_has_calls(calls)
|
||||
|
||||
@mock.patch('os.path.exists', return_value=False)
|
||||
@mock.patch.object(remotefs.RemoteFsClient, '_read_mounts',
|
||||
return_value=[])
|
||||
def test_vzstorage_with_mds_list(self, mock_read_mounts, mock_exists):
|
||||
client = remotefs.RemoteFsClient("vzstorage", root_helper='true',
|
||||
vzstorage_mount_point_base='/mnt')
|
||||
cluster_name = 'qwe'
|
||||
mds_list = ['10.0.0.1', '10.0.0.2']
|
||||
share = '%s:/%s' % (','.join(mds_list), cluster_name)
|
||||
mount_point = client.get_mount_point(share)
|
||||
vz_conf_dir = os.path.join('/etc/pstorage/clusters/', cluster_name)
|
||||
|
||||
tmp_dir = '/tmp/fake_dir/'
|
||||
|
||||
with mock.patch.object(tempfile, 'mkdtemp',
|
||||
return_value=tmp_dir):
|
||||
mock_open = mock.mock_open()
|
||||
with mock.patch.object(six.moves.builtins, "open",
|
||||
mock_open, create=True):
|
||||
client.mount(share)
|
||||
|
||||
write_calls = [mock.call(tmp_dir + 'bs_list', 'w'),
|
||||
mock.call().__enter__(),
|
||||
mock.call().write('10.0.0.1\n'),
|
||||
mock.call().write('10.0.0.2\n'),
|
||||
mock.call().__exit__(None, None, None)]
|
||||
|
||||
mock_open.assert_has_calls(write_calls)
|
||||
calls = [mock.call('mkdir', '-p', mount_point, check_exit_code=0),
|
||||
mock.call('cp', '-rf', tmp_dir, vz_conf_dir,
|
||||
run_as_root=True, root_helper='true'),
|
||||
mock.call('chown', '-R', 'root:root', vz_conf_dir,
|
||||
run_as_root=True, root_helper='true'),
|
||||
mock.call('pstorage-mount', '-c', cluster_name, mount_point,
|
||||
root_helper='true', check_exit_code=0,
|
||||
run_as_root=True)]
|
||||
self.mock_execute.assert_has_calls(calls)
|
||||
|
||||
@mock.patch.object(remotefs.RemoteFsClient, '_read_mounts',
|
||||
return_value=[])
|
||||
def test_vzstorage_invalid_share(self, mock_read_mounts):
|
||||
client = remotefs.RemoteFsClient("vzstorage", root_helper='true',
|
||||
vzstorage_mount_point_base='/mnt')
|
||||
self.assertRaises(exception.BrickException, client.mount, ':')
|
||||
|
||||
@mock.patch.object(remotefs.RemoteFsClient, '_read_mounts',
|
||||
return_value=[])
|
||||
def test_nfs(self, mock_read_mounts):
|
||||
@ -201,11 +122,88 @@ class RemoteFsClientTestCase(base.TestCase):
|
||||
mock_check_nfs_options.assert_called_once_with()
|
||||
|
||||
|
||||
class VZStorageRemoteFSClientTestVase(RemoteFsClientTestCase):
|
||||
@mock.patch.object(remotefs.RemoteFsClient, '_read_mounts',
|
||||
return_value=[])
|
||||
def test_vzstorage_by_cluster_name(self, mock_read_mounts):
|
||||
client = remotefs.VZStorageRemoteFSClient(
|
||||
"vzstorage", root_helper='true', vzstorage_mount_point_base='/mnt')
|
||||
share = 'qwe'
|
||||
cluster_name = share
|
||||
mount_point = client.get_mount_point(share)
|
||||
client.mount(share)
|
||||
calls = [mock.call('mkdir', '-p', mount_point, check_exit_code=0),
|
||||
mock.call('pstorage-mount', '-c', cluster_name, mount_point,
|
||||
root_helper='true', check_exit_code=0,
|
||||
run_as_root=True)]
|
||||
self.mock_execute.assert_has_calls(calls)
|
||||
|
||||
@mock.patch.object(remotefs.RemoteFsClient, '_read_mounts',
|
||||
return_value=[])
|
||||
def test_vzstorage_with_auth(self, mock_read_mounts):
|
||||
client = remotefs.VZStorageRemoteFSClient(
|
||||
"vzstorage", root_helper='true', vzstorage_mount_point_base='/mnt')
|
||||
cluster_name = 'qwe'
|
||||
password = '123456'
|
||||
share = '%s:%s' % (cluster_name, password)
|
||||
mount_point = client.get_mount_point(share)
|
||||
client.mount(share)
|
||||
calls = [mock.call('mkdir', '-p', mount_point, check_exit_code=0),
|
||||
mock.call('pstorage', '-c', cluster_name, 'auth-node', '-P',
|
||||
process_input=password, root_helper='true',
|
||||
run_as_root=True),
|
||||
mock.call('pstorage-mount', '-c', cluster_name, mount_point,
|
||||
root_helper='true', check_exit_code=0,
|
||||
run_as_root=True)]
|
||||
self.mock_execute.assert_has_calls(calls)
|
||||
|
||||
@mock.patch('os.path.exists', return_value=False)
|
||||
@mock.patch.object(remotefs.RemoteFsClient, '_read_mounts',
|
||||
return_value=[])
|
||||
def test_vzstorage_with_mds_list(self, mock_read_mounts, mock_exists):
|
||||
client = remotefs.VZStorageRemoteFSClient(
|
||||
"vzstorage", root_helper='true', vzstorage_mount_point_base='/mnt')
|
||||
cluster_name = 'qwe'
|
||||
mds_list = ['10.0.0.1', '10.0.0.2']
|
||||
share = '%s:/%s' % (','.join(mds_list), cluster_name)
|
||||
mount_point = client.get_mount_point(share)
|
||||
vz_conf_dir = os.path.join('/etc/pstorage/clusters/', cluster_name)
|
||||
|
||||
tmp_dir = '/tmp/fake_dir/'
|
||||
|
||||
with mock.patch.object(tempfile, 'mkdtemp',
|
||||
return_value=tmp_dir):
|
||||
mock_open = mock.mock_open()
|
||||
with mock.patch.object(six.moves.builtins, "open",
|
||||
mock_open, create=True):
|
||||
client.mount(share)
|
||||
|
||||
write_calls = [mock.call(tmp_dir + 'bs_list', 'w'),
|
||||
mock.call().__enter__(),
|
||||
mock.call().write('10.0.0.1\n'),
|
||||
mock.call().write('10.0.0.2\n'),
|
||||
mock.call().__exit__(None, None, None)]
|
||||
|
||||
mock_open.assert_has_calls(write_calls)
|
||||
calls = [mock.call('mkdir', '-p', mount_point, check_exit_code=0),
|
||||
mock.call('cp', '-rf', tmp_dir, vz_conf_dir,
|
||||
run_as_root=True, root_helper='true'),
|
||||
mock.call('chown', '-R', 'root:root', vz_conf_dir,
|
||||
run_as_root=True, root_helper='true'),
|
||||
mock.call('pstorage-mount', '-c', cluster_name, mount_point,
|
||||
root_helper='true', check_exit_code=0,
|
||||
run_as_root=True)]
|
||||
self.mock_execute.assert_has_calls(calls)
|
||||
|
||||
@mock.patch.object(remotefs.RemoteFsClient, '_read_mounts',
|
||||
return_value=[])
|
||||
def test_vzstorage_invalid_share(self, mock_read_mounts):
|
||||
client = remotefs.VZStorageRemoteFSClient(
|
||||
"vzstorage", root_helper='true', vzstorage_mount_point_base='/mnt')
|
||||
self.assertRaises(exception.BrickException, client.mount, ':')
|
||||
|
||||
|
||||
class ScalityRemoteFsClientTestCase(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ScalityRemoteFsClientTestCase, self).setUp()
|
||||
|
||||
def test_no_mount_point_scality(self):
|
||||
self.assertRaises(exception.InvalidParameterValue,
|
||||
remotefs.ScalityRemoteFsClient,
|
||||
|
Loading…
Reference in New Issue
Block a user