Skip to content
Snippets Groups Projects
Commit b0d2a8c7 authored by Erwan Rouchet's avatar Erwan Rouchet Committed by Bastien Abadie
Browse files

Remove process_id parameter from CreateTask in Git imports

parent 63cf5199
No related branches found
No related tags found
1 merge request!355Remove process_id parameter from CreateTask in Git imports
Pipeline #21511 passed
......@@ -80,10 +80,6 @@ class GitWorkerImport(object):
"""
assert isinstance(versions, (set, list))
assert len(versions) > 0, "No versions"
assert "ARKINDEX_PROCESS_ID" in os.environ, (
"Missing ARKINDEX_PROCESS_ID environment variable"
" to create a build task for this worker version"
)
assert "PONOS_TASK" in os.environ, (
"Missing PONOS_TASK environment variable"
" to create a build task for this worker version"
......@@ -106,7 +102,6 @@ class GitWorkerImport(object):
default_client.request(
"CreateTask",
body={
"process_id": os.environ["ARKINDEX_PROCESS_ID"],
"slug": f"docker_build_{slug}",
"parents": [os.environ["PONOS_TASK"]],
"image": f"registry.gitlab.com/teklia/arkindex/tasks:{__version__}",
......@@ -146,17 +141,14 @@ class GitWorkerImport(object):
try:
worker = self.create_worker(worker_config)
version = self.create_worker_version(worker, worker_config)
if (
"ARKINDEX_PROCESS_ID" in os.environ
and "PONOS_TASK" in os.environ
):
if "PONOS_TASK" in os.environ:
# Index worker version per its dockerfile
dockerfile = worker_config["docker"]["build"] or "Dockerfile"
dockerfiles[dockerfile].add(version["id"])
else:
logger.warning(
"Couldn't create build task for this worker version since we aren't in a"
" ponos context: Missing ARKINDEX_PROCESS_ID and/or PONOS_TASK environment variables"
" ponos context: Missing PONOS_TASK environment variable"
)
except Exception as e:
failed_config += 1
......
......@@ -327,7 +327,7 @@ class TestWorker(TestCase):
],
)
def test_create_build_task_missing_process_id_var(self, req_mock):
def test_create_build_task_missing_ponos_task_var(self, req_mock):
repo_id = uuid4()
rev_id = uuid4()
version_id = uuid4()
......@@ -338,34 +338,13 @@ class TestWorker(TestCase):
with self.assertRaises(
AssertionError,
msg="Missing ARKINDEX_PROCESS_ID environment variable"
msg="Missing PONOS_TASK environment variable"
" to create a build task for this worker version",
):
git_worker_import.create_build_task("book_of_hours", [version_id])
self.assertEqual(req_mock.call_count, 0)
def test_create_build_task_missing_ponos_task_var(self, req_mock):
repo_id = uuid4()
rev_id = uuid4()
version_id = uuid4()
git_worker_import = GitWorkerImport(
repository_id=repo_id, revision_id=rev_id, config=self.config_worker
)
with patch.dict(
"arkindex_tasks.base.os.environ", {"ARKINDEX_PROCESS_ID": str(uuid4())}
):
with self.assertRaises(
AssertionError,
msg="Missing PONOS_TASK environment variable"
" to create a build task for this worker version",
):
git_worker_import.create_build_task("book_of_hours", [version_id])
self.assertEqual(req_mock.call_count, 0)
def test_create_build_task(self, req_mock):
repo_id = uuid4()
rev_id = uuid4()
......@@ -376,10 +355,9 @@ class TestWorker(TestCase):
with patch.dict(
"arkindex_tasks.base.os.environ",
{"ARKINDEX_PROCESS_ID": str(uuid4()), "PONOS_TASK": str(uuid4())},
{"PONOS_TASK": str(uuid4())},
):
payload = {
"process_id": os.environ["ARKINDEX_PROCESS_ID"],
"slug": "docker_build_book_of_hours",
"parents": [os.environ["PONOS_TASK"]],
"image": f"registry.gitlab.com/teklia/arkindex/tasks:{tasks_version}",
......@@ -405,9 +383,7 @@ class TestWorker(TestCase):
[("POST", "https://arkindex.teklia.com/api/v1/task/", payload)],
)
@patch.dict(
"os.environ", {"ARKINDEX_PROCESS_ID": str(uuid4()), "PONOS_TASK": str(uuid4())}
)
@patch.dict("os.environ", {"PONOS_TASK": str(uuid4())})
def test_run(self, req_mock):
repo_id, rev_id, worker_id, version_id = (
str(uuid4()),
......@@ -482,7 +458,6 @@ class TestWorker(TestCase):
"POST",
"https://arkindex.teklia.com/api/v1/task/",
{
"process_id": os.environ["ARKINDEX_PROCESS_ID"],
"slug": "docker_build_dockerfile1",
"parents": [os.environ["PONOS_TASK"]],
"image": f"registry.gitlab.com/teklia/arkindex/tasks:{tasks_version}",
......@@ -493,9 +468,7 @@ class TestWorker(TestCase):
],
)
@patch.dict(
"os.environ", {"ARKINDEX_PROCESS_ID": str(uuid4()), "PONOS_TASK": str(uuid4())}
)
@patch.dict("os.environ", {"PONOS_TASK": str(uuid4())})
def test_run_worker_error(self, req_mock):
"""
A single failure when creating any worker should cause the import to fail
......@@ -592,9 +565,7 @@ class TestWorker(TestCase):
],
)
@patch.dict(
"os.environ", {"ARKINDEX_PROCESS_ID": str(uuid4()), "PONOS_TASK": str(uuid4())}
)
@patch.dict("os.environ", {"PONOS_TASK": str(uuid4())})
def test_run_worker_version_error(self, req_mock):
"""
A single failure when creating any worker should cause the import to fail
......@@ -711,9 +682,7 @@ class TestWorker(TestCase):
],
)
@patch.dict(
"os.environ", {"ARKINDEX_PROCESS_ID": str(uuid4()), "PONOS_TASK": str(uuid4())}
)
@patch.dict("os.environ", {"PONOS_TASK": str(uuid4())})
def test_run_task_error(self, req_mock):
repo_id, rev_id, worker1_id, worker2_id, version1_id, version2_id = (
str(uuid4()),
......@@ -841,7 +810,6 @@ class TestWorker(TestCase):
"POST",
"https://arkindex.teklia.com/api/v1/task/",
{
"process_id": os.environ["ARKINDEX_PROCESS_ID"],
"slug": "docker_build_dockerfile1",
"parents": [os.environ["PONOS_TASK"]],
"image": f"registry.gitlab.com/teklia/arkindex/tasks:{tasks_version}",
......@@ -853,7 +821,6 @@ class TestWorker(TestCase):
"POST",
"https://arkindex.teklia.com/api/v1/task/",
{
"process_id": os.environ["ARKINDEX_PROCESS_ID"],
"slug": "docker_build_dockerfile2",
"parents": [os.environ["PONOS_TASK"]],
"image": f"registry.gitlab.com/teklia/arkindex/tasks:{tasks_version}",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment