diff --git a/.gitignore b/.gitignore index 7614b472..6d00fecc 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ dist/ dev/ .pytest_cache pytestdebug.log +.vscode/ diff --git a/juju/machine.py b/juju/machine.py index a46135cd..1dfe72cf 100644 --- a/juju/machine.py +++ b/juju/machine.py @@ -146,7 +146,8 @@ async def scp_to(self, source, destination, user='ubuntu', proxy=False, :param str destination: Remote destination of transferred files :param str user: Remote username :param bool proxy: Proxy through the Juju API server - :param str scp_opts: Additional options to the `scp` command + :param scp_opts: Additional options to the `scp` command + :type scp_opts: str or list """ if proxy: raise NotImplementedError('proxy option is not implemented') @@ -163,7 +164,8 @@ async def scp_from(self, source, destination, user='ubuntu', proxy=False, :param str destination: Local destination of transferred files :param str user: Remote username :param bool proxy: Proxy through the Juju API server - :param str scp_opts: Additional options to the `scp` command + :param scp_opts: Additional options to the `scp` command + :type scp_opts: str or list """ if proxy: raise NotImplementedError('proxy option is not implemented') @@ -181,10 +183,10 @@ async def _scp(self, source, destination, scp_opts): '-i', os.path.expanduser('~/.local/share/juju/ssh/juju_id_rsa'), '-o', 'StrictHostKeyChecking=no', '-q', - '-B', - source, destination + '-B' ] - cmd += scp_opts.split() + cmd.extend(scp_opts.split() if isinstance(scp_opts, str) else scp_opts) + cmd.extend([source, destination]) loop = self.model.loop process = await asyncio.create_subprocess_exec(*cmd, loop=loop) await process.wait() diff --git a/juju/unit.py b/juju/unit.py index 3be27f2e..79ad9e18 100644 --- a/juju/unit.py +++ b/juju/unit.py @@ -186,7 +186,8 @@ async def scp_to(self, source, destination, user='ubuntu', proxy=False, :param str destination: Remote destination of transferred files :param str user: Remote username :param bool proxy: Proxy through the Juju API server - :param str scp_opts: Additional options to the `scp` command + :param scp_opts: Additional options to the `scp` command + :type scp_opts: str or list """ await self.machine.scp_to(source, destination, user=user, proxy=proxy, scp_opts=scp_opts) @@ -199,7 +200,8 @@ async def scp_from(self, source, destination, user='ubuntu', proxy=False, :param str destination: Local destination of transferred files :param str user: Remote username :param bool proxy: Proxy through the Juju API server - :param str scp_opts: Additional options to the `scp` command + :param scp_opts: Additional options to the `scp` command + :type scp_opts: str or list """ await self.machine.scp_from(source, destination, user=user, proxy=proxy, scp_opts=scp_opts) diff --git a/tests/integration/test_machine.py b/tests/integration/test_machine.py index 9a5f0758..070208a5 100644 --- a/tests/integration/test_machine.py +++ b/tests/integration/test_machine.py @@ -58,8 +58,8 @@ async def test_scp(event_loop): with NamedTemporaryFile() as f: f.write(b'testcontents') f.flush() - await machine.scp_to(f.name, 'testfile') + await machine.scp_to(f.name, 'testfile', scp_opts='-p') with NamedTemporaryFile() as f: - await machine.scp_from('testfile', f.name) + await machine.scp_from('testfile', f.name, scp_opts='-p') assert f.read() == b'testcontents'