def process_image(self, img_id=None, diff=None):
     """
     Processing image file: copy from source to destination,
      create glance image
     :param img_id: image ID from source
     :param diff: diff file of root disk for instance
     :return: new image ID if image is created
     """
     with files.RemoteTempDir(self.src_runner) as src_tmp_dir,\
             files.RemoteTempDir(self.dst_runner) as dst_tmp_dir:
         diff_name = 'diff'
         base_name = 'base'
         diff_file = os.path.join(src_tmp_dir, diff_name)
         self.src_runner.run('cp {} {}'.format(diff, diff_file))
         base_file = os.path.join(src_tmp_dir, base_name)
         dst_base_file = os.path.join(dst_tmp_dir, base_name)
         qemu_img_src = self.src_cloud.qemu_img
         base = qemu_img_src.detect_backing_file(diff, self.src_host)
         if base is not None:
             self.src_runner.run('cp {} {}'.format(base, base_file))
             qemu_img_src.diff_rebase(base_file, diff_file, self.src_host)
             qemu_img_src.diff_commit(src_tmp_dir, diff_name, self.src_host)
             verified_file_copy(self.src_runner, self.dst_runner,
                                self.dst_user, base_file, dst_base_file,
                                self.dst_host, 1)
         else:
             verified_file_copy(self.src_runner, self.dst_runner,
                                self.dst_user, diff_file, dst_base_file,
                                self.dst_host, 1)
         image_resource = self.dst_cloud.resources[utils.IMAGE_RESOURCE]
         id = image_resource.glance_img_create(img_id, 'qcow2',
                                               dst_base_file)
         checksum = remote_md5_sum(self.dst_runner, dst_base_file)
         return {'id': id, 'checksum': checksum}
Example #2
0
    def test_retries_if_error_occurs(self, scp, _):
        src_runner = mock.Mock()
        dst_runner = mock.Mock()

        user = '******'
        src_path = '/tmp/srcfile'
        dst_path = '/tmp/dstfile'
        dest_host = 'desthostname'
        num_retries = 10

        scp.side_effect = remote_runner.RemoteExecutionError

        try:
            ssh_chunks.verified_file_copy(src_runner, dst_runner, user,
                                          src_path, dst_path, dest_host,
                                          num_retries)
        except ssh_chunks.FileCopyFailure:
            assert scp.call_count == num_retries + 1
 def process_image(self, img_id=None, diff=None):
     """
     Processing image file: copy from source to destination,
      create glance image
     :param img_id: image ID from source
     :param diff: diff file of root disk for instance
     :return: new image ID if image is created
     """
     with files.RemoteTempDir(self.src_runner) as src_tmp_dir,\
             files.RemoteTempDir(self.dst_runner) as dst_tmp_dir:
         diff_name = 'diff'
         base_name = 'base'
         diff_file = os.path.join(src_tmp_dir, diff_name)
         self.src_runner.run('cp {} {}'.format(diff, diff_file))
         base_file = os.path.join(src_tmp_dir, base_name)
         dst_base_file = os.path.join(dst_tmp_dir, base_name)
         qemu_img_src = self.src_cloud.qemu_img
         base = qemu_img_src.detect_backing_file(diff, self.src_host)
         if base is not None:
             self.src_runner.run('cp {} {}'.format(base, base_file))
             qemu_img_src.diff_rebase(base_file, diff_file, self.src_host)
             qemu_img_src.diff_commit(src_tmp_dir, diff_name, self.src_host)
             verified_file_copy(self.src_runner,
                                self.dst_runner,
                                self.dst_user,
                                base_file,
                                dst_base_file,
                                self.dst_host,
                                1)
         else:
             verified_file_copy(self.src_runner,
                                self.dst_runner,
                                self.dst_user,
                                diff_file,
                                dst_base_file,
                                self.dst_host,
                                1)
         image_resource = self.dst_cloud.resources[utils.IMAGE_RESOURCE]
         id = image_resource.glance_img_create(img_id, 'qcow2',
                                               dst_base_file)
         checksum = remote_md5_sum(self.dst_runner, dst_base_file)
         return {'id': id, 'checksum': checksum}