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()
 | 
			
		||||
 | 
			
		||||
        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'])
 | 
			
		||||
        self.assertEquals(snapshot['properties']['image_state'], 'available')
 | 
			
		||||
@@ -405,7 +405,7 @@ class LibvirtConnTestCase(test.TestCase):
 | 
			
		||||
        self.mox.ReplayAll()
 | 
			
		||||
 | 
			
		||||
        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'])
 | 
			
		||||
        self.assertEquals(snapshot['properties']['image_state'], 'available')
 | 
			
		||||
@@ -775,7 +775,7 @@ class LibvirtConnTestCase(test.TestCase):
 | 
			
		||||
        network_info = [(network, mapping)]
 | 
			
		||||
 | 
			
		||||
        try:
 | 
			
		||||
            conn.spawn(instance, network_info)
 | 
			
		||||
            conn.spawn(context.get_admin_context(), instance, network_info)
 | 
			
		||||
        except Exception, e:
 | 
			
		||||
            count = (0 <= str(e.message).find('Unexpected method call'))
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -227,7 +227,7 @@ class XenAPIVMTestCase(test.TestCase):
 | 
			
		||||
                               'mac': 'DE:AD:BE:EF:00:00',
 | 
			
		||||
                               'rxtx_cap': 3})]
 | 
			
		||||
            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)
 | 
			
		||||
        gt2 = eventlet.spawn(_do_build, 2, self.project.id, self.user.id)
 | 
			
		||||
@@ -257,14 +257,15 @@ class XenAPIVMTestCase(test.TestCase):
 | 
			
		||||
        instance = self._create_instance()
 | 
			
		||||
 | 
			
		||||
        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):
 | 
			
		||||
        stubs.stubout_instance_snapshot(self.stubs)
 | 
			
		||||
        instance = self._create_instance()
 | 
			
		||||
 | 
			
		||||
        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():
 | 
			
		||||
            vm_labels = []
 | 
			
		||||
@@ -422,7 +423,7 @@ class XenAPIVMTestCase(test.TestCase):
 | 
			
		||||
                           'label': 'fake',
 | 
			
		||||
                           'mac': 'DE:AD:BE:EF:00:00',
 | 
			
		||||
                           '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.check_vm_record(self.conn, check_injection)
 | 
			
		||||
        self.assertTrue(instance.os_type)
 | 
			
		||||
@@ -691,7 +692,7 @@ class XenAPIVMTestCase(test.TestCase):
 | 
			
		||||
                           'label': 'fake',
 | 
			
		||||
                           'mac': 'DE:AD:BE:EF:00:00',
 | 
			
		||||
                           'rxtx_cap': 3})]
 | 
			
		||||
        self.conn.spawn(instance, network_info)
 | 
			
		||||
        self.conn.spawn(self.context, instance, network_info)
 | 
			
		||||
        return instance
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -802,8 +803,9 @@ class XenAPIMigrateInstance(test.TestCase):
 | 
			
		||||
                           'label': 'fake',
 | 
			
		||||
                           'mac': 'DE:AD:BE:EF:00:00',
 | 
			
		||||
                           'rxtx_cap': 3})]
 | 
			
		||||
        conn.finish_resize(instance, dict(base_copy='hurr', cow='durr'),
 | 
			
		||||
                                                           network_info)
 | 
			
		||||
        conn.finish_resize(self.context, instance,
 | 
			
		||||
                           dict(base_copy='hurr', cow='durr'),
 | 
			
		||||
                           network_info)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class XenAPIDetermineDiskImageTestCase(test.TestCase):
 | 
			
		||||
 
 | 
			
		||||
@@ -28,8 +28,8 @@ from nova import utils
 | 
			
		||||
 | 
			
		||||
def stubout_instance_snapshot(stubs):
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def fake_fetch_image(cls, session, instance_id, image, user, project,
 | 
			
		||||
                         type):
 | 
			
		||||
    def fake_fetch_image(cls, context, session, instance_id, image, user,
 | 
			
		||||
                         project, type):
 | 
			
		||||
        from nova.virt.xenapi.fake import create_vdi
 | 
			
		||||
        name_label = "instance-%s" % instance_id
 | 
			
		||||
        #TODO: create fake SR record
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,8 @@ class ComputeDriver(object):
 | 
			
		||||
        """Return a list of InstanceInfo for all registered VMs"""
 | 
			
		||||
        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"""
 | 
			
		||||
        raise NotImplementedError()
 | 
			
		||||
 | 
			
		||||
@@ -118,11 +119,11 @@ class ComputeDriver(object):
 | 
			
		||||
        off the instance copies over the COW disk"""
 | 
			
		||||
        raise NotImplementedError()
 | 
			
		||||
 | 
			
		||||
    def snapshot(self, instance, image_id):
 | 
			
		||||
    def snapshot(self, context, instance, image_id):
 | 
			
		||||
        """Create snapshot from a running VM instance."""
 | 
			
		||||
        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"""
 | 
			
		||||
        raise NotImplementedError()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -129,7 +129,8 @@ class FakeConnection(driver.ComputeDriver):
 | 
			
		||||
            info_list.append(self._map_to_instance_info(instance))
 | 
			
		||||
        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.
 | 
			
		||||
 | 
			
		||||
@@ -153,7 +154,7 @@ class FakeConnection(driver.ComputeDriver):
 | 
			
		||||
        fake_instance = FakeInstance(name, state)
 | 
			
		||||
        self.instances[name] = fake_instance
 | 
			
		||||
 | 
			
		||||
    def snapshot(self, instance, name):
 | 
			
		||||
    def snapshot(self, context, instance, name):
 | 
			
		||||
        """
 | 
			
		||||
        Snapshots the specified instance.
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -139,7 +139,8 @@ class HyperVConnection(driver.ComputeDriver):
 | 
			
		||||
 | 
			
		||||
        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."""
 | 
			
		||||
        vm = self._lookup(instance.name)
 | 
			
		||||
        if vm is not None:
 | 
			
		||||
 
 | 
			
		||||
@@ -399,7 +399,7 @@ class LibvirtConnection(driver.ComputeDriver):
 | 
			
		||||
        virt_dom.detachDevice(xml)
 | 
			
		||||
 | 
			
		||||
    @exception.wrap_exception()
 | 
			
		||||
    def snapshot(self, instance, image_href):
 | 
			
		||||
    def snapshot(self, context, instance, image_href):
 | 
			
		||||
        """Create snapshot from a running VM instance.
 | 
			
		||||
 | 
			
		||||
        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
 | 
			
		||||
    # for xenapi(tr3buchet)
 | 
			
		||||
    @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,
 | 
			
		||||
                          block_device_mapping=block_device_mapping)
 | 
			
		||||
        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)))
 | 
			
		||||
        return lst_vm_names
 | 
			
		||||
 | 
			
		||||
    def spawn(self, instance, network_info):
 | 
			
		||||
    def spawn(self, context, instance, network_info):
 | 
			
		||||
        """
 | 
			
		||||
        Creates a VM instance.
 | 
			
		||||
 | 
			
		||||
@@ -329,7 +329,7 @@ class VMWareVMOps(object):
 | 
			
		||||
            LOG.debug(_("Powered on the VM instance %s") % instance.name)
 | 
			
		||||
        _power_on_vm()
 | 
			
		||||
 | 
			
		||||
    def snapshot(self, instance, snapshot_name):
 | 
			
		||||
    def snapshot(self, context, instance, snapshot_name):
 | 
			
		||||
        """
 | 
			
		||||
        Create snapshot from a running VM instance.
 | 
			
		||||
        Steps followed are:
 | 
			
		||||
 
 | 
			
		||||
@@ -124,13 +124,14 @@ class VMWareESXConnection(driver.ComputeDriver):
 | 
			
		||||
        """List VM 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."""
 | 
			
		||||
        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."""
 | 
			
		||||
        self._vmops.snapshot(instance, name)
 | 
			
		||||
        self._vmops.snapshot(context, instance, name)
 | 
			
		||||
 | 
			
		||||
    def reboot(self, instance, network_info):
 | 
			
		||||
        """Reboot VM instance."""
 | 
			
		||||
 
 | 
			
		||||
@@ -209,8 +209,8 @@ class VMOps(object):
 | 
			
		||||
 | 
			
		||||
            if instance.vm_mode != vm_mode:
 | 
			
		||||
                # Update database with normalized (or determined) value
 | 
			
		||||
                db.instance_update(context.get_admin_context(),
 | 
			
		||||
                                   instance['id'], {'vm_mode': vm_mode})
 | 
			
		||||
                db.instance_update(context, instance['id'],
 | 
			
		||||
                                   {'vm_mode': vm_mode})
 | 
			
		||||
            vm_ref = VMHelper.create_vm(self._session, instance,
 | 
			
		||||
                    kernel and kernel.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):
 | 
			
		||||
        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"""
 | 
			
		||||
        self._vmops.spawn(instance, network_info)
 | 
			
		||||
        self._vmops.spawn(context, instance, network_info)
 | 
			
		||||
 | 
			
		||||
    def revert_resize(self, instance):
 | 
			
		||||
        """Reverts a resize, powering back on the 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"""
 | 
			
		||||
        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 """
 | 
			
		||||
        self._vmops.snapshot(instance, image_id)
 | 
			
		||||
        self._vmops.snapshot(context, instance, image_id)
 | 
			
		||||
 | 
			
		||||
    def reboot(self, instance, network_info):
 | 
			
		||||
        """Reboot VM instance"""
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user