Skip to content

orchestra/remote: add resolve_ip method#2067

Merged
zmc merged 4 commits intoceph:mainfrom
kshtsk:wip-remote-resolve-ip
Jul 25, 2025
Merged

orchestra/remote: add resolve_ip method#2067
zmc merged 4 commits intoceph:mainfrom
kshtsk:wip-remote-resolve-ip

Conversation

@kshtsk
Copy link
Copy Markdown
Contributor

@kshtsk kshtsk commented Jul 17, 2025

Add utility method to resolve a hostname from within remote host. This is useful to resolve ip address of the remote host itself, because getting ip address from transport object of ssh is not suitable because it may have only bastion host and port, which is not relevant for the purpose of configuring a cluster.

@kshtsk kshtsk requested a review from a team as a code owner July 17, 2025 22:47
@kshtsk kshtsk requested review from amathuria and kamoltat and removed request for a team July 17, 2025 22:47
@kshtsk kshtsk force-pushed the wip-remote-resolve-ip branch from b7e2390 to 8441bb9 Compare July 18, 2025 15:35
@kshtsk kshtsk requested a review from zmc July 18, 2025 15:36
Comment thread teuthology/orchestra/remote.py Outdated
else:
raise Exception(f'Unknown IP version {ipv}, expected 4 or 6')
if 'has address' in remote_host_ip:
(host, ip) = remote_host_ip.strip().split(' has address ')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the name resolves to multiple addresses, we will get:

ValueError: too many values to unpack (expected 2)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hm, didn't test it against google.com, it has indeed strange response:

$ host -4 google.com
google.com has address 142.250.185.110
google.com has IPv6 address 2a00:1450:4001:80f::200e
google.com mail is handled by 10 smtp.google.com.

I only verified this against target nodes. I guess in this case it is only needed to find first occurrence of "has address" line if any.

Copy link
Copy Markdown
Member

@zmc zmc left a comment

Choose a reason for hiding this comment

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

I'm curious why we wouldn't prefer to use native python APIs, e.g.:

>>> pprint(socket.getaddrinfo('google.com', None))
[(<AddressFamily.AF_INET6: 30>,
  <SocketKind.SOCK_DGRAM: 2>,
  17,
  '',
  ('2607:f8b0:400f:802::200e', 0, 0, 0)),
 (<AddressFamily.AF_INET6: 30>,
  <SocketKind.SOCK_STREAM: 1>,
  6,
  '',
  ('2607:f8b0:400f:802::200e', 0, 0, 0)),
 (<AddressFamily.AF_INET: 2>,
  <SocketKind.SOCK_DGRAM: 2>,
  17,
  '',
  ('142.250.69.238', 0)),
 (<AddressFamily.AF_INET: 2>,
  <SocketKind.SOCK_STREAM: 1>,
  6,
  '',
  ('142.250.69.238', 0))]

It handles multiple results gracefully, and the same call can return both v4 and v6 addresses with an easy way to filter for one or the other if necessary.

@kshtsk
Copy link
Copy Markdown
Contributor Author

kshtsk commented Jul 18, 2025

I'm curious why we wouldn't prefer to use native python APIs, e.g.:

>>> pprint(socket.getaddrinfo('google.com', None))
[(<AddressFamily.AF_INET6: 30>,
  <SocketKind.SOCK_DGRAM: 2>,
  17,
  '',
  ('2607:f8b0:400f:802::200e', 0, 0, 0)),
 (<AddressFamily.AF_INET6: 30>,
  <SocketKind.SOCK_STREAM: 1>,
  6,
  '',
  ('2607:f8b0:400f:802::200e', 0, 0, 0)),
 (<AddressFamily.AF_INET: 2>,
  <SocketKind.SOCK_DGRAM: 2>,
  17,
  '',
  ('142.250.69.238', 0)),
 (<AddressFamily.AF_INET: 2>,
  <SocketKind.SOCK_STREAM: 1>,
  6,
  '',
  ('142.250.69.238', 0))]

It handles multiple results gracefully, and the same call can return both v4 and v6 addresses with an easy way to filter for one or the other if necessary.

because the idea is to get addresses remotely and not all targets can be resolved from teuthology host, for example, in case of using bastion hosts

@kshtsk kshtsk force-pushed the wip-remote-resolve-ip branch from 8441bb9 to 618ab8a Compare July 23, 2025 09:30
@kshtsk
Copy link
Copy Markdown
Contributor Author

kshtsk commented Jul 23, 2025

@zmc I updated the code, take another look please

Kyr Shatskyy added 2 commits July 23, 2025 13:37
Add utility method to resolve a hostname from within remote host.
This is useful to resolve ip address of the remote host itself,
because getting ip address from transport object of ssh is not
suitable because it may have only bastion host and port, which
is not relevant for the purpose of configuring a cluster.

Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@clyso.com>
Update before bootstrap

Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@clyso.com>
@kshtsk kshtsk force-pushed the wip-remote-resolve-ip branch from 618ab8a to 382c6d9 Compare July 23, 2025 11:38
@kshtsk
Copy link
Copy Markdown
Contributor Author

kshtsk commented Jul 23, 2025

I'm curious why we wouldn't prefer to use native python APIs, e.g.:

>>> pprint(socket.getaddrinfo('google.com', None))
[(<AddressFamily.AF_INET6: 30>,
  <SocketKind.SOCK_DGRAM: 2>,
  17,
  '',
  ('2607:f8b0:400f:802::200e', 0, 0, 0)),
 (<AddressFamily.AF_INET6: 30>,
  <SocketKind.SOCK_STREAM: 1>,
  6,
  '',
  ('2607:f8b0:400f:802::200e', 0, 0, 0)),
 (<AddressFamily.AF_INET: 2>,
  <SocketKind.SOCK_DGRAM: 2>,
  17,
  '',
  ('142.250.69.238', 0)),
 (<AddressFamily.AF_INET: 2>,
  <SocketKind.SOCK_STREAM: 1>,
  6,
  '',
  ('142.250.69.238', 0))]

It handles multiple results gracefully, and the same call can return both v4 and v6 addresses with an easy way to filter for one or the other if necessary.

I just tried this for google.com in sepia lab:

kyr@teuthology:~$ host -4 google.com
google.com has address 142.251.111.138
google.com has address 142.251.111.102
google.com has address 142.251.111.113
google.com has address 142.251.111.101
google.com has address 142.251.111.100
google.com has address 142.251.111.139
google.com has IPv6 address 2607:f8b0:4004:c19::64
google.com has IPv6 address 2607:f8b0:4004:c19::8b
google.com has IPv6 address 2607:f8b0:4004:c19::8a
google.com has IPv6 address 2607:f8b0:4004:c19::66
google.com mail is handled by 10 smtp.google.com.

That's interesting, a bunch of addresses of each type, however the introduced function is supposed to be used for target nodes only, which supposed to have only one address correspondingly, does it makes sense to take first found or to return all of them as a list.

Kyr Shatskyy added 2 commits July 23, 2025 15:23
This patch addresses the error in the logs, like this:

  Using python: python3.12
  /usr/bin/lsb_release
  Deleting existing virtual environment
  Creating new venv at ./virtualenv
  ./bootstrap: line 131: [: missing `]'
  ./bootstrap: line 131: 12: command not found

Fixes: 0b5a5bc

Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@clyso.com>
The `git config --unset` returns 5 if there is missing variable supposed
to be unset. Just always return true for this command so the bootstrap
can proceed.

Fixes: 7cc6ba4

Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@clyso.com>
Copy link
Copy Markdown
Member

@zmc zmc left a comment

Choose a reason for hiding this comment

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

Thanks for updating to handle the multiple-value-in-response case, and for adding a unit test. Looks good to me!

@zmc zmc merged commit a614c16 into ceph:main Jul 25, 2025
8 checks passed
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.

2 participants