Add context argument a lot more places and make unit tests work
This commit is contained in:
		@@ -365,7 +365,7 @@ class LibvirtConnTestCase(test.TestCase):
 | 
				
			|||||||
        self.mox.ReplayAll()
 | 
					        self.mox.ReplayAll()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        conn = connection.LibvirtConnection(False)
 | 
					        conn = connection.LibvirtConnection(False)
 | 
				
			||||||
        conn.snapshot(instance_ref, recv_meta['id'])
 | 
					        conn.snapshot(self.context, instance_ref, recv_meta['id'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        snapshot = image_service.show(context, recv_meta['id'])
 | 
					        snapshot = image_service.show(context, recv_meta['id'])
 | 
				
			||||||
        self.assertEquals(snapshot['properties']['image_state'], 'available')
 | 
					        self.assertEquals(snapshot['properties']['image_state'], 'available')
 | 
				
			||||||
@@ -405,7 +405,7 @@ class LibvirtConnTestCase(test.TestCase):
 | 
				
			|||||||
        self.mox.ReplayAll()
 | 
					        self.mox.ReplayAll()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        conn = connection.LibvirtConnection(False)
 | 
					        conn = connection.LibvirtConnection(False)
 | 
				
			||||||
        conn.snapshot(instance_ref, recv_meta['id'])
 | 
					        conn.snapshot(self.context, instance_ref, recv_meta['id'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        snapshot = image_service.show(context, recv_meta['id'])
 | 
					        snapshot = image_service.show(context, recv_meta['id'])
 | 
				
			||||||
        self.assertEquals(snapshot['properties']['image_state'], 'available')
 | 
					        self.assertEquals(snapshot['properties']['image_state'], 'available')
 | 
				
			||||||
@@ -775,7 +775,7 @@ class LibvirtConnTestCase(test.TestCase):
 | 
				
			|||||||
        network_info = [(network, mapping)]
 | 
					        network_info = [(network, mapping)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            conn.spawn(instance, network_info)
 | 
					            conn.spawn(context.get_admin_context(), instance, network_info)
 | 
				
			||||||
        except Exception, e:
 | 
					        except Exception, e:
 | 
				
			||||||
            count = (0 <= str(e.message).find('Unexpected method call'))
 | 
					            count = (0 <= str(e.message).find('Unexpected method call'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -227,7 +227,7 @@ class XenAPIVMTestCase(test.TestCase):
 | 
				
			|||||||
                               'mac': 'DE:AD:BE:EF:00:00',
 | 
					                               'mac': 'DE:AD:BE:EF:00:00',
 | 
				
			||||||
                               'rxtx_cap': 3})]
 | 
					                               'rxtx_cap': 3})]
 | 
				
			||||||
            instance = db.instance_create(self.context, values)
 | 
					            instance = db.instance_create(self.context, values)
 | 
				
			||||||
            self.conn.spawn(instance, network_info)
 | 
					            self.conn.spawn(self.context, instance, network_info)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        gt1 = eventlet.spawn(_do_build, 1, self.project.id, self.user.id)
 | 
					        gt1 = eventlet.spawn(_do_build, 1, self.project.id, self.user.id)
 | 
				
			||||||
        gt2 = eventlet.spawn(_do_build, 2, self.project.id, self.user.id)
 | 
					        gt2 = eventlet.spawn(_do_build, 2, self.project.id, self.user.id)
 | 
				
			||||||
@@ -257,14 +257,15 @@ class XenAPIVMTestCase(test.TestCase):
 | 
				
			|||||||
        instance = self._create_instance()
 | 
					        instance = self._create_instance()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        name = "MySnapshot"
 | 
					        name = "MySnapshot"
 | 
				
			||||||
        self.assertRaises(exception.Error, self.conn.snapshot, instance, name)
 | 
					        self.assertRaises(exception.Error, self.conn.snapshot,
 | 
				
			||||||
 | 
					                          self.context, instance, name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_instance_snapshot(self):
 | 
					    def test_instance_snapshot(self):
 | 
				
			||||||
        stubs.stubout_instance_snapshot(self.stubs)
 | 
					        stubs.stubout_instance_snapshot(self.stubs)
 | 
				
			||||||
        instance = self._create_instance()
 | 
					        instance = self._create_instance()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        name = "MySnapshot"
 | 
					        name = "MySnapshot"
 | 
				
			||||||
        template_vm_ref = self.conn.snapshot(instance, name)
 | 
					        template_vm_ref = self.conn.snapshot(self.context, instance, name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def ensure_vm_was_torn_down():
 | 
					        def ensure_vm_was_torn_down():
 | 
				
			||||||
            vm_labels = []
 | 
					            vm_labels = []
 | 
				
			||||||
@@ -422,7 +423,7 @@ class XenAPIVMTestCase(test.TestCase):
 | 
				
			|||||||
                           'label': 'fake',
 | 
					                           'label': 'fake',
 | 
				
			||||||
                           'mac': 'DE:AD:BE:EF:00:00',
 | 
					                           'mac': 'DE:AD:BE:EF:00:00',
 | 
				
			||||||
                           'rxtx_cap': 3})]
 | 
					                           'rxtx_cap': 3})]
 | 
				
			||||||
        self.conn.spawn(instance, network_info)
 | 
					        self.conn.spawn(self.context, instance, network_info)
 | 
				
			||||||
        self.create_vm_record(self.conn, os_type, instance_id)
 | 
					        self.create_vm_record(self.conn, os_type, instance_id)
 | 
				
			||||||
        self.check_vm_record(self.conn, check_injection)
 | 
					        self.check_vm_record(self.conn, check_injection)
 | 
				
			||||||
        self.assertTrue(instance.os_type)
 | 
					        self.assertTrue(instance.os_type)
 | 
				
			||||||
@@ -691,7 +692,7 @@ class XenAPIVMTestCase(test.TestCase):
 | 
				
			|||||||
                           'label': 'fake',
 | 
					                           'label': 'fake',
 | 
				
			||||||
                           'mac': 'DE:AD:BE:EF:00:00',
 | 
					                           'mac': 'DE:AD:BE:EF:00:00',
 | 
				
			||||||
                           'rxtx_cap': 3})]
 | 
					                           'rxtx_cap': 3})]
 | 
				
			||||||
        self.conn.spawn(instance, network_info)
 | 
					        self.conn.spawn(self.context, instance, network_info)
 | 
				
			||||||
        return instance
 | 
					        return instance
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -802,8 +803,9 @@ class XenAPIMigrateInstance(test.TestCase):
 | 
				
			|||||||
                           'label': 'fake',
 | 
					                           'label': 'fake',
 | 
				
			||||||
                           'mac': 'DE:AD:BE:EF:00:00',
 | 
					                           'mac': 'DE:AD:BE:EF:00:00',
 | 
				
			||||||
                           'rxtx_cap': 3})]
 | 
					                           'rxtx_cap': 3})]
 | 
				
			||||||
        conn.finish_resize(instance, dict(base_copy='hurr', cow='durr'),
 | 
					        conn.finish_resize(self.context, instance,
 | 
				
			||||||
                                                           network_info)
 | 
					                           dict(base_copy='hurr', cow='durr'),
 | 
				
			||||||
 | 
					                           network_info)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class XenAPIDetermineDiskImageTestCase(test.TestCase):
 | 
					class XenAPIDetermineDiskImageTestCase(test.TestCase):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,8 +28,8 @@ from nova import utils
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def stubout_instance_snapshot(stubs):
 | 
					def stubout_instance_snapshot(stubs):
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def fake_fetch_image(cls, session, instance_id, image, user, project,
 | 
					    def fake_fetch_image(cls, context, session, instance_id, image, user,
 | 
				
			||||||
                         type):
 | 
					                         project, type):
 | 
				
			||||||
        from nova.virt.xenapi.fake import create_vdi
 | 
					        from nova.virt.xenapi.fake import create_vdi
 | 
				
			||||||
        name_label = "instance-%s" % instance_id
 | 
					        name_label = "instance-%s" % instance_id
 | 
				
			||||||
        #TODO: create fake SR record
 | 
					        #TODO: create fake SR record
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -61,7 +61,8 @@ class ComputeDriver(object):
 | 
				
			|||||||
        """Return a list of InstanceInfo for all registered VMs"""
 | 
					        """Return a list of InstanceInfo for all registered VMs"""
 | 
				
			||||||
        raise NotImplementedError()
 | 
					        raise NotImplementedError()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def spawn(self, instance, network_info, block_device_mapping=None):
 | 
					    def spawn(self, context, instance, network_info,
 | 
				
			||||||
 | 
					              block_device_mapping=None):
 | 
				
			||||||
        """Launch a VM for the specified instance"""
 | 
					        """Launch a VM for the specified instance"""
 | 
				
			||||||
        raise NotImplementedError()
 | 
					        raise NotImplementedError()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -118,11 +119,11 @@ class ComputeDriver(object):
 | 
				
			|||||||
        off the instance copies over the COW disk"""
 | 
					        off the instance copies over the COW disk"""
 | 
				
			||||||
        raise NotImplementedError()
 | 
					        raise NotImplementedError()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def snapshot(self, instance, image_id):
 | 
					    def snapshot(self, context, instance, image_id):
 | 
				
			||||||
        """Create snapshot from a running VM instance."""
 | 
					        """Create snapshot from a running VM instance."""
 | 
				
			||||||
        raise NotImplementedError()
 | 
					        raise NotImplementedError()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def finish_resize(self, instance, disk_info):
 | 
					    def finish_resize(self, context, instance, disk_info):
 | 
				
			||||||
        """Completes a resize, turning on the migrated instance"""
 | 
					        """Completes a resize, turning on the migrated instance"""
 | 
				
			||||||
        raise NotImplementedError()
 | 
					        raise NotImplementedError()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -129,7 +129,8 @@ class FakeConnection(driver.ComputeDriver):
 | 
				
			|||||||
            info_list.append(self._map_to_instance_info(instance))
 | 
					            info_list.append(self._map_to_instance_info(instance))
 | 
				
			||||||
        return info_list
 | 
					        return info_list
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def spawn(self, instance, network_info, block_device_mapping=None):
 | 
					    def spawn(self, context, instance, network_info,
 | 
				
			||||||
 | 
					              block_device_mapping=None):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Create a new instance/VM/domain on the virtualization platform.
 | 
					        Create a new instance/VM/domain on the virtualization platform.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -153,7 +154,7 @@ class FakeConnection(driver.ComputeDriver):
 | 
				
			|||||||
        fake_instance = FakeInstance(name, state)
 | 
					        fake_instance = FakeInstance(name, state)
 | 
				
			||||||
        self.instances[name] = fake_instance
 | 
					        self.instances[name] = fake_instance
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def snapshot(self, instance, name):
 | 
					    def snapshot(self, context, instance, name):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Snapshots the specified instance.
 | 
					        Snapshots the specified instance.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -139,7 +139,8 @@ class HyperVConnection(driver.ComputeDriver):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return instance_infos
 | 
					        return instance_infos
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def spawn(self, instance, network_info, block_device_mapping=None):
 | 
					    def spawn(self, context, instance, network_info,
 | 
				
			||||||
 | 
					              block_device_mapping=None):
 | 
				
			||||||
        """ Create a new VM and start it."""
 | 
					        """ Create a new VM and start it."""
 | 
				
			||||||
        vm = self._lookup(instance.name)
 | 
					        vm = self._lookup(instance.name)
 | 
				
			||||||
        if vm is not None:
 | 
					        if vm is not None:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -399,7 +399,7 @@ class LibvirtConnection(driver.ComputeDriver):
 | 
				
			|||||||
        virt_dom.detachDevice(xml)
 | 
					        virt_dom.detachDevice(xml)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @exception.wrap_exception()
 | 
					    @exception.wrap_exception()
 | 
				
			||||||
    def snapshot(self, instance, image_href):
 | 
					    def snapshot(self, context, instance, image_href):
 | 
				
			||||||
        """Create snapshot from a running VM instance.
 | 
					        """Create snapshot from a running VM instance.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        This command only works with qemu 0.14+, the qemu_img flag is
 | 
					        This command only works with qemu 0.14+, the qemu_img flag is
 | 
				
			||||||
@@ -595,7 +595,8 @@ class LibvirtConnection(driver.ComputeDriver):
 | 
				
			|||||||
    # NOTE(ilyaalekseyev): Implementation like in multinics
 | 
					    # NOTE(ilyaalekseyev): Implementation like in multinics
 | 
				
			||||||
    # for xenapi(tr3buchet)
 | 
					    # for xenapi(tr3buchet)
 | 
				
			||||||
    @exception.wrap_exception()
 | 
					    @exception.wrap_exception()
 | 
				
			||||||
    def spawn(self, instance, network_info, block_device_mapping=None):
 | 
					    def spawn(self, context, instance, network_info,
 | 
				
			||||||
 | 
					              block_device_mapping=None):
 | 
				
			||||||
        xml = self.to_xml(instance, False, network_info=network_info,
 | 
					        xml = self.to_xml(instance, False, network_info=network_info,
 | 
				
			||||||
                          block_device_mapping=block_device_mapping)
 | 
					                          block_device_mapping=block_device_mapping)
 | 
				
			||||||
        block_device_mapping = block_device_mapping or []
 | 
					        block_device_mapping = block_device_mapping or []
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -89,7 +89,7 @@ class VMWareVMOps(object):
 | 
				
			|||||||
        LOG.debug(_("Got total of %s instances") % str(len(lst_vm_names)))
 | 
					        LOG.debug(_("Got total of %s instances") % str(len(lst_vm_names)))
 | 
				
			||||||
        return lst_vm_names
 | 
					        return lst_vm_names
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def spawn(self, instance, network_info):
 | 
					    def spawn(self, context, instance, network_info):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Creates a VM instance.
 | 
					        Creates a VM instance.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -329,7 +329,7 @@ class VMWareVMOps(object):
 | 
				
			|||||||
            LOG.debug(_("Powered on the VM instance %s") % instance.name)
 | 
					            LOG.debug(_("Powered on the VM instance %s") % instance.name)
 | 
				
			||||||
        _power_on_vm()
 | 
					        _power_on_vm()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def snapshot(self, instance, snapshot_name):
 | 
					    def snapshot(self, context, instance, snapshot_name):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Create snapshot from a running VM instance.
 | 
					        Create snapshot from a running VM instance.
 | 
				
			||||||
        Steps followed are:
 | 
					        Steps followed are:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -124,13 +124,14 @@ class VMWareESXConnection(driver.ComputeDriver):
 | 
				
			|||||||
        """List VM instances."""
 | 
					        """List VM instances."""
 | 
				
			||||||
        return self._vmops.list_instances()
 | 
					        return self._vmops.list_instances()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def spawn(self, instance, network_info, block_device_mapping=None):
 | 
					    def spawn(self, context, instance, network_info,
 | 
				
			||||||
 | 
					              block_device_mapping=None):
 | 
				
			||||||
        """Create VM instance."""
 | 
					        """Create VM instance."""
 | 
				
			||||||
        self._vmops.spawn(instance, network_info)
 | 
					        self._vmops.spawn(context, instance, network_info)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def snapshot(self, instance, name):
 | 
					    def snapshot(self, context, instance, name):
 | 
				
			||||||
        """Create snapshot from a running VM instance."""
 | 
					        """Create snapshot from a running VM instance."""
 | 
				
			||||||
        self._vmops.snapshot(instance, name)
 | 
					        self._vmops.snapshot(context, instance, name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def reboot(self, instance, network_info):
 | 
					    def reboot(self, instance, network_info):
 | 
				
			||||||
        """Reboot VM instance."""
 | 
					        """Reboot VM instance."""
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -209,8 +209,8 @@ class VMOps(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            if instance.vm_mode != vm_mode:
 | 
					            if instance.vm_mode != vm_mode:
 | 
				
			||||||
                # Update database with normalized (or determined) value
 | 
					                # Update database with normalized (or determined) value
 | 
				
			||||||
                db.instance_update(context.get_admin_context(),
 | 
					                db.instance_update(context, instance['id'],
 | 
				
			||||||
                                   instance['id'], {'vm_mode': vm_mode})
 | 
					                                   {'vm_mode': vm_mode})
 | 
				
			||||||
            vm_ref = VMHelper.create_vm(self._session, instance,
 | 
					            vm_ref = VMHelper.create_vm(self._session, instance,
 | 
				
			||||||
                    kernel and kernel.get('file', None) or None,
 | 
					                    kernel and kernel.get('file', None) or None,
 | 
				
			||||||
                    ramdisk and ramdisk.get('file', None) or None,
 | 
					                    ramdisk and ramdisk.get('file', None) or None,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -194,21 +194,22 @@ class XenAPIConnection(driver.ComputeDriver):
 | 
				
			|||||||
    def list_instances_detail(self):
 | 
					    def list_instances_detail(self):
 | 
				
			||||||
        return self._vmops.list_instances_detail()
 | 
					        return self._vmops.list_instances_detail()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def spawn(self, instance, network_info, block_device_mapping=None):
 | 
					    def spawn(self, context, instance, network_info,
 | 
				
			||||||
 | 
					              block_device_mapping=None):
 | 
				
			||||||
        """Create VM instance"""
 | 
					        """Create VM instance"""
 | 
				
			||||||
        self._vmops.spawn(instance, network_info)
 | 
					        self._vmops.spawn(context, instance, network_info)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def revert_resize(self, instance):
 | 
					    def revert_resize(self, instance):
 | 
				
			||||||
        """Reverts a resize, powering back on the instance"""
 | 
					        """Reverts a resize, powering back on the instance"""
 | 
				
			||||||
        self._vmops.revert_resize(instance)
 | 
					        self._vmops.revert_resize(instance)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def finish_resize(self, instance, disk_info, network_info):
 | 
					    def finish_resize(self, context, instance, disk_info, network_info):
 | 
				
			||||||
        """Completes a resize, turning on the migrated instance"""
 | 
					        """Completes a resize, turning on the migrated instance"""
 | 
				
			||||||
        self._vmops.finish_resize(instance, disk_info, network_info)
 | 
					        self._vmops.finish_resize(context, instance, disk_info, network_info)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def snapshot(self, instance, image_id):
 | 
					    def snapshot(self, context, instance, image_id):
 | 
				
			||||||
        """ Create snapshot from a running VM instance """
 | 
					        """ Create snapshot from a running VM instance """
 | 
				
			||||||
        self._vmops.snapshot(instance, image_id)
 | 
					        self._vmops.snapshot(context, instance, image_id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def reboot(self, instance, network_info):
 | 
					    def reboot(self, instance, network_info):
 | 
				
			||||||
        """Reboot VM instance"""
 | 
					        """Reboot VM instance"""
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user