Skip to content

Commit

Permalink
baremetal: Make volume driver use a correct source device
Browse files Browse the repository at this point in the history
attach_volume() have to take the source device path from returning of
LibVirtVolumeDriver.connect_volume() rather than connection_info.

It also adds a test for attach_volume().

Change-Id: I3bee80560342104e2df614066301171624497a04
Closes-Bug: #1208707
  • Loading branch information
no2a committed Nov 11, 2013
1 parent 9c5b976 commit fbe3c73
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
40 changes: 40 additions & 0 deletions nova/tests/virt/baremetal/test_volume_driver.py
Expand Up @@ -163,6 +163,11 @@ def test_get_iqn(self):
self.assertEquals('iqn.2012-12.a.b:instname-dev-vdx', iqn)


class FakeConf(object):
def __init__(self, source_path):
self.source_path = source_path


class BareMetalLibVirtVolumeDriverTestCase(test.TestCase):

def setUp(self):
Expand All @@ -178,6 +183,14 @@ def setUp(self):
'type': 'baremetal',
}
self.connection_info = {'driver_volume_type': 'fake'}
self.mount_point = '/dev/vdc'
self.source_path = '/dev/sdx'
self.instance = {'name': 'instance-00000001'}
self.fixed_ips = [{'address': '10.2.3.4'},
{'address': '172.16.17.18'},
]
self.iqn = 'iqn.fake:instance-00000001-dev-vdc'
self.tid = 100

def test_init_loads_libvirt_volume_drivers(self):
self.assertEqual(type(self.driver.volume_drivers['fake']),
Expand All @@ -191,3 +204,30 @@ def test_fake_connect_volume(self):
self.driver._volume_driver_method('connect_volume',
self.connection_info,
self.disk_info)

def test_attach_volume(self):
self.mox.StubOutWithMock(volume_driver, '_get_fixed_ips')
self.mox.StubOutWithMock(self.driver, '_volume_driver_method')
self.mox.StubOutWithMock(volume_driver, '_get_iqn')
self.mox.StubOutWithMock(volume_driver, '_get_next_tid')
self.mox.StubOutWithMock(volume_driver, '_create_iscsi_export_tgtadm')
self.mox.StubOutWithMock(volume_driver, '_allow_iscsi_tgtadm')
volume_driver._get_fixed_ips(self.instance).AndReturn(self.fixed_ips)
self.driver._volume_driver_method('connect_volume',
self.connection_info,
self.disk_info).\
AndReturn(FakeConf(self.source_path))
volume_driver._get_iqn(self.instance['name'], self.mount_point).\
AndReturn(self.iqn)
volume_driver._get_next_tid().AndReturn(self.tid)
volume_driver._create_iscsi_export_tgtadm(self.source_path,
self.tid,
self.iqn)
volume_driver._allow_iscsi_tgtadm(self.tid,
self.fixed_ips[0]['address'])
volume_driver._allow_iscsi_tgtadm(self.tid,
self.fixed_ips[1]['address'])
self.mox.ReplayAll()
self.driver.attach_volume(self.connection_info,
self.instance,
self.mount_point)
13 changes: 9 additions & 4 deletions nova/virt/baremetal/volume_driver.py
Expand Up @@ -235,10 +235,15 @@ def attach_volume(self, connection_info, instance, mountpoint):
'No fixed PXE IP is associated to %s') % instance['uuid'])

mount_device = mountpoint.rpartition("/")[2]
self._volume_driver_method('connect_volume',
connection_info,
mount_device)
device_path = connection_info['data']['device_path']
disk_info = {
'dev': mount_device,
'bus': 'baremetal',
'type': 'baremetal',
}
conf = self._volume_driver_method('connect_volume',
connection_info,
disk_info)
device_path = conf.source_path
iqn = _get_iqn(instance['name'], mountpoint)
tid = _get_next_tid()
_create_iscsi_export_tgtadm(device_path, tid, iqn)
Expand Down

0 comments on commit fbe3c73

Please sign in to comment.