Merge lp:~tamura-yoshiaki/nova/bug-805312 into lp:~hudson-openstack/nova/trunk

Proposed by Yoshiaki Tamura
Status: Merged
Approved by: Vish Ishaya
Approved revision: 1246
Merged at revision: 1317
Proposed branch: lp:~tamura-yoshiaki/nova/bug-805312
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 76 lines (+23/-7)
2 files modified
nova/virt/libvirt.xml.template (+5/-1)
nova/virt/libvirt/connection.py (+18/-6)
To merge this branch: bzr merge lp:~tamura-yoshiaki/nova/bug-805312
Reviewer Review Type Date Requested Status
Christopher MacGown (community) Approve
Devin Carlen (community) Approve
Review via email: mp+66744@code.launchpad.net

Commit message

Fix boot from volume failure for network block devices.

This patch looks up the device_path and swithes between 'block' and 'network' when creating libvirt.xml.

To post a comment you must log in.
Revision history for this message
Devin Carlen (devcamcar) wrote :

This looks good but it looks like there is some logic is being duplicated:

35 + if vol['device_path'].startswith('/dev/'):
36 + vol['type'] = 'block'
37 + elif ':' in vol['device_path']:
38 + (protocol, name) = vol['device_path'].split(':')
39 + vol['type'] = 'network'
40 + vol['protocol'] = protocol
41 + vol['device_path'] = name
42 + else:
43 + raise exception.InvalidDevicePath(path=vol['device_path'])

There is very similar logic in the attach_volume method. I recommend fixing this so that there is no repetition. Maybe something like:

def _get_volume_device_type(self, device_path):
    if device_path.startswith('/dev/'):
        return 'block'
    elif ':' in device_path:
        return 'network'
    else:
        raise exception.InvalidDevicePath(path=device_path)

And then re-use that.

review: Needs Fixing
Revision history for this message
Yoshiaki Tamura (tamura-yoshiaki) wrote :

> This looks good but it looks like there is some logic is being duplicated:
>
> 35 + if vol['device_path'].startswith('/dev/'):
> 36 + vol['type'] = 'block'
> 37 + elif ':' in vol['device_path']:
> 38 + (protocol, name) = vol['device_path'].split(':')
> 39 + vol['type'] = 'network'
> 40 + vol['protocol'] = protocol
> 41 + vol['device_path'] = name
> 42 + else:
> 43 + raise
> exception.InvalidDevicePath(path=vol['device_path'])
>
> There is very similar logic in the attach_volume method. I recommend fixing
> this so that there is no repetition. Maybe something like:
>
> def _get_volume_device_type(self, device_path):
> if device_path.startswith('/dev/'):
> return 'block'
> elif ':' in device_path:
> return 'network'
> else:
> raise exception.InvalidDevicePath(path=device_path)
>
> And then re-use that.

Sorry for my slow response. Applied your comments.

Revision history for this message
Devin Carlen (devcamcar) wrote :

great, thanks!

review: Approve
Revision history for this message
Devin Carlen (devcamcar) wrote :

Don't forget to set it to "Ready for review" again.

Revision history for this message
Christopher MacGown (0x44) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'nova/virt/libvirt.xml.template'
--- nova/virt/libvirt.xml.template 2011-06-24 12:01:51 +0000
+++ nova/virt/libvirt.xml.template 2011-07-20 07:23:37 +0000
@@ -82,9 +82,13 @@
82 </disk>82 </disk>
83 #end if83 #end if
84 #for $vol in $volumes84 #for $vol in $volumes
85 <disk type='block'>85 <disk type='${vol.type}'>
86 <driver type='raw'/>86 <driver type='raw'/>
87 #if $vol.type == 'network'
88 <source protocol='${vol.protocol}' name='${vol.name}'/>
89 #else
87 <source dev='${vol.device_path}'/>90 <source dev='${vol.device_path}'/>
91 #end if
88 <target dev='${vol.mount_device}' bus='${disk_bus}'/>92 <target dev='${vol.mount_device}' bus='${disk_bus}'/>
89 </disk>93 </disk>
90 #end for94 #end for
9195
=== modified file 'nova/virt/libvirt/connection.py'
--- nova/virt/libvirt/connection.py 2011-07-13 18:19:32 +0000
+++ nova/virt/libvirt/connection.py 2011-07-20 07:23:37 +0000
@@ -335,21 +335,20 @@
335 def attach_volume(self, instance_name, device_path, mountpoint):335 def attach_volume(self, instance_name, device_path, mountpoint):
336 virt_dom = self._lookup_by_name(instance_name)336 virt_dom = self._lookup_by_name(instance_name)
337 mount_device = mountpoint.rpartition("/")[2]337 mount_device = mountpoint.rpartition("/")[2]
338 if device_path.startswith('/dev/'):338 (type, protocol, name) = \
339 self._get_volume_device_info(vol['device_path'])
340 if type == 'block':
339 xml = """<disk type='block'>341 xml = """<disk type='block'>
340 <driver name='qemu' type='raw'/>342 <driver name='qemu' type='raw'/>
341 <source dev='%s'/>343 <source dev='%s'/>
342 <target dev='%s' bus='virtio'/>344 <target dev='%s' bus='virtio'/>
343 </disk>""" % (device_path, mount_device)345 </disk>""" % (device_path, mount_device)
344 elif ':' in device_path:346 elif type == 'network':
345 (protocol, name) = device_path.split(':')
346 xml = """<disk type='network'>347 xml = """<disk type='network'>
347 <driver name='qemu' type='raw'/>348 <driver name='qemu' type='raw'/>
348 <source protocol='%s' name='%s'/>349 <source protocol='%s' name='%s'/>
349 <target dev='%s' bus='virtio'/>350 <target dev='%s' bus='virtio'/>
350 </disk>""" % (protocol,351 </disk>""" % (protocol, name, mount_device)
351 name,
352 mount_device)
353 else:352 else:
354 raise exception.InvalidDevicePath(path=device_path)353 raise exception.InvalidDevicePath(path=device_path)
355354
@@ -971,6 +970,16 @@
971 return True970 return True
972 return False971 return False
973972
973 @exception.wrap_exception
974 def _get_volume_device_info(self, device_path):
975 if device_path.startswith('/dev/'):
976 return ('block', None, None)
977 elif ':' in device_path:
978 (protocol, name) = device_path.split(':')
979 return ('network', protocol, name)
980 else:
981 raise exception.InvalidDevicePath(path=device_path)
982
974 def _prepare_xml_info(self, instance, rescue=False, network_info=None,983 def _prepare_xml_info(self, instance, rescue=False, network_info=None,
975 block_device_mapping=None):984 block_device_mapping=None):
976 block_device_mapping = block_device_mapping or []985 block_device_mapping = block_device_mapping or []
@@ -993,6 +1002,9 @@
9931002
994 for vol in block_device_mapping:1003 for vol in block_device_mapping:
995 vol['mount_device'] = _strip_dev(vol['mount_device'])1004 vol['mount_device'] = _strip_dev(vol['mount_device'])
1005 (vol['type'], vol['protocol'], vol['name']) = \
1006 self._get_volume_device_info(vol['device_path'])
1007
996 ebs_root = self._volume_in_mapping(self.root_mount_device,1008 ebs_root = self._volume_in_mapping(self.root_mount_device,
997 block_device_mapping)1009 block_device_mapping)
998 if self._volume_in_mapping(self.local_mount_device,1010 if self._volume_in_mapping(self.local_mount_device,