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

« back to all changes in this revision

Viewing changes to nova/tests/test_powervm.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:
19
19
"""
20
20
 
21
21
import contextlib
 
22
import os
22
23
 
23
24
from nova import context
24
25
from nova import db
38
39
from nova.virt.powervm import driver as powervm_driver
39
40
from nova.virt.powervm import exception
40
41
from nova.virt.powervm import lpar
41
 
from nova.virt.powervm import operator
 
42
from nova.virt.powervm import operator as powervm_operator
42
43
 
43
44
LOG = logging.getLogger(__name__)
44
45
 
50
51
                     uptime=939395, state='Running')
51
52
 
52
53
 
53
 
class FakeIVMOperator(object):
 
54
class FakePowerVMOperator(powervm_operator.PowerVMOperator):
 
55
 
 
56
    def get_lpar(self, instance_name, resource_type='lpar'):
 
57
        return fake_lpar(instance_name)
 
58
 
 
59
    def run_vios_command(self, cmd):
 
60
        pass
 
61
 
 
62
 
 
63
class FakeIVMOperator(powervm_operator.IVMOperator):
54
64
 
55
65
    def get_lpar(self, instance_name, resource_type='lpar'):
56
66
        return fake_lpar(instance_name)
105
115
    def rename_lpar(self, old, new):
106
116
        pass
107
117
 
 
118
    def _remove_file(self, file_path):
 
119
        pass
 
120
 
108
121
    def set_lpar_mac_base_value(self, instance_name, mac):
109
122
        pass
110
123
 
152
165
 
153
166
 
154
167
def fake_get_powervm_operator():
155
 
    return FakeIVMOperator()
 
168
    return FakeIVMOperator(None)
156
169
 
157
170
 
158
171
class PowerVMDriverTestCase(test.TestCase):
160
173
 
161
174
    def setUp(self):
162
175
        super(PowerVMDriverTestCase, self).setUp()
163
 
        self.stubs.Set(operator, 'get_powervm_operator',
 
176
        self.stubs.Set(powervm_operator, 'get_powervm_operator',
164
177
                       fake_get_powervm_operator)
165
 
        self.stubs.Set(operator, 'get_powervm_disk_adapter',
 
178
        self.stubs.Set(powervm_operator, 'get_powervm_disk_adapter',
166
179
                       lambda: FakeBlockAdapter())
167
180
        self.powervm_connection = powervm_driver.PowerVMDriver(None)
168
181
        self.instance = self._create_instance()
390
403
        expected_path = 'some/image/path/logical-vol-name_rsz.gz'
391
404
        self.assertEqual(file_path, expected_path)
392
405
 
 
406
    def test_deploy_from_migrated_file(self):
 
407
        instance = self.instance
 
408
        context = 'fake_context'
 
409
        network_info = []
 
410
        network_info.append({'address': 'fa:89:f0:8b:9b:39'})
 
411
        dest = '10.8.46.20'
 
412
        disk_info = {}
 
413
        disk_info['root_disk_file'] = 'some/file/path.gz'
 
414
        disk_info['old_lv_size'] = 30
 
415
        self.flags(powervm_mgr=dest)
 
416
        fake_op = self.powervm_connection._powervm
 
417
        self.deploy_from_vios_file_called = False
 
418
 
 
419
        def fake_deploy_from_vios_file(lpar, file_path, size,
 
420
                                       decompress):
 
421
            exp_file_path = 'some/file/path.gz'
 
422
            exp_size = 40 * 1024 ** 3
 
423
            exp_decompress = True
 
424
            self.deploy_from_vios_file_called = True
 
425
            self.assertEqual(exp_file_path, file_path)
 
426
            self.assertEqual(exp_size, size)
 
427
            self.assertEqual(exp_decompress, decompress)
 
428
 
 
429
        self.stubs.Set(fake_op, '_deploy_from_vios_file',
 
430
                       fake_deploy_from_vios_file)
 
431
        self.powervm_connection.finish_migration(context, None,
 
432
                         instance, disk_info, network_info,
 
433
                         None, resize_instance=True,
 
434
                         block_device_info=None)
 
435
        self.assertEqual(self.deploy_from_vios_file_called, True)
 
436
 
393
437
    def test_set_lpar_mac_base_value(self):
394
438
        instance = self.instance
395
439
        context = 'fake_context'
417
461
 
418
462
        def fake_set_lpar_mac_base_value(inst_name, mac, *args, **kwargs):
419
463
            # get expected mac address from FakeIVM set
420
 
            fake_ivm = FakeIVMOperator()
 
464
            fake_ivm = FakeIVMOperator(None)
421
465
            exp_mac = fake_ivm.macs_for_instance(inst_name).pop()
422
466
            self.assertEqual(exp_mac, mac)
423
467
 
513
557
        self.assertEquals(host_stats['supported_instances'][0][0], "ppc64")
514
558
        self.assertEquals(host_stats['supported_instances'][0][1], "powervm")
515
559
        self.assertEquals(host_stats['supported_instances'][0][2], "hvm")
 
560
 
 
561
 
 
562
class PowerVMLocalVolumeAdapterTestCase(test.TestCase):
 
563
    """
 
564
    Unit tests for nova.virt.powervm.blockdev.PowerVMLocalVolumeAdapter.
 
565
    """
 
566
 
 
567
    def setUp(self):
 
568
        super(PowerVMLocalVolumeAdapterTestCase, self).setUp()
 
569
        self.connection = common.Connection(host='fake_compute_1',
 
570
                                            username='fake_user',
 
571
                                            password='fake_pass')
 
572
        self.powervm_adapter = powervm_blockdev.PowerVMLocalVolumeAdapter(
 
573
                                                            self.connection)
 
574
 
 
575
    def test_copy_image_file_ftp_failed(self):
 
576
        file_path = os.tempnam('/tmp', 'image')
 
577
        remote_path = '/mnt/openstack/images'
 
578
        exp_remote_path = os.path.join(remote_path,
 
579
                                       os.path.basename(file_path))
 
580
        exp_cmd = ' '.join(['/usr/bin/rm -f', exp_remote_path])
 
581
 
 
582
        fake_noop = lambda *args, **kwargs: None
 
583
        fake_op = self.powervm_adapter
 
584
        self.stubs.Set(fake_op, 'run_vios_command', fake_noop)
 
585
        self.stubs.Set(fake_op, '_checksum_local_file', fake_noop)
 
586
 
 
587
        self.mox.StubOutWithMock(common, 'ftp_put_command')
 
588
        self.mox.StubOutWithMock(self.powervm_adapter,
 
589
                                 'run_vios_command_as_root')
 
590
        msg_args = {'ftp_cmd': 'PUT',
 
591
                    'source_path': file_path,
 
592
                    'dest_path': remote_path}
 
593
        exp_exception = exception.PowerVMFTPTransferFailed(**msg_args)
 
594
 
 
595
        common.ftp_put_command(self.connection, file_path,
 
596
                               remote_path).AndRaise(exp_exception)
 
597
 
 
598
        self.powervm_adapter.run_vios_command_as_root(exp_cmd).AndReturn([])
 
599
 
 
600
        self.mox.ReplayAll()
 
601
 
 
602
        self.assertRaises(exception.PowerVMFTPTransferFailed,
 
603
                          self.powervm_adapter._copy_image_file,
 
604
                          file_path, remote_path)
 
605
 
 
606
    def test_copy_image_file_wrong_checksum(self):
 
607
        file_path = os.tempnam('/tmp', 'image')
 
608
        remote_path = '/mnt/openstack/images'
 
609
        exp_remote_path = os.path.join(remote_path,
 
610
                                       os.path.basename(file_path))
 
611
        exp_cmd = ' '.join(['/usr/bin/rm -f', exp_remote_path])
 
612
 
 
613
        def fake_md5sum_remote_file(remote_path):
 
614
            return '3202937169'
 
615
 
 
616
        def fake_checksum_local_file(source_path):
 
617
            return '3229026618'
 
618
 
 
619
        fake_noop = lambda *args, **kwargs: None
 
620
        fake_op = self.powervm_adapter
 
621
        self.stubs.Set(fake_op, 'run_vios_command', fake_noop)
 
622
        self.stubs.Set(fake_op, '_md5sum_remote_file',
 
623
                       fake_md5sum_remote_file)
 
624
        self.stubs.Set(fake_op, '_checksum_local_file',
 
625
                       fake_checksum_local_file)
 
626
        self.stubs.Set(common, 'ftp_put_command', fake_noop)
 
627
 
 
628
        self.mox.StubOutWithMock(self.powervm_adapter,
 
629
                                 'run_vios_command_as_root')
 
630
        self.powervm_adapter.run_vios_command_as_root(exp_cmd).AndReturn([])
 
631
 
 
632
        self.mox.ReplayAll()
 
633
 
 
634
        self.assertRaises(exception.PowerVMFileTransferFailed,
 
635
                          self.powervm_adapter._copy_image_file,
 
636
                          file_path, remote_path)
 
637
 
 
638
    def test_checksum_local_file(self):
 
639
        file_path = os.tempnam('/tmp', 'image')
 
640
        img_file = file(file_path, 'w')
 
641
        img_file.write('This is a test')
 
642
        img_file.close()
 
643
        exp_md5sum = 'ce114e4501d2f4e2dcea3e17b546f339'
 
644
 
 
645
        self.assertEqual(self.powervm_adapter._checksum_local_file(file_path),
 
646
                         exp_md5sum)
 
647
        os.remove(file_path)
 
648
 
 
649
    def test_copy_image_file_from_host_with_wrong_checksum(self):
 
650
        local_path = 'some/tmp'
 
651
        remote_path = os.tempnam('/mnt/openstack/images', 'image')
 
652
 
 
653
        def fake_md5sum_remote_file(remote_path):
 
654
            return '3202937169'
 
655
 
 
656
        def fake_checksum_local_file(source_path):
 
657
            return '3229026618'
 
658
 
 
659
        fake_noop = lambda *args, **kwargs: None
 
660
        fake_op = self.powervm_adapter
 
661
        self.stubs.Set(fake_op, 'run_vios_command_as_root', fake_noop)
 
662
        self.stubs.Set(fake_op, '_md5sum_remote_file',
 
663
                       fake_md5sum_remote_file)
 
664
        self.stubs.Set(fake_op, '_checksum_local_file',
 
665
                       fake_checksum_local_file)
 
666
        self.stubs.Set(common, 'ftp_get_command', fake_noop)
 
667
 
 
668
        self.assertRaises(exception.PowerVMFileTransferFailed,
 
669
                          self.powervm_adapter._copy_image_file_from_host,
 
670
                          remote_path, local_path)