~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/tests/test_libvirt.py

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman
  • Date: 2013-08-09 10:12:27 UTC
  • mfrom: (1.1.74)
  • Revision ID: package-import@ubuntu.com-20130809101227-4n60fzcgra8dzk3d
Tags: 1:2013.1.3-0ubuntu1
* Resynchronize with stable/grizzly (89c7ee4) (LP: #1210447):
  - [8e6edd2] Bump stable/grizzly next version to 2013.1.3
  - [61fc529] attach quantum security group to an existing vm failed
    LP: 1189059
  - [60774bd] nova-compute fails to start if quantum is down LP: 1186357
  - [8e6d4b6] asymmetric routes in nova network with external gateway and
    routing_source_ip LP: 1182143
  - [8849413] Failed VM's not set to error state on exception LP: 1182056
  - [ef10eee] Double healing of info_cache with cells LP: 1180304
  - [7422d83] Can't log into  VM after powervm is resized LP: 1169848
  - [49ab0e8] stack trace when instance_actions extension can not find
    instance in GET LP: 1182867
  - [e71247c] nova service-list returns illegal result with non db service
    heartbeat LP: 1168861
  - [3f60606] Volume IO usage gets reset to 0 after a reboot / crash
    LP: 1169097
  - [19c443b] unused method  list_interfaces in vmware driver can be removed
    LP: 1187251
  - [a8dab9f] No cleanup done when file transfer fails with powervm driver
    LP: 1173017
  - [fc98015] nova consoleauth depends on Conductor Service LP: 1186123
  - [1066418] VMware drivers are no longer passing quantum port-id to
    vCenter LP: 1183452
  - [b92075c] nova net-list fails on empty list with Quantum backend
    LP: 1189976
  - [3ba31f2] Create VM with no networks with Quantum Gives SecurityGroups
    Exception LP: 1191044
  - [89150b2] Periodic ValueErrors when using qpid LP: 1185465
  - [0e0d615] Libvirt pre-Grizzly instances cannot be block migrated
    LP: 1185588
  - [27960ef] ZMQ ipc socket file is created using un-sanitized network
    input LP: 1122763
  - [265b868] cannot block migrate old style instances libvirt complains
    LP: 1175286
  - [008a68a] code logical error exists in vmwareapi vif.py  LP: 1177635
  - [378c045] Instance IP addresses are re-used even when previous instance
    could not be powered off LP: 1180178
  - [48ddffe] Reboot of compute node breaks VMs with volumes LP: 1188326
  - [f427f01] Missing dashes from console-log LP: 1194032
  - [78ebf1a] network-create returns an internal error when network
    conflicts LP: 1158075
  - [767c850] Instance nics are reorder after reboot LP: 1187092
  - [0b45996] instance directory naming update to use uuid  LP: 1186944
  - [06cfad5] Disassociate failed dhcp fixed ip in deallocate_for_instance()
    method LP: 1180766
  - [cbcdfc5] Allow confirm_resize action on an instance in 'deleting'
    status LP: 1189391
  - [2563c44] aggregate_get_by_host returns aggregates from other hosts
    LP: 1201277
  - [109f3a9] nova libvirt driver requires iscsi initiator name regardless
    of using it in volume drivers LP: 1007084
  - [7f1c336] Host is always set to None in get_instance_nw_info(...)
    LP: 1194178
  - [1cf30a3] nova boot with colume should fail if the volume is already
    attached to another instance LP: 1166770
  - [9cb9361] Aggregate metadata filtering by key returns unrelated metadata
    LP: 1201283
  - [a61872b] Need clean up  ftp transfer faiure  in powervm driver
    LP: 1188884
  - [91bcd15] Race can cause soft deleted instance to be erased by mistake
    LP: 1186243
  - [c57fded] Nova fails to create a security group rule if ::0/0 is used as
    cidr LP: 1199943
  - [c698dd3] VMwareESXDriver and VMwareVCDriver report incorrect stat
    LP: 1180779
  - [e572faf] novnc fails when amqp_rpc_single_reply_queue=True LP: 1193031
  - [34ddd27] eventlet.monkey_patch() for spice and vnc proxy
  - [864837f] hypervisor_hostname not updated on evacuate LP: 1198284
  - [756a772] libvirt migrate/resize on shared storage can cause data loss
    LP: 1177247
  - [889b215] nova live-migration of volume-backed VM fails because of image
    is None LP: 1199811
  - [60712a4] VNC console does not work with VCDriver LP: 1178369
  - [e0aa0f5] metadata service throws error 500 when compute_driver is not
    set LP: 1184641
  - [340d337] Instance IP addresses are re-used even when previous instance
    could not be powered off LP: 1180178
  - [8247dc8] Resource limit circumvention in Nova private flavors
    (CVE-2013-2256) LP: 1194093
  - [bd7e467] Denial of Service in Nova network source security groups
    (CVE-2013-4185) LP: 1184041
  - [c3fddb7] Resize a VM when a volume is attached fails LP: 1190364
  - [01edbaa] Hyper-V versions before 2012 are not properly recognized
    LP: 1203059
  - [b18818a] driver libvirt doesn't honor vif quota LP: 1185030
  - [798984d] config drive not visible to windows LP: 1155842
  - [d18ceb1] nova live-migration failed due to exception.MigrationError
    LP: 1171526
  - [1934dbc] vmware Hyper for nova vnc console url parameters error
    LP: 1172177
  - [89c7ee4] [OSSA 2013-023] Potential unsafe XML usage (CVE-2013-4179,
    CVE-2013-4202) LP: 1190229
* debian/rules: Clean new setuptools-git cruft.
* debian/control: Update Vcs fields.

Show diffs side-by-side

added added

removed removed

Lines of Context:
542
542
 
543
543
        self.assertEquals(type(cfg.devices[2]),
544
544
                          vconfig.LibvirtConfigGuestDisk)
545
 
        self.assertEquals(cfg.devices[2].target_dev, 'vdz')
 
545
        self.assertEquals(cfg.devices[2].target_dev, 'hdd')
546
546
 
547
547
    def test_get_guest_config_with_vnc(self):
548
548
        self.flags(libvirt_type='kvm',
2190
2190
        conn._check_shared_storage_test_file("file").AndReturn(False)
2191
2191
 
2192
2192
        self.mox.StubOutWithMock(conn, "_assert_dest_node_has_enough_disk")
2193
 
        conn._assert_dest_node_has_enough_disk(self.context, instance_ref,
2194
 
                                        dest_check_data['disk_available_mb'],
2195
 
                                               False)
 
2193
        conn._assert_dest_node_has_enough_disk(
 
2194
            self.context, instance_ref, dest_check_data['disk_available_mb'],
 
2195
            False)
2196
2196
 
2197
2197
        self.mox.ReplayAll()
2198
2198
        conn.check_can_live_migrate_source(self.context, instance_ref,
2393
2393
            self.mox.ReplayAll()
2394
2394
            migrate_data = {'is_shared_storage': False,
2395
2395
                            'is_volume_backed': True,
2396
 
                            'block_migration': False
 
2396
                            'block_migration': False,
 
2397
                            'instance_relative_path': inst_ref['name']
2397
2398
                            }
2398
2399
            ret = conn.pre_live_migration(c, inst_ref, vol, nw_info,
2399
2400
                                          migrate_data)
2400
2401
            self.assertEqual(ret, None)
2401
2402
            self.assertTrue(os.path.exists('%s/%s/' % (tmpdir,
2402
 
                                                       inst_ref['uuid'])))
 
2403
                                                       inst_ref['name'])))
2403
2404
        db.instance_destroy(self.context, inst_ref['uuid'])
2404
2405
 
2405
2406
    def test_pre_block_migration_works_correctly(self):
2502
2503
 
2503
2504
        db.instance_destroy(self.context, instance_ref['uuid'])
2504
2505
 
 
2506
    def test_get_instance_disk_info_excludes_volumes(self):
 
2507
        # Test data
 
2508
        instance_ref = db.instance_create(self.context, self.test_instance)
 
2509
        dummyxml = ("<domain type='kvm'><name>instance-0000000a</name>"
 
2510
                    "<devices>"
 
2511
                    "<disk type='file'><driver name='qemu' type='raw'/>"
 
2512
                    "<source file='/test/disk'/>"
 
2513
                    "<target dev='vda' bus='virtio'/></disk>"
 
2514
                    "<disk type='file'><driver name='qemu' type='qcow2'/>"
 
2515
                    "<source file='/test/disk.local'/>"
 
2516
                    "<target dev='vdb' bus='virtio'/></disk>"
 
2517
                    "<disk type='file'><driver name='qemu' type='qcow2'/>"
 
2518
                    "<source file='/fake/path/to/volume1'/>"
 
2519
                    "<target dev='vdc' bus='virtio'/></disk>"
 
2520
                    "<disk type='file'><driver name='qemu' type='qcow2'/>"
 
2521
                    "<source file='/fake/path/to/volume2'/>"
 
2522
                    "<target dev='vdd' bus='virtio'/></disk>"
 
2523
                    "</devices></domain>")
 
2524
 
 
2525
        # Preparing mocks
 
2526
        vdmock = self.mox.CreateMock(libvirt.virDomain)
 
2527
        self.mox.StubOutWithMock(vdmock, "XMLDesc")
 
2528
        vdmock.XMLDesc(0).AndReturn(dummyxml)
 
2529
 
 
2530
        def fake_lookup(instance_name):
 
2531
            if instance_name == instance_ref['name']:
 
2532
                return vdmock
 
2533
        self.create_fake_libvirt_mock(lookupByName=fake_lookup)
 
2534
 
 
2535
        GB = 1024 * 1024 * 1024
 
2536
        fake_libvirt_utils.disk_sizes['/test/disk'] = 10 * GB
 
2537
        fake_libvirt_utils.disk_sizes['/test/disk.local'] = 20 * GB
 
2538
        fake_libvirt_utils.disk_backing_files['/test/disk.local'] = 'file'
 
2539
 
 
2540
        self.mox.StubOutWithMock(os.path, "getsize")
 
2541
        os.path.getsize('/test/disk').AndReturn((10737418240))
 
2542
        os.path.getsize('/test/disk.local').AndReturn((3328599655))
 
2543
 
 
2544
        ret = ("image: /test/disk\n"
 
2545
               "file format: raw\n"
 
2546
               "virtual size: 20G (21474836480 bytes)\n"
 
2547
               "disk size: 3.1G\n"
 
2548
               "cluster_size: 2097152\n"
 
2549
               "backing file: /test/dummy (actual path: /backing/file)\n")
 
2550
 
 
2551
        self.mox.StubOutWithMock(os.path, "exists")
 
2552
        os.path.exists('/test/disk.local').AndReturn(True)
 
2553
 
 
2554
        self.mox.StubOutWithMock(utils, "execute")
 
2555
        utils.execute('env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
 
2556
                      '/test/disk.local').AndReturn((ret, ''))
 
2557
 
 
2558
        self.mox.ReplayAll()
 
2559
        conn_info = {'driver_volume_type': 'fake'}
 
2560
        info = {'block_device_mapping': [
 
2561
                  {'connection_info': conn_info, 'mount_device': '/dev/vdc'},
 
2562
                  {'connection_info': conn_info, 'mount_device': '/dev/vdd'}]}
 
2563
        conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
 
2564
        info = conn.get_instance_disk_info(instance_ref['name'],
 
2565
                                           block_device_info=info)
 
2566
        info = jsonutils.loads(info)
 
2567
        self.assertEquals(info[0]['type'], 'raw')
 
2568
        self.assertEquals(info[0]['path'], '/test/disk')
 
2569
        self.assertEquals(info[0]['disk_size'], 10737418240)
 
2570
        self.assertEquals(info[0]['backing_file'], "")
 
2571
        self.assertEquals(info[0]['over_committed_disk_size'], 0)
 
2572
        self.assertEquals(info[1]['type'], 'qcow2')
 
2573
        self.assertEquals(info[1]['path'], '/test/disk.local')
 
2574
        self.assertEquals(info[1]['virt_disk_size'], 21474836480)
 
2575
        self.assertEquals(info[1]['backing_file'], "file")
 
2576
        self.assertEquals(info[1]['over_committed_disk_size'], 18146236825)
 
2577
 
 
2578
        db.instance_destroy(self.context, instance_ref['uuid'])
 
2579
 
2505
2580
    def test_spawn_with_network_info(self):
2506
2581
        # Preparing mocks
2507
2582
        def fake_none(*args, **kwargs):
3071
3146
                    "uuid": "875a8070-d0b9-4949-8b31-104d125c9a64"}
3072
3147
        conn.destroy(instance, [])
3073
3148
 
 
3149
    def test_destroy_timed_out(self):
 
3150
        mock = self.mox.CreateMock(libvirt.virDomain)
 
3151
        mock.ID()
 
3152
        mock.destroy().AndRaise(libvirt.libvirtError("timed out"))
 
3153
        self.mox.ReplayAll()
 
3154
 
 
3155
        def fake_lookup_by_name(instance_name):
 
3156
            return mock
 
3157
 
 
3158
        def fake_get_error_code(self):
 
3159
            return libvirt.VIR_ERR_OPERATION_TIMEOUT
 
3160
 
 
3161
        conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
 
3162
        self.stubs.Set(conn, '_lookup_by_name', fake_lookup_by_name)
 
3163
        self.stubs.Set(libvirt.libvirtError, 'get_error_code',
 
3164
                fake_get_error_code)
 
3165
        instance = {"name": "instancename", "id": "instanceid",
 
3166
                    "uuid": "875a8070-d0b9-4949-8b31-104d125c9a64"}
 
3167
        self.assertRaises(exception.InstancePowerOffFailure,
 
3168
                conn.destroy, instance, [])
 
3169
 
3074
3170
    def test_private_destroy_not_found(self):
3075
3171
        mock = self.mox.CreateMock(libvirt.virDomain)
3076
3172
        mock.ID()
3715
3811
        conn.set_cache_mode(fake_conf)
3716
3812
        self.assertEqual(fake_conf.driver_cache, 'fake')
3717
3813
 
 
3814
    def _test_shared_storage_detection(self, is_same):
 
3815
        conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
 
3816
        self.mox.StubOutWithMock(conn, 'get_host_ip_addr')
 
3817
        self.mox.StubOutWithMock(utils, 'execute')
 
3818
        self.mox.StubOutWithMock(os.path, 'exists')
 
3819
        self.mox.StubOutWithMock(os, 'unlink')
 
3820
        conn.get_host_ip_addr().AndReturn('bar')
 
3821
        utils.execute('ssh', 'foo', 'touch', mox.IgnoreArg())
 
3822
        os.path.exists(mox.IgnoreArg()).AndReturn(is_same)
 
3823
        if is_same:
 
3824
            os.unlink(mox.IgnoreArg())
 
3825
        else:
 
3826
            utils.execute('ssh', 'foo', 'rm', mox.IgnoreArg())
 
3827
        self.mox.ReplayAll()
 
3828
        return conn._is_storage_shared_with('foo', '/path')
 
3829
 
 
3830
    def test_shared_storage_detection_same_host(self):
 
3831
        self.assertTrue(self._test_shared_storage_detection(True))
 
3832
 
 
3833
    def test_shared_storage_detection_different_host(self):
 
3834
        self.assertFalse(self._test_shared_storage_detection(False))
 
3835
 
 
3836
    def test_shared_storage_detection_easy(self):
 
3837
        conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
 
3838
        self.mox.StubOutWithMock(conn, 'get_host_ip_addr')
 
3839
        self.mox.StubOutWithMock(utils, 'execute')
 
3840
        self.mox.StubOutWithMock(os.path, 'exists')
 
3841
        self.mox.StubOutWithMock(os, 'unlink')
 
3842
        conn.get_host_ip_addr().AndReturn('foo')
 
3843
        self.mox.ReplayAll()
 
3844
        self.assertTrue(conn._is_storage_shared_with('foo', '/path'))
 
3845
 
3718
3846
 
3719
3847
class HostStateTestCase(test.TestCase):
3720
3848
 
3963
4091
        from nova.network import linux_net
3964
4092
        linux_net.iptables_manager.execute = fake_iptables_execute
3965
4093
 
3966
 
        _fake_stub_out_get_nw_info(self.stubs, lambda *a, **kw: network_model)
 
4094
        from nova.compute import utils as compute_utils
 
4095
        self.stubs.Set(compute_utils, 'get_nw_info_for_instance',
 
4096
                       lambda instance: network_model)
3967
4097
 
3968
4098
        network_info = network_model.legacy()
3969
4099
        self.fw.prepare_instance_filter(instance_ref, network_info)
4408
4538
        result = libvirt_utils.get_iscsi_initiator()
4409
4539
        self.assertEqual(initiator, result)
4410
4540
 
 
4541
    def test_get_missing_iscsi_initiator(self):
 
4542
        self.mox.StubOutWithMock(utils, 'execute')
 
4543
        file_path = '/etc/iscsi/initiatorname.iscsi'
 
4544
        utils.execute('cat', file_path, run_as_root=True).AndRaise(
 
4545
            exception.FileNotFound(file_path=file_path)
 
4546
        )
 
4547
        # Start test
 
4548
        self.mox.ReplayAll()
 
4549
        result = libvirt_utils.get_iscsi_initiator()
 
4550
        self.assertIsNone(result)
 
4551
 
4411
4552
    def test_create_image(self):
4412
4553
        self.mox.StubOutWithMock(utils, 'execute')
4413
4554
        utils.execute('qemu-img', 'create', '-f', 'raw',
4734
4875
        .migrate_disk_and_power_off. """
4735
4876
 
4736
4877
        self.counter = 0
 
4878
        self.checked_shared_storage = False
4737
4879
 
4738
 
        def fake_get_instance_disk_info(instance, xml=None):
 
4880
        def fake_get_instance_disk_info(instance, xml=None,
 
4881
                                        block_device_info=None):
4739
4882
            return '[]'
4740
4883
 
4741
4884
        def fake_destroy(instance):
4752
4895
        def fake_os_path_exists(path):
4753
4896
            return True
4754
4897
 
 
4898
        def fake_is_storage_shared(dest, inst_base):
 
4899
            self.checked_shared_storage = True
 
4900
            return False
 
4901
 
4755
4902
        self.stubs.Set(self.libvirtconnection, 'get_instance_disk_info',
4756
4903
                       fake_get_instance_disk_info)
4757
4904
        self.stubs.Set(self.libvirtconnection, '_destroy', fake_destroy)
4758
4905
        self.stubs.Set(self.libvirtconnection, 'get_host_ip_addr',
4759
4906
                       fake_get_host_ip_addr)
 
4907
        self.stubs.Set(self.libvirtconnection, '_is_storage_shared_with',
 
4908
                       fake_is_storage_shared)
4760
4909
        self.stubs.Set(utils, 'execute', fake_execute)
4761
4910
        self.stubs.Set(os.path, 'exists', fake_os_path_exists)
4762
4911
 
4780
4929
                      'disk_size': '83886080'}]
4781
4930
        disk_info_text = jsonutils.dumps(disk_info)
4782
4931
 
4783
 
        def fake_get_instance_disk_info(instance, xml=None):
 
4932
        def fake_get_instance_disk_info(instance, xml=None,
 
4933
                                        block_device_info=None):
4784
4934
            return disk_info_text
4785
4935
 
4786
4936
        def fake_destroy(instance):