33
44import mock
55import yaml
6- from kubernetes .client import V1PodList , V1Pod , V1PodStatus , V1PodCondition
6+ from kubernetes .client import V1PodCondition
77
88from ads .opctl .backend .marketplace .local_marketplace import LocalMarketplaceOperatorBackend
99from ads .opctl .backend .marketplace .models .marketplace_type import HelmMarketplaceListingDetails
@@ -28,34 +28,6 @@ def test_helm_values_to_yaml(file_writer: Mock):
2828 file_writer .return_value .__enter__ ().write .assert_called_once_with (yaml .dump (sample_helm_value ))
2929
3030
31- @patch ('ads.opctl.backend.marketplace.local_marketplace.time' )
32- @patch ('ads.opctl.backend.marketplace.local_marketplace.client.CoreV1Api' )
33- @patch ('ads.opctl.backend.marketplace.local_marketplace.config.load_kube_config' )
34- def test_wait_for_pod_healthy (kube_config : Mock , kube_client : Mock , timer : Mock ):
35- local_marketplace_operator = LocalMarketplaceOperatorBackend (config = {'execution' : {}})
36- timer .time = Mock (side_effect = [0.0 , 11 * 60 ])
37- kube_client .return_value .list_namespaced_pod .return_value .items .__getitem__ .return_value .status .conditions .__iter__ = Mock (
38- return_value = iter ([V1PodCondition (type = "Ready" , status = "True" )]))
39-
40- assert local_marketplace_operator ._wait_for_pod_ready ('namespace' , 'pod_name' ) == 0
41- kube_client .return_value .list_namespaced_pod .assert_called_once_with (namespace = 'namespace' ,
42- label_selector = 'app.kubernetes.io/instance=pod_name' )
43- kube_config .assert_called ()
44-
45-
46- @patch ('ads.opctl.backend.marketplace.local_marketplace.time' )
47- @patch ('ads.opctl.backend.marketplace.local_marketplace.client.CoreV1Api' )
48- @patch ('ads.opctl.backend.marketplace.local_marketplace.config.load_kube_config' )
49- def test_wait_for_pod_unhealthy (kube_config : Mock , kube_client : Mock , timer : Mock ):
50- local_marketplace_operator = LocalMarketplaceOperatorBackend (config = {'execution' : {}})
51- timer .time = Mock (return_value = 0.0 )
52- kube_client .return_value .list_namespaced_pod .return_value .items .__getitem__ .return_value .status .conditions .__iter__ = Mock (
53- return_value = iter ([V1PodCondition (type = "Ready" , status = "False" )]))
54-
55- assert local_marketplace_operator ._wait_for_pod_ready ('namespace' , 'pod_name' ) == - 1
56- kube_client .return_value .list_namespaced_pod .assert_called ()
57- kube_config .assert_called ()
58-
5931
6032@patch ('ads.opctl.backend.marketplace.local_marketplace.export_helm_chart' )
6133@patch ('ads.opctl.backend.marketplace.local_marketplace.list_container_images' )
@@ -73,19 +45,19 @@ def test_export_helm_chart_to_container_registry(list_api: Mock, export_api: Moc
7345 assert result [pattern ] == f"{ pattern } -1"
7446
7547
48+ @patch ('ads.opctl.backend.marketplace.local_marketplace.wait_for_pod_ready' )
7649@patch ('ads.opctl.backend.marketplace.local_marketplace.check_helm_login' )
7750@patch ('ads.opctl.backend.marketplace.local_marketplace.check_prerequisites' )
7851@patch ('ads.opctl.backend.marketplace.local_marketplace.run_helm_install' )
7952@patch ('ads.opctl.backend.marketplace.local_marketplace.MarketplaceBackendRunner' )
8053@patch ('ads.opctl.backend.marketplace.local_marketplace.operator_runtime' )
8154def test_run_with_python_success (operator_runtime : Mock , backend_runner : Mock , helm_install_api : Mock ,
82- check_prerequisites : Mock , check_helm_login : Mock
55+ check_prerequisites : Mock , check_helm_login : Mock , wait_for_pod_api : Mock
8356 ):
8457 local_marketplace_operator = LocalMarketplaceOperatorBackend (config = {'execution' : {}}, operator_info = OperatorInfo ())
8558 local_marketplace_operator ._export_helm_chart_to_container_registry_ = Mock ()
8659 local_marketplace_operator ._save_helm_values_to_yaml_ = Mock ()
87- local_marketplace_operator .run_bugfix_command = Mock ()
88- local_marketplace_operator ._wait_for_pod_ready = Mock (return_value = 0 )
60+ wait_for_pod_api .return_value = 0
8961 mock_helm_detail = Mock (spec = HelmMarketplaceListingDetails )
9062 mock_helm_detail .helm_values = {}
9163 mock_helm_detail .helm_app_name = 'helm_app_name'
0 commit comments