Ejemplo n.º 1
0
 def test_backing_file_does_not_fail_if_json_has_no_such_file(self):
     json = """{
         "virtual-size": 7516192768,
         "filename": "/var/lib/nova/instances/6a475e2d-993a-453a-a8be-
                      b1ab549f54a7/disk",
         "cluster-size": 65536,
         "format": "qcow2",
         "actual-size": 19398656,
         "format-specific": {
             "type": "qcow2",
             "data": {
                 "compat": "1.1",
                 "lazy-refcounts": false
             }
         },
         "dirty-flag": false
     }"""
     remote_runner = mock.Mock()
     remote_runner.run.return_value = json
     lv = libvirt.Libvirt(remote_runner)
     try:
         backing_file = lv.get_backing_file('inst-id')
         self.assertIsNone(backing_file)
     except:
         self.fail("get_backing_file should return None if backing file is "
                   "not present in qemu-img")
Ejemplo n.º 2
0
 def test_backing_file_returns_none_in_case_of_error(self):
     remote_runner = mock.Mock()
     remote_runner.run.return_value = None
     lv = libvirt.Libvirt(remote_runner)
     try:
         backing = lv.get_backing_file("some-id")
         self.assertIsNone(backing)
     except Exception:
         self.fail("get_backing_volume should return None in case of "
                   "failure")
Ejemplo n.º 3
0
 def test_backing_file_returns_expected_value(self):
     qemu_img_info = """{
         "virtual-size": 41126400,
         "filename": "disk",
         "cluster-size": 65536,
         "format": "qcow2",
         "actual-size": 1122304,
         "format-specific": {
             "type": "qcow2",
             "data": {
                 "compat": "1.1",
                 "lazy-refcounts": false
             }
         },
         "backing-filename": "/var/lib/nova/instances/_base/migrationDisk",
         "dirty-flag": false
     }"""
     remote_runner = mock.Mock()
     remote_runner.run.return_value = qemu_img_info
     lv = libvirt.Libvirt(remote_runner)
     backing_file = lv.get_backing_file('inst-id')
     self.assertEqual(backing_file,
                      "/var/lib/nova/instances/_base/migrationDisk")
Ejemplo n.º 4
0
    def run(self, info=None, **kwargs):
        new_id, instance = info[utils.INSTANCES_TYPE].items()[0]
        old_id = instance['old_id']

        dst_compute = self.dst_cloud.resources[utils.COMPUTE_RESOURCE]
        src_compute = self.src_cloud.resources[utils.COMPUTE_RESOURCE]

        dst_compute.change_status('active', instance_id=new_id)

        dst_instance = dst_compute.get_instance(new_id)
        src_instance = src_compute.get_instance(old_id)

        # do not attempt to live migrate inactive instances
        if src_instance.status.lower() not in ['active', 'verify_resize']:
            LOG.debug(
                "Skipping live migration of VM '%s', because it's "
                "inactive", src_instance.name)
            return

        src_host = instance_host(src_instance)
        dst_host = instance_host(dst_instance)

        src_runner = remote_runner.RemoteRunner(src_host,
                                                cfglib.CONF.src.ssh_user)
        dst_runner = remote_runner.RemoteRunner(dst_host,
                                                cfglib.CONF.dst.ssh_user)

        src_libvirt = libvirt.Libvirt(src_runner)
        dst_libvirt = libvirt.Libvirt(dst_runner)

        src_virsh_name = instance_libvirt_name(src_instance)
        dst_virsh_name = instance_libvirt_name(dst_instance)

        src_vm_xml = src_libvirt.get_xml(src_virsh_name)
        dst_vm_xml = dst_libvirt.get_xml(dst_virsh_name)

        src_vm_xml.disk_file = dst_vm_xml.disk_file
        src_vm_xml.serial_file = dst_vm_xml.serial_file
        src_vm_xml.console_file = dst_vm_xml.console_file
        src_vm_xml.interfaces = dst_vm_xml.interfaces

        dst_backing_file = dst_libvirt.get_backing_file(new_id)
        src_backing_file = src_libvirt.get_backing_file(old_id)
        migration_backing_file = os.path.join(
            libvirt.nova_instances_path, '_base',
            'migration_disk_{}'.format(old_id))
        dst_compute.wait_for_status(new_id, dst_compute.get_status, 'active')

        with files.RemoteTempFile(src_runner,
                                  "migrate-{}".format(old_id),
                                  src_vm_xml.dump()) as migration_file,\
                files.RemoteSymlink(src_runner,
                                    src_backing_file,
                                    migration_backing_file),\
                files.RemoteSymlink(dst_runner,
                                    dst_backing_file,
                                    migration_backing_file),\
                ubuntu.StopNovaCompute(dst_runner),\
                libvirt.QemuBackingFileMover(src_libvirt.runner,
                                             migration_backing_file,
                                             old_id):

            destroyer = libvirt.DestNovaInstanceDestroyer(
                dst_libvirt, dst_compute, dst_virsh_name, dst_instance.id)
            try:
                destroyer.do()
                src_libvirt.live_migrate(src_virsh_name, dst_host,
                                         migration_file.filename)
            except remote_runner.RemoteExecutionError:
                destroyer.undo()
            finally:
                dst_libvirt.move_backing_file(dst_backing_file, new_id)