diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-10-24 21:52:49 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-10-24 21:52:49 +0000 |
| commit | 43aa3f13d780c24df64086ecebf9dd2fc139c764 (patch) | |
| tree | bc9adb5f488cbabc8383e9ec75d3659fa1a41d62 /nova | |
| parent | 805a875e46716d1ad515a6f552e4e5492c204072 (diff) | |
| parent | fb94618662006a076899f9741383acac09bfd024 (diff) | |
Merge "Remove mountpoint from parse_volume_info"
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/tests/test_xenapi.py | 15 | ||||
| -rw-r--r-- | nova/virt/xenapi/volume_utils.py | 16 | ||||
| -rw-r--r-- | nova/virt/xenapi/volumeops.py | 6 |
3 files changed, 21 insertions, 16 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index d50379b48..7b92c352d 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -215,20 +215,19 @@ class XenAPIVolumeTestCase(stubs.XenAPITestBase): self.assertEqual(actual, expected, '%s yielded %s, not %s' % (input, actual, expected)) - def test_parse_volume_info_raise_exception(self): - self.assertRaises(volume_utils.StorageError, - volume_utils.parse_volume_info, - self._make_connection_data(), - 'dev/sd' - ) - def test_parse_volume_info_parsing_auth_details(self): result = volume_utils.parse_volume_info( - self._make_connection_data(), '/dev/sda') + self._make_connection_data()) self.assertEquals('username', result['chapuser']) self.assertEquals('password', result['chappassword']) + def test_get_device_number_raise_exception_on_wrong_mountpoint(self): + self.assertRaises( + volume_utils.StorageError, + volume_utils.get_device_number, + 'dev/sd') + def test_attach_volume(self): """This shows how to test Ops classes' methods.""" stubs.stubout_session(self.stubs, stubs.FakeSessionForVolumeTests) diff --git a/nova/virt/xenapi/volume_utils.py b/nova/virt/xenapi/volume_utils.py index cbad15b99..7de29bf24 100644 --- a/nova/virt/xenapi/volume_utils.py +++ b/nova/virt/xenapi/volume_utils.py @@ -275,7 +275,15 @@ def purge_sr(session, sr_ref): forget_sr(session, sr_rec['uuid']) -def parse_volume_info(connection_data, mountpoint): +def get_device_number(mountpoint): + device_number = mountpoint_to_number(mountpoint) + if device_number < 0: + raise StorageError(_('Unable to obtain target information' + ' %(mountpoint)s') % locals()) + return device_number + + +def parse_volume_info(connection_data): """ Parse device_path and mountpoint as they can be used by XenAPI. In particular, the mountpoint (e.g. /dev/sdc) must be translated @@ -288,7 +296,6 @@ def parse_volume_info(connection_data, mountpoint): db in the iscsi_target table with the necessary info and modify the iscsi driver to set them. """ - device_number = mountpoint_to_number(mountpoint) volume_id = connection_data['volume_id'] target_portal = connection_data['target_portal'] target_host = _get_target_host(target_portal) @@ -296,12 +303,11 @@ def parse_volume_info(connection_data, mountpoint): target_iqn = connection_data['target_iqn'] LOG.debug('(vol_id,number,host,port,iqn): (%s,%s,%s,%s)', volume_id, target_host, target_port, target_iqn) - if (device_number < 0 or - volume_id is None or + if (volume_id is None or target_host is None or target_iqn is None): raise StorageError(_('Unable to obtain target information' - ' %(connection_data)s, %(mountpoint)s') % locals()) + ' %(connection_data)s') % locals()) volume_info = {} volume_info['id'] = volume_id volume_info['target'] = target_host diff --git a/nova/virt/xenapi/volumeops.py b/nova/virt/xenapi/volumeops.py index f5ca8af2d..715554c5a 100644 --- a/nova/virt/xenapi/volumeops.py +++ b/nova/virt/xenapi/volumeops.py @@ -119,6 +119,8 @@ class VolumeOps(object): raise exception.VolumeDriverNotFound(driver_type=driver_type) connection_data = connection_info['data'] + dev_number = volume_utils.get_device_number(mountpoint) + if 'name_label' not in connection_data: label = 'tempSR-%s' % connection_data['volume_id'] else: @@ -133,8 +135,7 @@ class VolumeOps(object): LOG.debug(connection_info) sr_params = {} if u'sr_uuid' not in connection_data: - sr_params = volume_utils.parse_volume_info(connection_data, - mountpoint) + sr_params = volume_utils.parse_volume_info(connection_data) uuid = "FA15E-D15C-" + str(sr_params['id']) sr_params['sr_type'] = 'iscsi' else: @@ -172,7 +173,6 @@ class VolumeOps(object): raise Exception(_('Unable to create VDI on SR %(sr_ref)s for' ' instance %(instance_name)s') % locals()) - dev_number = volume_utils.mountpoint_to_number(mountpoint) try: vbd_ref = vm_utils.create_vbd(self._session, vm_ref, vdi_ref, dev_number, bootable=False) |
