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
Branches
No related tags found
No related merge requests found
repos:
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.5.0
rev: v3.0.1
hooks:
- id: reorder-python-imports
language_version: python3
- repo: https://github.com/psf/black
rev: 21.6b0
rev: 22.1.0
hooks:
- id: black
args: [--safe, --quiet, --line-length, "100"]
......@@ -20,7 +20,7 @@ repos:
- --max-line-length=100
- --ignore=W503,E203
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.1.0
hooks:
- id: trailing-whitespace
language_version: python3
......@@ -29,7 +29,7 @@ repos:
- id: debug-statements
language_version: python3
- repo: https://github.com/asottile/pyupgrade
rev: v2.19.3
rev: v2.31.1
hooks:
- id: pyupgrade
language_version: python3
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
......@@ -14,7 +14,7 @@ RUN dnf install -y git-core make go ncurses && \
chmod a+x out/binaries/gitlab-runner && \
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
......
......@@ -33,6 +33,8 @@ The container expects the following environment variables:
`PRIVATE_KEY` - Private key content
`SSH_TIMEOUT` - Timeout for establishing SSH connection
### GitLab Runner variables
`RUNNER_TAG_LIST` - Tag list
......
......@@ -4,7 +4,7 @@ cat << EOS
{
"driver": {
"name": "Openstack",
"version": "2021.10.07.0"
"version": "2022.03.28.0"
}
}
EOS
......@@ -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")
USERNAME = os.getenv("CUSTOM_ENV_USERNAME") or os.getenv("USERNAME")
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")
SYSTEM_FAILURE_EXIT_CODE = os.getenv("SYSTEM_FAILURE_EXIT_CODE")
......@@ -5,13 +5,16 @@ import traceback
import openstack
import paramiko
from tenacity import retry
from tenacity import RetryCallState
from tenacity import stop_after_attempt
from tenacity import wait_fixed
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)
flavor = conn.compute.find_flavor(env.FLAVOR)
network = conn.network.find_network(env.NETWORK)
......@@ -34,10 +37,21 @@ def get_server_ip(
def check_ssh(ip: str) -> None:
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())
@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():
ssh_client.connect(
hostname=ip,
......@@ -45,7 +59,7 @@ def check_ssh(ip: str) -> None:
pkey=pkey,
look_for_keys=False,
allow_agent=False,
timeout=20,
timeout=int(env.SSH_TIMEOUT),
)
connect()
......@@ -53,6 +67,10 @@ def check_ssh(ip: str) -> 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)
try:
conn = openstack.connect()
......@@ -61,7 +79,7 @@ def main() -> None:
ip = get_server_ip(conn, server)
print(f"Instance {env.VM_NAME} is running on address {ip}", flush=True)
conn.close()
print("Checking SSH connection", flush=True)
print("Waiting for SSH connection", flush=True)
check_ssh(ip)
print("SSH connection has been established", flush=True)
except Exception:
......
......@@ -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:
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.connect(
hostname=ip,
......@@ -36,7 +36,7 @@ def get_ssh_client(ip: str) -> paramiko.client.SSHClient:
pkey=pkey,
look_for_keys=False,
allow_agent=False,
timeout=60,
timeout=int(env.SSH_TIMEOUT),
)
return ssh_client
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment