1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

ChromeOsTarget: Fix building SSH connection parameter list

'if list.get(elem, None)' like probing ignores list elements whose
values are falsy.

Here is a sample test code:
```Python
connection_settings={'host': '127.0.0.1',
                     'port': 8022,
                     'username': 'root',
                     'password': 'root',
                     'strict_host_check': False}

ssh_conn_params = ['host', 'username', 'password', 'port', 'strict_host_check']

print(f'connection_settings={connection_settings}')

ssh_connection_settings = {}
for setting in ssh_conn_params:
    if connection_settings.get(setting, None):
        print(f'1. setting "{setting}" to "{connection_settings[setting]}"...')
        ssh_connection_settings[setting] = connection_settings[setting]
    else:
        print(f'1. "{setting}" is None!')

ssh_connection_settings = {}
for setting in ssh_conn_params:
    if setting in connection_settings:
        print(f'2. setting "{setting}" to "{connection_settings[setting]}"...')
        ssh_connection_settings[setting] = connection_settings[setting]
    else:
        print(f'2. "{setting}" is None!')
```

And its output:
```
connection_settings={'host': '127.0.0.1', 'port': 8022, 'username': 'root', 'password': 'root', 'strict_host_check': False}

1. setting "host" to "127.0.0.1"...
1. setting "username" to "root"...
1. setting "password" to "root"...
1. setting "port" to "8022"...
1. "strict_host_check" is None!

2. setting "host" to "127.0.0.1"...
2. setting "username" to "root"...
2. setting "password" to "root"...
2. setting "port" to "8022"...
2. setting "strict_host_check" to "False"...
```

Also fix a typo in a log message.

Signed-off-by: Metin Kaya <metin.kaya@arm.com>
This commit is contained in:
Metin Kaya 2024-01-17 10:45:52 +00:00 committed by Marc Bonnici
parent be7e73db16
commit 613b4fabba

View File

@ -505,7 +505,7 @@ class Target(object):
self.hard_reset() # pylint: disable=no-member self.hard_reset() # pylint: disable=no-member
else: else:
if not self.is_connected: if not self.is_connected:
message = 'Cannot reboot target becuase it is disconnected. ' +\ message = 'Cannot reboot target because it is disconnected. ' +\
'Either connect() first, or specify hard=True ' +\ 'Either connect() first, or specify hard=True ' +\
'(in which case, a hard_reset module must be installed)' '(in which case, a hard_reset module must be installed)'
raise TargetTransientError(message) raise TargetTransientError(message)
@ -2970,9 +2970,11 @@ class ChromeOsTarget(LinuxTarget):
'total_transfer_timeout', 'poll_transfers', 'total_transfer_timeout', 'poll_transfers',
'start_transfer_poll_delay'] 'start_transfer_poll_delay']
self.ssh_connection_settings = {} self.ssh_connection_settings = {}
for setting in ssh_conn_params: self.ssh_connection_settings.update(
if connection_settings.get(setting, None): (key, value)
self.ssh_connection_settings[setting] = connection_settings[setting] for key, value in connection_settings.items()
if key in ssh_conn_params
)
super(ChromeOsTarget, self).__init__(connection_settings=self.ssh_connection_settings, super(ChromeOsTarget, self).__init__(connection_settings=self.ssh_connection_settings,
platform=platform, platform=platform,
@ -2991,9 +2993,11 @@ class ChromeOsTarget(LinuxTarget):
# Pull out adb connection settings # Pull out adb connection settings
adb_conn_params = ['device', 'adb_server', 'timeout'] adb_conn_params = ['device', 'adb_server', 'timeout']
self.android_connection_settings = {} self.android_connection_settings = {}
for setting in adb_conn_params: self.android_connection_settings.update(
if connection_settings.get(setting, None): (key, value)
self.android_connection_settings[setting] = connection_settings[setting] for key, value in connection_settings.items()
if key in adb_conn_params
)
# If adb device is not explicitly specified use same as ssh host # If adb device is not explicitly specified use same as ssh host
if not connection_settings.get('device', None): if not connection_settings.get('device', None):