Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Operator deprecations during rm request, if present #731

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions iib/workers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion iib/workers/tasks/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 /<temp_dir>/from_index/configs if exists
# remove operators and operator deprecations from /<temp_dir>/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(
Expand Down
37 changes: 35 additions & 2 deletions tests/test_workers/test_tasks/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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')
Expand Down