Skip to content

Commit

Permalink
Remove Operator deprecations during rm request, if present
Browse files Browse the repository at this point in the history
Refers to CLOUDDST-23448
  • Loading branch information
yashvardhannanavati committed Oct 1, 2024
1 parent 25d1034 commit 550a95b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
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
12 changes: 11 additions & 1 deletion iib/workers/tasks/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,12 +1077,22 @@ 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 from from_index FBC %s',
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('_operator-deprecations-content')
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

0 comments on commit 550a95b

Please sign in to comment.