예제 #1
0
    def _copy_volume(self,src_vol_dir,des_vol_dir,src_vol_size,vol_dd_size,sync=False):
        if src_vol_dir is None or des_vol_dir is None:
            return False

        bksize,count=vutils._calculate_count(src_vol_size, vol_dd_size)

        
        extra_flags = []
        if vutils.check_for_odirect_support(src_vol_dir, des_vol_dir, 'iflag=direct'):
            extra_flags.append('iflag=direct')

        if vutils.check_for_odirect_support(src_vol_dir, des_vol_dir, 'oflag=direct'):
            extra_flags.append('oflag=direct') 
        
        if sync and not extra_flags:
            extra_flags.append('conv=sync')
        
        cmdstr = ['dd', 'if=%s' % src_vol_dir, 'of=%s' % des_vol_dir,
           'count=%d' % count, 'bs=%s' % bksize]
        cmdstr.extend(extra_flags)    

         
        try:
            self._execute(*cmdstr,root_helper=self.r_helper,run_as_root=True)          
        except putils.ProcessExecutionError as err:
            LOG.error(_('Cmd     :%s') % err.cmd)
            LOG.error(_('StdOut  :%s') % err.stdout)
            LOG.error(_('StdErr  :%s') % err.stderr)
            raise NameError('Error:failed to dd data from snapshot:%s' % src_vol_dir)        
        
        return True
예제 #2
0
 def copy_volume(self, srcstr, deststr, size_in_m, blocksize, sync=False,
             execute=utils.execute, ionice=None):
     # Use O_DIRECT to avoid thrashing the system buffer cache
     extra_flags = ['iflag=direct', 'oflag=direct']
 
     # Check whether O_DIRECT is supported
     try:
         execute('dd', 'count=0', 'if=%s' % srcstr, 'of=%s' % deststr,
                 *extra_flags, run_as_root=True)
     except processutils.ProcessExecutionError:
         extra_flags = []
 
     # If the volume is being unprovisioned then
     # request the data is persisted before returning,
     # so that it's not discarded from the cache.
     if sync and not extra_flags:
         extra_flags.append('conv=sync')
 
     blocksize, count = volutils._calculate_count(size_in_m, blocksize)
 
     cmd = ['dd', 'if=%s' % srcstr, 'of=%s' % deststr,
            'count=%d' % count, 'bs=%s' % blocksize]
     cmd.extend(extra_flags)
 
     if ionice is not None:
         cmd = ['ionice', ionice] + cmd
 
     # Perform the copy
     execute(*cmd, run_as_root=True)
예제 #3
0
    def test_convert_blocksize_option(self):
        # Test valid volume_dd_blocksize
        bs, count = volume_utils._calculate_count(1024, '10M')
        self.assertEqual(bs, '10M')
        self.assertEqual(count, 103)

        bs, count = volume_utils._calculate_count(1024, '1xBBB')
        self.assertEqual(bs, '1M')
        self.assertEqual(count, 1024)

        # Test 'volume_dd_blocksize' with fraction
        bs, count = volume_utils._calculate_count(1024, '1.3M')
        self.assertEqual(bs, '1M')
        self.assertEqual(count, 1024)

        # Test zero-size 'volume_dd_blocksize'
        bs, count = volume_utils._calculate_count(1024, '0M')
        self.assertEqual(bs, '1M')
        self.assertEqual(count, 1024)

        # Test negative 'volume_dd_blocksize'
        bs, count = volume_utils._calculate_count(1024, '-1M')
        self.assertEqual(bs, '1M')
        self.assertEqual(count, 1024)

        # Test non-digital 'volume_dd_blocksize'
        bs, count = volume_utils._calculate_count(1024, 'ABM')
        self.assertEqual(bs, '1M')
        self.assertEqual(count, 1024)
예제 #4
0
    def test_convert_blocksize_option(self):
        # Test valid volume_dd_blocksize
        bs, count = volume_utils._calculate_count(1024, '10M')
        self.assertEqual('10M', bs)
        self.assertEqual(103, count)

        bs, count = volume_utils._calculate_count(1024, '1xBBB')
        self.assertEqual('1M', bs)
        self.assertEqual(1024, count)

        # Test 'volume_dd_blocksize' with fraction
        bs, count = volume_utils._calculate_count(1024, '1.3M')
        self.assertEqual('1M', bs)
        self.assertEqual(1024, count)

        # Test zero-size 'volume_dd_blocksize'
        bs, count = volume_utils._calculate_count(1024, '0M')
        self.assertEqual('1M', bs)
        self.assertEqual(1024, count)

        # Test negative 'volume_dd_blocksize'
        bs, count = volume_utils._calculate_count(1024, '-1M')
        self.assertEqual('1M', bs)
        self.assertEqual(1024, count)

        # Test non-digital 'volume_dd_blocksize'
        bs, count = volume_utils._calculate_count(1024, 'ABM')
        self.assertEqual('1M', bs)
        self.assertEqual(1024, count)
예제 #5
0
    def test_convert_blocksize_option(self):
        # Test valid volume_dd_blocksize
        CONF.set_override('volume_dd_blocksize', '10M')
        bs, count = volume_utils._calculate_count(1024)
        self.assertEquals(bs, '10M')
        self.assertEquals(count, 103)

        CONF.set_override('volume_dd_blocksize', '1xBBB')
        bs, count = volume_utils._calculate_count(1024)
        self.assertEquals(bs, '1M')
        self.assertEquals(count, 1024)

        # Test 'volume_dd_blocksize' with fraction
        CONF.set_override('volume_dd_blocksize', '1.3M')
        bs, count = volume_utils._calculate_count(1024)
        self.assertEquals(bs, '1M')
        self.assertEquals(count, 1024)

        # Test zero-size 'volume_dd_blocksize'
        CONF.set_override('volume_dd_blocksize', '0M')
        bs, count = volume_utils._calculate_count(1024)
        self.assertEquals(bs, '1M')
        self.assertEquals(count, 1024)

        # Test negative 'volume_dd_blocksize'
        CONF.set_override('volume_dd_blocksize', '-1M')
        bs, count = volume_utils._calculate_count(1024)
        self.assertEquals(bs, '1M')
        self.assertEquals(count, 1024)

        # Test non-digital 'volume_dd_blocksize'
        CONF.set_override('volume_dd_blocksize', 'ABM')
        bs, count = volume_utils._calculate_count(1024)
        self.assertEquals(bs, '1M')
        self.assertEquals(count, 1024)
예제 #6
0
    def test_convert_blocksize_option(self):
        # Test valid volume_dd_blocksize
        bs, count = volume_utils._calculate_count(1024, "10M")
        self.assertEqual("10M", bs)
        self.assertEqual(103, count)

        bs, count = volume_utils._calculate_count(1024, "1xBBB")
        self.assertEqual("1M", bs)
        self.assertEqual(1024, count)

        # Test 'volume_dd_blocksize' with fraction
        bs, count = volume_utils._calculate_count(1024, "1.3M")
        self.assertEqual("1M", bs)
        self.assertEqual(1024, count)

        # Test zero-size 'volume_dd_blocksize'
        bs, count = volume_utils._calculate_count(1024, "0M")
        self.assertEqual("1M", bs)
        self.assertEqual(1024, count)

        # Test negative 'volume_dd_blocksize'
        bs, count = volume_utils._calculate_count(1024, "-1M")
        self.assertEqual("1M", bs)
        self.assertEqual(1024, count)

        # Test non-digital 'volume_dd_blocksize'
        bs, count = volume_utils._calculate_count(1024, "ABM")
        self.assertEqual("1M", bs)
        self.assertEqual(1024, count)