Skip to content

Conversation

rushikeshjadhav
Copy link
Contributor

@rushikeshjadhav rushikeshjadhav commented Jun 30, 2025

Using the same path for both source and destination may cause scp to fail, especially when the source path (e.g. a temp path on macOS) does not exist on the remote system. Thus, resorting to use mktemp on destination.

lib/host.py Outdated
script.write(script_contents)
script.flush()
self.scp(script.name, script.name)
self.scp(script.name, "/tmp/" + script.name.split('/')[-1])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better use os.path.basneame

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, made the change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping @ydirson

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better, but computing the same path 3 times is suboptimal also for reading :)

Copy link
Contributor

@Millefeuille42 Millefeuille42 Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of computing paths each time, you could eventually use mktemp on the remote:

(Like in a fixture here)

@pytest.fixture(scope="module")
def temp_dir(running_unix_vm):
    vm = running_unix_vm
    tempdir = vm.ssh("mktemp -d")

    yield tempdir

    # teardown
    vm.ssh(f"rm -r {tempdir}")

Or something like this for local use:

import tempfile

### Either using contexts
with tempfile.TemporaryDirectory() as tmpdirname:
     print('created temporary directory', tmpdirname)

### Either controlling the lifetime manually
temp_dir = tempfile.TemporaryDirectory()
print(temp_dir.name)
temp_dir.cleanup()

This is for dirs but is quite the same for files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this fixture :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Straight up borrowed from #324 😁
It could be great to have this kind of generic fixtures available for all tests 👀 (eventually platform agnostic unlike the one I suggested)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, please see the latest update if it works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's all good for me

@rushikeshjadhav rushikeshjadhav force-pushed the issue-325-host-execute-script branch from 87dab23 to 9414d56 Compare July 2, 2025 19:30
@rushikeshjadhav rushikeshjadhav force-pushed the issue-325-host-execute-script branch from 9414d56 to 1963450 Compare September 19, 2025 09:21
lib/host.py Outdated
Comment on lines 235 to 236
self.scp(script.name, remote_path)
self.ssh(['chmod', '0755', remote_path])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be moved in try scope in case for some reason a call fails even if unlikely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, have moved them.

…te_script scp

Using the same path for both source and destination may cause scp to fail,
especially when the source path (e.g. a temp path on macOS) does not exist
on the remote system. Thus, resorting to use mktemp on destination.

Signed-off-by: Rushikesh Jadhav <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants