Fix bug to locate hdfs command in HDFS native driver

No longer to locate hdfs command.
Assume the ssh user has the authority to launch hdfs command.
And the user must add hdfs in default PATH manually.

Change-Id: Ia5d118a49ecea092848796067ae48dbead83c40e
Closes-Bug: #1481568
This commit is contained in:
weiting-chen 2015-08-10 21:16:21 +08:00
parent bed9b9f3f2
commit cf3ea378f0
2 changed files with 6 additions and 30 deletions

View File

@ -100,7 +100,7 @@ class HDFSNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
else:
self._hdfs_execute = self._hdfs_remote_execute
self._hdfs_bin = self._get_hdfs_bin_path()
self._hdfs_bin = 'hdfs'
self._hdfs_base_path = (
'hdfs://' + self.configuration.hdfs_namenode_ip + ':'
+ six.text_type(self.configuration.hdfs_namenode_port))
@ -159,24 +159,6 @@ class HDFSNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
LOG.error(msg)
raise exception.HDFSException(msg)
def _get_hdfs_bin_path(self):
try:
(out, __) = self._hdfs_execute('locate', '/bin/hdfs')
except exception.ProcessExecutionError as e:
msg = (_('Can not get the execution path of hdfs. '
'Error: %(excmsg)s.') %
{'excmsg': six.text_type(e)})
LOG.error(msg)
raise exception.HDFSException(msg)
lines = out.splitlines()
if lines and lines[0].endswith('/bin/hdfs'):
return lines[0]
else:
msg = _('Can not get the execution path of hdfs.')
LOG.error(msg)
raise exception.HDFSException(msg)
def _create_share(self, share):
"""Creates a share."""
if share['share_proto'].lower() != 'hdfs':
@ -373,20 +355,14 @@ class HDFSNativeShareDriver(driver.ExecuteMixin, driver.ShareDriver):
try:
(out, __) = self._hdfs_execute(self._hdfs_bin, 'fsck', '/')
except exception.ProcessExecutionError as e:
msg = _('Failed to check the utility of hdfs.')
LOG.error(msg)
raise exception.HDFSException(msg)
lines = out.splitlines()
try:
hdfs_state = lines[1].split()[1]
except (IndexError, ValueError) as e:
msg = (_('Failed to check hdfs state. Error: %(excmsg)s.') %
{'excmsg': six.text_type(e)})
LOG.error(msg)
raise exception.HDFSException(msg)
if hdfs_state.upper() != 'HEALTHY':
if 'HEALTHY' in out:
return True
else:
return False
return True
def check_for_setup_error(self):
"""Return an error if the prerequisites are met."""

View File

@ -52,6 +52,7 @@ class HDFSNativeShareDriverTestCase(test.TestCase):
self._driver = hdfs_native.HDFSNativeShareDriver(
execute=self._hdfs_execute,
configuration=self.fake_conf)
self.hdfs_bin = 'hdfs'
self._driver._hdfs_bin = 'fake_hdfs_bin'
self.share = fake_share.fake_share(share_proto='HDFS')
self.snapshot = fake_share.fake_snapshot(share_proto='HDFS')
@ -66,9 +67,8 @@ class HDFSNativeShareDriverTestCase(test.TestCase):
['127.0.0.1', self.local_ip]))
def test_do_setup(self):
self._driver._get_hdfs_bin_path = mock.Mock()
self._driver.do_setup(self._context)
self._driver._get_hdfs_bin_path.assert_called_once_with()
self.assertEqual(self._driver._hdfs_bin, self.hdfs_bin)
def test_create_share(self):
self._driver._create_share = mock.Mock()