Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to skip push in login #1715

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/login/keep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1

METHODS="${METHODS:-virtual}"

rlJournalStart
rlPhaseStartSetup
rlRun "tmp=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $tmp"
rlPhaseEnd

for method in $METHODS; do

rlPhaseStartTest "provision $method"
rlRun -s "tmt run -r plans --default provision -h $method prepare -h shell --script 'touch X' login -k -c 'test -e X; echo @@@$?@@@' finish"
rlAssertGrep '@@@0@@@' $rlRun_LOG
rlPhaseEnd

done

rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $tmp" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalEnd
8 changes: 8 additions & 0 deletions tests/login/main.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@
/test:
summary: Log into the guest after each test
test: ./test.sh

/keep:
summary: Leave workdir untouched by login
test: ./keep.sh
adjust:
- when: how is not defined or how != full
enabled: false
because: Can happen only when push is implemented
19 changes: 12 additions & 7 deletions tmt/steps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,9 @@ def command(
@click.option(
'-t', '--test', is_flag=True,
help='Log into the guest after each executed test in the execute phase.')
@click.option(
'-k', '--keep', is_flag=True,
help='Do not overwrite workdir by push to the guest before the login')
def login(context: 'tmt.cli.Context', **kwargs: Any) -> None:
"""
Provide user with an interactive shell on the guest.
Expand Down Expand Up @@ -1159,15 +1162,17 @@ def _login(
env: Optional[tmt.utils.EnvironmentType] = None) -> None:
""" Run the interactive command """
commands: List[str] = self.opt('command')
keep = self.opt('keep')
self.info('login', 'Starting interactive shell', color='yellow')
for guest in self.parent.plan.provision.guests():
# Attempt to push the workdir to the guest
try:
guest.push()
cwd = cwd or self.parent.plan.worktree
except tmt.utils.GeneralError:
self.warn("Failed to push workdir to the guest.")
cwd = None
cwd = cwd or self.parent.plan.worktree
if not keep:
# Attempt to push the workdir to the guest
try:
guest.push()
except tmt.utils.GeneralError:
self.warn("Failed to push workdir to the guest.")
cwd = None
# Execute all requested commands
for command in commands:
self.debug(f"Run '{command}' in interactive mode.")
Expand Down