Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ jobs:
cd ./virtualenv/lib/python*
touch no-global-site-packages.txt
working-directory: ./teuthology
- name: Refresh system repos
run: |
sudo apt update -y
sudo apt upgrade -y
- name: Initial bootstrap
run: ./bootstrap install
working-directory: ./teuthology
Expand Down
2 changes: 1 addition & 1 deletion bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ PY_MAJOR=$($VENV/bin/python -c "import sys; print(sys.version_info[0])")
PY_MINOR=$($VENV/bin/python -c "import sys; print(sys.version_info[1])")

# Python version check
if [ "$PY_MAJOR" -ne 3 || "$PY_MINOR" -lt 10 ]; then
if [[ "$PY_MAJOR" -ne 3 || "$PY_MINOR" -lt 10 ]]; then
echo "Python version should be 3.10 or higher, found $PY_MAJOR.$PY_MINOR"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion containers/teuthology-dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
PIP_INSTALL_FLAGS="-r requirements.txt" ./bootstrap
COPY . /teuthology
RUN \
git config -f ./.git/config --unset 'http.https://github.com/.extraheader' && \
(git config -f ./.git/config --unset 'http.https://github.com/.extraheader' || true ) && \
./bootstrap
COPY containers/teuthology-dev/containerized_node.yaml /teuthology
COPY containers/teuthology-dev/.teuthology.yaml /root
Expand All @@ -42,4 +42,4 @@
chmod 600 $HOME/.ssh/id_rsa && \
echo "StrictHostKeyChecking=no" > $HOME/.ssh/config && \
echo "UserKnownHostsFile=/dev/null" >> $HOME/.ssh/config
ENTRYPOINT /teuthology.sh

Check warning on line 45 in containers/teuthology-dev/Dockerfile

View workflow job for this annotation

GitHub Actions / docker

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for ENTRYPOINT to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/
40 changes: 40 additions & 0 deletions teuthology/orchestra/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,46 @@ def _set_iface_and_cidr(self):
return
raise RuntimeError("Could not determine interface/CIDR!")


def resolve_ip(self, name=None, ipv='4') -> str:
"""
Resolve IP address of the remote host via remote host

Because remote object maybe behind bastion host we need
the remote host address resolvable from remote side.
So in order to the ip address we just call `host` remotely
and parse output like:
'smithi001.front.sepia.ceph.com has address 172.21.15.1\n'

:param name: hostname to resolve, by defaults remote host itself.
:param ipv: the IP version, 4 or 6, defaults to 4.

:raises: :class:`Exception`: when the hostname cannot be resolved.
:raises: :class:`ValueError`: when the ipv argument mismatch 4 or 6.

:returns: str object, the ip addres of the remote host.
"""
hostname = name or self.hostname
version = str(ipv)
if version in ['4', '6']:
remote_host_ip = self.sh(f'host -{ipv} {hostname}')
else:
raise ValueError(f'Unknown IP version {ipv}, expected 4 or 6')
# `host -4` or `host -6` may have multiline output: a host can have
# several address; thus try and find the first suitable
for info in remote_host_ip.split("\n"):
if version == '4' and 'has address' in info:
(host, ip) = info.strip().split(' has address ')
if hostname in host:
return ip
elif version == '6' and 'has IPv6 address' in info:
(host, ip) = info.strip().split(' has IPv6 address ')
if hostname in host:
return ip
else:
raise Exception(f'Cannot get IPv{ipv} address for the host "{hostname}" via remote "{self.hostname}"')


@property
def hostname(self):
if not hasattr(self, '_hostname'):
Expand Down
25 changes: 25 additions & 0 deletions teuthology/orchestra/test/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,31 @@ def test_is_container(self):
rem2._runner = m_run
assert not rem2.is_container

@patch("teuthology.orchestra.remote.Remote.sh")
def test_resolve_ip(self, m_sh):
r = remote.Remote(name="jdoe@xyzzy.example.com", ssh=self.m_ssh)
m_sh.return_value = "smithi001.front.sepia.ceph.com has address 172.21.15.1\n"
ip4 = remote.Remote.resolve_ip(r, 'smithi001')
assert ip4 == "172.21.15.1"
m_sh.return_value = "\n"
try:
ip4 = remote.Remote.resolve_ip(r, 'smithi001')
except Exception as e:
assert 'Cannot get IPv4 address' in str(e)
try:
ip4 = remote.Remote.resolve_ip(r, 'smithi001', 5)
except Exception as e:
assert 'Unknown IP version' in str(e)

m_sh.return_value = ("google.com has address 142.251.37.14\n"
"google.com has IPv6 address 2a00:1450:4016:80b::200e\n"
"google.com mail is handled by 10 smtp.google.com.\n")
ip4 = remote.Remote.resolve_ip(r, 'google.com')
assert ip4 == "142.251.37.14"
ip6 = remote.Remote.resolve_ip(r, 'google.com', '6')
assert ip6 == "2a00:1450:4016:80b::200e"


@patch("teuthology.orchestra.remote.Remote.run")
def test_write_file(self, m_run):
file = "fakefile"
Expand Down