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) self.assertEqual(0, self.client.profiles.get.call_count)
container.stop.assert_called_once_with(wait=True) container.stop.assert_called_once_with(wait=True)
@mock.patch('os.readlink') @mock.patch('os.major')
def test_attach_volume(self, readlink): @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() profile = mock.Mock()
self.client.profiles.get.return_value = profile 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() ctx = context.get_admin_context()
instance = fake_instance.fake_instance_obj(ctx, name='test') instance = fake_instance.fake_instance_obj(ctx, name='test')
connection_info = fake_connection_info( connection_info = fake_connection_info(
{'id': 1, 'name': 'volume-00000001'}, {'id': 1, 'name': 'volume-00000001'},
'10.0.2.15:3260', 'iqn.2010-10.org.openstack:volume-00000001', '10.0.2.15:3260', 'iqn.2010-10.org.openstack:volume-00000001',
auth=True) auth=True)
mountpoint = mock.Mock() mountpoint = '/dev/sdd'
lxd_driver = driver.LXDDriver(None) lxd_driver = driver.LXDDriver(None)
lxd_driver.init_host(None) lxd_driver.init_host(None)

View File

@ -479,12 +479,14 @@ class LXDDriver(driver.ComputeDriver):
device_info = self.storage_driver.connect_volume( device_info = self.storage_driver.connect_volume(
connection_info['data']) 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'] vol_id = connection_info['data']['volume_id']
disk_device = { disk_device = {
vol_id: { 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' 'type': 'unix-block'
} }
} }