diff --git a/manila/share/drivers/hdfs/hdfs_native.py b/manila/share/drivers/hdfs/hdfs_native.py index de8d79b88a..d57717fe07 100644 --- a/manila/share/drivers/hdfs/hdfs_native.py +++ b/manila/share/drivers/hdfs/hdfs_native.py @@ -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.""" diff --git a/manila/tests/share/drivers/hdfs/test_hdfs_native.py b/manila/tests/share/drivers/hdfs/test_hdfs_native.py index e221e3389b..26cb3bd25d 100644 --- a/manila/tests/share/drivers/hdfs/test_hdfs_native.py +++ b/manila/tests/share/drivers/hdfs/test_hdfs_native.py @@ -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()