diff options
| author | Chuck Short <chuck.short@canonical.com> | 2013-02-15 14:07:03 -0600 |
|---|---|---|
| committer | Chuck Short <chuck.short@canonical.com> | 2013-02-16 07:31:46 -0600 |
| commit | 4cc266427307f4d9776207d30ceb1fbec35b3111 (patch) | |
| tree | 1ad08597a5c78c9268f0495bf25536741d5bc856 | |
| parent | dc5a994e333c743f8ae8970ce0a2d8ca8c48d9f3 (diff) | |
libvirt: Fix LXC container creation
Recent changes to the blockdev creation introduced in
7be531fe9462f2b07d4a1abf6687f649d1dfbb89 caused a regression
when LXC containers were being created.
When the image is being fetched from glance, the disk mappings
for the disk bus, disk information, etc is checked before being
copied. However since LXC does not understand this concept it was
not passing any information, so the image was never being copied.
Send some basic information about the disk when the instance is being
created in order for the image to begin. Fixes LP: #1126348
Change-Id: I90daf853903737013be0cd23f78c7f61e4e15a77
Signed-off-by: Chuck Short <chuck.short@canonical.com>
| -rw-r--r-- | nova/tests/test_libvirt_blockinfo.py | 15 | ||||
| -rw-r--r-- | nova/virt/libvirt/blockinfo.py | 21 | ||||
| -rwxr-xr-x | nova/virt/libvirt/driver.py | 2 |
3 files changed, 37 insertions, 1 deletions
diff --git a/nova/tests/test_libvirt_blockinfo.py b/nova/tests/test_libvirt_blockinfo.py index 68f1fa394..5560e63fd 100644 --- a/nova/tests/test_libvirt_blockinfo.py +++ b/nova/tests/test_libvirt_blockinfo.py @@ -178,6 +178,21 @@ class LibvirtBlockInfoTest(test.TestCase): } self.assertEqual(mapping, expect) + def test_get_disk_mapping_lxc(self): + # A simple disk mapping setup, but for lxc + + user_context = context.RequestContext(self.user_id, self.project_id) + instance_ref = db.instance_create(user_context, self.test_instance) + + mapping = blockinfo.get_disk_mapping("lxc", instance_ref, + "lxc", "lxc", + None) + expect = { + 'disk': {'bus': 'lxc', 'dev': None, 'type': 'disk'}, + 'root': {'bus': 'lxc', 'dev': None, 'type': 'disk'} + } + self.assertEqual(mapping, expect) + def test_get_disk_mapping_simple_iso(self): # A simple disk mapping setup, but with a ISO for root device diff --git a/nova/virt/libvirt/blockinfo.py b/nova/virt/libvirt/blockinfo.py index 0098410cd..09e3809d9 100644 --- a/nova/virt/libvirt/blockinfo.py +++ b/nova/virt/libvirt/blockinfo.py @@ -116,6 +116,8 @@ def get_dev_prefix_for_disk_bus(disk_bus): return "sd" elif disk_bus == "uml": return "ubd" + elif disk_bus == "lxc": + return None else: raise exception.NovaException( _("Unable to determine disk prefix for %s") % @@ -150,6 +152,9 @@ def find_disk_dev_for_disk_bus(mapping, bus, last_device=False): """ dev_prefix = get_dev_prefix_for_disk_bus(bus) + if dev_prefix is None: + return None + max_dev = get_dev_count_for_disk_bus(bus) if last_device: devs = [max_dev - 1] @@ -172,6 +177,7 @@ def is_disk_bus_valid_for_virt(virt_type, disk_bus): 'kvm': ['virtio', 'scsi', 'ide', 'usb'], 'xen': ['xen', 'ide'], 'uml': ['uml'], + 'lxc': ['lxc'], } if virt_type not in valid_bus: @@ -207,6 +213,8 @@ def get_disk_bus_for_device_type(virt_type, if virt_type == "uml": if device_type == "disk": return "uml" + elif virt_type == "lxc": + return "lxc" elif virt_type == "xen": if device_type == "cdrom": return "ide" @@ -293,6 +301,19 @@ def get_disk_mapping(virt_type, instance, mapping = {} if virt_type == "lxc": + # NOTE(zul): This information is not used by the libvirt driver + # however we need to populate mapping so the image can be + # created when the instance is started. This can + # be removed when we convert LXC to use block devices. + root_disk_bus = disk_bus + root_device_type = 'disk' + + root_info = get_next_disk_info(mapping, + root_disk_bus, + root_device_type) + mapping['root'] = root_info + mapping['disk'] = root_info + return mapping if rescue: diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 4e2fb9d39..fde085525 100755 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -1794,7 +1794,7 @@ class LibvirtDriver(driver.ComputeDriver): guest.cpu = self.get_guest_cpu_config() - if 'root' in disk_mapping: + if 'root' in disk_mapping and disk_mapping['root']['dev'] is not None: root_device_name = "/dev/" + disk_mapping['root']['dev'] else: root_device_name = None |
