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

Skip Git imports for .arkindex.yml version 3

parent 7a4a0794
No related branches found
No related tags found
1 merge request!359Skip Git imports for .arkindex.yml version 3
Pipeline #131725 passed
......@@ -15,6 +15,9 @@ from arkindex_tasks.import_git.worker import GitWorkerImport
logging.basicConfig(format="[%(levelname)s] %(message)s", level=logging.INFO)
logger = logging.getLogger(__name__)
# Minimum .arkindex.yml version that causes the Git import to do nothing
SKIP_IMPORT_CONFIG_VERSION = 3
class GitImportTask(object):
def __init__(self, revision_id):
......@@ -57,6 +60,12 @@ class GitImportTask(object):
return config
def launch_import(self, config, path):
if config["version"] >= SKIP_IMPORT_CONFIG_VERSION:
logger.info(
f"Repository defines an .arkindex.yml with version {SKIP_IMPORT_CONFIG_VERSION} or later; skipping import"
)
return
if not config["workers"]:
raise ValueError("workers attribute inside config dict is empty")
......@@ -80,6 +89,7 @@ class GitImportTask(object):
self.repository["git_clone_url"], self.revision["hash"]
)
config = self.retrieve_config(extract_path)
self.launch_import(config, extract_path)
except Exception as e:
logger.error(f"Git import failed: {str(e)}")
......
---
version: 3
workers:
- workers/recursive/**/*.yml
- workers/worker2.yml
- name: Book of hours
slug: book_of_hours
type: classifier
docker:
command: python blabla.py
image: hub.docker.com/project/image:tag
shm_size: 42b
environment:
VARIABLE: VALUE
configuration:
classes: [X, Y, Z]
model: project/model.hdf5
width: 120
height: 120
key: value
......@@ -307,7 +307,7 @@ class TestBase(TestCase):
new_callable=mock_open,
read_data=dedent(
"""
version:
version: null
workers:
- name: a worker
slug: a_worker
......@@ -326,7 +326,7 @@ class TestBase(TestCase):
open(config_file).read(),
dedent(
"""
version:
version: null
workers:
- name: a worker
slug: a_worker
......@@ -356,7 +356,7 @@ class TestBase(TestCase):
def test_launch_import_workers_attribute_empty(self, req_mock):
git_task = MOCK_GIT_IMPORT_TASK
config_dict = {"workers": []}
config_dict = {"version": 2, "workers": []}
with self.assertRaises(
ValueError, msg="workers attribute inside config dict is empty"
):
......@@ -373,6 +373,7 @@ class TestBase(TestCase):
git_task.repository = {"id": repo_id}
config_dict = {
"version": 2,
"workers": ["path/to/worker.yml"],
}
git_task.launch_import(config_dict, ".")
......@@ -382,6 +383,22 @@ class TestBase(TestCase):
git_worker_import_mock.call_args, call(repo_id, rev_id, config_dict)
)
@patch("arkindex_tasks.import_git.base.GitWorkerImport")
def test_launch_import_skip(self, req_mock, git_worker_import_mock):
git_task = MOCK_GIT_IMPORT_TASK
rev_id = uuid4()
repo_id = uuid4()
git_task.revision = {"id": rev_id}
git_task.repository = {"id": repo_id}
config_dict = {
"version": 3,
"workers": ["path/to/worker.yml"],
}
git_task.launch_import(config_dict, ".")
self.assertFalse(git_worker_import_mock.called)
@patch("arkindex_tasks.import_git.base.logger")
@patch("shutil.rmtree")
def test_cleanup_non_existing_folder(self, req_mock, rm_mock, logger_mock):
......
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