qontract-reconcile 0.10.1rc69__py3-none-any.whl → 0.10.1rc70__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: qontract-reconcile
3
- Version: 0.10.1rc69
3
+ Version: 0.10.1rc70
4
4
  Summary: Collection of tools to reconcile services with their desired state as defined in the app-interface DB.
5
5
  Home-page: https://github.com/app-sre/qontract-reconcile
6
6
  Author: Red Hat App-SRE Team
@@ -384,7 +384,7 @@ reconcile/test/test_utils_metrics.py,sha256=1GDG23ek7jV3Fo0vCMrptWbH6T3qTPDSp9Za
384
384
  reconcile/test/test_utils_models.py,sha256=9sY44ASmjzr342PImiUWl68It7XgksIaB08vZrD6jsw,10869
385
385
  reconcile/test/test_utils_mr.py,sha256=KYnF8SY8ybBVqXLQu8K40ZGcO8wSEkOW4PIS8RexLGQ,6622
386
386
  reconcile/test/test_utils_mr_clusters_updates.py,sha256=HZi70vg60huxjGKpasR07Ap0tYag_kJCFQQfxqi9LAU,2333
387
- reconcile/test/test_utils_oc.py,sha256=k3PwZ8QpJ0x4vSh2tX1Zov2oObauxYnfZ-gPQUmbj0Q,33590
387
+ reconcile/test/test_utils_oc.py,sha256=qZEesUct3Hhf0NT-STJlvQlXLSBSSe9WRxw_DO6VGo0,35903
388
388
  reconcile/test/test_utils_ocm.py,sha256=0oI2kTetsHLPdGKZbIZBDr1rJK7MAZ0jIC4Y0OnUXag,3348
389
389
  reconcile/test/test_utils_pagerduty_api.py,sha256=nGudGdVgruBRh1btuJ28CFaJTFqchHfsp2JnXY-_5Oo,7827
390
390
  reconcile/test/test_utils_parse_dhms_duration.py,sha256=OyTzWqU8QYNvr31dWrnWFVNHvRBqU2agR5fbQbnS4OU,753
@@ -500,7 +500,7 @@ reconcile/utils/lean_terraform_client.py,sha256=no9MMgG6TsgjM3EypIhLQtRmPZl9eNnZ
500
500
  reconcile/utils/make.py,sha256=QaEwucrzbl8-VHS66Wfdjfo0ubmAcvt_hZGpiGsKU50,231
501
501
  reconcile/utils/metrics.py,sha256=nKywg_TBGhpCyVnJnp4UtV63xplsH8hid0NlmrluVwM,13962
502
502
  reconcile/utils/models.py,sha256=0Y8HOYdL7tk4WUcRI59EQ9lMKeLmE2L1wwYAlpEjgSg,4774
503
- reconcile/utils/oc.py,sha256=gLGMhrXVDRUonesMM5HTIuL7f_2_6DQCvC1I_wTCA9E,64454
503
+ reconcile/utils/oc.py,sha256=AIkBSXLnsJCE_9HCMN66-QK359pMBNPs4Q2XPI9zjyU,64780
504
504
  reconcile/utils/oc_connection_parameters.py,sha256=mUP0WtpozdFDufcdNKy2OGweRvI3Faq8YLiR0ngJYes,9799
505
505
  reconcile/utils/oc_filters.py,sha256=RWn8pC5A7ZZT7C6WPq9bOw5KBNkiAb5puFSr_FpdAf8,1358
506
506
  reconcile/utils/oc_map.py,sha256=nT69J5pdPeIDnIYjD9fwY6GkE3BMQCf-AF0rmHJuUNw,9068
@@ -590,8 +590,8 @@ tools/sre_checkpoints/util.py,sha256=zEDbGr18ZeHNQwW8pUsr2JRjuXIPz--WAGJxZo9sv_Y
590
590
  tools/test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
591
591
  tools/test/test_qontract_cli.py,sha256=awwTHEc2DWlykuqGIYM0WOBoSL0KRnOraCLk3C7izis,1401
592
592
  tools/test/test_sre_checkpoints.py,sha256=SKqPPTl9ua0RFdSSofnoQX-JZE6dFLO3LRhfQzqtfh8,2607
593
- qontract_reconcile-0.10.1rc69.dist-info/METADATA,sha256=PEOvrOo_EJ1p9naDF1ydL7aq2Nr-UIjgJ90yatS0BwI,2290
594
- qontract_reconcile-0.10.1rc69.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
595
- qontract_reconcile-0.10.1rc69.dist-info/entry_points.txt,sha256=Af70EWPJxsTiCNF6gA-pWdw1A0Heqn-PZF-oBc5NmiU,302
596
- qontract_reconcile-0.10.1rc69.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
597
- qontract_reconcile-0.10.1rc69.dist-info/RECORD,,
593
+ qontract_reconcile-0.10.1rc70.dist-info/METADATA,sha256=DKCL0AtninblHvju2MBH3JYnMQOZZ7yHqlgqpumfbtM,2290
594
+ qontract_reconcile-0.10.1rc70.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
595
+ qontract_reconcile-0.10.1rc70.dist-info/entry_points.txt,sha256=Af70EWPJxsTiCNF6gA-pWdw1A0Heqn-PZF-oBc5NmiU,302
596
+ qontract_reconcile-0.10.1rc70.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
597
+ qontract_reconcile-0.10.1rc70.dist-info/RECORD,,
@@ -573,9 +573,9 @@ class TestOCMapGetClusters(TestCase):
573
573
 
574
574
 
575
575
  @pytest.fixture
576
- def oc(monkeypatch):
576
+ def oc_cli(monkeypatch) -> OCCli:
577
577
  monkeypatch.setenv("USE_NATIVE_CLIENT", "False")
578
- return OC("cluster", "server", "token", local=True)
578
+ return OC("cluster", "server", "token", local=True) # type: ignore[return-value]
579
579
 
580
580
 
581
581
  @pytest.fixture
@@ -620,44 +620,44 @@ def pod():
620
620
  }
621
621
 
622
622
 
623
- def test_get_resources_used_in_pod_spec_unsupported_kind(oc):
623
+ def test_get_resources_used_in_pod_spec_unsupported_kind(oc_cli):
624
624
  with pytest.raises(KeyError):
625
- oc.get_resources_used_in_pod_spec({}, "Deployment")
625
+ oc_cli.get_resources_used_in_pod_spec({}, "Deployment")
626
626
 
627
627
 
628
- def test_get_resources_used_in_pod_spec_secret(oc, pod):
628
+ def test_get_resources_used_in_pod_spec_secret(oc_cli, pod):
629
629
  expected = {"secret1": set(), "secret2": set(), "secret3": {"secretkey3"}}
630
- results = oc.get_resources_used_in_pod_spec(pod["spec"], "Secret")
630
+ results = oc_cli.get_resources_used_in_pod_spec(pod["spec"], "Secret")
631
631
  assert results == expected
632
632
 
633
633
 
634
- def test_get_resources_used_in_pod_spec_configmap(oc, pod):
634
+ def test_get_resources_used_in_pod_spec_configmap(oc_cli, pod):
635
635
  expected = {
636
636
  "configmap1": set(),
637
637
  "configmap2": set(),
638
638
  "configmap3": {"configmapkey3"},
639
639
  }
640
- results = oc.get_resources_used_in_pod_spec(pod["spec"], "ConfigMap")
640
+ results = oc_cli.get_resources_used_in_pod_spec(pod["spec"], "ConfigMap")
641
641
  assert results == expected
642
642
 
643
643
 
644
- def test_secret_used_in_pod_true(oc, pod):
645
- result = oc.secret_used_in_pod("secret1", pod)
644
+ def test_secret_used_in_pod_true(oc_cli, pod):
645
+ result = oc_cli.secret_used_in_pod("secret1", pod)
646
646
  assert result is True
647
647
 
648
648
 
649
- def test_secret_used_in_pod_false(oc, pod):
650
- result = oc.secret_used_in_pod("secret9999", pod)
649
+ def test_secret_used_in_pod_false(oc_cli, pod):
650
+ result = oc_cli.secret_used_in_pod("secret9999", pod)
651
651
  assert result is False
652
652
 
653
653
 
654
- def test_configmap_used_in_pod_true(oc, pod):
655
- result = oc.configmap_used_in_pod("configmap1", pod)
654
+ def test_configmap_used_in_pod_true(oc_cli, pod):
655
+ result = oc_cli.configmap_used_in_pod("configmap1", pod)
656
656
  assert result is True
657
657
 
658
658
 
659
- def test_configmap_used_in_pod_false(oc, pod):
660
- result = oc.configmap_used_in_pod("configmap9999", pod)
659
+ def test_configmap_used_in_pod_false(oc_cli, pod):
660
+ result = oc_cli.configmap_used_in_pod("configmap9999", pod)
661
661
  assert result is False
662
662
 
663
663
 
@@ -897,10 +897,14 @@ def replicasets(deployment):
897
897
  ]
898
898
 
899
899
 
900
- def test_get_owned_replicasets(mocker, oc: OCNative, deployment):
901
- oc__get = mocker.patch.object(oc, "get", autospec=True)
900
+ def test_get_owned_replicasets(
901
+ mocker,
902
+ oc_cli: OCCli,
903
+ deployment,
904
+ ):
905
+ oc__get = mocker.patch.object(oc_cli, "get", autospec=True)
902
906
  oc__get_obj_root_owner = mocker.patch.object(
903
- oc, "get_obj_root_owner", autospec=True
907
+ oc_cli, "get_obj_root_owner", autospec=True
904
908
  )
905
909
  oc__get.return_value = {"items": ["stub1", "stub2", "stub3"]}
906
910
  oc__get_obj_root_owner.side_effect = [
@@ -908,40 +912,56 @@ def test_get_owned_replicasets(mocker, oc: OCNative, deployment):
908
912
  deployment,
909
913
  {"kind": "ownerkind", "metadata": {"name": "notownername"}},
910
914
  ]
911
- owned_replicasets = oc.get_owned_replicasets("namespace", deployment)
915
+ owned_replicasets = oc_cli.get_owned_replicasets("namespace", deployment)
912
916
  assert len(owned_replicasets) == 2
913
917
 
914
918
 
915
- def test_get_replicaset(patch_sleep, mocker, oc: OCNative, deployment, replicasets):
919
+ def test_get_replicaset(
920
+ patch_sleep,
921
+ mocker,
922
+ oc_cli: OCCli,
923
+ deployment,
924
+ replicasets,
925
+ ):
916
926
  oc__get_owned_replicasets = mocker.patch.object(
917
- oc, "get_owned_replicasets", autospec=True
927
+ oc_cli, "get_owned_replicasets", autospec=True
918
928
  )
919
929
  oc__get_owned_replicasets.return_value = replicasets
920
930
 
921
931
  assert (
922
- oc.get_replicaset("namespace", deployment)["metadata"]["name"]
932
+ oc_cli.get_replicaset("namespace", deployment)["metadata"]["name"]
923
933
  == "busybox-current"
924
934
  )
925
935
 
926
936
 
927
- def test_get_replicaset_fail(patch_sleep, mocker, oc: OCNative, deployment):
937
+ def test_get_replicaset_fail(
938
+ patch_sleep,
939
+ mocker,
940
+ oc_cli: OCCli,
941
+ deployment,
942
+ ):
928
943
  oc__get_owned_replicasets = mocker.patch.object(
929
- oc, "get_owned_replicasets", autospec=True
944
+ oc_cli, "get_owned_replicasets", autospec=True
930
945
  )
931
946
  oc__get_owned_replicasets.return_value = []
932
947
 
933
948
  with pytest.raises(ResourceNotFoundError):
934
949
  # pylint: disable-next=expression-not-assigned
935
- oc.get_replicaset("namespace", deployment)["metadata"]["name"]
950
+ oc_cli.get_replicaset("namespace", deployment)["metadata"]["name"]
936
951
  assert oc__get_owned_replicasets.call_count == GET_REPLICASET_MAX_ATTEMPTS
937
952
 
938
953
 
939
- def test_get_replicaset_allow_empty(patch_sleep, mocker, oc: OCNative, deployment):
954
+ def test_get_replicaset_allow_empty(
955
+ patch_sleep,
956
+ mocker,
957
+ oc_cli: OCCli,
958
+ deployment,
959
+ ):
940
960
  oc__get_owned_replicasets = mocker.patch.object(
941
- oc, "get_owned_replicasets", autospec=True
961
+ oc_cli, "get_owned_replicasets", autospec=True
942
962
  )
943
963
  oc__get_owned_replicasets.return_value = []
944
- assert oc.get_replicaset("namespace", deployment, allow_empty=True) == {}
964
+ assert oc_cli.get_replicaset("namespace", deployment, allow_empty=True) == {}
945
965
 
946
966
 
947
967
  @pytest.fixture
@@ -959,11 +979,11 @@ def api_resources():
959
979
 
960
980
 
961
981
  @pytest.fixture
962
- def oc_api_resources(monkeypatch, mocker, api_resources):
982
+ def oc_api_resources(monkeypatch, mocker, api_resources) -> OCCli:
963
983
  monkeypatch.setenv("USE_NATIVE_CLIENT", "False")
964
984
  get_api_resources = mocker.patch.object(OCCli, "get_api_resources", autospec=True)
965
985
  get_api_resources.return_value = api_resources
966
- return OC("cluster", "server", "token", local=True, init_api_resources=True)
986
+ return OC("cluster", "server", "token", local=True, init_api_resources=True) # type: ignore[return-value]
967
987
 
968
988
 
969
989
  def test_is_kind_namespaced(oc_api_resources):
@@ -980,3 +1000,71 @@ def test_is_kind_not_namespaced(oc_api_resources):
980
1000
 
981
1001
  def test_is_kind_not_namespaced_full_name(oc_api_resources):
982
1002
  assert not oc_api_resources.is_kind_namespaced("kind2.group2")
1003
+
1004
+
1005
+ @pytest.fixture
1006
+ def oc_native(
1007
+ monkeypatch,
1008
+ mocker,
1009
+ api_resources: dict,
1010
+ ) -> OCNative:
1011
+ monkeypatch.setenv("USE_NATIVE_CLIENT", "True")
1012
+ get_api_resources = mocker.patch.object(OCCli, "get_api_resources", autospec=True)
1013
+ get_api_resources.return_value = api_resources
1014
+ mocker.patch.object(OCNative, "_get_client", autospec=True)
1015
+ return OC("cluster", "server", "token", local=True) # type: ignore[return-value]
1016
+
1017
+
1018
+ def test_oc_native_get(oc_native: OCNative) -> None:
1019
+ oc_native.get("namespace", "kind1", "name")
1020
+
1021
+ oc_native.client.resources.get.assert_called_once_with(
1022
+ api_version="group1/v1",
1023
+ kind="kind1",
1024
+ )
1025
+ oc_native.client.resources.get.return_value.get.assert_called_once_with(
1026
+ namespace="namespace",
1027
+ name="name",
1028
+ _request_timeout=60,
1029
+ )
1030
+
1031
+
1032
+ def test_oc_native_get_items(oc_native: OCNative) -> None:
1033
+ oc_native.get_items("kind1", labels={"label1": "value1"})
1034
+
1035
+ oc_native.client.resources.get.assert_called_once_with(
1036
+ api_version="group1/v1",
1037
+ kind="kind1",
1038
+ )
1039
+ oc_native.client.resources.get.return_value.get.assert_called_once_with(
1040
+ namespace="",
1041
+ label_selector="label1=value1",
1042
+ _request_timeout=60,
1043
+ )
1044
+
1045
+
1046
+ def test_oc_native_get_items_with_resource_names(oc_native: OCNative) -> None:
1047
+ oc_native.get_items("kind1", labels={"label1": "value1"}, resource_names=["name"])
1048
+
1049
+ oc_native.client.resources.get.assert_called_once_with(
1050
+ api_version="group1/v1",
1051
+ kind="kind1",
1052
+ )
1053
+ oc_native.client.resources.get.return_value.get.assert_called_once_with(
1054
+ namespace="",
1055
+ name="name",
1056
+ label_selector="label1=value1",
1057
+ _request_timeout=60,
1058
+ )
1059
+
1060
+
1061
+ def test_oc_native_get_all(oc_native: OCNative) -> None:
1062
+ oc_native.get_all("kind1")
1063
+
1064
+ oc_native.client.resources.get.assert_called_once_with(
1065
+ api_version="group1/v1",
1066
+ kind="kind1",
1067
+ )
1068
+ oc_native.client.resources.get.return_value.get.assert_called_once_with(
1069
+ _request_timeout=60,
1070
+ )
reconcile/utils/oc.py CHANGED
@@ -1194,6 +1194,9 @@ class OCCli: # pylint: disable=too-many-public-methods
1194
1194
  return kind_resources[0].namespaced
1195
1195
 
1196
1196
 
1197
+ REQUEST_TIMEOUT = 60
1198
+
1199
+
1197
1200
  class OCNative(OCCli):
1198
1201
  def __init__(
1199
1202
  self,
@@ -1322,7 +1325,10 @@ class OCNative(OCCli):
1322
1325
  for resource_name in resource_names:
1323
1326
  try:
1324
1327
  item = obj_client.get(
1325
- name=resource_name, namespace=namespace, label_selector=labels
1328
+ name=resource_name,
1329
+ namespace=namespace,
1330
+ label_selector=labels,
1331
+ _request_timeout=REQUEST_TIMEOUT,
1326
1332
  )
1327
1333
  if item:
1328
1334
  items.append(item.to_dict())
@@ -1331,7 +1337,9 @@ class OCNative(OCCli):
1331
1337
  items_list = {"items": items}
1332
1338
  else:
1333
1339
  items_list = obj_client.get(
1334
- namespace=namespace, label_selector=labels
1340
+ namespace=namespace,
1341
+ label_selector=labels,
1342
+ _request_timeout=REQUEST_TIMEOUT,
1335
1343
  ).to_dict()
1336
1344
 
1337
1345
  items = items_list.get("items")
@@ -1345,7 +1353,11 @@ class OCNative(OCCli):
1345
1353
  k, group_version = self._parse_kind(kind)
1346
1354
  obj_client = self._get_obj_client(group_version=group_version, kind=k)
1347
1355
  try:
1348
- obj = obj_client.get(name=name, namespace=namespace)
1356
+ obj = obj_client.get(
1357
+ name=name,
1358
+ namespace=namespace,
1359
+ _request_timeout=REQUEST_TIMEOUT,
1360
+ )
1349
1361
  return obj.to_dict()
1350
1362
  except NotFoundError as e:
1351
1363
  if allow_not_found:
@@ -1356,7 +1368,7 @@ class OCNative(OCCli):
1356
1368
  k, group_version = self._parse_kind(kind)
1357
1369
  obj_client = self._get_obj_client(group_version=group_version, kind=k)
1358
1370
  try:
1359
- return obj_client.get().to_dict()
1371
+ return obj_client.get(_request_timeout=REQUEST_TIMEOUT).to_dict()
1360
1372
  except NotFoundError as e:
1361
1373
  raise StatusCodeError(f"[{self.server}]: {e}")
1362
1374