test(functional): switch to new runner registration API · python-gitlab/python-gitlab@cbc613d

Original file line numberDiff line numberDiff line change

@@ -8,7 +8,7 @@

88

import time

99

import uuid

1010

from subprocess import check_output

11-

from typing import Sequence

11+

from typing import Sequence, TYPE_CHECKING

1212
1313

import pytest

1414

import requests

@@ -260,6 +260,7 @@ def gl(gitlab_url: str, gitlab_token: str) -> gitlab.Gitlab:

260260
261261

logging.info("Instantiating python-gitlab gitlab.Gitlab instance")

262262

instance = gitlab.Gitlab(gitlab_url, private_token=gitlab_token)

263+

instance.auth()

263264
264265

logging.info("Reset GitLab")

265266

reset_gitlab(instance)

@@ -291,33 +292,36 @@ def gitlab_ultimate(gitlab_plan, request) -> None:

291292
292293
293294

@pytest.fixture(scope="session")

294-

def gitlab_runner(gl):

295+

def gitlab_runner(gl: gitlab.Gitlab):

295296

container = "gitlab-runner-test"

296-

runner_name = "python-gitlab-runner"

297-

token = "registration-token"

297+

runner_description = "python-gitlab-runner"

298+

if TYPE_CHECKING:

299+

assert gl.user is not None

300+
301+

runner = gl.user.runners.create(

302+

{"runner_type": "instance_type", "run_untagged": True}

303+

)

298304

url = "http://gitlab"

299305
300306

docker_exec = ["docker", "exec", container, "gitlab-runner"]

301307

register = [

302308

"register",

303-

"--run-untagged",

304309

"--non-interactive",

305-

"--registration-token",

306-

token,

307-

"--name",

308-

runner_name,

310+

"--token",

311+

runner.token,

312+

"--description",

313+

runner_description,

309314

"--url",

310315

url,

311316

"--clone-url",

312317

url,

313318

"--executor",

314319

"shell",

315320

]

316-

unregister = ["unregister", "--name", runner_name]

317321
318322

yield check_output(docker_exec + register).decode()

319323
320-

check_output(docker_exec + unregister).decode()

324+

gl.runners.delete(token=runner.token)

321325
322326
323327

@pytest.fixture(scope="module")