diff --git a/iib/workers/config.py b/iib/workers/config.py index 59fc9c76..f6379dae 100644 --- a/iib/workers/config.py +++ b/iib/workers/config.py @@ -90,6 +90,9 @@ class Config(object): # path where catalog resides in fbc_fragment # might need to be changed, currently based on test fbc-fragment fbc_fragment_catalog_path: str = '/configs' + # path where operator deprecations will be stored + # it's a sub-directory of fbc_fragment_catalog_path + operator_deprecations_dir: str = '_operator-deprecations-content' # The task messages will be acknowledged after the task has been executed, # instead of just before task_acks_late: bool = True diff --git a/iib/workers/tasks/build.py b/iib/workers/tasks/build.py index a433083e..4108f8ab 100644 --- a/iib/workers/tasks/build.py +++ b/iib/workers/tasks/build.py @@ -1077,12 +1077,23 @@ def handle_rm_request( catalog_from_index = get_catalog_dir( from_index=from_index_resolved, base_dir=os.path.join(temp_dir, 'from_index') ) - # remove operators from //from_index/configs if exists + # remove operators and operator deprecations from //from_index/configs + # if they exist for operator in operators: operator_path = os.path.join(catalog_from_index, operator) + operator_deprecations_path = os.path.join( + catalog_from_index, worker_config['operator_deprecations_dir'], operator + ) if os.path.exists(operator_path): log.debug('Removing operator from from_index FBC %s', operator_path) shutil.rmtree(operator_path) + if os.path.exists(operator_deprecations_path): + log.debug( + 'Removing operator deprecation for package %s from from_index FBC %s', + operator, + operator_deprecations_path, + ) + shutil.rmtree(operator_deprecations_path) # if operator is not opted in, remove from db operators_in_db, index_db_path = verify_operators_exists( diff --git a/tests/test_workers/test_tasks/test_build.py b/tests/test_workers/test_tasks/test_build.py index b0b62648..02c3bf69 100644 --- a/tests/test_workers/test_tasks/test_build.py +++ b/tests/test_workers/test_tasks/test_build.py @@ -1096,7 +1096,31 @@ def test_handle_rm_request_fbc( mock_voe, mock_gbj, mock_opmvalidate, + tmpdir, ): + configs_dir = tmpdir.mkdir('configs') + deprecations_dir = configs_dir.mkdir(worker_config['operator_deprecations_dir']) + operator_deprecation_dir = deprecations_dir.mkdir('some-operator') + deprecation_template = textwrap.dedent( + """\ + { + "schema": "olm.deprecations", + "package": "some-operator", + "entries": [ + { + "reference": { + "name": "my-operator.v1.57.7", + "schema": "olm.bundle" + }, + "message": "my-operator.v1.57.7 is deprecated.\n" + } + ] + } + """ + ) + deprecation_file = operator_deprecation_dir.join('some-operator.json') + deprecation_file.write(deprecation_template) + mock_voe.return_value = ['some-operator'], '/tmp/xyz/database/index.db' mock_govn.return_value = '0.9.0' mock_iifbc.return_value = True @@ -1113,7 +1137,11 @@ def test_handle_rm_request_fbc( mock_ogd.return_value = "/tmp/xyz/index.Dockerfile" mock_om.return_value = "/tmp/xyz/catalog" mock_orrf.return_value = "/tmp/fbc_dir", "/tmp/cache_dir" - mock_gcd.return_value = "/some/path" + mock_gcd.return_value = configs_dir + + # Assert deprecations file was created as expected + assert os.path.exists(deprecation_file) + build.handle_rm_request( operators=['some-operator'], request_id=5, @@ -1135,7 +1163,7 @@ def test_handle_rm_request_fbc( assert mock_or.call_count == 2 mock_gcd.assert_called_once() mock_gcl.assert_called_once() - mock_mcd.assert_called_once_with(mock.ANY, '/some/path') + mock_mcd.assert_called_once_with(mock.ANY, configs_dir) mock_orrf.assert_called_once() mock_opmvalidate.assert_called_once() assert mock_alti.call_count == 2 @@ -1147,6 +1175,11 @@ def test_handle_rm_request_fbc( mock_uiips.assert_called_once() assert mock_srs.call_args[0][1] == 'complete' + # Assert deprecations were removed correctly + assert not os.path.exists(deprecation_file) + assert not operator_deprecation_dir.check() + assert deprecations_dir.check(dir=True) + @mock.patch('iib.workers.tasks.build.set_registry_token') @mock.patch('iib.workers.tasks.build.get_resolved_image')