Merge lp:~nttdata/nova/850602 into lp:~hudson-openstack/nova/trunk

Proposed by Kei Masumoto
Status: Rejected
Rejected by: Brian Waldon
Proposed branch: lp:~nttdata/nova/850602
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 145 lines (+47/-12)
2 files modified
nova/tests/test_libvirt.py (+17/-9)
nova/virt/libvirt/connection.py (+30/-3)
To merge this branch: bzr merge lp:~nttdata/nova/850602
Reviewer Review Type Date Requested Status
Jason Kölker (community) Approve
Brian Waldon (community) Approve
Review via email: mp+75480@code.launchpad.net

Description of the change

block migration needs to copy backing_file.
This branch enables existing nova handling backing_file.
Changes has been done to 2 methods in nova.virt.libvirt.connection.py.
 - pre_block_migration
 - get_instance_disk_info

Unit-test is also changed following this changes.

To post a comment you must log in.
Revision history for this message
Jason Kölker (jason-koelker) wrote :

Functionality looks good. Just a few fixes in the tests:

15 + #network_info = _fake_network_info(self.stubs, 1)
Instead of leaving the other network_info lines comented out, they should be deleted.

56 + open('/tmp/aaa', 'w+').write(str(info))
Do you mean to leave this file around?

Other than that, looks good.

review: Needs Fixing
Revision history for this message
Jason Kölker (jason-koelker) wrote :

There are also some pep8 issues that should be fixed before it hits trunk:

$ ./run_tests.sh -N -x -p
Running pep8 ...
nova/tests/test_libvirt.py:586:63: W291 trailing whitespace
        # as _fake_network_info calls utils.import_class() and
                                                              ^
    JCR: Trailing whitespace is superfluous.
    FBM: Except when it occurs as part of a blank line (i.e. the line is
         nothing but whitespace). According to Python docs[1] a line with only
         whitespace is considered a blank line, and is to be ignored. However,
         matching a blank line to its indentation level avoids mistakenly
         terminating a multi-line statement (e.g. class declaration) when
         pasting code into the standard Python interpreter.

         [1] http://docs.python.org/reference/lexical_analysis.html#blank-lines

    The warning returned varies on whether the line itself is blank, for easier
    filtering for those who want to indent their blank lines.

    Okay: spam(1)
    W291: spam(1)\s
    W293: class Foo(object):\n \n bang = 12
nova/tests/test_libvirt.py:771:63: W291 trailing whitespace
        # as _fake_network_info calls utils.import_class() and
                                                              ^
    JCR: Trailing whitespace is superfluous.
    FBM: Except when it occurs as part of a blank line (i.e. the line is
         nothing but whitespace). According to Python docs[1] a line with only
         whitespace is considered a blank line, and is to be ignored. However,
         matching a blank line to its indentation level avoids mistakenly
         terminating a multi-line statement (e.g. class declaration) when
         pasting code into the standard Python interpreter.

         [1] http://docs.python.org/reference/lexical_analysis.html#blank-lines

    The warning returned varies on whether the line itself is blank, for easier
    filtering for those who want to indent their blank lines.

    Okay: spam(1)
    W291: spam(1)\s
    W293: class Foo(object):\n \n bang = 12
nova/virt/libvirt/connection.py:1748:1: W293 blank line contains whitespace

^
    JCR: Trailing whitespace is superfluous.
    FBM: Except when it occurs as part of a blank line (i.e. the line is
         nothing but whitespace). According to Python docs[1] a line with only
         whitespace is considered a blank line, and is to be ignored. However,
         matching a blank line to its indentation level avoids mistakenly
         terminating a multi-line statement (e.g. class declaration) when
         pasting code into the standard Python interpreter.

         [1] http://docs.python.org/reference/lexical_analysis.html#blank-lines

    The warning returned varies on whether the line itself is blank, for easier
    filtering for those who want to indent their blank lines.

    Okay: spam(1)
    W291: spam(1)\s
    W293: class Foo(object):\n \n bang = 12

Revision history for this message
Brian Waldon (bcwaldon) wrote :

15, 85: I would prefer you just delete these lines rather than leave them commented out

115: This will definitely cause someone a headache down the road. Can you check local_gb instead of the name?

review: Needs Fixing
Revision history for this message
Kei Masumoto (masumotok) wrote :

Hello Jason and Brian,
Thanks for review this path, and sorry late reply.
I fixed based on your comment. can you check this?

Revision history for this message
Brian Waldon (bcwaldon) wrote :

Thanks, Kei. Looks good!

review: Approve
Revision history for this message
Jason Kölker (jason-koelker) wrote :

Is Bueno!

review: Approve
Revision history for this message
Rafi Khardalian (rkhardalian) wrote :

Prior to having this patch I was having my root disks corrupted with block migrations using the latest Diablo release packages. I just applied the patch to my compute nodes and re-tested and it resolved the issue.

Revision history for this message
Brian Waldon (bcwaldon) wrote :

Kei: can you migrate this MP over to review.openstack.org?

lp:~nttdata/nova/850602 updated
1575. By Kei Masumoto

delete unnecessary os.remove(disk) in pre_block_migration. block_migration fails if disk is removed.

Revision history for this message
Kei Masumoto (masumotok) wrote :

Brian, thanks for notification! I migrated this MP, but unfortunately, "approbe" is not migrated. So could you check it again?

<https://review.openstack.org/#change,716>

Kei
-----Original Message-----
From: <email address hidden> [mailto:<email address hidden>] On Behalf Of Brian Waldon
Sent: Tuesday, September 27, 2011 2:18 AM
To: <email address hidden>
Subject: Re: [Merge] lp:~nttdata/nova/850602 into lp:nova/diablo

Kei: can you migrate this MP over to review.openstack.org?
--
https://code.launchpad.net/~nttdata/nova/850602/+merge/75480
Your team NTT DATA is subscribed to branch lp:~nttdata/nova/850602.

Revision history for this message
Brian Waldon (bcwaldon) wrote :

moved to gerrit

Unmerged revisions

1575. By Kei Masumoto

delete unnecessary os.remove(disk) in pre_block_migration. block_migration fails if disk is removed.

1574. By Kei Masumoto

using instance['local_gb'] on creating backing file

1573. By Kei Masumoto

pep8 error and unnecessary debug statement fixed

1572. By Kei Masumoto

fix bugs

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'nova/tests/test_libvirt.py'
--- nova/tests/test_libvirt.py 2011-09-19 14:22:34 +0000
+++ nova/tests/test_libvirt.py 2011-09-28 13:07:25 +0000
@@ -629,9 +629,12 @@
629629
630 fake_timer = FakeTime()630 fake_timer = FakeTime()
631631
632 # _fake_network_info must be called before create_fake_libvirt_mock(),
633 # as _fake_network_info calls utils.import_class() and
634 # create_fake_libvirt_mock() mocks utils.import_class().
635 network_info = _fake_network_info(self.stubs, 1)
632 self.create_fake_libvirt_mock()636 self.create_fake_libvirt_mock()
633 instance_ref = db.instance_create(self.context, self.test_instance)637 instance_ref = db.instance_create(self.context, self.test_instance)
634 network_info = _fake_network_info(self.stubs, 1)
635638
636 # Start test639 # Start test
637 self.mox.ReplayAll()640 self.mox.ReplayAll()
@@ -684,10 +687,7 @@
684 return vdmock687 return vdmock
685688
686 self.create_fake_libvirt_mock(lookupByName=fake_lookup)689 self.create_fake_libvirt_mock(lookupByName=fake_lookup)
687# self.mox.StubOutWithMock(self.compute, "recover_live_migration")
688 self.mox.StubOutWithMock(self.compute, "rollback_live_migration")690 self.mox.StubOutWithMock(self.compute, "rollback_live_migration")
689# self.compute.recover_live_migration(self.context, instance_ref,
690# dest='dest')
691 self.compute.rollback_live_migration(self.context, instance_ref,691 self.compute.rollback_live_migration(self.context, instance_ref,
692 'dest', False)692 'dest', False)
693693
@@ -722,7 +722,8 @@
722722
723 # Test data723 # Test data
724 instance_ref = db.instance_create(self.context, self.test_instance)724 instance_ref = db.instance_create(self.context, self.test_instance)
725 dummyjson = '[{"path": "%s/disk", "local_gb": "10G", "type": "raw"}]'725 dummyjson = ('[{"path": "%s/disk", "local_gb": "10G",'
726 ' "type": "raw", "backing_file": ""}]')
726727
727 # Preparing mocks728 # Preparing mocks
728 # qemu-img should be mockd since test environment might not have729 # qemu-img should be mockd since test environment might not have
@@ -763,7 +764,10 @@
763 "</devices></domain>")764 "</devices></domain>")
764765
765 ret = ("image: /test/disk\nfile format: raw\n"766 ret = ("image: /test/disk\nfile format: raw\n"
766 "virtual size: 20G (21474836480 bytes)\ndisk size: 3.1G\n")767 "virtual size: 20G (21474836480 bytes)\ndisk size: 3.1G\n"
768 "disk size: 102M\n"
769 "cluster_size: 2097152\n"
770 "backing file: /test/dummy (actual path: /backing/file)\n")
767771
768 # Preparing mocks772 # Preparing mocks
769 vdmock = self.mox.CreateMock(libvirt.virDomain)773 vdmock = self.mox.CreateMock(libvirt.virDomain)
@@ -793,7 +797,9 @@
793 info[0]['path'] == '/test/disk' and797 info[0]['path'] == '/test/disk' and
794 info[1]['path'] == '/test/disk.local' and798 info[1]['path'] == '/test/disk.local' and
795 info[0]['local_gb'] == '10G' and799 info[0]['local_gb'] == '10G' and
796 info[1]['local_gb'] == '20G')800 info[1]['local_gb'] == '20G' and
801 info[0]['backing_file'] == "" and
802 info[1]['backing_file'] == "file")
797803
798 db.instance_destroy(self.context, instance_ref['id'])804 db.instance_destroy(self.context, instance_ref['id'])
799805
@@ -806,6 +812,10 @@
806 def fake_none(self, instance):812 def fake_none(self, instance):
807 return813 return
808814
815 # _fake_network_info must be called before create_fake_libvirt_mock(),
816 # as _fake_network_info calls utils.import_class() and
817 # create_fake_libvirt_mock() mocks utils.import_class().
818 network_info = _fake_network_info(self.stubs, 1)
809 self.create_fake_libvirt_mock()819 self.create_fake_libvirt_mock()
810 instance = db.instance_create(self.context, self.test_instance)820 instance = db.instance_create(self.context, self.test_instance)
811821
@@ -815,8 +825,6 @@
815 conn.firewall_driver.setattr('setup_basic_filtering', fake_none)825 conn.firewall_driver.setattr('setup_basic_filtering', fake_none)
816 conn.firewall_driver.setattr('prepare_instance_filter', fake_none)826 conn.firewall_driver.setattr('prepare_instance_filter', fake_none)
817827
818 network_info = _fake_network_info(self.stubs, 1)
819
820 try:828 try:
821 conn.spawn(self.context, instance, network_info)829 conn.spawn(self.context, instance, network_info)
822 except Exception, e:830 except Exception, e:
823831
=== modified file 'nova/virt/libvirt/connection.py'
--- nova/virt/libvirt/connection.py 2011-09-20 10:12:01 +0000
+++ nova/virt/libvirt/connection.py 2011-09-28 13:07:25 +0000
@@ -1726,9 +1726,31 @@
17261726
1727 for info in disk_info:1727 for info in disk_info:
1728 base = os.path.basename(info['path'])1728 base = os.path.basename(info['path'])
1729 # Get image type and create empty disk image.1729 # Get image type and create empty disk image, and
1730 # create backing file in case of qcow2.
1730 instance_disk = os.path.join(instance_dir, base)1731 instance_disk = os.path.join(instance_dir, base)
1731 utils.execute('qemu-img', 'create', '-f', info['type'],1732 if not info['backing_file']:
1733 utils.execute('qemu-img', 'create', '-f', info['type'],
1734 instance_disk, info['local_gb'])
1735
1736 else:
1737 # Creating backing file follows same way as spawning instances.
1738 backing_file = os.path.join(FLAGS.instances_path,
1739 '_base', info['backing_file'])
1740
1741 if not os.path.exists(backing_file):
1742 self._cache_image(fn=self._fetch_image,
1743 context=ctxt,
1744 target=info['path'],
1745 fname=info['backing_file'],
1746 cow=FLAGS.use_cow_images,
1747 image_id=instance_ref['image_ref'],
1748 user_id=instance_ref['user_id'],
1749 project_id=instance_ref['project_id'],
1750 size=instance_ref['local_gb'])
1751
1752 utils.execute('qemu-img', 'create', '-f', info['type'],
1753 '-o', 'backing_file=%s' % backing_file,
1732 instance_disk, info['local_gb'])1754 instance_disk, info['local_gb'])
17331755
1734 # if image has kernel and ramdisk, just download1756 # if image has kernel and ramdisk, just download
@@ -1819,12 +1841,17 @@
1819 driver_nodes[cnt].get_properties().get_next().getContent()1841 driver_nodes[cnt].get_properties().get_next().getContent()
1820 if disk_type == 'raw':1842 if disk_type == 'raw':
1821 size = int(os.path.getsize(path))1843 size = int(os.path.getsize(path))
1844 backing_file = ""
1822 else:1845 else:
1823 out, err = utils.execute('qemu-img', 'info', path)1846 out, err = utils.execute('qemu-img', 'info', path)
1824 size = [i.split('(')[1].split()[0] for i in out.split('\n')1847 size = [i.split('(')[1].split()[0] for i in out.split('\n')
1825 if i.strip().find('virtual size') >= 0]1848 if i.strip().find('virtual size') >= 0]
1826 size = int(size[0])1849 size = int(size[0])
18271850
1851 backing_file = [i.split('actual path:')[1].strip()[:-1]
1852 for i in out.split('\n') if 0 <= i.find('backing file')]
1853 backing_file = os.path.basename(backing_file[0])
1854
1828 # block migration needs same/larger size of empty image on the1855 # block migration needs same/larger size of empty image on the
1829 # destination host. since qemu-img creates bit smaller size image1856 # destination host. since qemu-img creates bit smaller size image
1830 # depending on original image size, fixed value is necessary.1857 # depending on original image size, fixed value is necessary.
@@ -1840,7 +1867,7 @@
1840 break1867 break
18411868
1842 disk_info.append({'type': disk_type, 'path': path,1869 disk_info.append({'type': disk_type, 'path': path,
1843 'local_gb': size})1870 'local_gb': size, 'backing_file': backing_file})
18441871
1845 return utils.dumps(disk_info)1872 return utils.dumps(disk_info)
18461873