Skip to content

Commit 1385d6b

Browse files
authored
Merge pull request #258 from Ankit152/mtsre-692
[MTSRE-692] ocm client send namespace with labels
2 parents 0f3e0f4 + 008a787 commit 1385d6b

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

managedtenants/utils/ocm.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class OcmCli:
5050
"subOperators": "sub_operators",
5151
"managedService": "managed_service",
5252
"config": "config",
53+
"namespaces": "namespaces",
5354
}
5455

5556
IMAGESET_KEYS = {
@@ -415,6 +416,14 @@ def set_addon_config(self, addon, addon_id, config_obj, mapped_key):
415416

416417
return addon
417418

419+
def get_namespace_labels_list(self, namespaces, namespaceLabels):
420+
namespaceLabelsList = []
421+
for namespace in namespaces:
422+
namespaceLabelsList.append(
423+
{"name": namespace, "labels": namespaceLabels}
424+
)
425+
return namespaceLabelsList
426+
418427
def _addon_from_metadata(self, metadata):
419428
addon = {}
420429
# Set empty values if attrs are not present
@@ -427,6 +436,12 @@ def _addon_from_metadata(self, metadata):
427436
metadata["config"] = metadata.get("config", {})
428437
metadata["config"]["env"] = metadata["config"].get("env", [])
429438
metadata["config"]["secrets"] = metadata["config"].get("secrets", [])
439+
# ocm client to send in namespaces(along with labels)
440+
namespaceLabels = metadata.get("namespaceLabels")
441+
namespaces = metadata.get("namespaces", [])
442+
metadata["namespaces"] = self.get_namespace_labels_list(
443+
namespaces, namespaceLabels
444+
)
430445

431446
for key, val in metadata.items():
432447
if key in self.ADDON_KEYS:

tests/utils/test_ocm.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from managedtenants.data.paths import SCHEMAS_DIR
77
from managedtenants.utils.ocm import OcmCli
88
from tests.testutils.addon_helpers import ( # noqa: F401; noqa: F401; flake8: noqa: F401
9+
addon_with_deadmanssnitch,
910
addon_with_imageset_and_default_config,
1011
addon_with_imageset_and_multiple_config,
1112
addon_with_imageset_and_only_required_attrs,
@@ -230,3 +231,43 @@ def test_ocm_addon_default_values(addon_str, expected_result, request):
230231

231232
for k, expected_value in expected_result.items():
232233
assert ocm_addon.get(k) == expected_value
234+
235+
236+
@pytest.mark.parametrize(
237+
"addon_str,expected_result",
238+
[
239+
(
240+
"addon_without_imageset_and_only_required_attrs",
241+
{
242+
"namespaces": [
243+
{
244+
"name": "mock-operator",
245+
"labels": {"monitoring-key": "mock"},
246+
},
247+
],
248+
},
249+
),
250+
(
251+
"addon_with_deadmanssnitch",
252+
{
253+
"namespaces": [
254+
{
255+
"name": "redhat-test-operator",
256+
"labels": {},
257+
}
258+
],
259+
},
260+
),
261+
],
262+
)
263+
def test_ocm_addon_namespace_with_labels(addon_str, expected_result, request):
264+
addon = request.getfixturevalue(addon_str)
265+
ocm_cli = OcmCli(offline_token=None)
266+
if addon.imageset:
267+
ocm_addon = ocm_cli._addon_from_imageset(
268+
imageset=addon.imageset, metadata=addon.metadata
269+
)
270+
else:
271+
ocm_addon = ocm_cli._addon_from_metadata(metadata=addon.metadata)
272+
for k, expected_value in expected_result.items():
273+
assert ocm_addon.get(k) == expected_value

0 commit comments

Comments
 (0)