def test_error(self, popen_mock, tmpdir): input_mock = BytesIO() popen_mock.return_value.stdin = input_mock config = mock.Mock(user='******', barman_host='remote.barman.host', config=None, server_name='this-server', test=False) source_file = tmpdir.join('test-source/000000010000000000000001') source_file.write("test-content", ensure=True) source_path = source_file.strpath # Simulate a remote failure popen_mock.return_value.returncode = 5 # In python2 the source_path can be an unicode object if hasattr(source_path, 'decode'): source_path = source_path.decode() rwa = walarchive.RemotePutWal(config, source_path) popen_mock.assert_called_once_with([ 'ssh', '-q', '-T', '*****@*****.**', 'barman', 'put-wal', 'this-server' ], stdin=subprocess.PIPE) assert rwa.returncode == 5
def test_str_source_file(self, popen_mock, tmpdir): input_mock, output_mock = pipe_helper() popen_mock.return_value.stdin = input_mock popen_mock.return_value.returncode = 0 config = mock.Mock( user="******", barman_host="remote.barman.host", config=None, server_name="this-server", test=False, ) source_file = tmpdir.join("test-source/000000010000000000000001") source_file.write("test-content", ensure=True) source_path = source_file.strpath # In python2 the source_path can be an unicode object if hasattr(source_path, "decode"): source_path = source_path.decode() rpw = walarchive.RemotePutWal(config, source_path) popen_mock.assert_called_once_with( [ "ssh", "-q", "-T", "*****@*****.**", "barman", "put-wal", "this-server", ], stdin=subprocess.PIPE, ) assert rpw.returncode == 0 tar = tarfile.open(mode="r|", fileobj=output_mock) first = tar.next() with closing(tar.extractfile(first)) as fp: first_content = fp.read().decode() assert first.name == "000000010000000000000001" assert first_content == "test-content" second = tar.next() with closing(tar.extractfile(second)) as fp: second_content = fp.read().decode() assert second.name == "MD5SUMS" assert ( second_content == "%s *000000010000000000000001\n" % source_file.computehash("md5") ) assert tar.next() is None
def test_str_source_file(self, popen_mock, tmpdir): input_mock, output_mock = pipe_helper() popen_mock.return_value.stdin = input_mock popen_mock.return_value.returncode = 0 config = mock.Mock(user='******', barman_host='remote.barman.host', config=None, server_name='this-server', test=False) source_file = tmpdir.join('test-source/000000010000000000000001') source_file.write("test-content", ensure=True) source_path = source_file.strpath # In python2 the source_path can be an unicode object if hasattr(source_path, 'decode'): source_path = source_path.decode() rpw = walarchive.RemotePutWal(config, source_path) popen_mock.assert_called_once_with([ 'ssh', '-q', '-T', '*****@*****.**', 'barman', 'put-wal', 'this-server' ], stdin=subprocess.PIPE) assert rpw.returncode == 0 tar = tarfile.open(mode='r|', fileobj=output_mock) first = tar.next() with closing(tar.extractfile(first)) as fp: first_content = fp.read().decode() assert first.name == '000000010000000000000001' assert first_content == 'test-content' second = tar.next() with closing(tar.extractfile(second)) as fp: second_content = fp.read().decode() assert second.name == 'MD5SUMS' assert second_content == \ '%s *000000010000000000000001\n' % source_file.computehash('md5') assert tar.next() is None
def test_error(self, popen_mock, tmpdir): input_mock = BytesIO() popen_mock.return_value.stdin = input_mock config = mock.Mock( user="******", barman_host="remote.barman.host", config=None, server_name="this-server", test=False, ) source_file = tmpdir.join("test-source/000000010000000000000001") source_file.write("test-content", ensure=True) source_path = source_file.strpath # Simulate a remote failure popen_mock.return_value.returncode = 5 # In python2 the source_path can be an unicode object if hasattr(source_path, "decode"): source_path = source_path.decode() rwa = walarchive.RemotePutWal(config, source_path) popen_mock.assert_called_once_with( [ "ssh", "-q", "-T", "*****@*****.**", "barman", "put-wal", "this-server", ], stdin=subprocess.PIPE, ) assert rwa.returncode == 5