Skip to content
Snippets Groups Projects
Unverified Commit a8c94618 authored by Dmitrii Misharov's avatar Dmitrii Misharov Committed by GitHub
Browse files

Merge pull request #9 from RedHatQE/timeout

Added SSH_TIMEOUT env var, bumped paramiko version
parents e7a6c3cd 710f4861
No related branches found
No related tags found
No related merge requests found
repos: repos:
- repo: https://github.com/asottile/reorder_python_imports - repo: https://github.com/asottile/reorder_python_imports
rev: v2.5.0 rev: v3.0.1
hooks: hooks:
- id: reorder-python-imports - id: reorder-python-imports
language_version: python3 language_version: python3
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 21.6b0 rev: 22.1.0
hooks: hooks:
- id: black - id: black
args: [--safe, --quiet, --line-length, "100"] args: [--safe, --quiet, --line-length, "100"]
...@@ -20,7 +20,7 @@ repos: ...@@ -20,7 +20,7 @@ repos:
- --max-line-length=100 - --max-line-length=100
- --ignore=W503,E203 - --ignore=W503,E203
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1 rev: v4.1.0
hooks: hooks:
- id: trailing-whitespace - id: trailing-whitespace
language_version: python3 language_version: python3
...@@ -29,7 +29,7 @@ repos: ...@@ -29,7 +29,7 @@ repos:
- id: debug-statements - id: debug-statements
language_version: python3 language_version: python3
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/asottile/pyupgrade
rev: v2.19.3 rev: v2.31.1
hooks: hooks:
- id: pyupgrade - id: pyupgrade
language_version: python3 language_version: python3
ARG GITLAB_RUNNER_VERSION=v13.12.0 ARG GITLAB_RUNNER_VERSION=v13.12.0
FROM registry.access.redhat.com/ubi8:8.4 AS builder FROM registry.access.redhat.com/ubi8:8.5 AS builder
ARG GITLAB_RUNNER_VERSION ARG GITLAB_RUNNER_VERSION
...@@ -14,7 +14,7 @@ RUN dnf install -y git-core make go ncurses && \ ...@@ -14,7 +14,7 @@ RUN dnf install -y git-core make go ncurses && \
chmod a+x out/binaries/gitlab-runner && \ chmod a+x out/binaries/gitlab-runner && \
out/binaries/gitlab-runner --version out/binaries/gitlab-runner --version
FROM registry.access.redhat.com/ubi8:8.4 FROM registry.access.redhat.com/ubi8:8.5
ARG GITLAB_RUNNER_VERSION ARG GITLAB_RUNNER_VERSION
......
...@@ -33,6 +33,8 @@ The container expects the following environment variables: ...@@ -33,6 +33,8 @@ The container expects the following environment variables:
`PRIVATE_KEY` - Private key content `PRIVATE_KEY` - Private key content
`SSH_TIMEOUT` - Timeout for establishing SSH connection
### GitLab Runner variables ### GitLab Runner variables
`RUNNER_TAG_LIST` - Tag list `RUNNER_TAG_LIST` - Tag list
......
...@@ -4,7 +4,7 @@ cat << EOS ...@@ -4,7 +4,7 @@ cat << EOS
{ {
"driver": { "driver": {
"name": "Openstack", "name": "Openstack",
"version": "2021.10.07.0" "version": "2022.03.28.0"
} }
} }
EOS EOS
...@@ -9,6 +9,7 @@ KEY_PAIR_NAME = os.getenv("CUSTOM_ENV_KEY_PAIR_NAME") or os.getenv("KEY_PAIR_NAM ...@@ -9,6 +9,7 @@ KEY_PAIR_NAME = os.getenv("CUSTOM_ENV_KEY_PAIR_NAME") or os.getenv("KEY_PAIR_NAM
SECURITY_GROUP = os.getenv("CUSTOM_ENV_SECURITY_GROUP") or os.getenv("SECURITY_GROUP") SECURITY_GROUP = os.getenv("CUSTOM_ENV_SECURITY_GROUP") or os.getenv("SECURITY_GROUP")
USERNAME = os.getenv("CUSTOM_ENV_USERNAME") or os.getenv("USERNAME") USERNAME = os.getenv("CUSTOM_ENV_USERNAME") or os.getenv("USERNAME")
PRIVATE_KEY_PATH = f"{os.getenv('HOME')}/priv_key" PRIVATE_KEY_PATH = f"{os.getenv('HOME')}/priv_key"
SSH_TIMEOUT = os.getenv("CUSTOM_ENV_SSH_TIMEOUT") or os.getenv("SSH_TIMEOUT") or "30"
BUILD_FAILURE_EXIT_CODE = os.getenv("BUILD_FAILURE_EXIT_CODE") BUILD_FAILURE_EXIT_CODE = os.getenv("BUILD_FAILURE_EXIT_CODE")
SYSTEM_FAILURE_EXIT_CODE = os.getenv("SYSTEM_FAILURE_EXIT_CODE") SYSTEM_FAILURE_EXIT_CODE = os.getenv("SYSTEM_FAILURE_EXIT_CODE")
...@@ -5,13 +5,16 @@ import traceback ...@@ -5,13 +5,16 @@ import traceback
import openstack import openstack
import paramiko import paramiko
from tenacity import retry from tenacity import retry
from tenacity import RetryCallState
from tenacity import stop_after_attempt from tenacity import stop_after_attempt
from tenacity import wait_fixed from tenacity import wait_fixed
import env import env
def provision_server(conn: openstack.connection.Connection) -> openstack.compute.v2.server.Server: def provision_server(
conn: openstack.connection.Connection,
) -> openstack.compute.v2.server.Server:
image = conn.compute.find_image(env.BUILDER_IMAGE) image = conn.compute.find_image(env.BUILDER_IMAGE)
flavor = conn.compute.find_flavor(env.FLAVOR) flavor = conn.compute.find_flavor(env.FLAVOR)
network = conn.network.find_network(env.NETWORK) network = conn.network.find_network(env.NETWORK)
...@@ -34,10 +37,21 @@ def get_server_ip( ...@@ -34,10 +37,21 @@ def get_server_ip(
def check_ssh(ip: str) -> None: def check_ssh(ip: str) -> None:
ssh_client = paramiko.client.SSHClient() ssh_client = paramiko.client.SSHClient()
pkey = paramiko.rsakey.RSASHA256Key.from_private_key_file(env.PRIVATE_KEY_PATH) pkey = paramiko.rsakey.RSAKey.from_private_key_file(env.PRIVATE_KEY_PATH)
ssh_client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy()) ssh_client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
@retry(reraise=True, stop=stop_after_attempt(10), wait=wait_fixed(10)) def before_callback(retry_state: RetryCallState):
print(
f"Attempt: {retry_state.attempt_number}; timeout: {env.SSH_TIMEOUT} seconds",
flush=True,
)
@retry(
reraise=True,
stop=stop_after_attempt(10),
wait=wait_fixed(int(env.SSH_TIMEOUT)),
before=before_callback,
)
def connect(): def connect():
ssh_client.connect( ssh_client.connect(
hostname=ip, hostname=ip,
...@@ -45,7 +59,7 @@ def check_ssh(ip: str) -> None: ...@@ -45,7 +59,7 @@ def check_ssh(ip: str) -> None:
pkey=pkey, pkey=pkey,
look_for_keys=False, look_for_keys=False,
allow_agent=False, allow_agent=False,
timeout=20, timeout=int(env.SSH_TIMEOUT),
) )
connect() connect()
...@@ -53,6 +67,10 @@ def check_ssh(ip: str) -> None: ...@@ -53,6 +67,10 @@ def check_ssh(ip: str) -> None:
def main() -> None: def main() -> None:
print(
"Source code of this driver https://github.com/RedHatQE/openstack-gitlab-executor",
flush=True,
)
print("Connecting to Openstack", flush=True) print("Connecting to Openstack", flush=True)
try: try:
conn = openstack.connect() conn = openstack.connect()
...@@ -61,7 +79,7 @@ def main() -> None: ...@@ -61,7 +79,7 @@ def main() -> None:
ip = get_server_ip(conn, server) ip = get_server_ip(conn, server)
print(f"Instance {env.VM_NAME} is running on address {ip}", flush=True) print(f"Instance {env.VM_NAME} is running on address {ip}", flush=True)
conn.close() conn.close()
print("Checking SSH connection", flush=True) print("Waiting for SSH connection", flush=True)
check_ssh(ip) check_ssh(ip)
print("SSH connection has been established", flush=True) print("SSH connection has been established", flush=True)
except Exception: except Exception:
......
...@@ -16,7 +16,7 @@ munch==2.5.0 ...@@ -16,7 +16,7 @@ munch==2.5.0
netifaces==0.11.0 netifaces==0.11.0
openstacksdk==0.57.0 openstacksdk==0.57.0
os-service-types==1.7.0 os-service-types==1.7.0
paramiko @ git+https://github.com/kkovaacs/paramiko.git@d43ed76a44c451b2b9031883a1a7e55de59fdf79 # adds support of modern RSA keys paramiko==2.10.3
pbr==5.6.0 pbr==5.6.0
pycparser==2.20 pycparser==2.20
PyNaCl==1.4.0 PyNaCl==1.4.0
......
...@@ -28,7 +28,7 @@ def execute_script_on_server(ssh: paramiko.client.SSHClient, script_path: str) - ...@@ -28,7 +28,7 @@ def execute_script_on_server(ssh: paramiko.client.SSHClient, script_path: str) -
def get_ssh_client(ip: str) -> paramiko.client.SSHClient: def get_ssh_client(ip: str) -> paramiko.client.SSHClient:
ssh_client = paramiko.client.SSHClient() ssh_client = paramiko.client.SSHClient()
pkey = paramiko.rsakey.RSASHA256Key.from_private_key_file(env.PRIVATE_KEY_PATH) pkey = paramiko.rsakey.RSAKey.from_private_key_file(env.PRIVATE_KEY_PATH)
ssh_client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy()) ssh_client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
ssh_client.connect( ssh_client.connect(
hostname=ip, hostname=ip,
...@@ -36,7 +36,7 @@ def get_ssh_client(ip: str) -> paramiko.client.SSHClient: ...@@ -36,7 +36,7 @@ def get_ssh_client(ip: str) -> paramiko.client.SSHClient:
pkey=pkey, pkey=pkey,
look_for_keys=False, look_for_keys=False,
allow_agent=False, allow_agent=False,
timeout=60, timeout=int(env.SSH_TIMEOUT),
) )
return ssh_client return ssh_client
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment