Skip to content

Conversation

@victormlg
Copy link
Contributor

I changed the debug logging for ssh connections in aramid so that the user can better understand what is happening under the hood. For each task run with aramid, we log the type of action, the remote host and the command. I also added logging when the task times out (which happens often since timeout=1).

Since we already had logging in ssh_cmd, ssh_sudo and scp, I removed then because I think having the logging inside aramid is more informative.

(.venv) victor-moene@victomoe:~/northern.tech/cf-remote (logging-debug)$ python3 cf_remote --log-level=DEBUG info -H aws-ubu 
[INFO] Set the log level to DEBUG
[DEBUG] validate_args, hosts in args, args.hosts='aws-ubu'
[DEBUG] resolving hosts from 'aws-ubu'
[DEBUG] found name 'viaws-ubu-ubuntuclient0' in state, info='OrderedDict({'platform': 'ubuntu', 'size': 't2.micro', 'private_ips': ['172.31.33.211'], 'public_ips': ['3.252.235.29'], 'uuid': 'a3bd1ab9953abc58d63c7e6333859791d3a43fab', 'user': 'ubuntu', 'role': 'client', 'key_pair': 'victomoe-ed25519', 'security_groups': ['cfengine-test']})'
[DEBUG] found in cloud, adding '['[email protected]']'
[DEBUG] hosts='['[email protected]']'
[DEBUG] Connecting to '[email protected]'
[DEBUG] users= 'None'
[DEBUG] Attempting ssh: [email protected]:22
[DEBUG] Initializing Connection: host '3.252.235.29' user 'ubuntu' port '22'
[DEBUG] Attempting to open SSH Control Master process with command: ssh -M -N -p 22 -oControlPath=/home/victor-moene/.cfengine/cf-remote/%C -oLogLevel=ERROR -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -oBatchMode=yes -oHostKeyAlgorithms=+ssh-rsa -oPubkeyAcceptedKeyTypes=+ssh-rsa [email protected]
[DEBUG] Control Master is running, using it
[DEBUG] Running 'echo $UID' on [email protected] over ssh
[DEBUG] Connection timed out
[DEBUG] Running 'echo $UID' on [email protected] over ssh
[DEBUG] Connection initialized
[DEBUG] Control Master is running, using it
[DEBUG] Running 'whoami' on [email protected] over ssh
[DEBUG] Getting info about '[email protected]'
[DEBUG] Control Master is running, using it
[DEBUG] Running 'systeminfo' on [email protected] over ssh
[DEBUG] 
[DEBUG] bash: line 1: systeminfo: command not found
[...]

Ticket: CFE-4147
Signed-off-by: Victor Moene <[email protected]>
Comment on lines +186 to +187
if not hide:
print("Copying: '%s' to '%s'" % (file, remote))
Copy link
Member

Choose a reason for hiding this comment

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

Not a big deal, but you have changed the logging in a not-so-obvious way: Before it was only logged to one place: either print, or log.debug. Now, after your change, it's printed twice (always to log.debug, and sometimes to print).

import subprocess
import time
from urllib.parse import urlparse
from cf_remote import log
Copy link
Member

Choose a reason for hiding this comment

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

Before this change, aramid was an independent thing which didn't rely on anything from cf_remote. Now you've introduced a dependency on something from cf_remote, which means aramid can no longer be imported on its own as a separate module / library.

I think it's okay, but we could reverse this by:

Switching to only using python standard logging (https://docs.python.org/3/library/logging.html)

Or

Sending in a log object as a parameter when using aramid functions.

@olehermanse olehermanse merged commit 22858ce into cfengine:master May 22, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants