Skip to content

Print warning to stdout #6233

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions cli/src/pcluster/cli/commands/dcv_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ def _dcv_connect(args):

try:
url = _retry(_retrieve_dcv_session_url, func_args=[cmd, args.cluster_name, head_node_ip], attempts=4)
url_message = f"Please use the following one-time URL in your browser within 30 seconds:\n{url}"
url_message = f"Please use the following one-time URL in your browser within 30 seconds:"
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a test that should be changed accordingly:

assert_that(result.stdout).matches(
r"Please use the following one-time URL in your browser within 30 seconds:\n"
r"https:\/\/(\b(?:\d{1,3}\.){3}\d{1,3}\b):" + str(dcv_port) + r"\?authToken=(.*)"
)

Copy link
Contributor

Choose a reason for hiding this comment

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

With this change we are removing an explicative message from stdout to make it easier to consume the url.
What if this command returns a JSON, such as:

{
    "message": "Please use the following one-time URL in your browser within 30 seconds",
    "url": "https://...."
}

This would be consistent with the other pcluster commands returning JSON and would make possible to consume the url easily with jq or, even better, with the --query option of the pcluster CLI.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me. Please feel free to change it.


if args.show_url:
print(url_message)
print(url_message, file=sys.stderr)
print(f"{url}")
return

try:
Expand Down
4 changes: 3 additions & 1 deletion tests/integration-tests/tests/dcv/test_dcv.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ def _test_dcv_configuration(
# remove ssh key from jenkins user known hosts file
remove_keys_from_known_hosts(cluster.head_node_ip, host_keys_file, env=env)

assert_that(result.stdout).matches(
assert_that(result.stderr).matches(
r"Please use the following one-time URL in your browser within 30 seconds:\n"
)
assert_that(result.stdout).matches(
r"https:\/\/(\b(?:\d{1,3}\.){3}\d{1,3}\b):" + str(dcv_port) + r"\?authToken=(.*)"
)
if access_from == "0.0.0.0/0":
Expand Down