def test_backing_file_returned_for_good_ephemeral(self, mock_execute): cloud = mock.Mock() config = mock.Mock() host = "host1" ephemeral = "disk" expected_backing = "/path/to/backing/file" # dict is based on the actual output of qemu-img utility mock_execute.return_value = """{{ "virtual-size": 1073741824, "filename": "disk", "cluster-size": 65536, "format": "qcow2", "actual-size": 1974272, "format-specific": {{ "type": "qcow2", "data": {{ "compat": "1.1", "lazy-refcounts": false }} }}, "backing-filename": "{backing_file}", "dirty-flag": false }}""".format(backing_file=expected_backing) qi = qemu_img.QemuImg(cloud, config, host) actual_backing = qi.detect_backing_file(ephemeral, host) self.assertEqual(expected_backing, actual_backing)
def init_resources(self, cloud_config): resources = self.resources self.resources = dict() self.rbd_util = rbd_util.RbdUtil( getattr(self.config, "%s" % self.position), self.config.migrate) self.qemu_img = qemu_img.QemuImg( getattr(self.config, "%s" % self.position), self.config.migrate) self.ssh_util = ssh_util.SshUtil( getattr(self.config, "%s" % self.position), self.config.migrate) ident_conf = self.make_resource_config(self.config, self.position, cloud_config, 'identity') self.mysql_connector = self.get_db_method_create_connection( 'identity', ident_conf) identity = resources['identity'](ident_conf, self) self.resources['identity'] = identity skip_initialization = ['identity'] if not self.config.src_objstorage.service: skip_initialization.append('objstorage') for resource in resources: if resource not in skip_initialization: resource_config = self.make_resource_config( self.config, self.position, cloud_config, resource) self.mysql_connector = \ self.get_db_method_create_connection(resource, resource_config) self.resources[resource] = resources[resource](resource_config, self)
def test_backing_file_returns_none_if_not_available(self, _): cloud = mock.Mock() config = mock.Mock() host = mock.Mock() ephemeral = mock.Mock() qi = qemu_img.QemuImg(cloud, config, host) backing_file = qi.detect_backing_file(ephemeral, host) self.assertIsNone(backing_file)
def rebase_diff(dst_cloud, info): for instance_id, obj in info[utl.INSTANCES_TYPE].items(): image_id = obj['instance']['image_id'] new_backing_file = hashlib.sha1(image_id).hexdigest() diff = obj['diff'] host = diff['host_dst'] qemu_img = qemu_img_util.QemuImg(dst_cloud.config.dst, dst_cloud.config.migrate, host) diff_path = diff['path_dst'] backing_path = qemu_img.detect_backing_file(diff_path, None) backing_dir = os.path.dirname(backing_path) new_backing_path = os.path.join(backing_dir, new_backing_file) qemu_img.diff_rebase(new_backing_path, diff_path)
def init_resources(self, cloud_config): resources = self.resources self.resources = dict() self.mysql_connector = mysql_connector.MysqlConnector( getattr(self.config, "%s_mysql" % self.position), 'cinder') self.rbd_util = rbd_util.RbdUtil( getattr(self.config, "%s" % self.position), self.config.migrate) self.qemu_img = qemu_img.QemuImg( getattr(self.config, "%s" % self.position), self.config.migrate) self.ssh_util = ssh_util.SshUtil( getattr(self.config, "%s" % self.position), self.config.migrate) identity_conf = self.make_resource_config(self.config, self.position, cloud_config, 'identity') identity = resources['identity'](identity_conf, self) self.resources['identity'] = identity for resource in resources: if resource != 'identity': resource_config = self.make_resource_config( self.config, self.position, cloud_config, resource) self.resources[resource] = resources[resource](resource_config, self)