def setup_compression(self, _type): """Checks if compression algo is available on source and dest. Parameters ---------- _type : {str} Type of compression to use Returns ------- tuple(List(str)) Tuple of compress/decompress commands to use, (None, None) if compression is not available """ if _type == None or _type.lower() == 'none': return None, None # compress/decompress commands of different compression tools algos = { 'gzip': (['gzip', '-3'], ['gzip', '-dc']), 'lzop': (['lzop'], ['lzop', '-dfc']), 'bzip2': (['bzip2'], ['bzip2', '-dfc']), 'pigz': (['pigz'], ['pigz', '-dc']), 'xz': (['xz'], ['xz', '-d']), 'lz4': (['lz4'], ['lz4', '-dc']) } if _type not in algos: self.logger.warning( 'Compression method {:s} not supported. Will continue without...' .format(_type)) return None, None from pyznap.utils import exists # check if compression is available on source and dest if not exists(_type): self.logger.warning( '{:s} does not exist, continuing without compression...'. format(_type)) return None, None if not exists(_type, ssh=self): self.logger.warning( '{:s} does not exist on {:s}@{:s}, continuing without compression...' .format(_type, self.user, self.host)) return None, None self.logger.log(8, 'SSH: use compression {:s}'.format(_type)) return algos[_type]
def setup_pv(self): """Checks if pv is available on host Returns ------- List(str) pv command to use on host """ from pyznap.utils import exists if exists('pv', ssh=self): return lambda size: ['pv', '-f', '-w', '100', '-s', str(size)] else: return None
def check_mbuffer(self): """Checks if mbuffer is available on dest Returns ------- List(str) mbuffer command to use on dest """ from pyznap.utils import exists if not exists('mbuffer', ssh=self): return None else: return ['mbuffer', '-q', '-s', '128K', '-m', '512M']
def setup_mbuffer(self): """Checks if mbuffer is available on host Returns ------- List(str) mbuffer command to use on host """ from pyznap.utils import exists if exists('mbuffer', ssh=self): return lambda mem: ['mbuffer', '-q', '-s', '128K', '-m', '{:d}M'.format(mem)] else: return None
from datetime import datetime, timedelta import pytest import pyznap.pyzfs as zfs from pyznap.utils import open_ssh, read_config, parse_name, exists from pyznap.clean import clean_config from pyznap.take import take_config from pyznap.send import send_config from pyznap.process import DatasetNotFoundError logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s: %(message)s', datefmt='%b %d %H:%M:%S') logger = logging.getLogger(__name__) assert exists('faketime') def randomword(length): letters = string.ascii_lowercase return ''.join(random.choice(letters) for i in range(length)) # ssh connection to dest USER = '******' HOST = '127.0.0.1' PORT = 22 KEY = None ZPOOL = '/sbin/zpool' POOL0 = 'pyznap_test_source'