示例#1
0
 def testDeleteParameterFromJobFile(self):
     original_job_file = ('[global]\n'
                          'directory=/dev/sdb\n'
                          'filename=foo12_3\n'
                          '...')
     expected_job_file = ('[global]\n' '...')
     self.assertEqual(
         expected_job_file,
         fio.DeleteParameterFromJobFile(
             fio.DeleteParameterFromJobFile(original_job_file, 'directory'),
             'filename'))
def Prepare(benchmark_spec):
    """Prepare the virtual machine to run FIO.

     This includes installing fio, bc. and libaio1 and insuring that the
     attached disk is large enough to support the fio benchmark.

  Args:
    benchmark_spec: The benchmark specification. Contains all data that is
        required to run the benchmark.
  """
    vms = benchmark_spec.vms
    vm = vms[0]
    logging.info('FIO prepare on %s', vm)
    vm.Install('fio')
    file_path = data.ResourcePath(flags.FLAGS.fio_jobfile)

    disk_size_kb = vm.GetDeviceSizeFromPath(vm.GetScratchDir())
    amount_memory_kb = vm.total_memory_kb
    if disk_size_kb < amount_memory_kb * flags.FLAGS.memory_multiple:
        logging.error('%s must be larger than %dx memory"', vm.GetScratchDir(),
                      flags.FLAGS.memory_multiple)
        # TODO(user): exiting here is probably not the correct behavor.
        #    When FIO is run across a data set which is too not considerably
        #    larger than the amount of memory then the benchmark results will be
        #    invalid. Once the benchmark results are returned from Run() an
        #    invalid (or is that rather a 'valid' flag should be added.
        exit(1)
    if FLAGS.against_device:
        device_path = vm.scratch_disks[0].GetDevicePath()
        logging.info('Umount scratch disk on %s at %s', vm, device_path)
        vm.RemoteCommand('sudo umount %s' % vm.GetScratchDir())
        logging.info('Fill scratch disk on %s at %s', vm, device_path)
        command = (('sudo %s --filename=%s --ioengine=libaio '
                    '--name=fill-device --blocksize=512k --iodepth=64 '
                    '--rw=write --direct=1 --size=%s') %
                   (fio.FIO_PATH, device_path, FLAGS.device_fill_size))
        vm.RemoteCommand(command)
        logging.info('Removing directory and filename in job file.')
        with open(data.ResourcePath(flags.FLAGS.fio_jobfile)) as original_f:
            job_file = original_f.read()
        job_file = fio.DeleteParameterFromJobFile(job_file, 'directory')
        job_file = fio.DeleteParameterFromJobFile(job_file, 'filename')
        tmp_dir = vm_util.GetTempDir()
        file_path = vm_util.PrependTempDir(FLAGS.fio_jobfile)
        logging.info('Write modified job file to temp directory %s', tmp_dir)
        with open(file_path, 'w') as modified_f:
            modified_f.write(job_file)
    vm.PushFile(file_path)