From 1278af43c16daea1bcbd2d47cd2d81919fe2c37e Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Sun, 27 Feb 2011 12:51:19 -0500 Subject: Add lxc libvirt driver --- nova/virt/libvirt.xml.template | 14 ++++++++++++++ nova/virt/libvirt_conn.py | 13 +++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/nova/virt/libvirt.xml.template b/nova/virt/libvirt.xml.template index 88bfbc668..87dea9039 100644 --- a/nova/virt/libvirt.xml.template +++ b/nova/virt/libvirt.xml.template @@ -2,6 +2,12 @@ ${name} ${memory_kb} +#if $type == 'lxc' + #set $disk_prefix = '' + #set $disk_bus = '' + exe + /sbin/init +#else #if $type == 'uml' #set $disk_prefix = 'ubd' #set $disk_bus = 'uml' @@ -37,6 +43,7 @@ #end if #end if + #end if #end if @@ -44,6 +51,12 @@ ${vcpus} +#if $type == 'lxc' + + + + +#else #if $getVar('rescue', False) @@ -68,6 +81,7 @@ #end if + #end if #end if diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index 4e0fd106f..f97c10765 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -20,7 +20,7 @@ """ A connection to a hypervisor through libvirt. -Supports KVM, QEMU, UML, and XEN. +Supports KVM, LXC, QEMU, UML, and XEN. **Related Flags** @@ -83,7 +83,7 @@ flags.DEFINE_string('libvirt_xml_template', flags.DEFINE_string('libvirt_type', 'kvm', 'Libvirt domain type (valid options are: ' - 'kvm, qemu, uml, xen)') + 'kvm, lxc, qemu, uml, xen)') flags.DEFINE_string('libvirt_uri', '', 'Override the default libvirt URI (which is dependent' @@ -202,6 +202,8 @@ class LibvirtConnection(object): uri = FLAGS.libvirt_uri or 'uml:///system' elif FLAGS.libvirt_type == 'xen': uri = FLAGS.libvirt_uri or 'xen:///' + elif FLAGS.libvirt_type == 'lxc': + uri = FLAGS.libvirt_uri or 'lxc:///' else: uri = FLAGS.libvirt_uri or 'qemu:///system' return uri @@ -565,6 +567,10 @@ class LibvirtConnection(object): f.write(libvirt_xml) f.close() + if FLAGS.libvirt_type == 'lxc': + container_dir = '%s/rootfs' % basepath(suffix='') + utils.execute('mkdir -p %s' % container_dir) + # NOTE(vish): No need add the suffix to console.log os.close(os.open(basepath('console.log', ''), os.O_CREAT | os.O_WRONLY, 0660)) @@ -622,6 +628,9 @@ class LibvirtConnection(object): if not inst['kernel_id']: target_partition = "1" + if FLAGS.libvirt_type == 'lxc': + target_partition = None + key = str(inst['key_data']) net = None network_ref = db.network_get_by_instance(context.get_admin_context(), -- cgit From 2d6987d8c33477af19179e7664bbedf689bc08dc Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Sun, 27 Feb 2011 13:05:26 -0500 Subject: Add ability to mount containers --- nova/virt/disk.py | 26 ++++++++++++++++++++++++++ nova/virt/libvirt_conn.py | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index 2bded07a4..7cbc4a3be 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -114,6 +114,32 @@ def inject_data(image, key=None, net=None, partition=None, nbd=False): _unlink_device(device, nbd) +def setup_container(image, container_dir=None, partition=None, nbd=False): + """Setup the LXC container + + It will mount the loopback image to the container directory in order + to create the root filesystem for the container + """ + device = _link_device(image, nbd) + try: + if not partition is None: + # create partition + utils.execute('sudo kpartx -a %s' % device) + mapped_device = '/dev/mapper/%p%s' % (device.split('/')[-1], + partition) + else: + mapped_device = device + + utils.execute('sudo mount %s %s' %(mapped_device, container_dir)) + + except Exception as e: + LOG.warn(_('Unable to mount container')) + if not partition is None: + # remove partitions + utils.execute('sudo kpartx -s %s' % device) + _unlink_device(device, nbd) + + def _link_device(image, nbd): """Link image to device using loopback or nbd""" if nbd: diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index f97c10765..f7807a851 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -661,6 +661,12 @@ class LibvirtConnection(object): disk.inject_data(basepath('disk'), key, net, partition=target_partition, nbd=FLAGS.use_cow_images) + + if FLAGS.libvirt_type == 'lxc': + disk.setup_container(basepath('disk'), + container_dir=container_dir, + partition=target_partition, + nbd=FLAGS.use_cow_images) except Exception as e: # This could be a windows image, or a vmdk format disk LOG.warn(_('instance %(inst_name)s: ignoring error injecting' -- cgit From 33d7edb9d02d8f4dcb0b6ee85caf10434f060e1b Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Sun, 27 Feb 2011 13:29:05 -0500 Subject: Clean up the mount points when it shutsdown --- nova/virt/disk.py | 1 - nova/virt/libvirt_conn.py | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index 7cbc4a3be..28a4c11fb 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -139,7 +139,6 @@ def setup_container(image, container_dir=None, partition=None, nbd=False): utils.execute('sudo kpartx -s %s' % device) _unlink_device(device, nbd) - def _link_device(image, nbd): """Link image to device using loopback or nbd""" if nbd: diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index f7807a851..5e76edb0b 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -259,6 +259,8 @@ class LibvirtConnection(object): instance_name = instance['name'] LOG.info(_('instance %(instance_name)s: deleting instance files' ' %(target)s') % locals()) + if FLAGS.libvirt_type == 'lxc': + utils.execute('sudo umount %s/rootfs' % target) if os.path.exists(target): shutil.rmtree(target) -- cgit From 031205a26ae6fe906a47eefa716bbd575687c479 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Sun, 27 Feb 2011 13:35:10 -0500 Subject: Add lxc to the libvirt tests --- nova/tests/test_virt.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index f151ae911..04f943a1f 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -112,12 +112,15 @@ class LibvirtConnTestCase(test.TestCase): 'uml': ('uml:///system', [(lambda t: t.find('.').get('type'), 'uml'), (lambda t: t.find('./os/type').text, 'uml')]), + 'lxc': ('lxc://', + [(lambda t: t.find('.').get('type'), 'lxc'), + (lambda t: t.find('./os/type').text, 'lxc')]), 'xen': ('xen:///', [(lambda t: t.find('.').get('type'), 'xen'), (lambda t: t.find('./os/type').text, 'linux')]), } - for hypervisor_type in ['qemu', 'kvm', 'xen']: + for hypervisor_type in ['qemu', 'kvm', 'lxc', 'xen']: check_list = type_uri_map[hypervisor_type][1] if rescue: -- cgit From e502ad0243962aca98cc28bfa5cf69f8cd08991c Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Wed, 9 Mar 2011 21:43:45 -0500 Subject: Moved umount container to disk.py and try to remove loopback when destroying the container --- nova/virt/disk.py | 8 ++++++++ nova/virt/libvirt_conn.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index e1b0171b5..484317dd8 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -140,6 +140,14 @@ def setup_container(image, container_dir=None, partition=None, nbd=False): utils.execute('sudo kpartx -s %s' % device) _unlink_device(device, nbd) +def destroy_container(target, instance, nbd=False): + """Destroy the container once it terminates""" + try: + utils.execute('sudo umount %s/rootfs' % target) + image = os.path.join(FLAGS.instances_path, instance['name'], '' + 'disk') + except Exception as e: + LOG.warn(_('Unable to umount contianer')) + def _link_device(image, nbd): """Link image to device using loopback or nbd""" if nbd: diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index 97997513b..ef0eb20cd 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -260,7 +260,7 @@ class LibvirtConnection(object): LOG.info(_('instance %(instance_name)s: deleting instance files' ' %(target)s') % locals()) if FLAGS.libvirt_type == 'lxc': - utils.execute('sudo umount %s/rootfs' % target) + disk.destroy_container(target, instance, nbd=FLAGS.use_cow_images) if os.path.exists(target): shutil.rmtree(target) -- cgit From 743e82c0acac0fda78a55a8bbb65e601c4cb652c Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Mon, 14 Mar 2011 21:14:39 -0400 Subject: Refactor setup contianer/destroy container --- nova/virt/disk.py | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index f0b391efb..a3db1d882 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -122,31 +122,26 @@ def setup_container(image, container_dir=None, partition=None, nbd=False): to create the root filesystem for the container """ device = _link_device(image, nbd) - try: - if not partition is None: - # create partition - utils.execute('sudo kpartx -a %s' % device) - mapped_device = '/dev/mapper/%p%s' % (device.split('/')[-1], - partition) - else: - mapped_device = device - - utils.execute('sudo mount %s %s' %(mapped_device, container_dir)) - - except Exception as e: - LOG.warn(_('Unable to mount container')) - if not partition is None: - # remove partitions - utils.execute('sudo kpartx -s %s' % device) + err = utils.execute('sudo', 'mount', mapped_device, container_dir) + if err: + raise exception.Error(_('Failed to mount filesystem: %s') + % err) _unlink_device(device, nbd) def destroy_container(target, instance, nbd=False): """Destroy the container once it terminates""" try: - utils.execute('sudo umount %s/rootfs' % target) + container_dir = '%s/rootfs' % target + utils.execute('sudo', 'umount', container_dir) + finally: image = os.path.join(FLAGS.instances_path, instance['name'], '' + 'disk') - except Exception as e: - LOG.warn(_('Unable to umount contianer')) + out, err = utils.execute('sudo', 'losetup', '--find', '--show', image) + device = out.strip() + if err: + raise execption.Error(_('Could not find loopback image: %s') + %err) + utils.execute('sudo', 'losetup', '--detach', device) + def _link_device(image, nbd): """Link image to device using loopback or nbd""" -- cgit From 48d3dd7f9d2633d8955080b6dccc7c97bc8ef7c3 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Tue, 15 Mar 2011 07:56:26 -0400 Subject: Mount the right device --- nova/virt/disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index a3db1d882..2c0460f39 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -122,7 +122,7 @@ def setup_container(image, container_dir=None, partition=None, nbd=False): to create the root filesystem for the container """ device = _link_device(image, nbd) - err = utils.execute('sudo', 'mount', mapped_device, container_dir) + err = utils.execute('sudo', 'mount', device, container_dir) if err: raise exception.Error(_('Failed to mount filesystem: %s') % err) -- cgit From f60c9d0da8171b09bd7971fea52e9e032f98a143 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Tue, 15 Mar 2011 08:05:45 -0400 Subject: Add comments about the destroy container function --- nova/virt/disk.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index 2c0460f39..dd4352957 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -129,7 +129,11 @@ def setup_container(image, container_dir=None, partition=None, nbd=False): _unlink_device(device, nbd) def destroy_container(target, instance, nbd=False): - """Destroy the container once it terminates""" + """Destroy the container once it terminates + + It will umount the container that is mounted, try to find the loopback + device associated with the container and delete it. + """ try: container_dir = '%s/rootfs' % target utils.execute('sudo', 'umount', container_dir) -- cgit From 3c10c1ee1bcc3f3aad90e4e28761d1413ab203a9 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Tue, 15 Mar 2011 09:36:02 -0400 Subject: Really delete the loop --- nova/virt/disk.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index dd4352957..a44995613 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -23,6 +23,7 @@ Includes injection of SSH PGP keys into authorized_keys file. """ import os +import string import tempfile import time @@ -138,13 +139,10 @@ def destroy_container(target, instance, nbd=False): container_dir = '%s/rootfs' % target utils.execute('sudo', 'umount', container_dir) finally: - image = os.path.join(FLAGS.instances_path, instance['name'], '' + 'disk') - out, err = utils.execute('sudo', 'losetup', '--find', '--show', image) - device = out.strip() - if err: - raise execption.Error(_('Could not find loopback image: %s') - %err) - utils.execute('sudo', 'losetup', '--detach', device) + for loop in os.popen('sudo losetup -a').readlines(): + if instance['name'] in loop: + device = string.split(loop, ':') + utils.execute('sudo', 'losetup', '--detach', device) def _link_device(image, nbd): -- cgit From 7fbf061666516705e74592c3660155e86d3da895 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Wed, 16 Mar 2011 09:15:46 -0400 Subject: Fix up testsuite for lxc --- nova/tests/test_virt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index c149c9307..b3ca241cb 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -256,9 +256,9 @@ class LibvirtConnTestCase(test.TestCase): 'uml': ('uml:///system', [(lambda t: t.find('.').get('type'), 'uml'), (lambda t: t.find('./os/type').text, 'uml')]), - 'lxc': ('lxc://', + 'lxc': ('lxc://;', [(lambda t: t.find('.').get('type'), 'lxc'), - (lambda t: t.find('./os/type').text, 'lxc')]), + (lambda t: t.find('./os/type').text, 'exe')]), 'xen': ('xen:///', [(lambda t: t.find('.').get('type'), 'xen'), (lambda t: t.find('./os/type').text, 'linux')]), -- cgit From 8f9a5ecb7d3907456b9a77f3321ed09feb5c5f2f Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Wed, 16 Mar 2011 09:24:17 -0400 Subject: More execvp fallout --- nova/virt/libvirt_conn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index af2cbdce5..a79e0a065 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -599,7 +599,7 @@ class LibvirtConnection(object): if FLAGS.libvirt_type == 'lxc': container_dir = '%s/rootfs' % basepath(suffix='') - utils.execute('mkdir -p %s' % container_dir) + utils.execute('mkdir', '-p', container_dir) # NOTE(vish): No need add the suffix to console.log os.close(os.open(basepath('console.log', ''), -- cgit From a21efc63be6bad3bbde41eb96d6a1752e6d8174d Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Wed, 16 Mar 2011 09:26:37 -0400 Subject: Really fix testcase --- nova/tests/test_virt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index b3ca241cb..fed8ff803 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -256,7 +256,7 @@ class LibvirtConnTestCase(test.TestCase): 'uml': ('uml:///system', [(lambda t: t.find('.').get('type'), 'uml'), (lambda t: t.find('./os/type').text, 'uml')]), - 'lxc': ('lxc://;', + 'lxc': ('lxc:///', [(lambda t: t.find('.').get('type'), 'lxc'), (lambda t: t.find('./os/type').text, 'exe')]), 'xen': ('xen:///', -- cgit From c44ab013f5f5a078b27c4965e2e3c4abbfe30c59 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Wed, 16 Mar 2011 20:42:39 -0400 Subject: Revert testsuite changes --- nova/tests/test_virt.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index fed8ff803..b214f5ce7 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -256,15 +256,12 @@ class LibvirtConnTestCase(test.TestCase): 'uml': ('uml:///system', [(lambda t: t.find('.').get('type'), 'uml'), (lambda t: t.find('./os/type').text, 'uml')]), - 'lxc': ('lxc:///', - [(lambda t: t.find('.').get('type'), 'lxc'), - (lambda t: t.find('./os/type').text, 'exe')]), 'xen': ('xen:///', [(lambda t: t.find('.').get('type'), 'xen'), (lambda t: t.find('./os/type').text, 'linux')]), } - for hypervisor_type in ['qemu', 'kvm', 'lxc', 'xen']: + for hypervisor_type in ['qemu', 'kvm', 'xen']: check_list = type_uri_map[hypervisor_type][1] if rescue: -- cgit From fea850245835f867aa4cc741b612445e56e64236 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Wed, 16 Mar 2011 20:52:14 -0400 Subject: Add basic tests for lxc containers. --- nova/tests/test_virt.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index b214f5ce7..fab05de10 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -227,6 +227,42 @@ class LibvirtConnTestCase(test.TestCase): self._check_xml_and_uri(instance_data, expect_kernel=True, expect_ramdisk=True, rescue=True) + def test_lxc_container_and_uri(self): + instance_data = dict(self.test_instace) + self._check_xml_and_container(instance_data) + + def _check_xml_and_container(self, instance): + user_context = context.RequestContext(project=self.project, + user=self.user) + instance_ref = db.instance_create(user_context,instance) + host = self.network.get_network_host(user_context.elevated()) + network_ref= db.project_get_network(context.get_admin_context(), + self.project.id) + + fixed_ip = {'address': self.test_ip, + 'network_id': network_ref['id']} + + ctxt = context.get_admin_context() + fixed_ip_ref = db.fixed_ip_create(ctxt, fixed_ip) + db.fixed_ip_update(ctxt, self.test_ip, + {'allocated': True, + 'instance_id': instance_ref['id']}) + + FLAGS.libvirt_type = 'lxc' + self.assertEquals(uri, 'lxc:///') + + xml = conn.to_xml(instance_ref) + tree = xml_to_tree(xml) + + check = [ + (lambda t: t.find('.').get('type'), 'lxc'), + (lambda t: t.find('./os/type').text, 'exe') + ] + + for i (check, expected_result) in enumerate(check): + self.aseertEqual(check(time), + expected_result, + '%s failed common check %d' % (xml, i)) def _check_xml_and_uri(self, instance, expect_ramdisk, expect_kernel, rescue=False): user_context = context.RequestContext(project=self.project, -- cgit From 7f837b1f22922cb968b0ffb42bdb4d56c0d9f3c3 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 17 Mar 2011 07:06:58 -0400 Subject: Update Authors and testsuite --- Authors | 1 + nova/tests/test_virt.py | 41 ++++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Authors b/Authors index 9aad104a7..12d2f02de 100644 --- a/Authors +++ b/Authors @@ -11,6 +11,7 @@ Chiradeep Vittal Chmouel Boudjnah Chris Behrens Christian Berendt +Chuck Short Cory Wright Dan Prince David Pravec diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index fab05de10..92c80272b 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -228,16 +228,16 @@ class LibvirtConnTestCase(test.TestCase): expect_ramdisk=True, rescue=True) def test_lxc_container_and_uri(self): - instance_data = dict(self.test_instace) + instance_data = dict(self.test_instance) self._check_xml_and_container(instance_data) def _check_xml_and_container(self, instance): user_context = context.RequestContext(project=self.project, user=self.user) - instance_ref = db.instance_create(user_context,instance) + instance_ref = db.instance_create(user_context, instance) host = self.network.get_network_host(user_context.elevated()) - network_ref= db.project_get_network(context.get_admin_context(), - self.project.id) + network_ref = db.project_get_network(context.get_admin_context(), + self.project.id) fixed_ip = {'address': self.test_ip, 'network_id': network_ref['id']} @@ -245,24 +245,28 @@ class LibvirtConnTestCase(test.TestCase): ctxt = context.get_admin_context() fixed_ip_ref = db.fixed_ip_create(ctxt, fixed_ip) db.fixed_ip_update(ctxt, self.test_ip, - {'allocated': True, - 'instance_id': instance_ref['id']}) + {'allocated': True, + 'instance_id': instance_ref['id']}) FLAGS.libvirt_type = 'lxc' + conn = libvirt_conn.LibvirtConnection(True) + + uri = conn.get_uri() self.assertEquals(uri, 'lxc:///') xml = conn.to_xml(instance_ref) tree = xml_to_tree(xml) check = [ - (lambda t: t.find('.').get('type'), 'lxc'), - (lambda t: t.find('./os/type').text, 'exe') + (lambda t: t.find('.').get('type'), 'lxc'), + (lambda t: t.find('./os/type').text, 'exe'), ] - for i (check, expected_result) in enumerate(check): - self.aseertEqual(check(time), + for i, (check, expected_result) in enumerate(check): + self.assertEqual(check(tree), expected_result, '%s failed common check %d' % (xml, i)) + def _check_xml_and_uri(self, instance, expect_ramdisk, expect_kernel, rescue=False): user_context = context.RequestContext(project=self.project, @@ -322,6 +326,7 @@ class LibvirtConnTestCase(test.TestCase): check = (lambda t: t.find('./os/initrd'), None) check_list.append(check) + common_checks = [ (lambda t: t.find('.').tag, 'domain'), (lambda t: t.find( @@ -338,8 +343,9 @@ class LibvirtConnTestCase(test.TestCase): (lambda t: t.find('./devices/serial/source').get( 'path').split('/')[1], 'console.log'), (lambda t: t.find('./memory').text, '2097152')] + if rescue: - common_checks += [ + common_checks = [ (lambda t: t.findall('./devices/disk/source')[0].get( 'file').split('/')[1], 'disk.rescue'), (lambda t: t.findall('./devices/disk/source')[1].get( @@ -362,14 +368,15 @@ class LibvirtConnTestCase(test.TestCase): xml = conn.to_xml(instance_ref, rescue) tree = xml_to_tree(xml) for i, (check, expected_result) in enumerate(checks): - self.assertEqual(check(tree), - expected_result, - '%s failed check %d' % (xml, i)) + self.assertEqual(check(tree), + expected_result, + '%s failed check %d' % (xml, i)) + for i, (check, expected_result) in enumerate(common_checks): - self.assertEqual(check(tree), - expected_result, - '%s failed common check %d' % (xml, i)) + self.assertEqual(check(tree), + expected_result, + '%s failed common check %d' % (xml, i)) # This test is supposed to make sure we don't # override a specifically set uri -- cgit From 7701edd34f1fc9fa26b3dfcc77ff87018622bedc Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 17 Mar 2011 07:13:31 -0400 Subject: get_console_output is not supported by lxc and libvirt --- nova/virt/libvirt_conn.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index d08ca8b6a..9bfd3f841 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -490,6 +490,9 @@ class LibvirtConnection(object): instance['name']) data = self._flush_xen_console(virsh_output) fpath = self._append_to_file(data, console_log) + elif FLAGS.libvirt_type == 'lxc': + # LXC is also special + LOG.info(_("Unable to read LXC console")) else: fpath = console_log -- cgit From 70cd1a51ada85f4724190d2562130172e9495e5e Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 17 Mar 2011 07:53:25 -0400 Subject: Update authors again --- Authors | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Authors b/Authors index 12d2f02de..22a9fb8eb 100644 --- a/Authors +++ b/Authors @@ -11,7 +11,7 @@ Chiradeep Vittal Chmouel Boudjnah Chris Behrens Christian Berendt -Chuck Short +Chuck Short Cory Wright Dan Prince David Pravec -- cgit From 9ba500c304595dff037da296f26cb13d02bfbc04 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 17 Mar 2011 07:57:06 -0400 Subject: Fix pep8 errors --- nova/tests/test_virt.py | 2 -- nova/virt/disk.py | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index 92c80272b..7d50960a3 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -326,7 +326,6 @@ class LibvirtConnTestCase(test.TestCase): check = (lambda t: t.find('./os/initrd'), None) check_list.append(check) - common_checks = [ (lambda t: t.find('.').tag, 'domain'), (lambda t: t.find( @@ -372,7 +371,6 @@ class LibvirtConnTestCase(test.TestCase): expected_result, '%s failed check %d' % (xml, i)) - for i, (check, expected_result) in enumerate(common_checks): self.assertEqual(check(tree), expected_result, diff --git a/nova/virt/disk.py b/nova/virt/disk.py index a44995613..26976940e 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -129,6 +129,7 @@ def setup_container(image, container_dir=None, partition=None, nbd=False): % err) _unlink_device(device, nbd) + def destroy_container(target, instance, nbd=False): """Destroy the container once it terminates -- cgit From bb6096c51cde91dccaad0e9f584f2dc26057da1f Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 17 Mar 2011 08:49:52 -0400 Subject: Update mailmap --- .mailmap | 1 + 1 file changed, 1 insertion(+) diff --git a/.mailmap b/.mailmap index ccf2109a7..78cfef53b 100644 --- a/.mailmap +++ b/.mailmap @@ -10,6 +10,7 @@ + -- cgit From c98cead470f33041e928a6f82be801efeb94ccc3 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 17 Mar 2011 08:52:52 -0400 Subject: Remove nbd=FLAGS.use_cow_images for destroy container --- nova/virt/disk.py | 7 +++---- nova/virt/libvirt_conn.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index 26976940e..90d3cf499 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -23,7 +23,6 @@ Includes injection of SSH PGP keys into authorized_keys file. """ import os -import string import tempfile import time @@ -130,7 +129,7 @@ def setup_container(image, container_dir=None, partition=None, nbd=False): _unlink_device(device, nbd) -def destroy_container(target, instance, nbd=False): +def destroy_container(target, instance): """Destroy the container once it terminates It will umount the container that is mounted, try to find the loopback @@ -140,9 +139,9 @@ def destroy_container(target, instance, nbd=False): container_dir = '%s/rootfs' % target utils.execute('sudo', 'umount', container_dir) finally: - for loop in os.popen('sudo losetup -a').readlines(): + for loop in utils.popen('sudo losetup -a').readlines(): if instance['name'] in loop: - device = string.split(loop, ':') + device = loop.split(loop, ':') utils.execute('sudo', 'losetup', '--detach', device) diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index 9bfd3f841..9e0d0538d 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -275,7 +275,7 @@ class LibvirtConnection(object): LOG.info(_('instance %(instance_name)s: deleting instance files' ' %(target)s') % locals()) if FLAGS.libvirt_type == 'lxc': - disk.destroy_container(target, instance, nbd=FLAGS.use_cow_images) + disk.destroy_container(target, instance) if os.path.exists(target): shutil.rmtree(target) -- cgit From 6bd017262a5c61d915ede2e58ef2758f1f190ff3 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 17 Mar 2011 08:54:05 -0400 Subject: Remove target_partition for setup_container but still hardcode because its needed when you inject the keys into the image. --- nova/virt/libvirt_conn.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index 9e0d0538d..0ca27d629 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -700,8 +700,7 @@ class LibvirtConnection(object): if FLAGS.libvirt_type == 'lxc': disk.setup_container(basepath('disk'), container_dir=container_dir, - partition=target_partition, - nbd=FLAGS.use_cow_images) + partition=target_partition) except Exception as e: # This could be a windows image, or a vmdk format disk LOG.warn(_('instance %(inst_name)s: ignoring error injecting' -- cgit From cc716f9648355bc3737dd749a35dc327ebda1e6f Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 17 Mar 2011 09:15:33 -0400 Subject: Fixed typo when I was trying to add test cases for lxc --- nova/tests/test_virt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index 7d50960a3..c2b8ba0a1 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -344,7 +344,7 @@ class LibvirtConnTestCase(test.TestCase): (lambda t: t.find('./memory').text, '2097152')] if rescue: - common_checks = [ + common_checks += [ (lambda t: t.findall('./devices/disk/source')[0].get( 'file').split('/')[1], 'disk.rescue'), (lambda t: t.findall('./devices/disk/source')[1].get( -- cgit From 174d8ca2da7e2e53c9105ccc5e5d9a97bc12c0b8 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 17 Mar 2011 09:17:42 -0400 Subject: Set nbd to false when mounting the image --- nova/virt/disk.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index 90d3cf499..a84425de7 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -121,6 +121,7 @@ def setup_container(image, container_dir=None, partition=None, nbd=False): It will mount the loopback image to the container directory in order to create the root filesystem for the container """ + nbd=False device = _link_device(image, nbd) err = utils.execute('sudo', 'mount', device, container_dir) if err: -- cgit From bc0ef2c7aead759504eedcb4e2ab6d96dba7c266 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 17 Mar 2011 10:02:40 -0400 Subject: Fix up setup container --- nova/virt/disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index a84425de7..2fa7819d7 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -115,7 +115,7 @@ def inject_data(image, key=None, net=None, partition=None, nbd=False): _unlink_device(device, nbd) -def setup_container(image, container_dir=None, partition=None, nbd=False): +def setup_container(image, container_dir=None, partition=None): """Setup the LXC container It will mount the loopback image to the container directory in order -- cgit From abb86555f7417225a72126872beb377268acfdb1 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 17 Mar 2011 10:16:37 -0400 Subject: Remove me from mailmap --- .mailmap | 1 - 1 file changed, 1 deletion(-) diff --git a/.mailmap b/.mailmap index 78cfef53b..ccf2109a7 100644 --- a/.mailmap +++ b/.mailmap @@ -10,7 +10,6 @@ - -- cgit From 36285d3acb940c39dc1827699c1e3c0cc9846529 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 17 Mar 2011 10:22:57 -0400 Subject: Fix more pep8 errors --- nova/tests/test_virt.py | 12 ++++++------ nova/virt/disk.py | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index c2b8ba0a1..222975adc 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -367,14 +367,14 @@ class LibvirtConnTestCase(test.TestCase): xml = conn.to_xml(instance_ref, rescue) tree = xml_to_tree(xml) for i, (check, expected_result) in enumerate(checks): - self.assertEqual(check(tree), - expected_result, - '%s failed check %d' % (xml, i)) + self.assertEqual(check(tree), + expected_result, + '%s failed check %d' % (xml, i)) for i, (check, expected_result) in enumerate(common_checks): - self.assertEqual(check(tree), - expected_result, - '%s failed common check %d' % (xml, i)) + self.assertEqual(check(tree), + expected_result, + '%s failed common check %d' % (xml, i)) # This test is supposed to make sure we don't # override a specifically set uri diff --git a/nova/virt/disk.py b/nova/virt/disk.py index 2fa7819d7..6c5f126bd 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -121,7 +121,7 @@ def setup_container(image, container_dir=None, partition=None): It will mount the loopback image to the container directory in order to create the root filesystem for the container """ - nbd=False + nbd = False device = _link_device(image, nbd) err = utils.execute('sudo', 'mount', device, container_dir) if err: @@ -132,7 +132,7 @@ def setup_container(image, container_dir=None, partition=None): def destroy_container(target, instance): """Destroy the container once it terminates - + It will umount the container that is mounted, try to find the loopback device associated with the container and delete it. """ -- cgit From a06203c66af05c96c161b80511f4a6607ffe4905 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 17 Mar 2011 10:41:55 -0400 Subject: Fix up tests --- nova/tests/test_virt.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index 222975adc..fefc11f0d 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -239,8 +239,8 @@ class LibvirtConnTestCase(test.TestCase): network_ref = db.project_get_network(context.get_admin_context(), self.project.id) - fixed_ip = {'address': self.test_ip, - 'network_id': network_ref['id']} + fixed_ip = {'address': self.test_ip, + 'network_id': network_ref['id']} ctxt = context.get_admin_context() fixed_ip_ref = db.fixed_ip_create(ctxt, fixed_ip) @@ -259,13 +259,13 @@ class LibvirtConnTestCase(test.TestCase): check = [ (lambda t: t.find('.').get('type'), 'lxc'), - (lambda t: t.find('./os/type').text, 'exe'), + (lambda t: t.find('./os/type').text, 'exe') ] for i, (check, expected_result) in enumerate(check): - self.assertEqual(check(tree), - expected_result, - '%s failed common check %d' % (xml, i)) + self.assertEqual(check(tree), + expected_result, + '%s failed common check %d' % (xml, i)) def _check_xml_and_uri(self, instance, expect_ramdisk, expect_kernel, rescue=False): @@ -342,7 +342,6 @@ class LibvirtConnTestCase(test.TestCase): (lambda t: t.find('./devices/serial/source').get( 'path').split('/')[1], 'console.log'), (lambda t: t.find('./memory').text, '2097152')] - if rescue: common_checks += [ (lambda t: t.findall('./devices/disk/source')[0].get( -- cgit From dee8a59b5d575a0327464e27115d0d870cde97be Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 17 Mar 2011 10:43:48 -0400 Subject: more pep8 fixes --- nova/tests/test_virt.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index fefc11f0d..2510525fc 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -263,9 +263,9 @@ class LibvirtConnTestCase(test.TestCase): ] for i, (check, expected_result) in enumerate(check): - self.assertEqual(check(tree), - expected_result, - '%s failed common check %d' % (xml, i)) + self.assertEqual(check(tree), + expected_result, + '%s failed common check %d' % (xml, i)) def _check_xml_and_uri(self, instance, expect_ramdisk, expect_kernel, rescue=False): -- cgit From 4364a158fd31bdfcfa3ae835a2fd9c0f47d3632f Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 17 Mar 2011 10:45:31 -0400 Subject: pep8 fixes --- nova/tests/test_virt.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index 2510525fc..45f98fcde 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -259,8 +259,7 @@ class LibvirtConnTestCase(test.TestCase): check = [ (lambda t: t.find('.').get('type'), 'lxc'), - (lambda t: t.find('./os/type').text, 'exe') - ] + (lambda t: t.find('./os/type').text, 'exe')] for i, (check, expected_result) in enumerate(check): self.assertEqual(check(tree), -- cgit From b0e3b8e58a925ebf52fa741883f757ed2bc4383c Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 17 Mar 2011 10:47:19 -0400 Subject: more pep8 fixes --- nova/virt/disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index 6c5f126bd..f6e6795d6 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -132,7 +132,7 @@ def setup_container(image, container_dir=None, partition=None): def destroy_container(target, instance): """Destroy the container once it terminates - + It will umount the container that is mounted, try to find the loopback device associated with the container and delete it. """ -- cgit From 1378db7ac86b69b8a966448b63415b2136b6b5bc Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 24 Mar 2011 09:07:57 -0400 Subject: Fix up formatting of libvirt.xml.template --- nova/virt/libvirt.xml.template | 132 ++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/nova/virt/libvirt.xml.template b/nova/virt/libvirt.xml.template index 77c1b1997..26f528cb1 100644 --- a/nova/virt/libvirt.xml.template +++ b/nova/virt/libvirt.xml.template @@ -3,47 +3,47 @@ ${memory_kb} #if $type == 'lxc' - #set $disk_prefix = '' + #set $disk prefix = '' #set $disk_bus = '' exe /sbin/init #else -#if $type == 'uml' - #set $disk_prefix = 'ubd' - #set $disk_bus = 'uml' - uml - /usr/bin/linux - /dev/ubda -#else - #if $type == 'xen' - #set $disk_prefix = 'sd' - #set $disk_bus = 'scsi' - linux - /dev/xvda - #else - #set $disk_prefix = 'vd' - #set $disk_bus = 'virtio' - hvm - #end if - #if $getVar('rescue', False) - ${basepath}/kernel.rescue - ${basepath}/ramdisk.rescue - #else - #if $getVar('kernel', None) - ${kernel} - #if $type == 'xen' - ro - #else - root=/dev/vda console=ttyS0 - #end if - #if $getVar('ramdisk', None) - ${ramdisk} - #end if - #else - - #end if - #end if - #end if + #if $type == 'uml' + #set $disk_prefix = 'ubd' + #set $disk_bus = 'uml' + uml + /usr/bin/linux + /dev/ubda + #else + #if $type == 'xen' + #set $disk_prefix = 'sd' + #set $disk_bus = 'scsi' + linux + /dev/xvda + #else + #set $disk_prefix = 'vd' + #set $disk_bus = 'virtio' + hvm + #end if + #if $getVar('rescue', False) + ${basepath}/kernel.rescue + ${basepath}/ramdisk.rescue + #else + #if $getVar('kernel', None) + ${kernel} + #if $type == 'xen' + ro + #else + root=/dev/vda console=ttyS0 + #end if + #if $getVar('ramdisk', None) + ${ramdisk} + #end if + #else + + #end if + #end if + #end if #end if @@ -52,36 +52,36 @@ ${vcpus} #if $type == 'lxc' - - - - -#else -#if $getVar('rescue', False) - - - - - - - - - - + + + + #else - - - - - - #if $getVar('local', False) - - - - - - #end if - #end if + #if $getVar('rescue', False) + + + + + + + + + + + #else + + + + + + #if $getVar('local', False) + + + + + + #end if +#end if #end if -- cgit From da159d18b56af44f93cbf2c5e80b6aa3c98d5187 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 24 Mar 2011 09:12:24 -0400 Subject: Dont use popen in dettaching the lxc loop --- nova/virt/disk.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index f6e6795d6..0bdb04cde 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -140,7 +140,8 @@ def destroy_container(target, instance): container_dir = '%s/rootfs' % target utils.execute('sudo', 'umount', container_dir) finally: - for loop in utils.popen('sudo losetup -a').readlines(): + out, err = utils('sudo', 'losetup', '-a') + for loop in out.splitlines(): if instance['name'] in loop: device = loop.split(loop, ':') utils.execute('sudo', 'losetup', '--detach', device) -- cgit From 9632db75d229eac16970af1dfabbb047c2b71a4e Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Fri, 25 Mar 2011 08:20:56 -0400 Subject: Removed partition from setup_container --- nova/virt/disk.py | 4 ++-- nova/virt/libvirt_conn.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index 0bdb04cde..bbdcc8ddf 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -115,13 +115,13 @@ def inject_data(image, key=None, net=None, partition=None, nbd=False): _unlink_device(device, nbd) -def setup_container(image, container_dir=None, partition=None): +def setup_container(image, container_dir=None): """Setup the LXC container It will mount the loopback image to the container directory in order to create the root filesystem for the container """ - nbd = False + nbd = "False" device = _link_device(image, nbd) err = utils.execute('sudo', 'mount', device, container_dir) if err: diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index 9fb8ba955..bfb0a75f1 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -798,8 +798,7 @@ class LibvirtConnection(driver.ComputeDriver): if FLAGS.libvirt_type == 'lxc': disk.setup_container(basepath('disk'), - container_dir=container_dir, - partition=target_partition) + container_dir=container_dir) except Exception as e: # This could be a windows image, or a vmdk format disk LOG.warn(_('instance %(inst_name)s: ignoring error injecting' -- cgit From 47b54662c17c7af0bca9cf96dc5d4a498706fe8b Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Fri, 25 Mar 2011 08:37:47 -0400 Subject: Dont always assume qemu --- nova/virt/libvirt_conn.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index bfb0a75f1..840eaceeb 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -1053,7 +1053,8 @@ class LibvirtConnection(driver.ComputeDriver): total = 0 for dom_id in self._conn.listDomainsID(): dom = self._conn.lookupByID(dom_id) - total += len(dom.vcpus()[1]) + if dom is None: + total += len(dom.vcpus()[1]) return total def get_memory_mb_used(self): -- cgit From 3d8b55294702b531a570b279fb29db8d4ea104d3 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Fri, 25 Mar 2011 08:52:18 -0400 Subject: Fix up templating --- nova/virt/libvirt.xml.template | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/nova/virt/libvirt.xml.template b/nova/virt/libvirt.xml.template index c2c5384bb..26f528cb1 100644 --- a/nova/virt/libvirt.xml.template +++ b/nova/virt/libvirt.xml.template @@ -83,24 +83,21 @@ #end if #end if #end if - -#for $nic in $nics - - + + - - - -#if $getVar('nic.extra_params', False) - ${nic.extra_params} + + + +#if $getVar('extra_params', False) + ${extra_params} #end if -#if $getVar('nic.gateway_v6', False) - +#if $getVar('gateway_v6', False) + #end if -#end for -- cgit From 6ce4f9c6ae00138184e79cdcfb6f78fc3474580e Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Fri, 25 Mar 2011 08:52:54 -0400 Subject: Fix up destroy container --- nova/virt/disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index bbdcc8ddf..b9a8fb7e7 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -140,7 +140,7 @@ def destroy_container(target, instance): container_dir = '%s/rootfs' % target utils.execute('sudo', 'umount', container_dir) finally: - out, err = utils('sudo', 'losetup', '-a') + out, err = utils.execute('sudo', 'losetup', '-a') for loop in out.splitlines(): if instance['name'] in loop: device = loop.split(loop, ':') -- cgit From c8fb0c5a16852afc98349edf89bb31afac166749 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Fri, 25 Mar 2011 09:39:20 -0400 Subject: Revert dom check --- nova/virt/libvirt_conn.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index 840eaceeb..bfb0a75f1 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -1053,8 +1053,7 @@ class LibvirtConnection(driver.ComputeDriver): total = 0 for dom_id in self._conn.listDomainsID(): dom = self._conn.lookupByID(dom_id) - if dom is None: - total += len(dom.vcpus()[1]) + total += len(dom.vcpus()[1]) return total def get_memory_mb_used(self): -- cgit From cb8a13e3751cc12f7157094d094c7a26d6f583f0 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Sun, 27 Mar 2011 15:30:47 -0400 Subject: Fix utils checking --- nova/virt/disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index fd45e2c51..15cd49789 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -124,7 +124,7 @@ def setup_container(image, container_dir=None): """ nbd = "False" device = _link_device(image, nbd) - err = utils.execute('sudo', 'mount', device, container_dir) + out, err = utils.execute('sudo', 'mount', device, container_dir) if err: raise exception.Error(_('Failed to mount filesystem: %s') % err) -- cgit From 8922630e70e97b52e363a861c76fe4a01b8418ff Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Mon, 28 Mar 2011 09:37:05 -0400 Subject: Fix typo in libvirt xml template --- nova/virt/libvirt.xml.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/libvirt.xml.template b/nova/virt/libvirt.xml.template index 26f528cb1..a62c3b6a8 100644 --- a/nova/virt/libvirt.xml.template +++ b/nova/virt/libvirt.xml.template @@ -3,7 +3,7 @@ ${memory_kb} #if $type == 'lxc' - #set $disk prefix = '' + #set $disk_prefix = '' #set $disk_bus = '' exe /sbin/init -- cgit From 805cb3609379827d1643785be83f75b69b602d74 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Mon, 28 Mar 2011 13:44:33 -0400 Subject: Fix libvirt merge mistake --- nova/virt/libvirt.xml.template | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/nova/virt/libvirt.xml.template b/nova/virt/libvirt.xml.template index a62c3b6a8..894b216e9 100644 --- a/nova/virt/libvirt.xml.template +++ b/nova/virt/libvirt.xml.template @@ -83,22 +83,24 @@ #end if #end if #end if + +#for $nic in $nics - - + + - - - -#if $getVar('extra_params', False) - ${extra_params} + + + +#if $getVar('nic.extra_params', False) + ${nic.extra_params} #end if -#if $getVar('gateway_v6', False) - +#if $getVar('nic.gateway_v6', False) + #end if - +#end for -- cgit From 9c61085ea9612be24e9975ac3fba456874b89f08 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Mon, 28 Mar 2011 13:49:51 -0400 Subject: Add more unit tests for lxc --- nova/tests/test_virt.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index cee044279..ed7943ace 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -257,7 +257,9 @@ class LibvirtConnTestCase(test.TestCase): check = [ (lambda t: t.find('.').get('type'), 'lxc'), - (lambda t: t.find('./os/type').text, 'exe')] + (lambda t: t.find('./os/type').text, 'exe'), + (lambda t: t.find('./devices/filesystem/source').get('dir'), 'rootfs'), + (lambda t: t.find('./devices/filesystem/target').get('dir'), '/')] for i, (check, expected_result) in enumerate(check): self.assertEqual(check(tree), -- cgit From e44ce1a95baddd4f6d511d8be253167436395cb2 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Mon, 28 Mar 2011 14:07:33 -0400 Subject: More pep8 corrections --- nova/tests/test_virt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index ed7943ace..8cee55576 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -258,8 +258,8 @@ class LibvirtConnTestCase(test.TestCase): check = [ (lambda t: t.find('.').get('type'), 'lxc'), (lambda t: t.find('./os/type').text, 'exe'), - (lambda t: t.find('./devices/filesystem/source').get('dir'), 'rootfs'), - (lambda t: t.find('./devices/filesystem/target').get('dir'), '/')] + (lambda t: t.find('./devices/filesystem/source').get('dir'), 'rootfs'), + (lambda t: t.find('./devices/filesystem/target').get('dir'), '/')] for i, (check, expected_result) in enumerate(check): self.assertEqual(check(tree), -- cgit From c8e708af1789fda97674fb4c3904d86de8473a7e Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Mon, 28 Mar 2011 14:32:03 -0400 Subject: Dont make the test fail --- nova/tests/test_virt.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index 8cee55576..df29e69c2 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -258,7 +258,6 @@ class LibvirtConnTestCase(test.TestCase): check = [ (lambda t: t.find('.').get('type'), 'lxc'), (lambda t: t.find('./os/type').text, 'exe'), - (lambda t: t.find('./devices/filesystem/source').get('dir'), 'rootfs'), (lambda t: t.find('./devices/filesystem/target').get('dir'), '/')] for i, (check, expected_result) in enumerate(check): @@ -266,6 +265,9 @@ class LibvirtConnTestCase(test.TestCase): expected_result, '%s failed common check %d' % (xml, i)) + target = tree.find('./devices/filesystem/source').get('dir') + self.assertTrue(len(target) > 0) + def _check_xml_and_uri(self, instance, expect_ramdisk, expect_kernel, rescue=False): user_context = context.RequestContext(project=self.project, -- cgit From bb7ed6cb9cf625b675a666866a7f9fb762ca6bd2 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Mon, 28 Mar 2011 14:47:25 -0400 Subject: use self.flags in virt test --- nova/tests/test_virt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index df29e69c2..e6beb8e2e 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -246,7 +246,7 @@ class LibvirtConnTestCase(test.TestCase): {'allocated': True, 'instance_id': instance_ref['id']}) - FLAGS.libvirt_type = 'lxc' + self.flags(libvirt_type='lxc') conn = libvirt_conn.LibvirtConnection(True) uri = conn.get_uri() -- cgit From dbbceaebec3ca2a729582f9851f718b2b7c3f3b9 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Mon, 28 Mar 2011 15:57:18 -0400 Subject: Fix up libvirt.xml.template --- nova/virt/libvirt.xml.template | 138 ++++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 70 deletions(-) diff --git a/nova/virt/libvirt.xml.template b/nova/virt/libvirt.xml.template index 894b216e9..36d18ed95 100644 --- a/nova/virt/libvirt.xml.template +++ b/nova/virt/libvirt.xml.template @@ -3,47 +3,45 @@ ${memory_kb} #if $type == 'lxc' - #set $disk_prefix = '' - #set $disk_bus = '' - exe - /sbin/init + #set $disk_prefix = '' + #set $disk_bus = '' + exe + /sbin/init +#else if $type == 'uml' + #set $disk_prefix = 'ubd' + #set $disk_bus = 'uml' + uml + /usr/bin/linux + /dev/ubda #else - #if $type == 'uml' - #set $disk_prefix = 'ubd' - #set $disk_bus = 'uml' - uml - /usr/bin/linux - /dev/ubda - #else - #if $type == 'xen' - #set $disk_prefix = 'sd' - #set $disk_bus = 'scsi' - linux - /dev/xvda - #else - #set $disk_prefix = 'vd' - #set $disk_bus = 'virtio' - hvm - #end if - #if $getVar('rescue', False) - ${basepath}/kernel.rescue - ${basepath}/ramdisk.rescue - #else - #if $getVar('kernel', None) - ${kernel} - #if $type == 'xen' - ro - #else - root=/dev/vda console=ttyS0 - #end if - #if $getVar('ramdisk', None) - ${ramdisk} - #end if - #else - - #end if - #end if - #end if + #if $type == 'xen' + #set $disk_prefix = 'sd' + #set $disk_bus = 'scsi' + linux + /dev/xvda + #else + #set $disk_prefix = 'vd' + #set $disk_bus = 'virtio' + hvm + #end if + #if $getVar('rescue', False) + ${basepath}/kernel.rescue + ${basepath}/ramdisk.rescue + #else + #if $getVar('kernel', None) + ${kernel} + #if $type == 'xen' + ro + #else + root=/dev/vda console=ttyS0 + #end if + #if $getVar('ramdisk', None) + ${ramdisk} + #end if + #else + + #end if + #end if #end if @@ -52,36 +50,36 @@ ${vcpus} #if $type == 'lxc' - - - - + + + + #else - #if $getVar('rescue', False) - - - - - - - - - - - #else - - - - - - #if $getVar('local', False) - - - - - - #end if -#end if + #if $getVar('rescue', False) + + + + + + + + + + + #else + + + + + + #if $getVar('local', False) + + + + + + #end if + #end if #end if #for $nic in $nics @@ -91,7 +89,7 @@ - + #if $getVar('nic.extra_params', False) ${nic.extra_params} #end if -- cgit From 0e81c4175cad97359e848c993efd9a91eb981174 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Mon, 28 Mar 2011 21:22:53 -0400 Subject: Pass along the nbd flags although we dont support it just yet --- nova/virt/disk.py | 13 ++++++++----- nova/virt/libvirt_conn.py | 5 +++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index 15cd49789..11a7a969e 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -116,13 +116,14 @@ def inject_data(image, key=None, net=None, partition=None, nbd=False): _unlink_device(device, nbd) -def setup_container(image, container_dir=None): +def setup_container(image, container_dir=None, nbd=False): """Setup the LXC container It will mount the loopback image to the container directory in order - to create the root filesystem for the container + to create the root filesystem for the container. + + LXC does not support qcow2 images yet. """ - nbd = "False" device = _link_device(image, nbd) out, err = utils.execute('sudo', 'mount', device, container_dir) if err: @@ -131,11 +132,13 @@ def setup_container(image, container_dir=None): _unlink_device(device, nbd) -def destroy_container(target, instance): +def destroy_container(target, instance, nbd=False): """Destroy the container once it terminates It will umount the container that is mounted, try to find the loopback device associated with the container and delete it. + + LXC does not support qcow2 images yet. """ try: container_dir = '%s/rootfs' % target @@ -145,7 +148,7 @@ def destroy_container(target, instance): for loop in out.splitlines(): if instance['name'] in loop: device = loop.split(loop, ':') - utils.execute('sudo', 'losetup', '--detach', device) + _unlink_device(device, nbd) def _link_device(image, nbd): diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index 66d0d195b..af2dac9e8 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -342,7 +342,7 @@ class LibvirtConnection(driver.ComputeDriver): LOG.info(_('instance %(instance_name)s: deleting instance files' ' %(target)s') % locals()) if FLAGS.libvirt_type == 'lxc': - disk.destroy_container(target, instance) + disk.destroy_container(target, instance,nbd=FLAGS.use_cow_images) if os.path.exists(target): shutil.rmtree(target) @@ -797,7 +797,8 @@ class LibvirtConnection(driver.ComputeDriver): if FLAGS.libvirt_type == 'lxc': disk.setup_container(basepath('disk'), - container_dir=container_dir) + container_dir=container_dir, + nbd=FLAGS.use_cow_images) except Exception as e: # This could be a windows image, or a vmdk format disk LOG.warn(_('instance %(inst_name)s: ignoring error injecting' -- cgit From ad6735df0de8676768353516eee4af62af2c993c Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Tue, 29 Mar 2011 08:56:42 -0400 Subject: Catch the error that mount might through a bit better --- nova/virt/disk.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index 11a7a969e..8adef744f 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -124,11 +124,11 @@ def setup_container(image, container_dir=None, nbd=False): LXC does not support qcow2 images yet. """ - device = _link_device(image, nbd) - out, err = utils.execute('sudo', 'mount', device, container_dir) - if err: - raise exception.Error(_('Failed to mount filesystem: %s') - % err) + try: + device = _link_device(image, nbd) + utils.execute('sudo', 'mount', device, container_dir) + except Exception, exn: + LOG.exception(_('Failed to mount filesystem: %s'), exn) _unlink_device(device, nbd) -- cgit From beec33e8dbffbe3ea02eccec4952705698db377a Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Tue, 29 Mar 2011 10:01:54 -0400 Subject: Fix pep8 error --- nova/virt/libvirt_conn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index c4d41881d..ae3a967a4 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -347,7 +347,7 @@ class LibvirtConnection(driver.ComputeDriver): LOG.info(_('instance %(instance_name)s: deleting instance files' ' %(target)s') % locals()) if FLAGS.libvirt_type == 'lxc': - disk.destroy_container(target, instance,nbd=FLAGS.use_cow_images) + disk.destroy_container(target, instance, nbd=FLAGS.use_cow_images) if os.path.exists(target): shutil.rmtree(target) -- cgit From 8f4176f289142e48d4a2c584ad1ce270dfa53d82 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Tue, 29 Mar 2011 14:56:46 -0400 Subject: Fix up docstring --- nova/virt/disk.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/virt/disk.py b/nova/virt/disk.py index 8adef744f..ddea1a1f7 100644 --- a/nova/virt/disk.py +++ b/nova/virt/disk.py @@ -117,7 +117,7 @@ def inject_data(image, key=None, net=None, partition=None, nbd=False): def setup_container(image, container_dir=None, nbd=False): - """Setup the LXC container + """Setup the LXC container. It will mount the loopback image to the container directory in order to create the root filesystem for the container. @@ -133,7 +133,7 @@ def setup_container(image, container_dir=None, nbd=False): def destroy_container(target, instance, nbd=False): - """Destroy the container once it terminates + """Destroy the container once it terminates. It will umount the container that is mounted, try to find the loopback device associated with the container and delete it. -- cgit From 05a654211ab902cbb5b1b345dd3285efb1c6bf71 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Tue, 29 Mar 2011 15:48:02 -0400 Subject: Style fixes --- nova/tests/test_virt.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index e6beb8e2e..958c8e3e2 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -237,13 +237,13 @@ class LibvirtConnTestCase(test.TestCase): network_ref = db.project_get_network(context.get_admin_context(), self.project.id) - fixed_ip = {'address': self.test_ip, - 'network_id': network_ref['id']} + fixed_ip = {'address': self.test_ip, + 'network_id': network_ref['id']} ctxt = context.get_admin_context() fixed_ip_ref = db.fixed_ip_create(ctxt, fixed_ip) db.fixed_ip_update(ctxt, self.test_ip, - {'allocated': True, + {'allocated': True, 'instance_id': instance_ref['id']}) self.flags(libvirt_type='lxc') -- cgit