def _do_backup(master: Node, backup_local_path: Path) -> None: """ Automated ZooKeeper backup procedure. Intended to be consistent with the documentation. https://jira.mesosphere.com/browse/DCOS-51647 """ master.run(args=['systemctl', 'stop', 'dcos-exhibitor']) backup_name = backup_local_path.name # This must be an existing directory on the remote server. backup_remote_path = Path('/etc/') / backup_name master.run( args=[ '/opt/mesosphere/bin/dcos-shell', 'dcos-zk', 'backup', str(backup_remote_path), '-v', ], output=Output.LOG_AND_CAPTURE, ) master.run(args=['systemctl', 'start', 'dcos-exhibitor']) master.download_file( remote_path=backup_remote_path, local_path=backup_local_path, ) master.run(args=['rm', str(backup_remote_path)])
def test_local_file_already_exists( self, dcos_node: Node, tmp_path: Path, ) -> None: """ Downloading a file raises a ``ValueError`` if the local file path already exists. """ content = str(uuid.uuid4()) random = uuid.uuid4().hex local_file_name = 'local_file_{random}.txt'.format(random=random) local_file_path = tmp_path / local_file_name local_file_path.write_text(content) remote_file_name = 'remote_file_{random}.txt'.format(random=random) remote_file_path = Path('/etc/') / remote_file_name dcos_node.send_file( local_path=local_file_path, remote_path=remote_file_path, ) message = ('Failed to download a file to "{file}". ' 'A file already exists in that location.').format( file=local_file_path) with pytest.raises(ValueError) as exc: dcos_node.download_file( remote_path=remote_file_path, local_path=local_file_path, ) assert str(exc.value) == message
def test_file_to_file( self, dcos_node: Node, tmp_path: Path, ) -> None: """ It is possible to download a file from a node to a file path. """ content = str(uuid.uuid4()) random = uuid.uuid4().hex local_file_name = 'local_file_{random}.txt'.format(random=random) remote_file_name = 'remote_file_{random}.txt'.format(random=random) remote_file_path = Path('/etc/') / remote_file_name downloaded_file_name = 'downloaded_file_{random}.txt'.format( random=random, ) downloaded_file_path = tmp_path / downloaded_file_name local_file = tmp_path / local_file_name local_file.write_text(content) dcos_node.send_file( local_path=local_file, remote_path=remote_file_path, ) dcos_node.download_file( remote_path=remote_file_path, local_path=downloaded_file_path, ) assert downloaded_file_path.read_text() == content
def _do_backup(master: Node, backup_local_path: Path) -> None: backup_name = backup_local_path.name # This must be an existing directory on the remote server. backup_remote_path = Path("/etc/") / backup_name dcos_etcdctl_with_args = get_dcos_etcdctl() dcos_etcdctl_with_args += ["backup", str(backup_remote_path)] master.run( args=dcos_etcdctl_with_args, output=Output.LOG_AND_CAPTURE, ) master.download_file( remote_path=backup_remote_path, local_path=backup_local_path, ) master.run(args=["rm", str(backup_remote_path)])
def test_remote_file_does_not_exist( self, dcos_node: Node, ) -> None: """ Downloading a file raises a ``ValueError`` if the remote file path does not exist. """ random = uuid.uuid4().hex remote_file_path = Path('/etc/') / random message = ( 'Failed to download file from remote location "{location}". ' 'File does not exist.').format(location=remote_file_path) with pytest.raises(ValueError) as exc: dcos_node.download_file( remote_path=remote_file_path, local_path=Path('./blub'), ) assert str(exc.value) == message