Check for device node availability before mkfs

When using the generic driver, a volume is attached to the service
VM and then a mkfs is done to create a FS on that volume inside of
the VM. But it can be the case that it takes a bit of time before
the device node pops up inside of the VM. So wait some seconds
before doing a mkfs on a non-existing device node.

Change-Id: I42228d9a8ad836a95be5c59e43bd6762677dd85f
Closes-bug: #1547000
This commit is contained in:
Thomas Bechtold 2016-02-18 14:26:45 +01:00
parent f13e5ab039
commit b8e3f981a7
2 changed files with 22 additions and 0 deletions

View File

@ -250,8 +250,15 @@ class GenericShareDriver(driver.ExecuteMixin, driver.ShareDriver):
},
}
@utils.retry(exception.ProcessExecutionError, backoff_rate=1)
def _is_device_file_available(self, server_details, volume):
"""Checks whether the device file is available"""
command = ['sudo', 'test', '-b', volume['mountpoint']]
self._ssh_exec(server_details, command)
def _format_device(self, server_details, volume):
"""Formats device attached to the service vm."""
self._is_device_file_available(server_details, volume)
command = ['sudo', 'mkfs.%s' % self.configuration.share_volume_fstype,
volume['mountpoint']]
self._ssh_exec(server_details, command)

View File

@ -369,11 +369,26 @@ class GenericShareDriverTestCase(test.TestCase):
self.assertRaises(exception.InvalidShare, self._driver.create_share,
self._context, self.share, share_server=self.server)
def test_is_device_file_available(self):
volume = {'mountpoint': 'fake_mount_point'}
self.mock_object(self._driver, '_ssh_exec',
mock.Mock(return_value=None))
self._driver._is_device_file_available(self.server, volume)
self._driver._ssh_exec.assert_called_once_with(
self.server, ['sudo', 'test', '-b', volume['mountpoint']])
def test_format_device(self):
volume = {'mountpoint': 'fake_mount_point'}
self.mock_object(self._driver, '_ssh_exec',
mock.Mock(return_value=('', '')))
self.mock_object(self._driver, '_is_device_file_available')
self._driver._format_device(self.server, volume)
self._driver._is_device_file_available.assert_called_once_with(
self.server, volume)
self._driver._ssh_exec.assert_called_once_with(
self.server,
['sudo', 'mkfs.%s' % self.fake_conf.share_volume_fstype,