Merge "Fix usability issue when attaching block device"

This commit is contained in:
Jenkins 2016-09-26 20:41:48 +00:00 committed by Gerrit Code Review
commit 1153d1f129
2 changed files with 14 additions and 6 deletions

View File

@ -812,18 +812,24 @@ class LXDDriverTest(test.NoDBTestCase):
self.assertEqual(0, self.client.profiles.get.call_count)
container.stop.assert_called_once_with(wait=True)
@mock.patch('os.readlink')
def test_attach_volume(self, readlink):
@mock.patch('os.major')
@mock.patch('os.minor')
@mock.patch('os.stat')
@mock.patch('os.path.realpath')
def test_attach_volume(self, realpath, stat, minor, major):
profile = mock.Mock()
self.client.profiles.get.return_value = profile
readlink.return_value = '/dev/sdc'
realpath.return_value = '/dev/sdc'
stat.return_value.st_rdev = 2080
minor.return_value = 32
major.return_value = 8
ctx = context.get_admin_context()
instance = fake_instance.fake_instance_obj(ctx, name='test')
connection_info = fake_connection_info(
{'id': 1, 'name': 'volume-00000001'},
'10.0.2.15:3260', 'iqn.2010-10.org.openstack:volume-00000001',
auth=True)
mountpoint = mock.Mock()
mountpoint = '/dev/sdd'
lxd_driver = driver.LXDDriver(None)
lxd_driver.init_host(None)

View File

@ -479,12 +479,14 @@ class LXDDriver(driver.ComputeDriver):
device_info = self.storage_driver.connect_volume(
connection_info['data'])
disk = os.readlink(device_info['path']).rpartition("/")[2]
disk = os.stat(os.path.realpath(device_info['path']))
vol_id = connection_info['data']['volume_id']
disk_device = {
vol_id: {
'path': '/dev/%s' % disk,
'path': mountpoint,
'major': '%s' % os.major(disk.st_rdev),
'minor': '%s' % os.minor(disk.st_rdev),
'type': 'unix-block'
}
}